update voltage display

This commit is contained in:
Shuanglei Tao
2025-12-27 15:35:14 +08:00
parent f3d2f0aa8d
commit 2986d06100
5 changed files with 22 additions and 8 deletions

View File

@@ -244,7 +244,7 @@ void EPD_LED_BLINK(void) {
} }
} }
float EPD_ReadVoltage(void) { uint16_t EPD_ReadVoltage(void) {
#if defined(S112) #if defined(S112)
volatile int16_t value = 0; volatile int16_t value = 0;
NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL_10bit; NRF_SAADC->RESOLUTION = SAADC_RESOLUTION_VAL_10bit;
@@ -286,7 +286,7 @@ float EPD_ReadVoltage(void) {
NRF_ADC->ENABLE = 0; NRF_ADC->ENABLE = 0;
#endif #endif
NRF_LOG_DEBUG("ADC value: %d\n", value); NRF_LOG_DEBUG("ADC value: %d\n", value);
return (value * 3.6) / (1 << 10); return (value * 3600) / (1 << 10);
} }
// EPD models // EPD models

View File

@@ -218,7 +218,7 @@ void EPD_LED_Toggle(void);
void EPD_LED_BLINK(void); void EPD_LED_BLINK(void);
// VDD voltage // VDD voltage
float EPD_ReadVoltage(void); uint16_t EPD_ReadVoltage(void);
epd_model_t* epd_init(epd_model_id_t id); epd_model_t* epd_init(epd_model_id_t id);

View File

@@ -129,12 +129,26 @@ static void DrawTimeSyncTip(Adafruit_GFX* gfx, gui_data_t* data) {
GFX_printf(gfx, url); GFX_printf(gfx, url);
} }
static void DrawBattery(Adafruit_GFX* gfx, int16_t x, int16_t y, uint8_t iw, float voltage) { static uint8_t batt_cal(uint16_t voltage) {
uint16_t adc_sample = (voltage * 2047) / 3600;
if (adc_sample > 1705)
return 100;
else if (adc_sample <= 1705 && adc_sample > 1584)
return 28 + (uint8_t)(((((adc_sample - 1584) << 16) / (1705 - 1584)) * 72) >> 16);
else if (adc_sample <= 1584 && adc_sample > 1360)
return 4 + (uint8_t)(((((adc_sample - 1360) << 16) / (1584 - 1360)) * 24) >> 16);
else if (adc_sample <= 1360 && adc_sample > 1136)
return (uint8_t)(((((adc_sample - 1136) << 16) / (1360 - 1136)) * 4) >> 16);
else
return 0;
}
static void DrawBattery(Adafruit_GFX* gfx, int16_t x, int16_t y, uint8_t iw, uint16_t voltage) {
x -= iw; x -= iw;
uint8_t level = (uint8_t)(voltage * 100 / 3.6f); uint8_t level = batt_cal(voltage);
GFX_setFont(gfx, u8g2_font_wqy9_t_lunar); GFX_setFont(gfx, u8g2_font_wqy9_t_lunar);
GFX_setCursor(gfx, x - GFX_getUTF8Width(gfx, "3.2V") - 2, y + 9); GFX_setCursor(gfx, x - GFX_getUTF8Width(gfx, "3.2V") - 2, y + 9);
GFX_printf(gfx, "%.1fV", voltage); GFX_printf(gfx, "%d.%dV", voltage / 1000, (voltage % 1000) / 100);
GFX_fillRect(gfx, x, y, iw, 10, GFX_WHITE); GFX_fillRect(gfx, x, y, iw, 10, GFX_WHITE);
GFX_drawRect(gfx, x, y, iw, 10, GFX_BLACK); GFX_drawRect(gfx, x, y, iw, 10, GFX_BLACK);
GFX_fillRect(gfx, x + iw, y + 4, 2, 2, GFX_BLACK); GFX_fillRect(gfx, x + iw, y + 4, 2, 2, GFX_BLACK);

View File

@@ -17,7 +17,7 @@ typedef struct {
uint32_t timestamp; uint32_t timestamp;
uint8_t week_start; // 0: Sunday, 1: Monday uint8_t week_start; // 0: Sunday, 1: Monday
int8_t temperature; int8_t temperature;
float voltage; uint16_t voltage;
char ssid[20]; char ssid[20];
} gui_data_t; } gui_data_t;

View File

@@ -225,7 +225,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
.timestamp = g_display_time, .timestamp = g_display_time,
.week_start = g_week_start, .week_start = g_week_start,
.temperature = 25, .temperature = 25,
.voltage = 3.2f, .voltage = 2920,
.ssid = "NRF_EPD_84AC", .ssid = "NRF_EPD_84AC",
}; };