uv-k5-firmware-custom/ui/battery.c

57 lines
1.6 KiB
C
Raw Normal View History

2023-09-09 07:03:56 +00:00
/* Copyright 2023 Dual Tachyon
* https://github.com/DualTachyon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stddef.h>
#include <string.h>
2023-09-09 07:03:56 +00:00
#include "bitmaps.h"
#include "driver/st7565.h"
#include "functions.h"
#include "ui/battery.h"
2023-10-09 14:30:20 +00:00
void UI_DrawBattery(uint8_t* bitmap, uint8_t level, uint8_t blink)
2023-09-09 07:03:56 +00:00
{
2023-10-09 23:37:29 +00:00
if (level < 2 && blink == 1) {
memset(bitmap, 0, sizeof(BITMAP_BatteryLevel1));
}
else
2023-10-09 14:30:20 +00:00
{
2023-10-09 23:37:29 +00:00
memmove(bitmap, BITMAP_BatteryLevel1, sizeof(BITMAP_BatteryLevel1));
2023-11-02 01:44:05 +00:00
if (level > 2)
2023-09-09 07:03:56 +00:00
{
2023-10-09 23:37:29 +00:00
unsigned int i;
2023-11-02 01:44:05 +00:00
uint8_t bars = level - 2;
2023-10-09 23:37:29 +00:00
if (bars > 4)
bars = 4;
for (i = 0; i < bars; i++)
{
#ifndef ENABLE_REVERSE_BAT_SYMBOL
memcpy(bitmap + sizeof(BITMAP_BatteryLevel1) - 4 - (i * 3), BITMAP_BatteryLevel, 2);
#else
memcpy(bitmap + 3 + (i * 3) + 0, BITMAP_BatteryLevel, 2);
#endif
}
2023-09-09 07:03:56 +00:00
}
2023-10-09 14:30:20 +00:00
}
}
2023-10-09 14:30:20 +00:00
void UI_DisplayBattery(uint8_t level, uint8_t blink)
{
2023-10-09 23:37:29 +00:00
uint8_t bitmap[sizeof(BITMAP_BatteryLevel1)];
UI_DrawBattery(bitmap, level, blink);
ST7565_DrawLine(LCD_WIDTH - sizeof(bitmap), 0, sizeof(bitmap), bitmap);
2023-09-09 07:03:56 +00:00
}