mirror of
https://github.com/clockworkpi/PicoCalc.git
synced 2025-12-12 10:18:54 +01:00
Update picocalc_helloworld
battery info now has charging status flag
This commit is contained in:
parent
a1847ee338
commit
3b84959ee6
@ -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
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user