diff --git a/src/app/epd_2in13.c b/src/app/epd_2in13.c index 719584a..4b8a61e 100644 --- a/src/app/epd_2in13.c +++ b/src/app/epd_2in13.c @@ -197,7 +197,7 @@ static void EPD_2IN13_BWR(int width, int height, int left, int top) { // left up corner int w0 = EPD_PAD_LEFT + left; - int h0 = EPD_PAD_TOP + top; + int h0 = EPD_PAD_TOP + top/8; // right bottom corner int w1 = w0 + width - 1; @@ -244,9 +244,9 @@ void EPD_2IN13_WriteRam(uint8_t *image, int width, int height, int left, int top int size = width*height/8; // Set Ram X address - uint8_t x = (top + 8) / 8; + uint8_t x = (top + EPD_PAD_TOP) / 8; EPD_SSD_SendCommand(0x4E); - EPD_SSD_SendData(x); + EPD_SSD_SendData(x & 0xff); // Set Ram Y address uint16_t y = left + EPD_PAD_LEFT; @@ -466,6 +466,69 @@ void EPD_2IN13_Update_Image() epd_step = EPD_CMD_NC; } } + +void EPD_2IN13_BattChecker(void) +{ + // get battery by 14 times EPD refresh. +#define MAX_LOOP_CNT 14 + static int loop_cnt = 0; + if (loop_cnt > MAX_LOOP_CNT) { + return; + } + + // wakeup EPD + EPD_SSD_Reset(); + + uint16_t top, left; + if (loop_cnt < 8) { + top = (loop_cnt-1)*16; + left = 0; + } else { + top = (loop_cnt-8)*16; + left = 120; + } + + char buf[32]; + obdCreateVirtualDisplay(&obd, 120, 16, epd_buffer); + obdFill(&obd, 0, 0); + + if (loop_cnt == 0) { + EPD_2IN13_Clear(); + goto exit; + } else if (loop_cnt == 1) { + // show BLE name + extern void getBleAdvName(char* buf); + getBleAdvName(buf); + obdWriteStringCustom(&obd, (GFXfont *)&Dialog_plain_16, 0, 16, buf, 1); + } else { + // check battery + uint16_t v1 = INTFRAC2MV(epd_battery); + uint8_t v2 = EPD_BATT_Percent(); + System_snprintf(buf, 32, "%x:%4u %3u%%", loop_cnt - 1, v1, v2); + obdWriteStringCustom(&obd, (GFXfont *)&Dialog_plain_16, 0, 16, buf, 1); + } + + // edian and invent + for (int i=0; i MAX_LOOP_CNT) { + EPD_2IN13_Sleep(); + } +} + int EPD_SSD_Update(void) { if (epd_mode == EPD_MODE_IMG) { @@ -474,6 +537,11 @@ int EPD_SSD_Update(void) return 0; } + else if (epd_mode == EPD_MODE_BATTCHK) { + EPD_2IN13_BattChecker(); + return 1; + } + EPD_SSD_Update_Clock(); return 1; } diff --git a/src/app/epd_driver.h b/src/app/epd_driver.h index a0721f2..577dc97 100644 --- a/src/app/epd_driver.h +++ b/src/app/epd_driver.h @@ -39,6 +39,7 @@ extern uint16_t epd_battery; // in (3.8) frac, minium value extern uint8_t epd_mode; #define EPD_MODE_CLOCK 0 // realtime clock #define EPD_MODE_IMG 1 // static image +#define EPD_MODE_BATTCHK 2 // battery checker // TBD: split image display to steps in a dirty way. extern uint8_t epd_step; diff --git a/tools/cc2640r2_etag-2in13.html b/tools/cc2640r2_etag-2in13.html index e486514..bb13afb 100644 --- a/tools/cc2640r2_etag-2in13.html +++ b/tools/cc2640r2_etag-2in13.html @@ -156,7 +156,13 @@ break; case 'mode': - await chr.writeValueWithResponse(Uint8Array.from([epdCmd.EPD_CMD_MODE, data == 'image'?0x01:0x00])); + if (data == 'image') { + await chr.writeValueWithResponse(Uint8Array.from([epdCmd.EPD_CMD_MODE, 0x01])); + } else if (data == 'batt') { + await chr.writeValueWithResponse(Uint8Array.from([epdCmd.EPD_CMD_MODE, 0x02])); + } else { + await chr.writeValueWithResponse(Uint8Array.from([epdCmd.EPD_CMD_MODE, 0x00])); + } break; case 'buf': @@ -509,6 +515,7 @@ +