Browse Source

Added battery percentage and low battery indicate

* Raised low framerate to 11hz to get better feeling input latency
* Added question of Odroid-go-firmware license and note that I do use
their code
master
Macoy Madson 3 years ago
parent
commit
dc9bbc452c
  1. 2
      ReadMe.org
  2. 29
      app/src/main.c
  3. 10
      app/src/odroid/battery.c
  4. 1
      app/src/odroid/battery.h

2
ReadMe.org

@ -76,4 +76,4 @@ idf.py -p /dev/ttyUSB0 monitor
* Source
Thanks to [[https://austinmorlan.com/][Austin Morlan]] for his Odroid Go code (MIT license), some of which I have modified. It is kept in Dependencies/embedded-game-programming for reference, but that copy is not used in the app.
I found it much easier to get working than [[https://github.com/OtherCrashOverride/odroid-go-firmware][Odroid-Go-Firmware]] (note: different version of that firmware [[https://github.com/OtherCrashOverride/go-play][here]]).
I found it much easier to get working than [[https://github.com/OtherCrashOverride/odroid-go-firmware][Odroid-Go-Firmware]] (note: different version of that firmware [[https://github.com/OtherCrashOverride/go-play][here]]). I do use modified subsets of Odroid-Go-Firmware (I'm not sure of the license, so it may actually need to be extracted).

29
app/src/main.c

@ -13,7 +13,8 @@
#define ArraySize(array) sizeof((array)) / sizeof((array)[0])
static bool drawBattery = true;
static bool drawBatteryVoltage = false;
static bool drawBatteryPercent = true;
static bool drawTimeSinceBoot = false;
static bool drawFrameRate = true;
@ -201,6 +202,14 @@ void app_main(void)
{
memset(gFramebuffer, palette[0], 320 * 240 * 2);
{
float batteryPercentage = Odroid_ReadBatteryLevelPercentage();
if (batteryPercentage < 15.f)
Odroid_EnableBatteryLight();
else
Odroid_DisableBatteryLight();
}
int64_t currentTimeMicroSecs = esp_timer_get_time();
Odroid_Input input = Odroid_PollInput();
@ -264,11 +273,14 @@ void app_main(void)
{
if (backlightOn)
{
// TODO: Tell LCD driver to enter sleep
// TODO: Use esp light sleep mode
Odroid_BacklightDeinit();
waitForSleepActivateRelease = true;
}
else
Odroid_BacklightInit();
backlightOn = !backlightOn;
}
@ -307,14 +319,20 @@ void app_main(void)
/* } */
// Battery
if (drawBattery)
if (drawBatteryPercent)
{
char string[10];
snprintf(string, ArraySize(string), "B: %d", Odroid_ReadBatteryLevel());
/* snprintf(string, ArraySize(string), "B: %02d", Odroid_ReadBatteryLevel()); */
snprintf(string, ArraySize(string), "B: %.0f", Odroid_ReadBatteryLevelPercentage());
DrawText(gFramebuffer, string, ArraySize(string), 0, 0, palette[3]);
}
if (drawBatteryVoltage)
{
char string[10];
snprintf(string, ArraySize(string), "B: %03d", Odroid_ReadBatteryLevel());
DrawText(gFramebuffer, string, ArraySize(string), 0, 3, palette[3]);
}
// Time since boot
if (drawTimeSinceBoot)
{
@ -374,8 +392,9 @@ void app_main(void)
Odroid_DrawFrame(gFramebuffer);
// Just high enough that button presses feel responsive
if (enableLowFrameRate)
vTaskDelay(25);
vTaskDelay(5);
lastFrameInput = input;
}

10
app/src/odroid/battery.c

@ -61,6 +61,16 @@ uint32_t Odroid_ReadBatteryLevel(void)
return voltage;
}
float Odroid_ReadBatteryLevelPercentage()
{
uint32_t voltage = Odroid_ReadBatteryLevel();
const float FullVoltage = 4.27f;
const float EmptyVoltage = 3.5f;
return ((voltage / 1000.f) - EmptyVoltage) / (FullVoltage - EmptyVoltage) * 100.0f;
}
void Odroid_EnableBatteryLight(void)
{
gpio_set_level(BATTERY_LED_PIN, 1);

1
app/src/odroid/battery.h

@ -5,6 +5,7 @@
void Odroid_InitializeBatteryReader(void);
uint32_t Odroid_ReadBatteryLevel(void);
float Odroid_ReadBatteryLevelPercentage();
void Odroid_EnableBatteryLight(void);
void Odroid_DisableBatteryLight(void);

Loading…
Cancel
Save