mirror of
https://github.com/goodtft/LCD-show.git
synced 2024-12-05 02:24:12 +01:00
80 lines
3.9 KiB
C++
80 lines
3.9 KiB
C++
|
#include <string.h>
|
||
|
|
||
|
#include "config.h"
|
||
|
#include "low_battery.h"
|
||
|
#include "gpu.h"
|
||
|
#include "spi.h"
|
||
|
|
||
|
#ifdef LOW_BATTERY_PIN
|
||
|
|
||
|
#define LOW_BATTERY_ICON_TOP_LEFT_X 10
|
||
|
#define LOW_BATTERY_ICON_TOP_LEFT_Y 10
|
||
|
#define LOW_BATTERY_ICON_WIDTH 35
|
||
|
#define LOW_BATTERY_ICON_HEIGHT 20
|
||
|
#define LOW_BATTERY_FORE_COLOR 65535
|
||
|
#define LOW_BATTERY_BACK_COLOR 0
|
||
|
|
||
|
static bool lowBattery = false;
|
||
|
static uint64_t lowBatteryLastPolled = 0;
|
||
|
|
||
|
// Battery icon from: https://github.com/martinohanlon/grrl-bat-monitor
|
||
|
static uint16_t lowBatteryIcon [LOW_BATTERY_ICON_HEIGHT][LOW_BATTERY_ICON_WIDTH] = {
|
||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||
|
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
|
||
|
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
|
||
|
{0, 0, 1, 1, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0},
|
||
|
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0},
|
||
|
{0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0},
|
||
|
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
|
||
|
{0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
|
||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
|
||
|
|
||
|
|
||
|
void InitLowBatterySystem()
|
||
|
{
|
||
|
for(int y = 0; y < LOW_BATTERY_ICON_HEIGHT; ++y)
|
||
|
for(int x = 0; x < LOW_BATTERY_ICON_WIDTH; ++x)
|
||
|
lowBatteryIcon[y][x] = lowBatteryIcon[y][x] ? LOW_BATTERY_FORE_COLOR : LOW_BATTERY_BACK_COLOR;
|
||
|
PollLowBattery();
|
||
|
}
|
||
|
|
||
|
void PollLowBattery()
|
||
|
{
|
||
|
uint64_t now = tick();
|
||
|
if (now - lowBatteryLastPolled > LOW_BATTERY_POLLING_INTERVAL)
|
||
|
{
|
||
|
lowBattery = GET_GPIO(LOW_BATTERY_PIN) ? LOW_BATTERY_IS_ACTIVE_HIGH : !LOW_BATTERY_IS_ACTIVE_HIGH;
|
||
|
lowBatteryLastPolled = now;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void DrawLowBatteryIcon(uint16_t *framebuffer)
|
||
|
{
|
||
|
if (!lowBattery)
|
||
|
return;
|
||
|
|
||
|
for(int y = 0; y < LOW_BATTERY_ICON_HEIGHT; ++y)
|
||
|
{
|
||
|
int framebuffer_start_offset = (LOW_BATTERY_ICON_TOP_LEFT_Y+y)*(gpuFramebufferScanlineStrideBytes>>1)+LOW_BATTERY_ICON_TOP_LEFT_X;
|
||
|
memcpy(framebuffer+framebuffer_start_offset, lowBatteryIcon[y], LOW_BATTERY_ICON_WIDTH*2);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#else
|
||
|
|
||
|
void InitLowBatterySystem() {}
|
||
|
void PollLowBattery() {}
|
||
|
void DrawLowBatteryIcon(uint16_t *framebuffer) {}
|
||
|
|
||
|
#endif
|