Learn ic fix (#2253)

* WIP

* Fixed merge

* Added test code

* WIP

* Clean up

* add reset learned params

* ui fix

* ui fix2

* Updated func

* Fixed english

* WIP

* WIP testing

* Added new debug app

* Got new app for debug

* Got new app for debug

* Got one full page showing

* Got app working with all reg

* Got app working with all reg

* Got full hex showing

* Fixed dp

* Fixed dp

* Moved entities

* Enabled apps again

* SHow battery debug if ic

* WIP

* Refactored further

* WIP

* Refactor and clean up

* Refactor and clean up

* fix warning, add tte/ttf, add cycles counter.

* wip

* morse tx to ext app

* fix morse crash

* fix ui

* Updated wording

* WIP

* WIP

* Updated to display hours and minutes

---------

Co-authored-by: HTotoo <ttotoo@gmail.com>
This commit is contained in:
jLynx 2024-09-20 21:59:17 +12:00 committed by GitHub
parent 582bb02a75
commit 7feef9d38b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 905 additions and 726 deletions

View File

@ -292,6 +292,7 @@ set(CPPSRC
apps/ui_btle_rx.cpp apps/ui_btle_rx.cpp
# apps/ui_coasterp.cpp # apps/ui_coasterp.cpp
apps/ui_debug.cpp apps/ui_debug.cpp
apps/ui_debug_battery.cpp
apps/ui_dfu_menu.cpp apps/ui_dfu_menu.cpp
apps/ui_encoders.cpp apps/ui_encoders.cpp
apps/ui_fileman.cpp apps/ui_fileman.cpp
@ -306,7 +307,7 @@ set(CPPSRC
apps/ui_looking_glass_app.cpp apps/ui_looking_glass_app.cpp
apps/ui_mictx.cpp apps/ui_mictx.cpp
apps/ui_modemsetup.cpp apps/ui_modemsetup.cpp
apps/ui_morse.cpp # apps/ui_morse.cpp
# apps/ui_nrf_rx.cpp # apps/ui_nrf_rx.cpp
# apps/ui_nuoptix.cpp # apps/ui_nuoptix.cpp
apps/ui_playlist.cpp apps/ui_playlist.cpp

View File

@ -49,7 +49,10 @@ void BattinfoView::update_result() {
text_voltage.set("UNKNOWN"); text_voltage.set("UNKNOWN");
text_current.set("-"); text_current.set("-");
text_charge.set("-"); text_charge.set("-");
text_cycles.set("-");
text_ttef.set("-");
text_method.set("-"); text_method.set("-");
text_warn.set("");
return; return;
} }
bool uichg = false; bool uichg = false;
@ -73,11 +76,52 @@ void BattinfoView::update_result() {
text_current.set(to_string_dec_int(current) + " mA"); text_current.set(to_string_dec_int(current) + " mA");
text_charge.set(current >= 0 ? "Charging" : "Discharging"); text_charge.set(current >= 0 ? "Charging" : "Discharging");
labels_opt.hidden(false); labels_opt.hidden(false);
text_ttef.hidden(false);
} else { } else {
if (!labels_opt.hidden()) uichg = true; if (!labels_opt.hidden()) uichg = true;
labels_opt.hidden(true); labels_opt.hidden(true);
text_current.hidden(true); text_current.hidden(true);
text_charge.hidden(true); text_charge.hidden(true);
text_cycles.hidden(true);
text_ttef.hidden(true);
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));
} else {
text_cycles.hidden(true);
text_warn.set("");
}
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);
} }
if ((valid_mask & battery::BatteryManagement::BATT_VALID_PERCENT) == battery::BatteryManagement::BATT_VALID_PERCENT) { if ((valid_mask & battery::BatteryManagement::BATT_VALID_PERCENT) == battery::BatteryManagement::BATT_VALID_PERCENT) {
text_method.set("IC"); text_method.set("IC");
@ -102,7 +146,10 @@ BattinfoView::BattinfoView(NavigationView& nav)
&text_charge, &text_charge,
&text_method, &text_method,
&button_mode, &button_mode,
&button_exit}); &button_exit,
&text_cycles,
&text_warn,
&text_ttef});
button_exit.on_select = [this, &nav](Button&) { button_exit.on_select = [this, &nav](Button&) {
nav.pop(); nav.pop();

View File

@ -55,12 +55,15 @@ class BattinfoView : public View {
{{2 * 8, 1 * 16}, "Percent:", Theme::getInstance()->fg_light->foreground}, {{2 * 8, 1 * 16}, "Percent:", Theme::getInstance()->fg_light->foreground},
{{2 * 8, 2 * 16}, "Voltage:", Theme::getInstance()->fg_light->foreground}, {{2 * 8, 2 * 16}, "Voltage:", Theme::getInstance()->fg_light->foreground},
{{2 * 8, 3 * 16}, "Method:", Theme::getInstance()->fg_light->foreground}, {{2 * 8, 3 * 16}, "Method:", Theme::getInstance()->fg_light->foreground},
{{2 * 8, 7 * 16}, "Change method:", Theme::getInstance()->fg_light->foreground},
}; };
Labels labels_opt{ Labels labels_opt{
{{2 * 8, 4 * 16}, "Current:", Theme::getInstance()->fg_light->foreground}, {{2 * 8, 4 * 16}, "Current:", Theme::getInstance()->fg_light->foreground},
{{2 * 8, 5 * 16}, "Charge:", Theme::getInstance()->fg_light->foreground}}; {{2 * 8, 5 * 16}, "Charge:", Theme::getInstance()->fg_light->foreground},
{{2 * 8, 6 * 16}, "TTF/E:", Theme::getInstance()->fg_light->foreground},
{{2 * 8, 7 * 16}, "Cycles:", Theme::getInstance()->fg_light->foreground},
{{2 * 8, 10 * 16}, "Change method:", Theme::getInstance()->fg_light->foreground},
};
Text text_percent{ Text text_percent{
{13 * 8, 1 * 16, 10 * 16, 16}, {13 * 8, 1 * 16, 10 * 16, 16},
@ -77,9 +80,19 @@ class BattinfoView : public View {
Text text_charge{ Text text_charge{
{13 * 8, 5 * 16, 10 * 16, 16}, {13 * 8, 5 * 16, 10 * 16, 16},
"-"}; "-"};
Text text_ttef{
{13 * 8, 6 * 16, 10 * 16, 16},
"-"};
Text text_cycles{
{13 * 8, 7 * 16, 10 * 16, 16},
"-"};
Text text_warn{
{2 * 8, 8 * 16, 30 * 8, 2 * 16},
""};
Button button_mode{ Button button_mode{
{2 * 8, 8 * 16 + 5, 5 * 16, 32}, {2 * 8, 11 * 16 + 5, 5 * 16, 32},
"Volt"}; "Volt"};
Button button_exit{ Button button_exit{

View File

@ -36,6 +36,7 @@
#include "ui_font_fixed_8x16.hpp" #include "ui_font_fixed_8x16.hpp"
#include "ui_painter.hpp" #include "ui_painter.hpp"
#include "ui_external_items_menu_loader.hpp" #include "ui_external_items_menu_loader.hpp"
#include "ui_debug_battery.hpp"
#include "portapack.hpp" #include "portapack.hpp"
#include "portapack_persistent_memory.hpp" #include "portapack_persistent_memory.hpp"
@ -511,6 +512,11 @@ void DebugMenuView::on_populate() {
{"Reboot", ui::Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_setup, [this]() { nav_.push<DebugReboot>(); }}, {"Reboot", ui::Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_setup, [this]() { nav_.push<DebugReboot>(); }},
}); });
if (battery::BatteryManagement::detectedModule() == battery::BatteryManagement::BatteryModules::BATT_MAX17055) {
add_item(
{"Battery", ui::Theme::getInstance()->fg_darkcyan->foreground, &bitmap_icon_batt_icon, [this]() { nav_.push<BatteryCapacityView>(); }});
}
for (auto const& gridItem : ExternalItemsMenuLoader::load_external_items(app_location_t::DEBUG, nav_)) { for (auto const& gridItem : ExternalItemsMenuLoader::load_external_items(app_location_t::DEBUG, nav_)) {
add_item(gridItem); add_item(gridItem);
}; };

View File

@ -0,0 +1,104 @@
#include "ui_debug_battery.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];
}
return {"", 0, "", 0, false, "", false, 0, false, false, false, 0, false};
}
BatteryCapacityView::BatteryCapacityView(NavigationView& nav) {
for (size_t i = 0; i < ENTRIES_PER_PAGE; ++i) {
name_texts[i].set_parent_rect({0 * 8, static_cast<int>((i + 1) * 16), 8 * 8, 16});
addr_texts[i].set_parent_rect({9 * 8, static_cast<int>((i + 1) * 16), 4 * 8, 16});
hex_texts[i].set_parent_rect({14 * 8, static_cast<int>((i + 1) * 16), 6 * 8, 16});
value_texts[i].set_parent_rect({21 * 8, static_cast<int>((i + 1) * 16), 10 * 8, 16});
add_child(&name_texts[i]);
add_child(&addr_texts[i]);
add_child(&hex_texts[i]);
add_child(&value_texts[i]);
}
add_children({&labels, &page_text, &button_done});
button_done.on_select = [&nav](Button&) { nav.pop(); };
populate_page(0);
update_page_text();
}
void BatteryCapacityView::focus() {
button_done.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) {
current_page = new_page;
populate_page(current_page * ENTRIES_PER_PAGE);
update_page_text();
}
return true;
}
void BatteryCapacityView::update_values() {
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) {
const auto entry = get_entry(entry_index);
uint16_t raw_value = battery::BatteryManagement::read_register(entry.address);
hex_texts[i].set("0x" + to_string_hex(raw_value, 4));
float scaled_value;
if (entry.is_signed) {
int16_t signed_value = static_cast<int16_t>(raw_value);
scaled_value = signed_value * entry.scalar;
} else {
scaled_value = raw_value * entry.scalar;
}
// Format the value with appropriate decimal places
std::string formatted_value;
if (entry.resolution > 0) {
formatted_value = to_string_decimal(scaled_value, std::min(entry.resolution, 3));
} else {
formatted_value = to_string_dec_int(scaled_value); // Show up to 3 decimal places
}
value_texts[i].set(formatted_value + " " + entry.unit);
}
}
}
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) {
const auto entry = get_entry(entry_index);
name_texts[i].set(entry.name);
addr_texts[i].set("0x" + to_string_hex(entry.address, 2));
name_texts[i].hidden(false);
addr_texts[i].hidden(false);
hex_texts[i].hidden(false);
value_texts[i].hidden(false);
} else {
name_texts[i].hidden(true);
addr_texts[i].hidden(true);
hex_texts[i].hidden(true);
value_texts[i].hidden(true);
}
}
update_values();
}
void BatteryCapacityView::update_page_text() {
int total_pages = (battery::max17055::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));
}
} // namespace ui

View File

@ -0,0 +1,48 @@
#ifndef __UI_DEBUG_BATTERY_HPP__
#define __UI_DEBUG_BATTERY_HPP__
#include "ui.hpp"
#include "ui_widget.hpp"
#include "ui_navigation.hpp"
#include "battery.hpp"
#include "max17055.hpp"
namespace ui {
class BatteryCapacityView : public View {
public:
BatteryCapacityView(NavigationView& nav);
void focus() override;
std::string title() const override { return "Battery Registers"; }
bool on_encoder(const EncoderEvent delta) override;
using RegisterEntry = battery::max17055::RegisterEntry;
private:
static RegisterEntry get_entry(size_t index);
Labels labels{
{{0 * 8, 0 * 16}, "Reg", Theme::getInstance()->fg_yellow->foreground},
{{9 * 8, 0 * 16}, "Addr", Theme::getInstance()->fg_yellow->foreground},
{{14 * 8, 0 * 16}, "Hex", Theme::getInstance()->fg_yellow->foreground},
{{21 * 8, 0 * 16}, "Value", Theme::getInstance()->fg_yellow->foreground},
};
std::array<Text, 16> name_texts = {};
std::array<Text, 16> addr_texts = {};
std::array<Text, 16> hex_texts = {};
std::array<Text, 16> value_texts = {};
Text page_text{{144, 284, 80, 16}, "Page 1/1"};
Button button_done{{16, 280, 96, 24}, "Done"};
void update_values();
void populate_page(int start_index);
void update_page_text();
int current_page = 0;
static constexpr int ENTRIES_PER_PAGE = 16;
};
} // namespace ui
#endif // __UI_DEBUG_BATTERY_HPP__

View File

@ -969,6 +969,8 @@ SetBatteryView::SetBatteryView(NavigationView& nav) {
&button_cancel, &button_cancel,
&checkbox_overridebatt}); &checkbox_overridebatt});
if (battery::BatteryManagement::detectedModule() == battery::BatteryManagement::BATT_MAX17055) add_children({&button_reset, &labels2});
button_save.on_select = [&nav, this](Button&) { button_save.on_select = [&nav, this](Button&) {
pmem::set_ui_override_batt_calc(checkbox_overridebatt.value()); pmem::set_ui_override_batt_calc(checkbox_overridebatt.value());
battery::BatteryManagement::set_calc_override(checkbox_overridebatt.value()); battery::BatteryManagement::set_calc_override(checkbox_overridebatt.value());
@ -976,6 +978,13 @@ SetBatteryView::SetBatteryView(NavigationView& nav) {
nav.pop(); nav.pop();
}; };
button_reset.on_select = [&nav, this](Button&) {
if (battery::BatteryManagement::reset_learned())
nav.display_modal("Reset", "Battery parameters reset");
else
nav.display_modal("Error", "Error parameter reset");
};
checkbox_overridebatt.set_value(pmem::ui_override_batt_calc()); checkbox_overridebatt.set_value(pmem::ui_override_batt_calc());
button_cancel.on_select = [&nav, this](Button&) { button_cancel.on_select = [&nav, this](Button&) {
@ -1017,7 +1026,7 @@ void SettingsMenuView::on_populate() {
{"Theme", ui::Color::dark_cyan(), &bitmap_icon_setup, [this]() { nav_.push<SetThemeView>(); }}, {"Theme", ui::Color::dark_cyan(), &bitmap_icon_setup, [this]() { nav_.push<SetThemeView>(); }},
{"Autostart", ui::Color::dark_cyan(), &bitmap_icon_setup, [this]() { nav_.push<SetAutostartView>(); }}, {"Autostart", ui::Color::dark_cyan(), &bitmap_icon_setup, [this]() { nav_.push<SetAutostartView>(); }},
}); });
if (battery::BatteryManagement::isDetected()) add_item({"Battery", ui::Color::dark_cyan(), &bitmap_icon_setup, [this]() { nav_.push<SetBatteryView>(); }}); if (battery::BatteryManagement::isDetected()) add_item({"Battery", ui::Color::dark_cyan(), &bitmap_icon_batt_icon, [this]() { nav_.push<SetBatteryView>(); }});
} }
} /* namespace ui */ } /* namespace ui */

View File

@ -906,13 +906,14 @@ class SetBatteryView : public View {
Labels labels{ Labels labels{
{{1 * 8, 1 * 16}, "Override batt calculation", Theme::getInstance()->fg_light->foreground}, {{1 * 8, 1 * 16}, "Override batt calculation", Theme::getInstance()->fg_light->foreground},
{{1 * 8, 2 * 16}, "method to voltage based", Theme::getInstance()->fg_light->foreground}}; {{1 * 8, 2 * 16}, "method to voltage based", Theme::getInstance()->fg_light->foreground}};
Labels labels2{
{{1 * 8, 6 * 16}, "Reset IC's learned params.", Theme::getInstance()->fg_light->foreground}};
Button button_save{ Button button_save{
{2 * 8, 16 * 16, 12 * 8, 32}, {2 * 8, 16 * 16, 12 * 8, 32},
"Save"}; "Save"};
Checkbox checkbox_overridebatt{ Checkbox checkbox_overridebatt{
{2 * 8, 6 * 16}, {2 * 8, 4 * 16},
23, 23,
"Override"}; "Override"};
@ -920,6 +921,11 @@ class SetBatteryView : public View {
{16 * 8, 16 * 16, 12 * 8, 32}, {16 * 8, 16 * 16, 12 * 8, 32},
"Cancel", "Cancel",
}; };
Button button_reset{
{2 * 8, 8 * 16, 12 * 8, 32},
"Reset",
};
}; };
class SettingsMenuView : public BtnGridView { class SettingsMenuView : public BtnGridView {

View File

@ -76,7 +76,7 @@ __attribute__((section(".external_app.app_blespam.application_information"), use
/*.icon_color = */ ui::Color::yellow().v, /*.icon_color = */ ui::Color::yellow().v,
/*.menu_location = */ app_location_t::TX, /*.menu_location = */ app_location_t::TX,
/*.m4_app_tag = portapack::spi_flash::image_tag_afsk_rx */ {'P', 'B', 'T', 'T'}, /*.m4_app_tag = portapack::spi_flash::image_tag_btle_tx */ {'P', 'B', 'T', 'T'},
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time /*.m4_app_offset = */ 0x00000000, // will be filled at compile time
}; };
} }

View File

@ -88,6 +88,11 @@ set(EXTCPPSRC
#adsbtx #adsbtx
external/adsbtx/main.cpp external/adsbtx/main.cpp
external/adsbtx/ui_adsb_tx.cpp external/adsbtx/ui_adsb_tx.cpp
#morse_tx
external/morse_tx/main.cpp
external/morse_tx/ui_morse.cpp
) )
set(EXTAPPLIST set(EXTAPPLIST
@ -112,4 +117,5 @@ set(EXTAPPLIST
tpmsrx tpmsrx
protoview protoview
adsbtx adsbtx
morse_tx
) )

View File

@ -44,6 +44,7 @@ MEMORY
ram_external_app_tpmsrx(rwx) : org = 0xADC30000, len = 32k ram_external_app_tpmsrx(rwx) : org = 0xADC30000, len = 32k
ram_external_app_protoview(rwx) : org = 0xADC40000, len = 32k ram_external_app_protoview(rwx) : org = 0xADC40000, len = 32k
ram_external_app_adsbtx(rwx) : org = 0xADC50000, len = 32k ram_external_app_adsbtx(rwx) : org = 0xADC50000, len = 32k
ram_external_app_morse_tx(rwx) : org = 0xADC60000, len = 32k
} }
SECTIONS SECTIONS
@ -176,4 +177,11 @@ SECTIONS
} > ram_external_app_adsbtx } > ram_external_app_adsbtx
.external_app_morse_tx : ALIGN(4) SUBALIGN(4)
{
KEEP(*(.external_app.app_morse_tx.application_information));
*(*ui*external_app*morse_tx*);
} > ram_external_app_morse_tx
} }

View File

@ -0,0 +1,82 @@
/*
* Copyright (C) 2023 Bernd Herzog
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "ui.hpp"
#include "ui_morse.hpp"
#include "ui_navigation.hpp"
#include "external_app.hpp"
namespace ui::external_app::morse_tx {
void initialize_app(ui::NavigationView& nav) {
nav.push<MorseView>();
}
} // namespace ui::external_app::morse_tx
extern "C" {
__attribute__((section(".external_app.app_morse_tx.application_information"), used)) application_information_t _application_information_morse_tx = {
/*.memory_location = */ (uint8_t*)0x00000000,
/*.externalAppEntry = */ ui::external_app::morse_tx::initialize_app,
/*.header_version = */ CURRENT_HEADER_VERSION,
/*.app_version = */ VERSION_MD5,
/*.app_name = */ "Morse",
/*.bitmap_data = */ {
0x00,
0x00,
0xFE,
0x7F,
0xFF,
0xFF,
0xBB,
0xD0,
0xFF,
0xFF,
0xFF,
0xFF,
0x0B,
0xE1,
0xFF,
0xFF,
0xFF,
0xFF,
0xEB,
0xD0,
0xFF,
0xFF,
0xFE,
0x7F,
0x70,
0x00,
0x30,
0x00,
0x10,
0x00,
0x00,
0x00,
},
/*.icon_color = */ ui::Color::green().v,
/*.menu_location = */ app_location_t::TX,
/*.m4_app_tag = portapack::spi_flash::image_tag_tones */ {'P', 'T', 'O', 'N'},
/*.m4_app_offset = */ 0x00000000, // will be filled at compile time
};
}

View File

@ -36,7 +36,7 @@ using namespace portapack;
using namespace morse; using namespace morse;
using namespace hackrf::one; using namespace hackrf::one;
namespace ui { namespace ui::external_app::morse_tx {
static WORKING_AREA(ookthread_wa, 256); static WORKING_AREA(ookthread_wa, 256);
@ -194,7 +194,8 @@ void MorseView::set_foxhunt(size_t i) {
MorseView::MorseView( MorseView::MorseView(
NavigationView& nav) NavigationView& nav)
: nav_(nav) { : nav_(nav) {
baseband::run_image(portapack::spi_flash::image_tag_tones); // baseband::run_image(portapack::spi_flash::image_tag_tones);
baseband::run_prepared_image(portapack::memory::map::m4_code.base());
add_children({&labels, add_children({&labels,
&checkbox_foxhunt, &checkbox_foxhunt,
@ -284,4 +285,4 @@ MorseView::MorseView(
}; };
} }
} /* namespace ui */ } // namespace ui::external_app::morse_tx

View File

@ -39,7 +39,7 @@
using namespace morse; using namespace morse;
namespace ui { namespace ui::external_app::morse_tx {
class MorseView : public View { class MorseView : public View {
public: public:
@ -179,6 +179,6 @@ class MorseView : public View {
}}; }};
}; };
} /* namespace ui */ } // namespace ui::external_app::morse_tx
#endif /*__MORSE_TX_H__*/ #endif /*__MORSE_TX_H__*/

View File

@ -55,7 +55,7 @@
#include "ui_level.hpp" #include "ui_level.hpp"
#include "ui_looking_glass_app.hpp" #include "ui_looking_glass_app.hpp"
#include "ui_mictx.hpp" #include "ui_mictx.hpp"
#include "ui_morse.hpp" // #include "ui_morse.hpp" //moved to ext
// #include "ui_nrf_rx.hpp" //moved to ext // #include "ui_nrf_rx.hpp" //moved to ext
// #include "ui_numbers.hpp" // #include "ui_numbers.hpp"
// #include "ui_nuoptix.hpp" // #include "ui_nuoptix.hpp"
@ -90,7 +90,7 @@
#include "ais_app.hpp" #include "ais_app.hpp"
#include "analog_audio_app.hpp" #include "analog_audio_app.hpp"
// #include "analog_tv_app.hpp" //moved to ext // #include "analog_tv_app.hpp" //moved to ext
#include "ble_comm_app.hpp" // #include "ble_comm_app.hpp"
#include "ble_rx_app.hpp" #include "ble_rx_app.hpp"
#include "ble_tx_app.hpp" #include "ble_tx_app.hpp"
#include "capture_app.hpp" #include "capture_app.hpp"
@ -185,7 +185,7 @@ const NavigationView::AppList NavigationView::appList = {
{"aprstx", "APRS TX", TX, ui::Color::green(), &bitmap_icon_aprs, new ViewFactory<APRSTXView>()}, {"aprstx", "APRS TX", TX, ui::Color::green(), &bitmap_icon_aprs, new ViewFactory<APRSTXView>()},
{"bht", "BHT Xy/EP", TX, ui::Color::green(), &bitmap_icon_bht, new ViewFactory<BHTView>()}, {"bht", "BHT Xy/EP", TX, ui::Color::green(), &bitmap_icon_bht, new ViewFactory<BHTView>()},
{"bletx", "BLE Tx", TX, ui::Color::green(), &bitmap_icon_btle, new ViewFactory<BLETxView>()}, {"bletx", "BLE Tx", TX, ui::Color::green(), &bitmap_icon_btle, new ViewFactory<BLETxView>()},
{"morse", "Morse", TX, ui::Color::green(), &bitmap_icon_morse, new ViewFactory<MorseView>()}, //{"morse", "Morse", TX, ui::Color::green(), &bitmap_icon_morse, new ViewFactory<MorseView>()}, //moved to ext
//{"nuoptixdtmf", "Nuoptix DTMF", TX, ui::Color::green(), &bitmap_icon_nuoptix, new ViewFactory<NuoptixView>()}, //{"nuoptixdtmf", "Nuoptix DTMF", TX, ui::Color::green(), &bitmap_icon_nuoptix, new ViewFactory<NuoptixView>()},
{"ooktx", "OOK", TX, ui::Color::yellow(), &bitmap_icon_remote, new ViewFactory<EncodersView>()}, {"ooktx", "OOK", TX, ui::Color::yellow(), &bitmap_icon_remote, new ViewFactory<EncodersView>()},
{"pocsagtx", "POCSAG TX", TX, ui::Color::green(), &bitmap_icon_pocsag, new ViewFactory<POCSAGTXView>()}, {"pocsagtx", "POCSAG TX", TX, ui::Color::green(), &bitmap_icon_pocsag, new ViewFactory<POCSAGTXView>()},

View File

@ -23,16 +23,16 @@ bool BatteryManagement::calcOverride = false;
void BatteryManagement::detect() { void BatteryManagement::detect() {
// try to detect supported modules // try to detect supported modules
detected_ = BATT_NONE; detected_ = BATT_NONE;
if (battery_max17055.detect()) {
battery_max17055.init();
detected_ = BATT_MAX17055;
return;
}
if (battery_ads1110.detect()) { if (battery_ads1110.detect()) {
battery_ads1110.init(); battery_ads1110.init();
detected_ = BATT_ADS1110; detected_ = BATT_ADS1110;
return; return;
} }
if (battery_max17055.detect()) {
// battery_max17055.init(); //detect will call this on each "re detect"
detected_ = BATT_MAX17055;
return;
}
// add new supported module detect + init here // add new supported module detect + init here
@ -51,6 +51,13 @@ void BatteryManagement::init(bool override) {
create_thread(); create_thread();
} }
bool BatteryManagement::reset_learned() {
if (detected_ == BATT_MAX17055) {
return battery_max17055.reset_learned();
}
return false;
}
// set if the default percentage calculation should be overrided by voltage based one // set if the default percentage calculation should be overrided by voltage based one
void BatteryManagement::set_calc_override(bool override) { void BatteryManagement::set_calc_override(bool override) {
calcOverride = override; calcOverride = override;
@ -90,6 +97,26 @@ void BatteryManagement::getBatteryInfo(uint8_t& valid_mask, uint8_t& batteryPerc
(void)current; (void)current;
} }
uint16_t BatteryManagement::get_cycles() {
if (detected_ == BATT_MAX17055) {
return (uint16_t)battery_max17055.getValue("Cycles");
}
return 0;
}
float BatteryManagement::get_tte() {
if (detected_ == BATT_MAX17055) {
return battery_max17055.getValue("TTE");
}
return 0;
}
float BatteryManagement::get_ttf() {
if (detected_ == BATT_MAX17055) {
return battery_max17055.getValue("TTF");
}
return 0;
}
uint16_t BatteryManagement::read_register(const uint8_t reg) { uint16_t BatteryManagement::read_register(const uint8_t reg) {
if (detected_ == BATT_MAX17055) { if (detected_ == BATT_MAX17055) {
return battery_max17055.read_register(reg); return battery_max17055.read_register(reg);

View File

@ -44,6 +44,8 @@ class BatteryManagement {
BATT_VALID_VOLTAGE = 1, BATT_VALID_VOLTAGE = 1,
BATT_VALID_CURRENT = 2, BATT_VALID_CURRENT = 2,
BATT_VALID_PERCENT = 4, BATT_VALID_PERCENT = 4,
BATT_VALID_CYCLES = 8,
BATT_VALID_TTEF = 16,
}; };
static void init(bool override = false); static void init(bool override = false);
static void detect(); static void detect();
@ -56,6 +58,10 @@ class BatteryManagement {
static bool write_register(const uint8_t reg, const uint16_t value); static bool write_register(const uint8_t reg, const uint16_t value);
static void set_calc_override(bool override); static void set_calc_override(bool override);
static uint8_t calc_percent_voltage(uint16_t); // calculates battery percentage from the voltage static uint8_t calc_percent_voltage(uint16_t); // calculates battery percentage from the voltage
static bool reset_learned(); // resets the ic's learned parameters
static uint16_t get_cycles();
static float get_tte();
static float get_ttf();
private: private:
static void create_thread(); static void create_thread();

File diff suppressed because it is too large Load Diff

View File

@ -83,7 +83,7 @@
// Define Termination Current // Define Termination Current
#ifndef __MAX17055_Termination_Current__ #ifndef __MAX17055_Termination_Current__
#define __MAX17055_Termination_Current__ 0.1 // Termination Current #define __MAX17055_Termination_Current__ 200 // Termination Current
#endif #endif
// Define Minimum Temperature // Define Minimum Temperature
@ -253,49 +253,63 @@ namespace max17055 {
using address_t = uint8_t; using address_t = uint8_t;
struct RegisterEntry {
const char* name;
uint8_t address;
const char* type;
float scalar;
bool is_signed;
const char* unit;
bool abbr_units;
int resolution;
bool is_user;
bool is_save_restore;
bool is_nv;
uint16_t por_data;
bool is_read_only;
};
class MAX17055 { class MAX17055 {
public: public:
constexpr MAX17055(I2C& bus, const I2C::address_t bus_address) constexpr MAX17055(I2C& bus, const I2C::address_t bus_address)
: bus(bus), bus_address(bus_address), detected_(false) {} : bus(bus), bus_address(bus_address), detected_(false) {}
static const RegisterEntry entries[];
static constexpr size_t entries_count = 144;
uint16_t read_register(const uint8_t reg);
bool write_register(const uint8_t reg, const uint16_t value);
void init(); void init();
bool detect(); bool detect();
bool isDetected() const { return detected_; } bool isDetected() const { return detected_; }
uint16_t readVoltage();
uint8_t readPercentage();
void getBatteryInfo(uint8_t& valid_mask, uint8_t& batteryPercentage, uint16_t& voltage, int32_t& current); void getBatteryInfo(uint8_t& valid_mask, uint8_t& batteryPercentage, uint16_t& voltage, int32_t& current);
bool reset_learned();
uint16_t instantVoltage(void); float getValue(const char* entityName);
uint16_t averageVoltage(void); uint16_t averageMVoltage(void);
uint16_t emptyVoltage(void);
uint16_t recoveryVoltage(void);
int32_t instantCurrent(void); int32_t instantCurrent(void);
int32_t averageCurrent(void);
uint16_t stateOfCharge(void); uint16_t stateOfCharge(void);
uint16_t averageStateOfCharge(void);
uint16_t instantCapacity(void);
uint16_t designCapacity(void);
uint16_t fullCapacity(void);
uint16_t icTemperature(void);
uint16_t timeToEmpty(void);
uint16_t timeToFull(void);
uint16_t batteryAge(void);
uint16_t chargeCycle(void);
bool statusControl(const uint8_t _Status);
void statusClear(void);
uint16_t chargeTerminationCurrent(void);
uint16_t read_register(const uint8_t reg);
bool write_register(const uint8_t reg, const uint16_t value);
private: private:
I2C& bus; I2C& bus;
const I2C::address_t bus_address; const I2C::address_t bus_address;
bool detected_ = false; bool detected_ = false;
bool readRegister(uint8_t reg, uint16_t& value); const RegisterEntry* findEntry(const char* name) const;
bool readMultipleRegister(uint8_t reg, uint8_t* data, uint8_t length, bool endTransmission);
bool writeMultipleRegister(uint8_t reg, const uint8_t* data, uint8_t length); bool needsInitialization();
void partialInit();
bool statusControl(const uint8_t _Status);
bool statusClear();
bool full_reset_and_init();
bool soft_reset();
bool clear_por();
bool initialize_custom_parameters();
bool load_custom_parameters();
bool setEmptyVoltage(uint16_t _Empty_Voltage); bool setEmptyVoltage(uint16_t _Empty_Voltage);
bool setRecoveryVoltage(uint16_t _Recovery_Voltage); bool setRecoveryVoltage(uint16_t _Recovery_Voltage);

View File

@ -953,18 +953,15 @@ bool ui_hide_sd_card() {
bool ui_hide_fake_brightness() { bool ui_hide_fake_brightness() {
return data->ui_config2.hide_fake_brightness; return data->ui_config2.hide_fake_brightness;
} }
bool ui_hide_numeric_battery() { bool ui_hide_numeric_battery() {
return data->ui_config2.hide_numeric_battery; return data->ui_config2.hide_numeric_battery;
} }
bool ui_hide_battery_icon() { bool ui_hide_battery_icon() {
return data->ui_config2.hide_battery_icon; return data->ui_config2.hide_battery_icon;
} }
uint8_t ui_theme_id() { uint8_t ui_theme_id() {
return data->ui_config2.theme_id; return data->ui_config2.theme_id;
} }
bool ui_override_batt_calc() { bool ui_override_batt_calc() {
return data->ui_config2.override_batt_calc; return data->ui_config2.override_batt_calc;
} }