Update picocalc_helloworld

battery info now has charging status flag
This commit is contained in:
cuu 2025-04-21 15:46:18 +08:00
parent a1847ee338
commit 3b84959ee6
2 changed files with 21 additions and 8 deletions

View File

@ -17,4 +17,6 @@ void init_i2c_kbd();
int read_i2c_kbd(); int read_i2c_kbd();
int read_battery(); int read_battery();
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitClear(value, bit) ((value) &= ~(1 << (bit)))
#endif #endif

View File

@ -202,9 +202,25 @@ void pwm_interrupt_handler() {
// //
} }
} }
void test_battery(){
char buf[64];
int bat_pcnt = read_battery();
bat_pcnt = bat_pcnt>>8;
int bat_charging = bitRead(bat_pcnt,7);
bitClear(bat_pcnt,7);
sprintf(buf,"battery percent is %d\n",bat_pcnt);
printf("%s", buf);
lcd_print_string(buf);
if(bat_charging ==0 ){
sprintf(buf,"battery is not charging\n");
}else{
sprintf(buf,"battery is charging\n");
}
printf("%s", buf);
lcd_print_string(buf);
}
int main() { int main() {
char buf[64];
set_sys_clock_khz(133000, true); set_sys_clock_khz(133000, true);
stdio_init_all(); stdio_init_all();
@ -235,18 +251,13 @@ int main() {
// otherwise we won't get working battery infos // otherwise we won't get working battery infos
sleep_ms(2000); sleep_ms(2000);
int bat_pcnt = read_battery(); test_battery();
sprintf(buf,"battery percent is %d\n",bat_pcnt>>8);
printf(buf);
lcd_print_string(buf);
while (1) { while (1) {
int c = lcd_getc(0); int c = lcd_getc(0);
if(c != -1 && c > 0) { if(c != -1 && c > 0) {
lcd_putc(0,c); lcd_putc(0,c);
} }
sleep_ms(10); sleep_ms(20);
} }
} }