mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-14 02:17:39 +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:
@@ -125,6 +125,9 @@ set(CSRC
|
||||
${CHIBIOS}/os/various/chprintf.c
|
||||
)
|
||||
|
||||
#look for all i2cdev_ files
|
||||
file(GLOB I2CDEV_SOURCES ${COMMON}/i2cdev_*.cpp)
|
||||
|
||||
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
|
||||
# setting.
|
||||
set(CPPSRC
|
||||
@@ -176,8 +179,8 @@ set(CPPSRC
|
||||
${COMMON}/ui_language.cpp
|
||||
${COMMON}/utility.cpp
|
||||
${COMMON}/wm8731.cpp
|
||||
${COMMON}/ads1110.cpp
|
||||
${COMMON}/max17055.cpp
|
||||
${COMMON}/i2cdevmanager.cpp
|
||||
${I2CDEV_SOURCES}
|
||||
${COMMON}/battery.cpp
|
||||
${COMMON}/performance_counter.cpp
|
||||
${COMMON}/bmpfile.cpp
|
||||
@@ -292,7 +295,7 @@ set(CPPSRC
|
||||
apps/ui_btle_rx.cpp
|
||||
# apps/ui_coasterp.cpp
|
||||
apps/ui_debug.cpp
|
||||
apps/ui_debug_battery.cpp
|
||||
apps/ui_debug_max17055.cpp
|
||||
apps/ui_dfu_menu.cpp
|
||||
apps/ui_encoders.cpp
|
||||
apps/ui_fileman.cpp
|
||||
|
@@ -43,87 +43,86 @@ void BattinfoView::on_timer() {
|
||||
}
|
||||
}
|
||||
|
||||
void BattinfoView::update_result() {
|
||||
if (!battery::BatteryManagement::isDetected()) {
|
||||
text_percent.set("UNKNOWN");
|
||||
text_voltage.set("UNKNOWN");
|
||||
text_current.set("-");
|
||||
text_charge.set("-");
|
||||
text_cycles.set("-");
|
||||
text_ttef.set("-");
|
||||
text_method.set("-");
|
||||
text_warn.set("");
|
||||
return;
|
||||
}
|
||||
void BattinfoView::update_results_ads1110(i2cdev::I2cDev_ADS1110* dev) {
|
||||
bool uichg = false;
|
||||
uint8_t valid_mask = 0;
|
||||
battery::BatteryManagement::getBatteryInfo(valid_mask, percent, voltage, current);
|
||||
// update text fields
|
||||
if (percent <= 100 && (valid_mask & battery::BatteryManagement::BATT_VALID_VOLTAGE) == battery::BatteryManagement::BATT_VALID_VOLTAGE)
|
||||
auto voltage = dev->readVoltage();
|
||||
auto percent = battery::BatteryManagement::calc_percent_voltage(voltage);
|
||||
if (percent <= 100)
|
||||
text_percent.set(to_string_dec_uint(percent) + " %");
|
||||
else
|
||||
text_percent.set("UNKNOWN");
|
||||
if (voltage > 1 && (valid_mask & battery::BatteryManagement::BATT_VALID_VOLTAGE) == battery::BatteryManagement::BATT_VALID_VOLTAGE) {
|
||||
if (voltage > 1) {
|
||||
text_voltage.set(to_string_decimal(voltage / 1000.0, 3) + " V");
|
||||
} else {
|
||||
text_voltage.set("UNKNOWN");
|
||||
}
|
||||
if ((valid_mask & battery::BatteryManagement::BATT_VALID_CURRENT) == battery::BatteryManagement::BATT_VALID_CURRENT) {
|
||||
if (labels_opt.hidden()) uichg = true;
|
||||
labels_opt.hidden(false);
|
||||
text_current.hidden(false);
|
||||
text_charge.hidden(false);
|
||||
text_current.set(to_string_dec_int(current) + " mA");
|
||||
text_charge.set(current >= 0 ? "Charging" : "Discharging");
|
||||
labels_opt.hidden(false);
|
||||
|
||||
text_ttef.hidden(false);
|
||||
// ui hide:
|
||||
if (!labels_opt.hidden()) uichg = true;
|
||||
labels_opt.hidden(true);
|
||||
text_current.hidden(true);
|
||||
text_charge.hidden(true);
|
||||
labels_opt.hidden(true);
|
||||
text_ttef.hidden(true);
|
||||
text_cycles.hidden(true);
|
||||
text_warn.set("");
|
||||
text_ttef.hidden(true);
|
||||
text_method.set("Voltage");
|
||||
button_mode.set_text("Voltage");
|
||||
if (uichg) set_dirty();
|
||||
BatteryStateMessage msg{1, percent, false, voltage};
|
||||
EventDispatcher::send_message(msg);
|
||||
}
|
||||
|
||||
void BattinfoView::update_results_max17055(i2cdev::I2cDev_MAX17055* dev) {
|
||||
bool uichg = false;
|
||||
uint8_t valid_mask = 0;
|
||||
dev->getBatteryInfo(valid_mask, percent, voltage, current);
|
||||
// update text fields
|
||||
if (percent <= 100)
|
||||
text_percent.set(to_string_dec_uint(percent) + " %");
|
||||
else
|
||||
text_percent.set("UNKNOWN");
|
||||
if (voltage > 1) {
|
||||
text_voltage.set(to_string_decimal(voltage / 1000.0, 3) + " V");
|
||||
} else {
|
||||
if (!labels_opt.hidden()) uichg = true;
|
||||
labels_opt.hidden(true);
|
||||
text_current.hidden(true);
|
||||
text_charge.hidden(true);
|
||||
text_cycles.hidden(true);
|
||||
text_ttef.hidden(true);
|
||||
text_voltage.set("UNKNOWN");
|
||||
}
|
||||
if (labels_opt.hidden()) uichg = true;
|
||||
labels_opt.hidden(false);
|
||||
text_current.hidden(false);
|
||||
text_charge.hidden(false);
|
||||
text_current.set(to_string_dec_int(current) + " mA");
|
||||
text_charge.set(current >= 0 ? "Charging" : "Discharging");
|
||||
labels_opt.hidden(false);
|
||||
text_ttef.hidden(false);
|
||||
// cycles
|
||||
text_cycles.hidden(false);
|
||||
uint16_t cycles = (uint16_t)dev->getValue("Cycles");
|
||||
if (cycles < 2)
|
||||
text_warn.set("SoC improves after 2 cycles");
|
||||
else
|
||||
text_warn.set("");
|
||||
}
|
||||
if ((valid_mask & battery::BatteryManagement::BATT_VALID_CYCLES) == battery::BatteryManagement::BATT_VALID_CYCLES) {
|
||||
text_cycles.hidden(false);
|
||||
uint16_t cycles = battery::BatteryManagement::get_cycles();
|
||||
if (cycles < 2)
|
||||
text_warn.set("SoC improves after 2 cycles");
|
||||
else
|
||||
text_warn.set("");
|
||||
text_cycles.set(to_string_dec_uint(cycles));
|
||||
text_cycles.set(to_string_dec_uint(cycles));
|
||||
// ttef
|
||||
text_ttef.hidden(false);
|
||||
float ttef = 0;
|
||||
if (current <= 0) {
|
||||
ttef = dev->getValue("TTE");
|
||||
} else {
|
||||
text_cycles.hidden(true);
|
||||
text_warn.set("");
|
||||
ttef = dev->getValue("TTF");
|
||||
}
|
||||
if ((valid_mask & battery::BatteryManagement::BATT_VALID_TTEF) == battery::BatteryManagement::BATT_VALID_TTEF) {
|
||||
text_ttef.hidden(false);
|
||||
float ttef = 0;
|
||||
if (current <= 0) {
|
||||
ttef = battery::BatteryManagement::get_tte();
|
||||
} else {
|
||||
ttef = battery::BatteryManagement::get_ttf();
|
||||
}
|
||||
|
||||
// Convert ttef to hours and minutes
|
||||
uint8_t hours = static_cast<uint8_t>(ttef);
|
||||
uint8_t minutes = static_cast<uint8_t>((ttef - hours) * 60 + 0.5); // +0.5 for rounding
|
||||
|
||||
// Create the formatted string
|
||||
std::string formatted_time;
|
||||
if (hours > 0) {
|
||||
formatted_time += to_string_dec_uint(hours) + "h ";
|
||||
}
|
||||
formatted_time += to_string_dec_uint(minutes) + "m";
|
||||
|
||||
text_ttef.set(formatted_time);
|
||||
} else {
|
||||
text_ttef.hidden(true);
|
||||
// Convert ttef to hours and minutes
|
||||
uint8_t hours = static_cast<uint8_t>(ttef);
|
||||
uint8_t minutes = static_cast<uint8_t>((ttef - hours) * 60 + 0.5); // +0.5 for rounding
|
||||
// Create the formatted string
|
||||
std::string formatted_time;
|
||||
if (hours > 0) {
|
||||
formatted_time += to_string_dec_uint(hours) + "h ";
|
||||
}
|
||||
if ((valid_mask & battery::BatteryManagement::BATT_VALID_PERCENT) == battery::BatteryManagement::BATT_VALID_PERCENT) {
|
||||
formatted_time += to_string_dec_uint(minutes) + "m";
|
||||
text_ttef.set(formatted_time);
|
||||
if (!battery::BatteryManagement::calcOverride) {
|
||||
text_method.set("IC");
|
||||
button_mode.set_text("Volt");
|
||||
} else {
|
||||
@@ -136,6 +135,30 @@ void BattinfoView::update_result() {
|
||||
EventDispatcher::send_message(msg);
|
||||
}
|
||||
|
||||
void BattinfoView::update_result() {
|
||||
auto dev = i2cdev::I2CDevManager::get_dev_by_model(I2CDEVMDL_MAX17055);
|
||||
if (dev) {
|
||||
update_results_max17055((i2cdev::I2cDev_MAX17055*)dev);
|
||||
return;
|
||||
}
|
||||
|
||||
dev = i2cdev::I2CDevManager::get_dev_by_model(I2CDEVMDL_ADS1110);
|
||||
if (dev) {
|
||||
update_results_ads1110((i2cdev::I2cDev_ADS1110*)dev);
|
||||
return;
|
||||
}
|
||||
|
||||
// no dev found
|
||||
text_percent.set("UNKNOWN");
|
||||
text_voltage.set("UNKNOWN");
|
||||
text_current.set("-");
|
||||
text_charge.set("-");
|
||||
text_cycles.set("-");
|
||||
text_ttef.set("-");
|
||||
text_method.set("-");
|
||||
text_warn.set("");
|
||||
}
|
||||
|
||||
BattinfoView::BattinfoView(NavigationView& nav)
|
||||
: nav_{nav} {
|
||||
add_children({&labels,
|
||||
|
@@ -27,6 +27,9 @@
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "string_format.hpp"
|
||||
#include "i2cdevmanager.hpp"
|
||||
#include "i2cdev_max17055.hpp"
|
||||
#include "i2cdev_ads1110.hpp"
|
||||
|
||||
namespace ui {
|
||||
class BattinfoView : public View {
|
||||
@@ -43,6 +46,8 @@ class BattinfoView : public View {
|
||||
|
||||
private:
|
||||
void update_result();
|
||||
void update_results_max17055(i2cdev::I2cDev_MAX17055* dev);
|
||||
void update_results_ads1110(i2cdev::I2cDev_ADS1110* dev);
|
||||
void on_timer();
|
||||
NavigationView& nav_;
|
||||
uint16_t timer_period = 60;
|
||||
|
@@ -36,7 +36,7 @@
|
||||
#include "ui_font_fixed_8x16.hpp"
|
||||
#include "ui_painter.hpp"
|
||||
#include "ui_external_items_menu_loader.hpp"
|
||||
#include "ui_debug_battery.hpp"
|
||||
#include "ui_debug_max17055.hpp"
|
||||
|
||||
#include "portapack.hpp"
|
||||
#include "portapack_persistent_memory.hpp"
|
||||
@@ -226,8 +226,10 @@ uint32_t RegistersWidget::reg_read(const uint32_t register_number) {
|
||||
return radio::debug::second_if::register_read(register_number);
|
||||
case CT_SI5351:
|
||||
return portapack::clock_generator.read_register(register_number);
|
||||
case CT_BATTERY:
|
||||
return battery::BatteryManagement::read_register(register_number);
|
||||
case CT_MAX17055: {
|
||||
i2cdev::I2cDev_MAX17055* dev = (i2cdev::I2cDev_MAX17055*)i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDEVMDL_MAX17055);
|
||||
return dev->read_register(register_number);
|
||||
}
|
||||
case CT_AUDIO:
|
||||
return audio::debug::reg_read(register_number);
|
||||
}
|
||||
@@ -249,9 +251,11 @@ void RegistersWidget::reg_write(const uint32_t register_number, const uint32_t v
|
||||
case CT_SI5351:
|
||||
portapack::clock_generator.write_register(register_number, value);
|
||||
break;
|
||||
case CT_BATTERY:
|
||||
battery::BatteryManagement::write_register(register_number, value);
|
||||
case CT_MAX17055: {
|
||||
i2cdev::I2cDev_MAX17055* dev = (i2cdev::I2cDev_MAX17055*)i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDEVMDL_MAX17055);
|
||||
dev->write_register(register_number, value);
|
||||
break;
|
||||
}
|
||||
case CT_AUDIO:
|
||||
audio::debug::reg_write(register_number, value);
|
||||
break;
|
||||
@@ -465,9 +469,9 @@ void DebugPeripheralsMenuView::on_populate() {
|
||||
{si5351x, Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_peripherals_details, [this, si5351x]() { nav_.push<RegistersView>(si5351x, RegistersWidgetConfig{CT_SI5351, 188, 96, 8}); }},
|
||||
{audio::debug::codec_name(), Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_peripherals_details, [this]() { nav_.push<RegistersView>(audio::debug::codec_name(), RegistersWidgetConfig{CT_AUDIO, audio::debug::reg_count(), audio::debug::reg_count(), audio::debug::reg_bits()}); }},
|
||||
});
|
||||
if (battery::BatteryManagement::detectedModule() == battery::BatteryManagement::BatteryModules::BATT_MAX17055) {
|
||||
if (i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDEVMDL_MAX17055)) {
|
||||
add_item(
|
||||
{"MAX17055", Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_peripherals_details, [this]() { nav_.push<RegistersView>("MAX17055", RegistersWidgetConfig{CT_BATTERY, 256, 16, 16}); }});
|
||||
{"MAX17055", Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_peripherals_details, [this]() { nav_.push<RegistersView>("MAX17055", RegistersWidgetConfig{CT_MAX17055, 256, 16, 16}); }});
|
||||
}
|
||||
set_max_rows(2); // allow wider buttons
|
||||
}
|
||||
@@ -512,7 +516,7 @@ void DebugMenuView::on_populate() {
|
||||
{"Reboot", ui::Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_setup, [this]() { nav_.push<DebugReboot>(); }},
|
||||
});
|
||||
|
||||
if (battery::BatteryManagement::detectedModule() == battery::BatteryManagement::BatteryModules::BATT_MAX17055) {
|
||||
if (i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDEVMDL_MAX17055)) {
|
||||
add_item(
|
||||
{"Battery", ui::Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_batt_icon, [this]() { nav_.push<BatteryCapacityView>(); }});
|
||||
}
|
||||
|
@@ -139,7 +139,7 @@ typedef enum {
|
||||
CT_MAX283X,
|
||||
CT_SI5351,
|
||||
CT_AUDIO,
|
||||
CT_BATTERY,
|
||||
CT_MAX17055,
|
||||
} chip_type_t;
|
||||
|
||||
struct RegistersWidgetConfig {
|
||||
|
@@ -1,11 +1,11 @@
|
||||
#include "ui_debug_battery.hpp"
|
||||
#include "ui_debug_max17055.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
BatteryCapacityView::RegisterEntry BatteryCapacityView::get_entry(size_t index) {
|
||||
if (index < battery::max17055::MAX17055::entries_count) {
|
||||
return battery::max17055::MAX17055::entries[index];
|
||||
if (index < i2cdev::I2cDev_MAX17055::entries_count) {
|
||||
return i2cdev::I2cDev_MAX17055::entries[index];
|
||||
}
|
||||
return {"", 0, "", 0, false, "", false, 0, false, false, false, 0, false};
|
||||
}
|
||||
@@ -27,6 +27,12 @@ BatteryCapacityView::BatteryCapacityView(NavigationView& nav) {
|
||||
|
||||
button_done.on_select = [&nav](Button&) { nav.pop(); };
|
||||
|
||||
auto dev = (i2cdev::I2cDev_MAX17055*)i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDEVMDL_MAX17055);
|
||||
if (!dev) { // dev not found
|
||||
nav.pop();
|
||||
return;
|
||||
}
|
||||
|
||||
populate_page(0);
|
||||
update_page_text();
|
||||
}
|
||||
@@ -37,7 +43,7 @@ void BatteryCapacityView::focus() {
|
||||
|
||||
bool BatteryCapacityView::on_encoder(const EncoderEvent delta) {
|
||||
int32_t new_page = current_page + delta;
|
||||
if (new_page >= 0 && new_page < ((int32_t)battery::max17055::MAX17055::entries_count + ENTRIES_PER_PAGE - 1) / ENTRIES_PER_PAGE) {
|
||||
if (new_page >= 0 && new_page < ((int32_t)i2cdev::I2cDev_MAX17055::entries_count + ENTRIES_PER_PAGE - 1) / ENTRIES_PER_PAGE) {
|
||||
current_page = new_page;
|
||||
populate_page(current_page * ENTRIES_PER_PAGE);
|
||||
update_page_text();
|
||||
@@ -46,11 +52,12 @@ bool BatteryCapacityView::on_encoder(const EncoderEvent delta) {
|
||||
}
|
||||
|
||||
void BatteryCapacityView::update_values() {
|
||||
i2cdev::I2cDev_MAX17055* dev = (i2cdev::I2cDev_MAX17055*)i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDEVMDL_MAX17055);
|
||||
for (size_t i = 0; i < ENTRIES_PER_PAGE; ++i) {
|
||||
size_t entry_index = current_page * ENTRIES_PER_PAGE + i;
|
||||
if (entry_index < battery::max17055::MAX17055::entries_count) {
|
||||
if (entry_index < i2cdev::I2cDev_MAX17055::entries_count) {
|
||||
const auto entry = get_entry(entry_index);
|
||||
uint16_t raw_value = battery::BatteryManagement::read_register(entry.address);
|
||||
uint16_t raw_value = dev->read_register(entry.address);
|
||||
|
||||
hex_texts[i].set("0x" + to_string_hex(raw_value, 4));
|
||||
|
||||
@@ -78,7 +85,7 @@ void BatteryCapacityView::update_values() {
|
||||
void BatteryCapacityView::populate_page(int start_index) {
|
||||
for (size_t i = 0; i < ENTRIES_PER_PAGE; ++i) {
|
||||
size_t entry_index = start_index + i;
|
||||
if (entry_index < battery::max17055::MAX17055::entries_count) {
|
||||
if (entry_index < i2cdev::I2cDev_MAX17055::entries_count) {
|
||||
const auto entry = get_entry(entry_index);
|
||||
name_texts[i].set(entry.name);
|
||||
addr_texts[i].set("0x" + to_string_hex(entry.address, 2));
|
||||
@@ -97,7 +104,7 @@ void BatteryCapacityView::populate_page(int start_index) {
|
||||
}
|
||||
|
||||
void BatteryCapacityView::update_page_text() {
|
||||
int total_pages = (battery::max17055::MAX17055::entries_count + ENTRIES_PER_PAGE - 1) / ENTRIES_PER_PAGE;
|
||||
int total_pages = (i2cdev::I2cDev_MAX17055::entries_count + ENTRIES_PER_PAGE - 1) / ENTRIES_PER_PAGE;
|
||||
page_text.set("Page " + to_string_dec_uint(current_page + 1) + "/" + to_string_dec_uint(total_pages));
|
||||
}
|
||||
|
@@ -5,7 +5,8 @@
|
||||
#include "ui_widget.hpp"
|
||||
#include "ui_navigation.hpp"
|
||||
#include "battery.hpp"
|
||||
#include "max17055.hpp"
|
||||
#include "i2cdevmanager.hpp"
|
||||
#include "i2cdev_max17055.hpp"
|
||||
|
||||
namespace ui {
|
||||
|
||||
@@ -13,11 +14,11 @@ class BatteryCapacityView : public View {
|
||||
public:
|
||||
BatteryCapacityView(NavigationView& nav);
|
||||
void focus() override;
|
||||
std::string title() const override { return "Battery Registers"; }
|
||||
std::string title() const override { return "MAX17055 Registers"; }
|
||||
|
||||
bool on_encoder(const EncoderEvent delta) override;
|
||||
|
||||
using RegisterEntry = battery::max17055::RegisterEntry;
|
||||
using RegisterEntry = i2cdev::I2cDev_MAX17055::RegisterEntry;
|
||||
|
||||
private:
|
||||
static RegisterEntry get_entry(size_t index);
|
@@ -41,11 +41,6 @@ DfuMenu::DfuMenu(NavigationView& nav)
|
||||
&text_info_line_8,
|
||||
&text_info_line_9,
|
||||
&text_info_line_10});
|
||||
|
||||
if (battery::BatteryManagement::isDetected()) {
|
||||
add_child(&voltage_label);
|
||||
add_child(&text_info_line_11);
|
||||
}
|
||||
}
|
||||
|
||||
void DfuMenu::paint(Painter& painter) {
|
||||
@@ -53,7 +48,7 @@ void DfuMenu::paint(Painter& painter) {
|
||||
size_t m0_fragmented_free_space = 0;
|
||||
const auto m0_fragments = chHeapStatus(NULL, &m0_fragmented_free_space);
|
||||
|
||||
auto lines = (battery::BatteryManagement::isDetected() ? 11 : 10) + 2;
|
||||
auto lines = 10 + 2;
|
||||
|
||||
text_info_line_1.set(to_string_dec_uint(chCoreStatus(), 6));
|
||||
text_info_line_2.set(to_string_dec_uint(m0_fragmented_free_space, 6));
|
||||
@@ -65,9 +60,6 @@ void DfuMenu::paint(Painter& painter) {
|
||||
text_info_line_8.set(to_string_dec_uint(shared_memory.m4_performance_counter, 6));
|
||||
text_info_line_9.set(to_string_dec_uint(shared_memory.m4_buffer_missed, 6));
|
||||
text_info_line_10.set(to_string_dec_uint(chTimeNow() / 1000, 6));
|
||||
if (battery::BatteryManagement::isDetected()) {
|
||||
text_info_line_11.set(to_string_decimal_padding((float)battery::BatteryManagement::getVoltage() / 1000.0, 3, 6));
|
||||
}
|
||||
|
||||
constexpr auto margin = 5;
|
||||
|
||||
|
@@ -60,8 +60,6 @@ class DfuMenu : public View {
|
||||
{{6 * CHARACTER_WIDTH, 13 * LINE_HEIGHT}, "M4 miss:", Theme::getInstance()->fg_darkcyan->foreground},
|
||||
{{6 * CHARACTER_WIDTH, 14 * LINE_HEIGHT}, "Uptime:", Theme::getInstance()->fg_darkcyan->foreground}};
|
||||
|
||||
Labels voltage_label{{{6 * CHARACTER_WIDTH, 15 * LINE_HEIGHT}, "Voltage:", Theme::getInstance()->fg_darkcyan->foreground}};
|
||||
|
||||
Text text_info_line_1{{15 * CHARACTER_WIDTH, 5 * LINE_HEIGHT, 6 * CHARACTER_WIDTH, 1 * LINE_HEIGHT}, ""};
|
||||
Text text_info_line_2{{15 * CHARACTER_WIDTH, 6 * LINE_HEIGHT, 6 * CHARACTER_WIDTH, 1 * LINE_HEIGHT}, ""};
|
||||
Text text_info_line_3{{15 * CHARACTER_WIDTH, 7 * LINE_HEIGHT, 6 * CHARACTER_WIDTH, 1 * LINE_HEIGHT}, ""};
|
||||
@@ -72,7 +70,6 @@ class DfuMenu : public View {
|
||||
Text text_info_line_8{{15 * CHARACTER_WIDTH, 12 * LINE_HEIGHT, 6 * CHARACTER_WIDTH, 1 * LINE_HEIGHT}, ""};
|
||||
Text text_info_line_9{{15 * CHARACTER_WIDTH, 13 * LINE_HEIGHT, 6 * CHARACTER_WIDTH, 1 * LINE_HEIGHT}, ""};
|
||||
Text text_info_line_10{{15 * CHARACTER_WIDTH, 14 * LINE_HEIGHT, 6 * CHARACTER_WIDTH, 1 * LINE_HEIGHT}, ""};
|
||||
Text text_info_line_11{{15 * CHARACTER_WIDTH, 15 * LINE_HEIGHT, 6 * CHARACTER_WIDTH, 1 * LINE_HEIGHT}, ""};
|
||||
};
|
||||
|
||||
class DfuMenu2 : public View {
|
||||
|
@@ -50,6 +50,8 @@ namespace fs = std::filesystem;
|
||||
#include "ui_font_fixed_8x16.hpp"
|
||||
#include "cpld_update.hpp"
|
||||
#include "config_mode.hpp"
|
||||
#include "i2cdevmanager.hpp"
|
||||
#include "i2cdev_max17055.hpp"
|
||||
|
||||
extern ui::SystemView* system_view_ptr;
|
||||
|
||||
@@ -977,7 +979,7 @@ SetBatteryView::SetBatteryView(NavigationView& nav) {
|
||||
&button_cancel,
|
||||
&checkbox_overridebatt});
|
||||
|
||||
if (battery::BatteryManagement::detectedModule() == battery::BatteryManagement::BATT_MAX17055) add_children({&button_reset, &labels2});
|
||||
if (i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDEVMDL_MAX17055)) add_children({&button_reset, &labels2});
|
||||
|
||||
button_save.on_select = [&nav, this](Button&) {
|
||||
pmem::set_ui_override_batt_calc(checkbox_overridebatt.value());
|
||||
@@ -987,7 +989,8 @@ SetBatteryView::SetBatteryView(NavigationView& nav) {
|
||||
};
|
||||
|
||||
button_reset.on_select = [&nav, this](Button&) {
|
||||
if (battery::BatteryManagement::reset_learned())
|
||||
auto dev = (i2cdev::I2cDev_MAX17055*)i2cdev::I2CDevManager::get_dev_by_model(I2C_DEVMDL::I2CDEVMDL_MAX17055);
|
||||
if (dev->reset_learned())
|
||||
nav.display_modal("Reset", "Battery parameters reset");
|
||||
else
|
||||
nav.display_modal("Error", "Error parameter reset");
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -53,6 +53,8 @@ using asahi_kasei::ak4951::AK4951;
|
||||
#include "string_format.hpp"
|
||||
#include "bitmap.hpp"
|
||||
#include "ui_widget.hpp"
|
||||
#include "i2cdevmanager.hpp"
|
||||
#include "battery.hpp"
|
||||
|
||||
namespace portapack {
|
||||
|
||||
@@ -588,7 +590,8 @@ init_status_t init() {
|
||||
chThdSleepMilliseconds(10);
|
||||
|
||||
audio::init(portapack_audio_codec());
|
||||
battery::BatteryManagement::init(persistent_memory::ui_override_batt_calc());
|
||||
battery::BatteryManagement::set_calc_override(persistent_memory::ui_override_batt_calc());
|
||||
i2cdev::I2CDevManager::init();
|
||||
|
||||
if (lcd_fast_setup)
|
||||
draw_splash_screen_icon(4, ui::bitmap_icon_speaker);
|
||||
|
@@ -33,13 +33,9 @@
|
||||
#include "backlight.hpp"
|
||||
#include "usb_serial.hpp"
|
||||
|
||||
#include "ads1110.hpp"
|
||||
#include "max17055.hpp"
|
||||
|
||||
#include "radio.hpp"
|
||||
#include "clock_manager.hpp"
|
||||
#include "temperature_logger.hpp"
|
||||
#include "battery.hpp"
|
||||
#include "theme.hpp"
|
||||
|
||||
/* TODO: This would be better as a class to add
|
||||
|
@@ -388,7 +388,6 @@ void SystemStatusView::on_battery_data(const BatteryStateMessage* msg) {
|
||||
if (!batt_was_inited) {
|
||||
batt_was_inited = true;
|
||||
refresh();
|
||||
return;
|
||||
}
|
||||
if (!pmem::ui_hide_numeric_battery()) {
|
||||
battery_text.set_battery(msg->valid_mask, msg->percent, msg->on_charger);
|
||||
@@ -416,14 +415,11 @@ void SystemStatusView::refresh() {
|
||||
if (!pmem::ui_hide_fake_brightness() && !pmem::config_lcd_inverted_mode()) status_icons.add(&button_fake_brightness);
|
||||
if (battery::BatteryManagement::isDetected()) {
|
||||
batt_was_inited = true;
|
||||
uint8_t percent = battery::BatteryManagement::getPercent();
|
||||
if (!pmem::ui_hide_battery_icon()) {
|
||||
status_icons.add(&battery_icon);
|
||||
battery_text.set_battery(percent <= 100 ? 1 : 0, percent, false); // got an on select, that may pop up the details of the battery.
|
||||
};
|
||||
if (!pmem::ui_hide_numeric_battery()) {
|
||||
status_icons.add(&battery_text);
|
||||
battery_text.set_battery(percent <= 100 ? 1 : 0, percent, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -658,12 +654,10 @@ bool NavigationView::is_valid() const {
|
||||
|
||||
View* NavigationView::push_view(std::unique_ptr<View> new_view) {
|
||||
free_view();
|
||||
|
||||
const auto p = new_view.get();
|
||||
view_stack.emplace_back(ViewState{std::move(new_view), {}});
|
||||
|
||||
update_view();
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@@ -791,7 +785,9 @@ static void add_apps(NavigationView& nav, BtnGridView& grid, app_location_t loc)
|
||||
for (auto& app : NavigationView::appList) {
|
||||
if (app.menuLocation == loc) {
|
||||
grid.add_item({app.displayName, app.iconColor, app.icon,
|
||||
[&nav, &app]() { nav.push_view(std::unique_ptr<View>(app.viewFactory->produce(nav))); }});
|
||||
[&nav, &app]() {
|
||||
i2cdev::I2CDevManager::set_autoscan_interval(0); //if i navigate away from any menu, turn off autoscan
|
||||
nav.push_view(std::unique_ptr<View>(app.viewFactory->produce(nav))); }});
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -888,7 +884,6 @@ SystemMenuView::SystemMenuView(NavigationView& nav)
|
||||
|
||||
void SystemMenuView::on_populate() {
|
||||
add_apps(nav_, *this, HOME);
|
||||
|
||||
add_item({"HackRF", Theme::getInstance()->fg_cyan->foreground, &bitmap_icon_hackrf, [this]() { hackrf_mode(nav_); }});
|
||||
}
|
||||
|
||||
@@ -928,6 +923,7 @@ SystemView::SystemView(
|
||||
} else {
|
||||
add_child(&info_view);
|
||||
info_view.refresh();
|
||||
i2cdev::I2CDevManager::set_autoscan_interval(3); // turn on autoscan in sysmainv
|
||||
}
|
||||
|
||||
this->status_view.set_back_enabled(!this->navigation_view.is_top());
|
||||
|
@@ -939,7 +939,7 @@ static void cmd_gotorientation(BaseSequentialStream* chp, int argc, char* argv[]
|
||||
}
|
||||
|
||||
static void cmd_gotenv(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
const char* usage = "usage: gotenv <temperature> [humidity] [pressure] [light]\r\n";
|
||||
const char* usage = "usage: gotenv <temperature> [humidity] [pressure] [light]\r\n"; // keeping light here too for compatibility
|
||||
if (argc < 1 || argc > 4) {
|
||||
chprintf(chp, usage);
|
||||
return;
|
||||
@@ -950,8 +950,25 @@ static void cmd_gotenv(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
uint16_t light = 0;
|
||||
if (argc > 1) humi = atof(argv[1]);
|
||||
if (argc > 2) pressure = atof(argv[2]);
|
||||
if (argc > 3) light = strtol(argv[3], NULL, 10);
|
||||
EnvironmentDataMessage msg{temp, humi, pressure, light};
|
||||
if (argc > 3) light = strtol(argv[0], NULL, 10);
|
||||
EnvironmentDataMessage msg{temp, humi, pressure};
|
||||
EventDispatcher::send_message(msg);
|
||||
// compatibility:
|
||||
if (argc > 3) {
|
||||
LightDataMessage msg{light};
|
||||
EventDispatcher::send_message(msg);
|
||||
}
|
||||
chprintf(chp, "ok\r\n");
|
||||
}
|
||||
|
||||
static void cmd_gotlight(BaseSequentialStream* chp, int argc, char* argv[]) {
|
||||
const char* usage = "usage: gotlight <light_lux>\r\n";
|
||||
if (argc != 1) {
|
||||
chprintf(chp, usage);
|
||||
return;
|
||||
}
|
||||
uint16_t light = strtol(argv[0], NULL, 10);
|
||||
LightDataMessage msg{light};
|
||||
EventDispatcher::send_message(msg);
|
||||
chprintf(chp, "ok\r\n");
|
||||
}
|
||||
@@ -1191,6 +1208,7 @@ static const ShellCommand commands[] = {
|
||||
{"gotgps", cmd_gotgps},
|
||||
{"gotorientation", cmd_gotorientation},
|
||||
{"gotenv", cmd_gotenv},
|
||||
{"gotlight", cmd_gotlight},
|
||||
{"sysinfo", cmd_sysinfo},
|
||||
{"radioinfo", cmd_radioinfo},
|
||||
{"pmemreset", cmd_pmemreset},
|
||||
|
Reference in New Issue
Block a user