Skip to content

Commit

Permalink
feat: update main.cpp for a time demo
Browse files Browse the repository at this point in the history
  • Loading branch information
enzoevers committed Jun 8, 2024
1 parent f9a8388 commit 4bea212
Showing 1 changed file with 58 additions and 11 deletions.
69 changes: 58 additions & 11 deletions Code/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#endif

#if defined(USE_STM32)
#include "DateTimeStm32.h"
#include "DelayStm32.h"
#include "GPIOOutputStm32.h"
#endif
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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];
Expand All @@ -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<Monochrome> 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;
}

0 comments on commit 4bea212

Please sign in to comment.