@@ -43,87 +43,86 @@ void BattinfoView::on_timer() {
43
43
}
44
44
}
45
45
46
- void BattinfoView::update_result () {
47
- if (!battery::BatteryManagement::isDetected ()) {
46
+ void BattinfoView::update_results_ads1110 (i2cdev::I2cDev_ADS1110* dev) {
47
+ bool uichg = false ;
48
+ auto voltage = dev->readVoltage ();
49
+ auto percent = battery::BatteryManagement::calc_percent_voltage (voltage);
50
+ if (percent <= 100 )
51
+ text_percent.set (to_string_dec_uint (percent) + " %" );
52
+ else
48
53
text_percent.set (" UNKNOWN" );
54
+ if (voltage > 1 ) {
55
+ text_voltage.set (to_string_decimal (voltage / 1000.0 , 3 ) + " V" );
56
+ } else {
49
57
text_voltage.set (" UNKNOWN" );
50
- text_current.set (" -" );
51
- text_charge.set (" -" );
52
- text_cycles.set (" -" );
53
- text_ttef.set (" -" );
54
- text_method.set (" -" );
55
- text_warn.set (" " );
56
- return ;
57
58
}
59
+
60
+ // ui hide:
61
+ if (!labels_opt.hidden ()) uichg = true ;
62
+ labels_opt.hidden (true );
63
+ text_current.hidden (true );
64
+ text_charge.hidden (true );
65
+ labels_opt.hidden (true );
66
+ text_ttef.hidden (true );
67
+ text_cycles.hidden (true );
68
+ text_warn.set (" " );
69
+ text_ttef.hidden (true );
70
+ text_method.set (" Voltage" );
71
+ button_mode.set_text (" Voltage" );
72
+ if (uichg) set_dirty ();
73
+ BatteryStateMessage msg{1 , percent, false , voltage};
74
+ EventDispatcher::send_message (msg);
75
+ }
76
+
77
+ void BattinfoView::update_results_max17055 (i2cdev::I2cDev_MAX17055* dev) {
58
78
bool uichg = false ;
59
79
uint8_t valid_mask = 0 ;
60
- battery::BatteryManagement:: getBatteryInfo (valid_mask, percent, voltage, current);
80
+ dev-> getBatteryInfo (valid_mask, percent, voltage, current);
61
81
// update text fields
62
- if (percent <= 100 && (valid_mask & battery::BatteryManagement::BATT_VALID_VOLTAGE) == battery::BatteryManagement::BATT_VALID_VOLTAGE )
82
+ if (percent <= 100 )
63
83
text_percent.set (to_string_dec_uint (percent) + " %" );
64
84
else
65
85
text_percent.set (" UNKNOWN" );
66
- if (voltage > 1 && (valid_mask & battery::BatteryManagement::BATT_VALID_VOLTAGE) == battery::BatteryManagement::BATT_VALID_VOLTAGE ) {
86
+ if (voltage > 1 ) {
67
87
text_voltage.set (to_string_decimal (voltage / 1000.0 , 3 ) + " V" );
68
88
} else {
69
89
text_voltage.set (" UNKNOWN" );
70
90
}
71
- if ((valid_mask & battery::BatteryManagement::BATT_VALID_CURRENT) == battery::BatteryManagement::BATT_VALID_CURRENT) {
72
- if (labels_opt.hidden ()) uichg = true ;
73
- labels_opt.hidden (false );
74
- text_current.hidden (false );
75
- text_charge.hidden (false );
76
- text_current.set (to_string_dec_int (current) + " mA" );
77
- text_charge.set (current >= 0 ? " Charging" : " Discharging" );
78
- labels_opt.hidden (false );
79
-
80
- text_ttef.hidden (false );
81
- } else {
82
- if (!labels_opt.hidden ()) uichg = true ;
83
- labels_opt.hidden (true );
84
- text_current.hidden (true );
85
- text_charge.hidden (true );
86
- text_cycles.hidden (true );
87
- text_ttef.hidden (true );
91
+ if (labels_opt.hidden ()) uichg = true ;
92
+ labels_opt.hidden (false );
93
+ text_current.hidden (false );
94
+ text_charge.hidden (false );
95
+ text_current.set (to_string_dec_int (current) + " mA" );
96
+ text_charge.set (current >= 0 ? " Charging" : " Discharging" );
97
+ labels_opt.hidden (false );
98
+ text_ttef.hidden (false );
99
+ // cycles
100
+ text_cycles.hidden (false );
101
+ uint16_t cycles = (uint16_t )dev->getValue (" Cycles" );
102
+ if (cycles < 2 )
103
+ text_warn.set (" SoC improves after 2 cycles" );
104
+ else
88
105
text_warn.set (" " );
89
- }
90
- if ((valid_mask & battery::BatteryManagement::BATT_VALID_CYCLES) == battery::BatteryManagement::BATT_VALID_CYCLES) {
91
- text_cycles.hidden (false );
92
- uint16_t cycles = battery::BatteryManagement::get_cycles ();
93
- if (cycles < 2 )
94
- text_warn.set (" SoC improves after 2 cycles" );
95
- else
96
- text_warn.set (" " );
97
- text_cycles.set (to_string_dec_uint (cycles));
106
+ text_cycles.set (to_string_dec_uint (cycles));
107
+ // ttef
108
+ text_ttef.hidden (false );
109
+ float ttef = 0 ;
110
+ if (current <= 0 ) {
111
+ ttef = dev->getValue (" TTE" );
98
112
} else {
99
- text_cycles.hidden (true );
100
- text_warn.set (" " );
113
+ ttef = dev->getValue (" TTF" );
101
114
}
102
- if ((valid_mask & battery::BatteryManagement::BATT_VALID_TTEF) == battery::BatteryManagement::BATT_VALID_TTEF) {
103
- text_ttef.hidden (false );
104
- float ttef = 0 ;
105
- if (current <= 0 ) {
106
- ttef = battery::BatteryManagement::get_tte ();
107
- } else {
108
- ttef = battery::BatteryManagement::get_ttf ();
109
- }
110
-
111
- // Convert ttef to hours and minutes
112
- uint8_t hours = static_cast <uint8_t >(ttef);
113
- uint8_t minutes = static_cast <uint8_t >((ttef - hours) * 60 + 0.5 ); // +0.5 for rounding
114
-
115
- // Create the formatted string
116
- std::string formatted_time;
117
- if (hours > 0 ) {
118
- formatted_time += to_string_dec_uint (hours) + " h " ;
119
- }
120
- formatted_time += to_string_dec_uint (minutes) + " m" ;
121
-
122
- text_ttef.set (formatted_time);
123
- } else {
124
- text_ttef.hidden (true );
115
+ // Convert ttef to hours and minutes
116
+ uint8_t hours = static_cast <uint8_t >(ttef);
117
+ uint8_t minutes = static_cast <uint8_t >((ttef - hours) * 60 + 0.5 ); // +0.5 for rounding
118
+ // Create the formatted string
119
+ std::string formatted_time;
120
+ if (hours > 0 ) {
121
+ formatted_time += to_string_dec_uint (hours) + " h " ;
125
122
}
126
- if ((valid_mask & battery::BatteryManagement::BATT_VALID_PERCENT) == battery::BatteryManagement::BATT_VALID_PERCENT) {
123
+ formatted_time += to_string_dec_uint (minutes) + " m" ;
124
+ text_ttef.set (formatted_time);
125
+ if (!battery::BatteryManagement::calcOverride) {
127
126
text_method.set (" IC" );
128
127
button_mode.set_text (" Volt" );
129
128
} else {
@@ -136,6 +135,30 @@ void BattinfoView::update_result() {
136
135
EventDispatcher::send_message (msg);
137
136
}
138
137
138
+ void BattinfoView::update_result () {
139
+ auto dev = i2cdev::I2CDevManager::get_dev_by_model (I2CDEVMDL_MAX17055);
140
+ if (dev) {
141
+ update_results_max17055 ((i2cdev::I2cDev_MAX17055*)dev);
142
+ return ;
143
+ }
144
+
145
+ dev = i2cdev::I2CDevManager::get_dev_by_model (I2CDEVMDL_ADS1110);
146
+ if (dev) {
147
+ update_results_ads1110 ((i2cdev::I2cDev_ADS1110*)dev);
148
+ return ;
149
+ }
150
+
151
+ // no dev found
152
+ text_percent.set (" UNKNOWN" );
153
+ text_voltage.set (" UNKNOWN" );
154
+ text_current.set (" -" );
155
+ text_charge.set (" -" );
156
+ text_cycles.set (" -" );
157
+ text_ttef.set (" -" );
158
+ text_method.set (" -" );
159
+ text_warn.set (" " );
160
+ }
161
+
139
162
BattinfoView::BattinfoView (NavigationView& nav)
140
163
: nav_{nav} {
141
164
add_children ({&labels,
0 commit comments