diff --git a/Code/picocalc_keyboard/keyboard.h b/Code/picocalc_keyboard/keyboard.h index 69e5653..43c8cbf 100644 --- a/Code/picocalc_keyboard/keyboard.h +++ b/Code/picocalc_keyboard/keyboard.h @@ -58,6 +58,8 @@ enum key_state #define KEY_F9 0x89 #define KEY_F10 0x90 +#define KEY_POWER 0x91 + typedef void (*key_callback)(char, enum key_state); typedef void (*lock_callback)(bool, bool); diff --git a/Code/picocalc_keyboard/picocalc_keyboard.ino b/Code/picocalc_keyboard/picocalc_keyboard.ino index d1cb4a8..f4b2d44 100644 --- a/Code/picocalc_keyboard/picocalc_keyboard.ino +++ b/Code/picocalc_keyboard/picocalc_keyboard.ino @@ -18,7 +18,7 @@ #define DEBUG_UART TwoWire Wire2 = TwoWire(CONFIG_PMU_SDA, CONFIG_PMU_SCL); bool pmu_flag = 0; -bool pmu_online = 0; +uint8_t pmu_online = 0; uint8_t keycb_start = 0; uint8_t head_phone_status=LOW; @@ -168,6 +168,16 @@ void receiveEvent(int howMany) { write_buffer[1] = js_bits; write_buffer_len = 2; }break; + case REG_ID_OFF:{ + if(is_write){ + pmu_online = rcv_data[1]; + if(pmu_online < 6){ + pmu_online = 6; + } + } + write_buffer[0] = reg; + write_buffer[1] = 1; + }break; default: { write_buffer[0] = 0; write_buffer[1] = 0; @@ -265,6 +275,12 @@ void check_pmu_int() { if (!pmu_online) return; + if(pmu_online > 1) { + delay(1000*pmu_online); + PMU.shutdown(); + return; + } + if (time_uptime_ms() - run_time > 20000) { run_time = millis(); // reset time pcnt = PMU.getBatteryPercent(); @@ -345,6 +361,7 @@ void check_pmu_int() { if (PMU.isPekeyShortPressIrq()) { Serial1.println("isPekeyShortPress"); // enterPmuSleep(); + key_cb(KEY_POWER,KEY_STATE_PRESSED);//send a KEY_POWER to i2c Serial1.print("Read pmu data buffer ."); uint8_t data[4] = {0}; diff --git a/Code/picocalc_keyboard/reg.h b/Code/picocalc_keyboard/reg.h index 35f76b9..e82ebfa 100644 --- a/Code/picocalc_keyboard/reg.h +++ b/Code/picocalc_keyboard/reg.h @@ -19,6 +19,7 @@ enum reg_id REG_ID_BAT = 0x0b,// battery REG_ID_C64_MTX = 0x0c,// read c64 matrix REG_ID_C64_JS = 0x0d, // joystick io bits + REG_ID_OFF = 0x0e, // POWER OFF REG_ID_LAST, };