|
|
@ -13,13 +13,20 @@ |
|
|
|
|
|
|
|
#define ArraySize(array) sizeof((array)) / sizeof((array)[0]) |
|
|
|
|
|
|
|
static const char* LOG_TAG = "Main"; |
|
|
|
static uint16_t gFramebuffer[LCD_WIDTH * LCD_HEIGHT]; |
|
|
|
|
|
|
|
static bool drawBattery = true; |
|
|
|
static bool drawTimeSinceBoot = true; |
|
|
|
static bool drawTimeSinceBoot = false; |
|
|
|
static bool drawFrameRate = true; |
|
|
|
|
|
|
|
/* static bool printInput = true; */ |
|
|
|
static bool printInput = false; |
|
|
|
|
|
|
|
static bool enableLowFrameRate = true; |
|
|
|
|
|
|
|
static int64_t autoSleepModeMicroseconds = 10 * 1000000; |
|
|
|
|
|
|
|
static const char* LOG_TAG = "Main"; |
|
|
|
static uint16_t gFramebuffer[LCD_WIDTH * LCD_HEIGHT]; |
|
|
|
|
|
|
|
/* static const uint16_t lightPalette[4] = */ |
|
|
|
/* { */ |
|
|
|
/* 0xFFFF, */ |
|
|
@ -28,7 +35,7 @@ static bool drawFrameRate = true; |
|
|
|
/* 0x0000, */ |
|
|
|
/* }; */ |
|
|
|
|
|
|
|
static const uint16_t palette[4] = |
|
|
|
static const uint16_t darkPalette[4] = |
|
|
|
{ |
|
|
|
0x0000, |
|
|
|
0xAA52, |
|
|
@ -36,6 +43,8 @@ static const uint16_t palette[4] = |
|
|
|
0xFFFF, |
|
|
|
}; |
|
|
|
|
|
|
|
static const uint16_t* palette = darkPalette; |
|
|
|
|
|
|
|
static const uint8_t tiles[][16*16] = |
|
|
|
{ |
|
|
|
// White
|
|
|
@ -138,7 +147,6 @@ static int tileBuffer[15][40] = |
|
|
|
{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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void DrawTile(int index, int x, int y) |
|
|
|
{ |
|
|
|
int startX = x * 16; |
|
|
@ -160,29 +168,109 @@ void DrawTile(int index, int x, int y) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void app_main(void) |
|
|
|
{ |
|
|
|
Odroid_InitializeInput(); |
|
|
|
Odroid_InitializeDisplay(); |
|
|
|
// Does not work for me yet
|
|
|
|
/* Odroid_InitializeSdcard(); */ |
|
|
|
Odroid_InitializeBatteryReader(); |
|
|
|
/* Odroid_InitializeAudio(); */ |
|
|
|
|
|
|
|
ESP_LOGI(LOG_TAG, "Odroid initialization complete - entering main loop"); |
|
|
|
|
|
|
|
/* uint8_t frameIndex = 0; */ |
|
|
|
/* char snapFilename[20]; */ |
|
|
|
/* int xLeft = 0; */ |
|
|
|
|
|
|
|
uint8_t frameIndex = 0; |
|
|
|
char snapFilename[20]; |
|
|
|
int xLeft = 0; |
|
|
|
bool timerRunning = false; |
|
|
|
int64_t timerStartMicroSecs = 0; |
|
|
|
// Includes timings before pause, not current timing
|
|
|
|
int64_t timerTotalMicroSecsPrePause = 0; |
|
|
|
|
|
|
|
int64_t lastFrameTimeMicroSecs = esp_timer_get_time(); |
|
|
|
|
|
|
|
for (;;) |
|
|
|
int64_t timeSinceLastInputMicroSecs = esp_timer_get_time(); |
|
|
|
|
|
|
|
Odroid_Input lastFrameInput = {0}; |
|
|
|
|
|
|
|
bool backlightOn = true; |
|
|
|
bool waitForSleepActivateRelease = false; |
|
|
|
|
|
|
|
while (true) |
|
|
|
{ |
|
|
|
memset(gFramebuffer, palette[0], 320*240*2); |
|
|
|
memset(gFramebuffer, palette[0], 320 * 240 * 2); |
|
|
|
|
|
|
|
int64_t currentTimeMicroSecs = esp_timer_get_time(); |
|
|
|
|
|
|
|
Odroid_Input input = Odroid_PollInput(); |
|
|
|
bool hasInputsThisFrame = Odroid_HasAnyInput(&input); |
|
|
|
if (hasInputsThisFrame) |
|
|
|
timeSinceLastInputMicroSecs = esp_timer_get_time(); |
|
|
|
|
|
|
|
if (printInput) |
|
|
|
Odroid_PrintInputState(&input); |
|
|
|
|
|
|
|
// Sleep mode
|
|
|
|
if (!backlightOn) |
|
|
|
{ |
|
|
|
if (!waitForSleepActivateRelease && hasInputsThisFrame) |
|
|
|
{ |
|
|
|
Odroid_BacklightInit(); |
|
|
|
backlightOn = true; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if (!input.b) |
|
|
|
waitForSleepActivateRelease = false; |
|
|
|
|
|
|
|
// Try to save battery while still listening to inputs
|
|
|
|
// TODO: Use the ESP sleep modes
|
|
|
|
vTaskDelay(250); |
|
|
|
|
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (input.a && !lastFrameInput.a) |
|
|
|
{ |
|
|
|
printf("Pause timer\n"); |
|
|
|
timerRunning = !timerRunning; |
|
|
|
|
|
|
|
if (timerRunning) |
|
|
|
timerStartMicroSecs = currentTimeMicroSecs; |
|
|
|
else |
|
|
|
timerTotalMicroSecsPrePause += currentTimeMicroSecs - timerStartMicroSecs; |
|
|
|
|
|
|
|
/* esp_err_t err = ledc_stop(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0); */ |
|
|
|
/* if (err != ESP_OK) */ |
|
|
|
/* { */ |
|
|
|
/* printf("%s: ledc_stop failed.\n", __func__); */ |
|
|
|
/* } */ |
|
|
|
} |
|
|
|
|
|
|
|
if (input.start && !lastFrameInput.start) |
|
|
|
{ |
|
|
|
printf("Reset timer\n"); |
|
|
|
|
|
|
|
timerRunning = false; |
|
|
|
timerTotalMicroSecsPrePause = 0; |
|
|
|
} |
|
|
|
|
|
|
|
bool sleepModeActivate = |
|
|
|
currentTimeMicroSecs - timeSinceLastInputMicroSecs > autoSleepModeMicroseconds || |
|
|
|
(input.b && !lastFrameInput.b); |
|
|
|
if (sleepModeActivate) |
|
|
|
{ |
|
|
|
if (backlightOn) |
|
|
|
{ |
|
|
|
Odroid_BacklightDeinit(); |
|
|
|
waitForSleepActivateRelease = true; |
|
|
|
} |
|
|
|
else |
|
|
|
Odroid_BacklightInit(); |
|
|
|
backlightOn = !backlightOn; |
|
|
|
} |
|
|
|
|
|
|
|
// Movement
|
|
|
|
/* if (input.left) */ |
|
|
@ -222,7 +310,7 @@ void app_main(void) |
|
|
|
if (drawBattery) |
|
|
|
{ |
|
|
|
char string[10]; |
|
|
|
snprintf(string, ArraySize(string), "B: %02d", Odroid_ReadBatteryLevel()); |
|
|
|
snprintf(string, ArraySize(string), "B: %d", Odroid_ReadBatteryLevel()); |
|
|
|
/* snprintf(string, ArraySize(string), "B: %02d", Odroid_ReadBatteryLevel()); */ |
|
|
|
DrawText(gFramebuffer, string, ArraySize(string), 0, 0, palette[3]); |
|
|
|
} |
|
|
@ -247,6 +335,26 @@ void app_main(void) |
|
|
|
lastFrameTimeMicroSecs = currentTimeMicroSecs; |
|
|
|
} |
|
|
|
|
|
|
|
// Timer
|
|
|
|
{ |
|
|
|
char string[18]; |
|
|
|
int64_t currentTimeMicroSecs = esp_timer_get_time(); |
|
|
|
float timerSeconds = |
|
|
|
timerRunning ? |
|
|
|
((timerTotalMicroSecsPrePause + (currentTimeMicroSecs - timerStartMicroSecs)) / |
|
|
|
1000000.f) : |
|
|
|
timerTotalMicroSecsPrePause / 1000000.f; |
|
|
|
snprintf(string, ArraySize(string), "%d:%.2d", (int)timerSeconds / 60, |
|
|
|
(int)timerSeconds % 60); |
|
|
|
DrawText(gFramebuffer, string, ArraySize(string), 3, 5, palette[3]); |
|
|
|
|
|
|
|
if (!timerRunning) |
|
|
|
{ |
|
|
|
snprintf(string, ArraySize(string), "Paused"); |
|
|
|
DrawText(gFramebuffer, string, ArraySize(string), 3, 6, palette[3]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// Save screenshots for making gifs
|
|
|
|
/* if (input.menu) */ |
|
|
|
/* { */ |
|
|
@ -264,11 +372,14 @@ void app_main(void) |
|
|
|
/* ++frameIndex; */ |
|
|
|
/* } */ |
|
|
|
|
|
|
|
|
|
|
|
Odroid_DrawFrame(gFramebuffer); |
|
|
|
|
|
|
|
if (enableLowFrameRate) |
|
|
|
vTaskDelay(25); |
|
|
|
|
|
|
|
lastFrameInput = input; |
|
|
|
} |
|
|
|
|
|
|
|
// Should never get here
|
|
|
|
esp_restart(); |
|
|
|
} |
|
|
|
|
|
|
|