generated from m5stack/M5Template-C-CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
866 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ jobs: | |
unit: | ||
- UnitAmeter | ||
- UnitVmeter | ||
- UnitKMeterISO | ||
|
||
sketch: | ||
- PlotToSerial | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ jobs: | |
unit: | ||
- UnitAmeter | ||
- UnitVmeter | ||
- UnitKmeterISO | ||
|
||
example: | ||
- PlotToSerial | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
examples/UnitUnified/UnitKMeterISO/PlotToSerial/PlotToSerial.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
/* | ||
Example using M5UnitUnified for UnitKmeterISO | ||
*/ | ||
#include "main/PlotToSerial.cpp" |
83 changes: 83 additions & 0 deletions
83
examples/UnitUnified/UnitKMeterISO/PlotToSerial/main/PlotToSerial.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
/* | ||
Example: UnitKmeterISO | ||
*/ | ||
|
||
// #define USING_M5HAL // When using M5HAL | ||
|
||
#include <M5Unified.h> | ||
#include <M5UnitUnified.h> | ||
#include <M5UnitUnifiedMETER.h> | ||
#if !defined(USING_M5HAL) | ||
#include <Wire.h> | ||
#endif | ||
|
||
namespace { | ||
m5::unit::UnitUnified Units; | ||
m5::unit::UnitKmeterISO unit; | ||
auto& lcd = M5.Display; | ||
} // namespace | ||
|
||
void setup() | ||
{ | ||
M5.begin(); | ||
|
||
m5::utility::delay(3000); | ||
|
||
auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda); | ||
auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl); | ||
M5_LOGI("getPin: SDA:%u SCL:%u", pin_num_sda, pin_num_scl); | ||
|
||
#if defined(USING_M5HAL) | ||
#pragma message "Using M5HAL" | ||
// Using M5HAL | ||
m5::hal::bus::I2CBusConfig i2c_cfg; | ||
i2c_cfg.pin_sda = m5::hal::gpio::getPin(pin_num_sda); | ||
i2c_cfg.pin_scl = m5::hal::gpio::getPin(pin_num_scl); | ||
auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg); | ||
M5_LOGI("Bus:%d", i2c_bus.has_value()); | ||
if (!Units.add(unit, i2c_bus ? i2c_bus.value() : nullptr) || !Units.begin()) { | ||
M5_LOGE("Failed to begin"); | ||
lcd.clear(TFT_RED); | ||
while (true) { | ||
m5::utility::delay(10000); | ||
} | ||
} | ||
#else | ||
#pragma message "Using Wire" | ||
// Using TwoWire | ||
Wire.begin(pin_num_sda, pin_num_scl, 100000U); | ||
for (int i = 0; i < 10; ++i) { | ||
Wire.beginTransmission(unit.address()); | ||
auto wret = Wire.endTransmission(); | ||
M5_LOGW(">>%d", wret); | ||
delay(10); | ||
} | ||
|
||
if (!Units.add(unit, Wire) || !Units.begin()) { | ||
M5_LOGE("Failed to begin"); | ||
lcd.clear(TFT_RED); | ||
while (true) { | ||
m5::utility::delay(10000); | ||
} | ||
} | ||
#endif | ||
|
||
M5_LOGI("M5UnitUnified has been begun"); | ||
M5_LOGI("%s", Units.debugInfo().c_str()); | ||
lcd.clear(TFT_DARKGREEN); | ||
} | ||
|
||
void loop() | ||
{ | ||
M5.update(); | ||
Units.update(); | ||
if (unit.updated()) { | ||
M5_LOGI("\n>Temperature:%f", unit.temperature()); | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.