mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-15 01:57:50 +00:00
I2C device manager (#2282)
* message on dev list change * dc detect * added sht3x sensor. * separete environment data from light * max17055 moved to i2c dev * sht fix, goterror detection fix * fix ext sensor app display for a lot of devices. * added bh1750 driver * autoscan on main view * added devlist mutex * better timing * fix h2 sw8 on poweron by usb
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "rtc_time.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
#include "i2cdevmanager.hpp"
|
||||
|
||||
using namespace portapack;
|
||||
using namespace ui;
|
||||
@@ -29,7 +30,7 @@ using namespace ui;
|
||||
namespace ui::external_app::extsensors {
|
||||
|
||||
void ExtSensorsView::focus() {
|
||||
text_info.focus();
|
||||
console.focus();
|
||||
}
|
||||
|
||||
ExtSensorsView::ExtSensorsView(NavigationView& nav)
|
||||
@@ -39,10 +40,33 @@ ExtSensorsView::ExtSensorsView(NavigationView& nav)
|
||||
&text_gps,
|
||||
&text_orientation,
|
||||
&text_envl1,
|
||||
&text_envl2});
|
||||
&text_envl2,
|
||||
&text_envl3,
|
||||
&console});
|
||||
|
||||
prev_scan_int = i2cdev::I2CDevManager::get_autoscan_interval();
|
||||
refreshi2c();
|
||||
i2cdev::I2CDevManager::set_autoscan_interval(3); // scan each 3 sec for new i2c devices
|
||||
}
|
||||
|
||||
void ExtSensorsView::on_new_dev() {
|
||||
refreshi2c();
|
||||
}
|
||||
|
||||
void ExtSensorsView::refreshi2c() {
|
||||
console.clear(true);
|
||||
console.writeln("Found I2C devices:");
|
||||
auto addrlist = i2cdev::I2CDevManager::get_gev_list_by_addr();
|
||||
for (size_t i = 0; i < addrlist.size(); ++i) {
|
||||
console.write("0x");
|
||||
console.write(to_string_hex(addrlist[i]));
|
||||
console.write(", ");
|
||||
}
|
||||
if (addrlist.size() == 0) console.writeln("No I2C devs found.");
|
||||
}
|
||||
|
||||
ExtSensorsView::~ExtSensorsView() {
|
||||
i2cdev::I2CDevManager::set_autoscan_interval(prev_scan_int);
|
||||
}
|
||||
|
||||
void ExtSensorsView::on_any() {
|
||||
@@ -78,9 +102,14 @@ void ExtSensorsView::on_environment(const EnvironmentDataMessage* msg) {
|
||||
tmp += "C";
|
||||
tmp += "; H: " + to_string_decimal(msg->humidity, 1) + "%"; // humidity
|
||||
text_envl1.set(tmp);
|
||||
tmp = "P: " + to_string_decimal(msg->pressure, 1) + " hPa; L:"; // pressure
|
||||
tmp += to_string_dec_int(msg->light) + " LUX"; // light
|
||||
tmp = "P: " + to_string_decimal(msg->pressure, 1) + " hPa"; // pressure
|
||||
text_envl2.set(tmp);
|
||||
}
|
||||
|
||||
void ExtSensorsView::on_light(const LightDataMessage* msg) {
|
||||
on_any();
|
||||
std::string tmp = "L: " + to_string_dec_int(msg->light) + " LUX";
|
||||
text_envl3.set(tmp);
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::extsensors
|
@@ -53,6 +53,7 @@ class ExtSensorsView : public View {
|
||||
NavigationView& nav_;
|
||||
|
||||
bool has_data = false;
|
||||
uint16_t prev_scan_int = 0;
|
||||
|
||||
Labels labels{
|
||||
{{0 * 8, 3 * 16}, "GPS:", Theme::getInstance()->fg_light->foreground},
|
||||
@@ -64,9 +65,15 @@ class ExtSensorsView : public View {
|
||||
Text text_orientation{{5 * 8, 5 * 16, 24 * 8, 16}, "-"};
|
||||
Text text_envl1{{5 * 8, 7 * 16, 24 * 8, 16}, "-"};
|
||||
Text text_envl2{{1 * 8, 9 * 16, 24 * 8, 16}, "-"};
|
||||
Text text_envl3{{1 * 8, 11 * 16, 24 * 8, 16}, "-"};
|
||||
Console console{
|
||||
{1, 13 * 16, screen_width - 1, screen_height - 13 * 16}};
|
||||
|
||||
void refreshi2c();
|
||||
void on_new_dev();
|
||||
void on_any();
|
||||
|
||||
void on_light(const LightDataMessage* msg);
|
||||
void on_gps(const GPSPosDataMessage* msg);
|
||||
void on_orientation(const OrientationDataMessage* msg);
|
||||
void on_environment(const EnvironmentDataMessage* msg);
|
||||
@@ -90,6 +97,20 @@ class ExtSensorsView : public View {
|
||||
const auto message = static_cast<const EnvironmentDataMessage*>(p);
|
||||
this->on_environment(message);
|
||||
}};
|
||||
|
||||
MessageHandlerRegistration message_handler_light{
|
||||
Message::ID::LightData,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const LightDataMessage*>(p);
|
||||
this->on_light(message);
|
||||
}};
|
||||
|
||||
MessageHandlerRegistration message_handler_dev{
|
||||
Message::ID::I2CDevListChanged,
|
||||
[this](Message* const p) {
|
||||
(void)p; // make compiler happy
|
||||
this->on_new_dev();
|
||||
}};
|
||||
};
|
||||
}; // namespace ui::external_app::extsensors
|
||||
|
||||
|
Reference in New Issue
Block a user