A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Avoid leaving screens mid-display update

Was leave the EPD in a bad state, blocking further actions

+24 -13
+13 -12
src/screens/EpubReaderScreen.cpp
··· 18 18 return; 19 19 } 20 20 21 - sectionMutex = xSemaphoreCreateMutex(); 21 + renderingMutex = xSemaphoreCreateMutex(); 22 22 23 23 epub->setupCacheDir(); 24 24 ··· 45 45 } 46 46 47 47 void EpubReaderScreen::onExit() { 48 - xSemaphoreTake(sectionMutex, portMAX_DELAY); 48 + // Wait until not rendering to delete task to avoid killing mid-instruction to EPD 49 + xSemaphoreTake(renderingMutex, portMAX_DELAY); 49 50 if (displayTaskHandle) { 50 51 vTaskDelete(displayTaskHandle); 51 52 displayTaskHandle = nullptr; 52 53 } 53 - vSemaphoreDelete(sectionMutex); 54 - sectionMutex = nullptr; 54 + vSemaphoreDelete(renderingMutex); 55 + renderingMutex = nullptr; 55 56 delete section; 56 57 section = nullptr; 57 58 delete epub; ··· 82 83 if (section->currentPage > 0) { 83 84 section->currentPage--; 84 85 } else { 85 - xSemaphoreTake(sectionMutex, portMAX_DELAY); 86 + // We don't want to delete the section mid-render, so grab the semaphore 87 + xSemaphoreTake(renderingMutex, portMAX_DELAY); 86 88 nextPageNumber = UINT16_MAX; 87 89 currentSpineIndex--; 88 90 delete section; 89 91 section = nullptr; 90 - xSemaphoreGive(sectionMutex); 92 + xSemaphoreGive(renderingMutex); 91 93 } 92 94 } else if (input.button == VOLUME_DOWN || input.button == RIGHT) { 93 95 if (section->currentPage < section->pageCount - 1) { 94 96 section->currentPage++; 95 97 } else { 96 - xSemaphoreTake(sectionMutex, portMAX_DELAY); 98 + // We don't want to delete the section mid-render, so grab the semaphore 99 + xSemaphoreTake(renderingMutex, portMAX_DELAY); 97 100 nextPageNumber = 0; 98 101 currentSpineIndex++; 99 102 delete section; 100 103 section = nullptr; 101 - xSemaphoreGive(sectionMutex); 104 + xSemaphoreGive(renderingMutex); 102 105 } 103 106 } 104 107 ··· 112 115 while (true) { 113 116 if (updateRequired) { 114 117 updateRequired = false; 118 + xSemaphoreTake(renderingMutex, portMAX_DELAY); 115 119 renderPage(); 120 + xSemaphoreGive(renderingMutex); 116 121 } 117 122 vTaskDelay(10 / portTICK_PERIOD_MS); 118 123 } ··· 127 132 currentSpineIndex = 0; 128 133 } 129 134 130 - xSemaphoreTake(sectionMutex, portMAX_DELAY); 131 135 if (!section) { 132 136 const auto filepath = epub->getSpineItem(currentSpineIndex); 133 137 Serial.printf("Loading file: %s, index: %d\n", filepath.c_str(), currentSpineIndex); ··· 153 157 Serial.println("Failed to persist page data to SD"); 154 158 delete section; 155 159 section = nullptr; 156 - xSemaphoreGive(sectionMutex); 157 160 return; 158 161 } 159 162 } else { ··· 186 189 data[3] = (section->currentPage >> 8) & 0xFF; 187 190 f.write(data, 4); 188 191 f.close(); 189 - 190 - xSemaphoreGive(sectionMutex); 191 192 } 192 193 193 194 void EpubReaderScreen::renderStatusBar() const {
+1 -1
src/screens/EpubReaderScreen.h
··· 11 11 Epub* epub; 12 12 Section* section = nullptr; 13 13 TaskHandle_t displayTaskHandle = nullptr; 14 - SemaphoreHandle_t sectionMutex = nullptr; 14 + SemaphoreHandle_t renderingMutex = nullptr; 15 15 int currentSpineIndex = 0; 16 16 int nextPageNumber = 0; 17 17 int pagesUntilFullRefresh = 0;
+8
src/screens/FileSelectionScreen.cpp
··· 30 30 } 31 31 32 32 void FileSelectionScreen::onEnter() { 33 + renderingMutex = xSemaphoreCreateMutex(); 34 + 33 35 basepath = "/"; 34 36 loadFiles(); 35 37 selectorIndex = 0; ··· 46 48 } 47 49 48 50 void FileSelectionScreen::onExit() { 51 + // Wait until not rendering to delete task to avoid killing mid-instruction to EPD 52 + xSemaphoreTake(renderingMutex, portMAX_DELAY); 49 53 if (displayTaskHandle) { 50 54 vTaskDelete(displayTaskHandle); 51 55 displayTaskHandle = nullptr; 52 56 } 57 + vSemaphoreDelete(renderingMutex); 58 + renderingMutex = nullptr; 53 59 files.clear(); 54 60 } 55 61 ··· 85 91 while (true) { 86 92 if (updateRequired) { 87 93 updateRequired = false; 94 + xSemaphoreTake(renderingMutex, portMAX_DELAY); 88 95 render(); 96 + xSemaphoreGive(renderingMutex); 89 97 } 90 98 vTaskDelay(10 / portTICK_PERIOD_MS); 91 99 }
+2
src/screens/FileSelectionScreen.h
··· 1 1 #pragma once 2 2 #include <freertos/FreeRTOS.h> 3 3 #include <freertos/task.h> 4 + #include <freertos/semphr.h> 4 5 5 6 #include <functional> 6 7 #include <string> ··· 10 11 11 12 class FileSelectionScreen final : public Screen { 12 13 TaskHandle_t displayTaskHandle = nullptr; 14 + SemaphoreHandle_t renderingMutex = nullptr; 13 15 std::string basepath = "/"; 14 16 std::vector<std::string> files; 15 17 int selectorIndex = 0;