From 4bea2126c0571bcad88af9158c6eddcc71f3ac7f Mon Sep 17 00:00:00 2001 From: Enzo Evers Date: Sat, 8 Jun 2024 22:51:55 +0200 Subject: [PATCH] feat: update main.cpp for a time demo --- Code/main.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/Code/main.cpp b/Code/main.cpp index 9d50ffe..0459070 100644 --- a/Code/main.cpp +++ b/Code/main.cpp @@ -10,6 +10,7 @@ #endif #if defined(USE_STM32) +#include "DateTimeStm32.h" #include "DelayStm32.h" #include "GPIOOutputStm32.h" #endif @@ -47,9 +48,24 @@ int main() { latch.SetupConfiguration({&GPIOD->ODR, GPIO_ODR_14}); ledOE.SetupConfiguration({&GPIOD->ODR, GPIO_ODR_15}); } + uint32_t tim3Hertz = 40000000; auto mainDelay = DelayStm32(); mainDelay.SetupConfiguration({&TIM3->SR, &TIM3->ARR, &TIM3->CR1, &TIM3->PSC, tim3Hertz, TIM_SR_UIF, TIM_CR1_CEN}); + + auto dateTime = DateTimeStm32(); + dateTime.SetConfig({.PWR_CR = &PWR->CR, + .RTC_WPR = &RTC->WPR, + .RTC_ISR = &RTC->ISR, + .RTC_CR = &RTC->CR, + .RTC_TR = &RTC->TR, + .RTC_DR = &RTC->DR, + .RTC_SSR = &RTC->SSR, + .PWR_CR_DBP_pos = PWR_CR_DBP_Pos, + .RTC_ISR_INIT_pos = RTC_ISR_INIT_Pos, + .RTC_ISR_INITF_pos = RTC_ISR_INITF_Pos, + .RTC_CR_FMF_pos = RTC_CR_FMT_Pos}); + #endif #if defined(USE_DESKTOP) @@ -80,11 +96,9 @@ int main() { hanoverOL037A.SetGPIOInterface(hanoverOL037A_GPIOInterface); hanoverOL037A.SetDelayManager(&mainDelay); - // Clear the display - // hanoverOL037A.UpdateDisplay(); - auto textBmhFormat = TextBmhFormat(); textBmhFormat.SetFont(&Bitstream_Vera_Sans_Mono_12::font_data); + std::string text = "Hello World!"; const auto pixelAreaSize = textBmhFormat.GetRequiredSizeString(text, 1); Monochrome pixelAreaData[pixelAreaSize.x * pixelAreaSize.y]; @@ -96,15 +110,48 @@ int main() { hanoverOL037A.SetArea({10, 0}, pixelArea); hanoverOL037A.UpdateDisplay(); - // hanoverOL037A.SetPixel({0, 0}, 1); - // hanoverOL037A.SetPixel({39, 0}, 1); - // hanoverOL037A.SetPixel({0, 7}, 1); - // hanoverOL037A.SetPixel({39, 7}, 1); + mainDelay.SynchronousWait_us(1000000); - // for (auto y = 0; y < 19; y++) { - // hanoverOL037A.SetPixel({7, y}, 1); - // } - // hanoverOL037A.UpdateDisplay(); + // Reset display + std::memset(pixelAreaData, 0, sizeof(pixelAreaData)); + hanoverOL037A.SetArea({10, 0}, pixelArea); + hanoverOL037A.UpdateDisplay(); + + dateTime.SetDateTime({ + .time = {.hours = 14, .minutes = 4, .seconds = 25, .milliseconds = 0}, + .date = {.year = 2021, .month = 9, .day = 1, .weekday = Weekday::Wednesday}, + }); + + const auto screenResolution = hanoverOL037A.GetResolution(); + DateTime lastDateTime; + while (true) { + auto currentDateTime = dateTime.GetDateTime(); + if (currentDateTime == lastDateTime) { + continue; + } + lastDateTime = currentDateTime; + + char timeTextBuffer[13]; + std::snprintf(&timeTextBuffer[0], sizeof(timeTextBuffer), "%.2u : %.2u : %.2u", currentDateTime.time.hours, + currentDateTime.time.minutes, currentDateTime.time.seconds); + + const auto pixelAreaSize = textBmhFormat.GetRequiredSizeString(timeTextBuffer, 1); + Monochrome pixelAreaData[pixelAreaSize.x * pixelAreaSize.y]; + std::memset(pixelAreaData, 0, sizeof(pixelAreaData)); + PixelArea pixelArea{pixelAreaSize, pixelAreaData}; + Vec2D offset{0, 0}; + textBmhFormat.SetString(timeTextBuffer, 1, offset, pixelArea); + + hanoverOL037A.SetArea({5, 0}, pixelArea); + hanoverOL037A.UpdateDisplay(); + + // Clear all screen pixels + for (auto y = 0; y < screenResolution.y; ++y) { + for (auto x = 0; x < screenResolution.x; ++x) { + hanoverOL037A.SetPixel({x, y}, 0); + } + } + } return 0; } \ No newline at end of file