mirror of
https://github.com/clockworkpi/PicoCalc.git
synced 2026-03-20 02:52:39 +01:00
bug fix for REG_ID_BAT
The correct power-on sequence for obtaining the battery percentage is to first power on the PicoCalc with the battery inserted Then connect the USB Type-C cable to read the battery percentage. The battery percentage also can be retrieved via I2C communication within the UF2 program. PicoCalc keyboard firmware updating required.
This commit is contained in:
@@ -42,6 +42,8 @@ uint8_t write_buffer_len = 0;
|
||||
uint8_t io_matrix[9];//for IO matrix,last bytye is the restore key(c64 only)
|
||||
uint8_t js_bits=0xff;// c64 joystick bits
|
||||
|
||||
static int current_bat_pcnt = 0;
|
||||
|
||||
unsigned long time_uptime_ms() { return millis(); }
|
||||
|
||||
void lock_cb(bool caps_changed, bool num_changed) {
|
||||
@@ -134,12 +136,10 @@ void receiveEvent(int howMany) {
|
||||
write_buffer[1] = reg_get_value(REG_ID_BKL);
|
||||
} break;
|
||||
case REG_ID_BAT:{
|
||||
//Serial1.print("REG_ID_BAT getBatteryPercent:");Serial1.print(current_bat_pcnt);Serial1.println("%");
|
||||
write_buffer[0] = reg;
|
||||
if (PMU.isBatteryConnect()) {
|
||||
write_buffer[1] = PMU.getBatteryPercent();
|
||||
}else{
|
||||
write_buffer[1] = 0x00;
|
||||
}
|
||||
write_buffer[1] = (uint8_t)current_bat_pcnt;
|
||||
|
||||
}break;
|
||||
case REG_ID_KEY: {
|
||||
write_buffer[0] = fifo_count();
|
||||
@@ -229,19 +229,20 @@ void printPMU() {
|
||||
}
|
||||
|
||||
void check_pmu_int() {
|
||||
/// 40 secs check battery percent
|
||||
|
||||
int pcnt;
|
||||
|
||||
if (!pmu_online) return;
|
||||
|
||||
if (time_uptime_ms() - run_time > 40000) {
|
||||
|
||||
if (time_uptime_ms() - run_time > 20000) {
|
||||
run_time = millis(); // reset time
|
||||
pcnt = PMU.getBatteryPercent();
|
||||
//Serial1.print("check_pmu_int: ");Serial1.print(pcnt);Serial1.println();
|
||||
if (pcnt < 0) { // disconnect
|
||||
pcnt = 0;
|
||||
pmu_status = 0xff;
|
||||
current_bat_pcnt = pcnt;
|
||||
} else { // battery connected
|
||||
current_bat_pcnt = pcnt;
|
||||
if (PMU.isCharging()) {
|
||||
pmu_status = bitSet(pcnt, 7);
|
||||
} else {
|
||||
@@ -304,11 +305,12 @@ void check_pmu_int() {
|
||||
} else {
|
||||
pmu_status = pcnt;
|
||||
}
|
||||
|
||||
current_bat_pcnt = pcnt;
|
||||
Serial1.println("isBatInsert");
|
||||
}
|
||||
if (PMU.isBatRemoveIrq()) {
|
||||
pmu_status = 0xff;
|
||||
current_bat_pcnt = 0;
|
||||
Serial1.println("isBatRemove");
|
||||
stop_chg();
|
||||
}
|
||||
@@ -359,6 +361,7 @@ void check_pmu_int() {
|
||||
pcnt = 0;
|
||||
pmu_status = 0xff;
|
||||
}
|
||||
current_bat_pcnt = pcnt;
|
||||
pmu_status = bitClear(pcnt, 7);
|
||||
Serial1.println("isBatChagerDone");
|
||||
stop_chg();
|
||||
@@ -369,6 +372,7 @@ void check_pmu_int() {
|
||||
pcnt = 0;
|
||||
pmu_status = 0xff;
|
||||
}
|
||||
current_bat_pcnt = pcnt;
|
||||
pmu_status = bitSet(pcnt, 7);
|
||||
Serial1.println("isBatChagerStart");
|
||||
if(PMU.isBatteryConnect()) {
|
||||
@@ -517,8 +521,7 @@ void setup() {
|
||||
// 5% ~= 3.5V
|
||||
// 1% ~= 3.4V
|
||||
PMU.setLowBatShutdownThreshold(1); //This is related to the battery charging and discharging logic. If you're not sure what you're doing, please don't modify it, as it could damage the battery.
|
||||
|
||||
|
||||
|
||||
run_time = 0;
|
||||
keycb_start = 1;
|
||||
low_bat();
|
||||
|
||||
Reference in New Issue
Block a user