Skip to content

Commit

Permalink
fix: make display thread safe (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
AJ-Koenig authored Apr 30, 2024
1 parent b433f0e commit 39ee15f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Software/src/ossm/Events.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Error {};

// Definitions to make the table easier to read.
static auto buttonPress = sml::event<ButtonPress>;
static auto doublePress = sml::event<ButtonPress>;
static auto doublePress = sml::event<DoublePress>;
static auto done = sml::event<Done>;
static auto error = sml::event<Error>;

Expand Down
3 changes: 3 additions & 0 deletions Software/src/ossm/OSSM.Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void OSSM::drawMenuTask(void *pvParameters) {
isFirstDraw = false;
currentEncoderValue = ossm->encoder.readEncoder();

displayMutex.lock();
ossm->display.clearBuffer();

// Drawing Variables.
Expand Down Expand Up @@ -124,6 +125,8 @@ void OSSM::drawMenuTask(void *pvParameters) {
}

ossm->display.sendBuffer();
displayMutex.unlock();


vTaskDelay(1);
};
Expand Down
7 changes: 6 additions & 1 deletion Software/src/ossm/OSSM.PlayControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ void OSSM::drawPlayControlsTask(void *pvParameters) {
break;
};


displayMutex.lock();
ossm->display.clearBuffer();
drawStr::title(menuString);
String speedString = UserConfig::language.Speed + ": " +
Expand All @@ -52,6 +54,8 @@ void OSSM::drawPlayControlsTask(void *pvParameters) {
drawStr::multiLine(0, 40, UserConfig::language.SpeedWarning);

ossm->display.sendBuffer();
displayMutex.unlock();

vTaskDelay(100);
} while (isInPreflight(ossm));

Expand Down Expand Up @@ -116,6 +120,7 @@ void OSSM::drawPlayControlsTask(void *pvParameters) {
continue;
}

displayMutex.lock();
ossm->display.clearBuffer();
ossm->display.setFont(Config::Font::base);

Expand Down Expand Up @@ -183,7 +188,7 @@ void OSSM::drawPlayControlsTask(void *pvParameters) {
strokeString.c_str());

ossm->display.sendBuffer();

displayMutex.unlock();
// Saying hi to the watchdog :).
vTaskDelay(200);
}
Expand Down
9 changes: 9 additions & 0 deletions Software/src/ossm/OSSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,37 +64,46 @@ void OSSM::drawHelloTask(void *pvParameters) {
// increment the frame index
frameIdx++;

displayMutex.lock();
ossm->display.clearBuffer();
ossm->display.setFont(u8g2_font_maniac_tf);
ossm->display.drawUTF8(startX, heights[0], "O");
ossm->display.drawUTF8(startX + letterSpacing, heights[1], "S");
ossm->display.drawUTF8(startX + letterSpacing * 2, heights[2], "S");
ossm->display.drawUTF8(startX + letterSpacing * 3, heights[3], "M");
ossm->display.sendBuffer();
displayMutex.unlock();
// Saying hi to the watchdog :).
vTaskDelay(1);
};

// Delay for a second, then show the RDLogo.
vTaskDelay(1500);

displayMutex.lock();
ossm->display.clearBuffer();
drawStr::title("Research and Desire");
ossm->display.drawXBMP(35, 14, 57, 50, Images::RDLogo);
ossm->display.sendBuffer();
displayMutex.unlock();

vTaskDelay(1000);

displayMutex.lock();
ossm->display.clearBuffer();
drawStr::title("Kinky Makers");
ossm->display.drawXBMP(40, 14, 50, 50, Images::KMLogo);
ossm->display.sendBuffer();
displayMutex.unlock();

vTaskDelay(1000);

displayMutex.lock();
ossm->display.clearBuffer();
drawStr::title(UserConfig::language.MeasuringStroke);
ossm->display.drawXBMP(40, 14, 50, 50, Images::KMLogo);
ossm->display.sendBuffer();
displayMutex.unlock();

// delete the task
vTaskDelete(nullptr);
Expand Down
2 changes: 2 additions & 0 deletions Software/src/services/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*
* https://github.com/olikraus/u8g2/wiki/fntlistallplain
*/

static ESP32RecursiveMutex displayMutex;
static U8G2_SSD1306_128X64_NONAME_F_HW_I2C display(U8G2_R0,
Pins::Display::oledReset,
Pins::Remote::displayClock,
Expand Down

0 comments on commit 39ee15f

Please sign in to comment.