diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/storm700.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/storm700.c index 2916dc3..c8936d7 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/storm700.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/storm700.c @@ -79,6 +79,7 @@ ErrorStatus Storm700_construct(struct Storm700* self, const struct IODevice* dev KeyboardDevice_construct(&self->keyboardDevice, &kbParameters, read); self->initialized = true; + } } diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c index 767597d..b72f77c 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/src/oli_stm32_h107.c @@ -805,6 +805,11 @@ static ErrorStatus initPlatformDevices (void) MAX5715_writePOWER_NORMAL(max5715, MAX5715_SEL_DACA | MAX5715_SEL_DACB | MAX5715_SEL_DACC); // Set external DAC LATCH mode off for channels A, B, C MAX5715_writeCONFIG_LATCH_OFF(max5715, MAX5715_SEL_DACA | MAX5715_SEL_DACB | MAX5715_SEL_DACC); + + // Set output voltage to 0 + MAX5715Channel_setValue(&max5715->dac[0], 0); + MAX5715Channel_setValue(&max5715->dac[1], 0); + MAX5715Channel_setValue(&max5715->dac[2], 0); } else if (PCBA_getInstance()->pcba == Tesla) { @@ -815,6 +820,9 @@ static ErrorStatus initPlatformDevices (void) MAX5715_writePOWER_NORMAL(max5715, MAX5715_SEL_DACB); // Set external DAC LATCH mode off for channels B MAX5715_writeCONFIG_LATCH_OFF(max5715, MAX5715_SEL_DACB); + + // Set output voltage to 0 + MAX5715Channel_setValue(&max5715->dac[1], 0); } } diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairMenu.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairMenu.h index 8158455..d899ffc 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairMenu.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairMenu.h @@ -38,6 +38,12 @@ #include "semphr.h" #include "stm32f10x.h" +#include "repairPreset.h" +#include "repairProcess.h" + +#include "keypadMatrix.h" +#include "Observable.h" +#include "rtc.h" // ----------------------------------------------------------------------------- // Constant and macro definitions @@ -51,10 +57,17 @@ + typedef enum { - MAINMENU, - REPAIRMENU + MAINMENU = 0, + REPAIRMENU, + ADMINMENU, + CALIBRATIONMENU, + PRESETMENU, + START_REPAIR, + NO_MENU, + NUMBER_OF_MENUS } T_MenuState; struct RepairMenu @@ -66,7 +79,14 @@ struct RepairMenu SemaphoreHandle_t secondsSyncronisation; bool initialized; struct Display* display; + struct KeyboardDevice* keyboardDevice; T_MenuState menuState; + Keypad_KeyState keyStateTrigger; + int cursorIndex; + int scrollOffset; + struct RepairProcess repairProcess; + const struct RepairPreset* repairPreset; + struct RepairProcessParameters rpParameters; }; // ----------------------------------------------------------------------------- @@ -80,15 +100,17 @@ struct RepairMenu * * @param self * @param display + * @param keyboardDevice * @param taskPriority * @param stackSize + * @param keyStateTrigger * * @return ErrorStatus * * @todo * ----------------------------------------------------------------------------- */ -extern ErrorStatus repairMenu_construct(struct RepairMenu* self, struct Display* display, int taskPriority, uint16_t stackSize); +extern ErrorStatus repairMenu_construct(struct RepairMenu* self, struct Display* display, struct KeyboardDevice* keyboardDevice, int taskPriority, uint16_t stackSize, Keypad_KeyState keyStateTrigger); /** ---------------------------------------------------------------------------- diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairProcess.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairProcess.h index c8a8f11..88f9cac 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairProcess.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/repairProcess.h @@ -104,6 +104,8 @@ struct RepairProcess * Description of function * * @param self The process object + * @param parameters + * @param preset * @param taskPriority Task priority for the repair process * @param stackSize Stacksize of the task * @@ -113,7 +115,7 @@ struct RepairProcess * @todo * ----------------------------------------------------------------------------- */ -extern ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairProcessParameters* parameters, int taskPriority, uint16_t stackSize); +extern ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairProcessParameters* parameters, const struct RepairPreset* preset, int taskPriority, uint16_t stackSize); /** ---------------------------------------------------------------------------- diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c index 9332be6..7fc7af1 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Display.c @@ -56,7 +56,8 @@ static void DisplayTask(void* parameters); inline static void Display_characterUpdate (struct DisplayCharacter* displayCharacter, char character); inline static bool Display_isCharacterUpdated (struct DisplayCharacter* displayCharacter); inline static char Display_getUpdatedCharacter (struct DisplayCharacter* displayCharacter); -static void Display_characterUpdateAll(struct Display* self); +inline static void Display_characterUpdateAll(struct Display* self); +inline static void Display_clearShadow(struct Display* self); // ----------------------------------------------------------------------------- // Function definitions @@ -86,16 +87,7 @@ ErrorStatus Display_construct(struct Display* self, struct DisplayDevice* displa vSemaphoreCreateBinary(self->displayWriteRequest); - // Clear the display shadow - size_t rowCounter; - size_t colCounter; - for (rowCounter = 0; rowCounter < self->displayDevice->parameters.numberOfRows; rowCounter++) - { - for (colCounter = 0; colCounter < self->displayDevice->parameters.numberOfColumns; colCounter++) - { - Display_characterUpdate(&self->displayShadow[rowCounter][colCounter], 0x20); - } - } + Display_clearShadow(self); } self->runTask = true; @@ -132,6 +124,7 @@ void Display_destruct(struct Display* self) ErrorStatus Display_clearScreen(struct Display* self) { + Display_clearShadow(self); return DisplayDevice_clear(self->displayDevice); } @@ -260,7 +253,7 @@ inline static char Display_getUpdatedCharacter (struct DisplayCharacter* display } -static void Display_characterUpdateAll(struct Display* self) +inline static void Display_characterUpdateAll(struct Display* self) { size_t rowCounter; size_t colCounter; @@ -281,6 +274,23 @@ static void Display_characterUpdateAll(struct Display* self) } +inline static void Display_clearShadow(struct Display* self) +{ + // Clear the display shadow + size_t rowCounter; + size_t colCounter; + char buffer[self->displayDevice->parameters.numberOfColumns]; + for (rowCounter = 0; rowCounter < self->displayDevice->parameters.numberOfRows; rowCounter++) + { + for (colCounter = 0; colCounter < self->displayDevice->parameters.numberOfColumns; colCounter++) + { + buffer[colCounter] = 0x20; + } + Display_write(self, buffer, self->displayDevice->parameters.numberOfColumns, rowCounter + 1, 1); + } +} + + static void DisplayTask(void* parameters) { struct Display* self = (struct Display*)parameters; @@ -386,7 +396,7 @@ static void DisplayTask(void* parameters) Display_characterUpdateAll(self); } - vTaskDelay(10); +// vTaskDelay(10); } vTaskDelay(10); diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c index bceaaf9..2b060df 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/main.c @@ -95,8 +95,6 @@ static xTaskHandle sysTaskHandle; static struct HwValidationMenu _hwValidation = {.initialized = false}; static struct HwValidationMenuItems hwTestItems; - - struct HwValidationMenu* hwValidation = &_hwValidation; @@ -221,11 +219,14 @@ static void initTask(void* parameters) // Construct the repair menu repairMenus_construct(); + + GPIO_setValue(power6v5Enable, false); + // Delete this init task vTaskDelete(NULL); - } + static void ledBlinkTask (void* parameters) { char high = 1; diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenu.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenu.c index b18dc2e..5867f39 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenu.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenu.c @@ -44,23 +44,72 @@ // Constant and macro definitions // ----------------------------------------------------------------------------- - - -//static const char menuMain[4][20] = -// " 1.Tube repair" -// " 2.Operator" -// " 3.Calibration"; +#define MENU_HAS_CURSOR (true) +#define MENU_HAS_NO_CURSOR (false) +#define REPAIRMENU_MAX_NUMBER_OF_ROWS (11) +#define REPAIRMENU_MAX_NUMBER_OF_KEYS (16) // ----------------------------------------------------------------------------- // Type definitions // ----------------------------------------------------------------------------- +typedef void (*RepairMenuFunctionCall)(struct RepairMenu* self, int cursorIndex); + +typedef enum +{ + NO_ACTION = 0, + HOTKEY_SELECT, + SELECT, + SCROLL_UP, + SCROLL_DOWN, + DIGIT_INSERT +} T_KeyAction; + +struct MenuRow +{ + char text[20]; + int newState; + RepairMenuFunctionCall actionPointer; +}; + +struct KeyActionBinding +{ + char key; + T_KeyAction action; + int argument; +}; + + +struct MenuPage +{ + bool hasCursor; + int numberOfRows; + struct MenuRow row[REPAIRMENU_MAX_NUMBER_OF_ROWS]; + struct KeyActionBinding keyActionBinding[REPAIRMENU_MAX_NUMBER_OF_KEYS]; +}; // ----------------------------------------------------------------------------- // File-scope variables // ----------------------------------------------------------------------------- +//TODO THIS IS UGLY +static struct RepairProcess* rp = NULL; +static const char cursorValue = 0x7E; +static struct MenuPage menuArray[NUMBER_OF_MENUS]; + + +// TEMPORARY PRESET STORAGE +static const struct RepairPreset preset1 = {.numberOfStages = 1, .preset[0].softstartDuration = 100, .preset[0].duration = 200, .preset[0].voltage = 100}; +static const struct RepairPreset preset2 = {.numberOfStages = 1, .preset[0].softstartDuration = 200, .preset[0].duration = 400, .preset[0].voltage = 200}; +static const struct RepairPreset preset3 = {.numberOfStages = 1, .preset[0].softstartDuration = 300, .preset[0].duration = 600, .preset[0].voltage = 300}; +static const struct RepairPreset preset4 = {.numberOfStages = 1, .preset[0].softstartDuration = 400, .preset[0].duration = 800, .preset[0].voltage = 400}; +static const struct RepairPreset preset5 = {.numberOfStages = 1, .preset[0].softstartDuration = 500, .preset[0].duration = 1000, .preset[0].voltage = 500}; +static const struct RepairPreset preset6 = {.numberOfStages = 1, .preset[0].softstartDuration = 600, .preset[0].duration = 1200, .preset[0].voltage = 600}; +static const struct RepairPreset preset7 = {.numberOfStages = 1, .preset[0].softstartDuration = 700, .preset[0].duration = 1400, .preset[0].voltage = 700}; +static const struct RepairPreset preset8 = {.numberOfStages = 1, .preset[0].softstartDuration = 800, .preset[0].duration = 1600, .preset[0].voltage = 800}; +static const struct RepairPreset preset9 = {.numberOfStages = 1, .preset[0].softstartDuration = 900, .preset[0].duration = 1800, .preset[0].voltage = 900}; +static const struct RepairPreset* presetArray[9] = {&preset1, &preset2, &preset3, &preset4, &preset5, &preset6, &preset7, &preset8, &preset9}; // ----------------------------------------------------------------------------- // Function declarations @@ -68,42 +117,146 @@ static void repairMenu_task(void* parameters); -static void repairMenu_selectMenu(struct RepairMenu* self, char key); static void repairMenu_printMenu(struct RepairMenu* self); +static void repairMenu_printCursor(struct RepairMenu* self); +static void repairMenu_performAction(struct RepairMenu* self, char key); +static struct KeyActionBinding repairMenu_findKeyAction(struct RepairMenu* self, char key); +static void repairMenu_scrollIndexHandlerReset (struct RepairMenu* self); +static void repairMenu_scrollUpIndexHandler(struct RepairMenu* self); +static void repairMenu_scrollDownIndexHandler(struct RepairMenu* self); +static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorIndex); +static ErrorStatus repairMenu_feedProcessSecondsCounter(const void* const data); + +static void repairMenu_selectPreset(struct RepairMenu* self, int cursorIndex); + +static void repairMenu_createMenuPage (struct MenuPage* self, bool hasCursor, int numberOfRows); +static void repairMenu_addMenuPageRow (struct MenuPage* self, int rowIndex, char* text, int newState, RepairMenuFunctionCall actionCall); +static void repairMenu_addMenuPageKeyAction (struct MenuPage* self, int keyActionIndex, char key, T_KeyAction action, int argument); // ----------------------------------------------------------------------------- // Function definitions // ----------------------------------------------------------------------------- -ErrorStatus repairMenu_construct(struct RepairMenu* self, struct Display* display, int taskPriority, uint16_t stackSize) +ErrorStatus repairMenu_construct(struct RepairMenu* self, struct Display* display, struct KeyboardDevice* keyboardDevice, int taskPriority, uint16_t stackSize, Keypad_KeyState keyStateTrigger) { ErrorStatus returnValue = SUCCESS; if (!self->initialized) { - // Create a semaphore to sync access to the display shadow - vSemaphoreCreateBinary(self->secondsSyncronisation); - xSemaphoreGive(self->secondsSyncronisation); - - - BaseType_t rv = xTaskCreate(repairMenu_task, "RepairMenu", stackSize, self, taskPriority, &self->taskHandle); - if (rv != pdTRUE) + if (returnValue == SUCCESS) { - returnValue = ERROR; + if (display->initialized) + { + self->display = display; + } + else + { + returnValue = ERROR; + } } if (returnValue == SUCCESS) { - LOGGER_INFO(mainLog, "Repair Menu task started"); - self->runTask = true; - self->initialized = true; - self->display = display; - self->menuState = MAINMENU; + if (keyboardDevice->initialized) + { + self->keyboardDevice = keyboardDevice; + } + else + { + returnValue = ERROR; + } } - else + + if (returnValue == SUCCESS) { - LOGGER_ERROR(mainLog, "FAILED to start repair Menu with code %d", (int)rv); + // Create a semaphore to sync access to the display shadow + vSemaphoreCreateBinary(self->secondsSyncronisation); + xSemaphoreGive(self->secondsSyncronisation); + + // Construct the menu based on PCBA information + repairMenu_createMenuPage(&menuArray[MAINMENU], MENU_HAS_CURSOR, 4); + repairMenu_addMenuPageRow(&menuArray[MAINMENU], 0, PCBA_getInstance()->name, MAINMENU, NULL); + repairMenu_addMenuPageRow(&menuArray[MAINMENU], 1, " 1.Tube repair", REPAIRMENU, NULL); + repairMenu_addMenuPageRow(&menuArray[MAINMENU], 2, " 2.Administrator", ADMINMENU, NULL); + repairMenu_addMenuPageRow(&menuArray[MAINMENU], 3, " 3.Calibration", CALIBRATIONMENU, NULL); + repairMenu_addMenuPageKeyAction(&menuArray[MAINMENU], 0, 'U', SCROLL_UP, 0); + repairMenu_addMenuPageKeyAction(&menuArray[MAINMENU], 1, 'D', SCROLL_DOWN, 0); + repairMenu_addMenuPageKeyAction(&menuArray[MAINMENU], 2, 'E', SELECT, 0); + repairMenu_addMenuPageKeyAction(&menuArray[MAINMENU], 3, '1', HOTKEY_SELECT, 1); + repairMenu_addMenuPageKeyAction(&menuArray[MAINMENU], 4, '2', HOTKEY_SELECT, 2); + repairMenu_addMenuPageKeyAction(&menuArray[MAINMENU], 5, '3', HOTKEY_SELECT, 3); + + repairMenu_createMenuPage(&menuArray[REPAIRMENU], MENU_HAS_CURSOR, 4); + repairMenu_addMenuPageRow(&menuArray[REPAIRMENU], 0, "Tube repair", REPAIRMENU, NULL); + repairMenu_addMenuPageRow(&menuArray[REPAIRMENU], 1, " 1.Select preset", PRESETMENU, NULL); + repairMenu_addMenuPageRow(&menuArray[REPAIRMENU], 2, " 2.Start", START_REPAIR, repairMenu_startRepairProcess); + repairMenu_addMenuPageRow(&menuArray[REPAIRMENU], 3, " 3.To main menu", MAINMENU, NULL); + repairMenu_addMenuPageKeyAction(&menuArray[REPAIRMENU], 0, 'U', SCROLL_UP, 0); + repairMenu_addMenuPageKeyAction(&menuArray[REPAIRMENU], 1, 'D', SCROLL_DOWN, 0); + repairMenu_addMenuPageKeyAction(&menuArray[REPAIRMENU], 2, 'E', SELECT, 0); + repairMenu_addMenuPageKeyAction(&menuArray[REPAIRMENU], 3, '1', HOTKEY_SELECT, 1); + repairMenu_addMenuPageKeyAction(&menuArray[REPAIRMENU], 4, '2', HOTKEY_SELECT, 2); + repairMenu_addMenuPageKeyAction(&menuArray[REPAIRMENU], 5, 'X', HOTKEY_SELECT, 3); + + repairMenu_createMenuPage(&menuArray[ADMINMENU], MENU_HAS_NO_CURSOR, 2); + repairMenu_addMenuPageRow(&menuArray[ADMINMENU], 0, "Administration", ADMINMENU, NULL); + repairMenu_addMenuPageRow(&menuArray[ADMINMENU], 1, " 1.To main menu", MAINMENU, NULL); + repairMenu_addMenuPageKeyAction(&menuArray[ADMINMENU], 0, 'E', SELECT, 0); + repairMenu_addMenuPageKeyAction(&menuArray[ADMINMENU], 1, '1', HOTKEY_SELECT, 1); + repairMenu_addMenuPageKeyAction(&menuArray[ADMINMENU], 2, 'X', HOTKEY_SELECT, 1); + + repairMenu_createMenuPage(&menuArray[CALIBRATIONMENU], MENU_HAS_NO_CURSOR, 2); + repairMenu_addMenuPageRow(&menuArray[CALIBRATIONMENU], 0, "Calibration", CALIBRATIONMENU, NULL); + repairMenu_addMenuPageRow(&menuArray[CALIBRATIONMENU], 1, " 1.To main menu", MAINMENU, NULL); + repairMenu_addMenuPageKeyAction(&menuArray[CALIBRATIONMENU], 0, 'E', SELECT, 0); + repairMenu_addMenuPageKeyAction(&menuArray[CALIBRATIONMENU], 1, '1', HOTKEY_SELECT, 1); + repairMenu_addMenuPageKeyAction(&menuArray[CALIBRATIONMENU], 2, 'X', HOTKEY_SELECT, 1); + + + repairMenu_createMenuPage(&menuArray[PRESETMENU], MENU_HAS_CURSOR, 11); + repairMenu_addMenuPageRow(&menuArray[PRESETMENU], 0, "Select preset", PRESETMENU, NULL); + repairMenu_addMenuPageRow(&menuArray[PRESETMENU], 1, " 1.Preset1", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&menuArray[PRESETMENU], 2, " 2.Preset2", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&menuArray[PRESETMENU], 3, " 3.Preset3", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&menuArray[PRESETMENU], 4, " 4.Preset4", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&menuArray[PRESETMENU], 5, " 5.Preset5", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&menuArray[PRESETMENU], 6, " 6.Preset6", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&menuArray[PRESETMENU], 7, " 7.Preset7", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&menuArray[PRESETMENU], 8, " 8.Preset8", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&menuArray[PRESETMENU], 9, " 9.Preset9", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&menuArray[PRESETMENU], 10, " 10.To repair menu", REPAIRMENU, NULL); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 0, 'U', SCROLL_UP, 0); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 1, 'D', SCROLL_DOWN, 0); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 2, 'E', SELECT, 0); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 3, '1', HOTKEY_SELECT, 1); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 4, '2', HOTKEY_SELECT, 2); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 5, '3', HOTKEY_SELECT, 3); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 6, '4', HOTKEY_SELECT, 4); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 7, '5', HOTKEY_SELECT, 5); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 8, '6', HOTKEY_SELECT, 6); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 9, '7', HOTKEY_SELECT, 7); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 10, '8', HOTKEY_SELECT, 8); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 11, '9', HOTKEY_SELECT, 9); + repairMenu_addMenuPageKeyAction(&menuArray[PRESETMENU], 12, 'X', HOTKEY_SELECT, 10); + + + self->menuState = MAINMENU; + self->runTask = true; + + BaseType_t rv = xTaskCreate(repairMenu_task, "RepairMenu", stackSize, self, taskPriority, &self->taskHandle); + if (rv != pdTRUE) + { + returnValue = ERROR; + LOGGER_ERROR(mainLog, "FAILED to start repair Menu with code %d", (int)rv); + } + else + { + self->initialized = true; + self->cursorIndex = 1; + self->scrollOffset = 0; + LOGGER_INFO(mainLog, "Repair Menu task started"); + } } } else @@ -155,20 +308,24 @@ static void repairMenu_task(void* parameters) char key; Keypad_KeyState keyState; - // Get a new key from keyboard - if (KeyboardDevice_read(&storm700->keyboardDevice, &key, &keyState) == SUCCESS) + // Clear the screen for a new menu + Display_clearScreen(self->display); + // Print menu content to output device + repairMenu_printMenu(self); + // Add cursor if necessary + repairMenu_printCursor(self); + + while (KeyboardDevice_read(&storm700->keyboardDevice, &key, &keyState) != SUCCESS) { - // New key read - if (keyState == RELEASED) - { - LOGGER_INFO(mainLog, "Key %c is released", key); - } - else - { - LOGGER_INFO(mainLog, "Key %c is pressed", key); - } + vTaskDelay(10); } - vTaskDelay(100); + + if (keyState == self->keyStateTrigger) + { + repairMenu_performAction(self, key); + } + + } LOGGER_INFO(mainLog, "Deleting RepairMenu task"); @@ -176,35 +333,213 @@ static void repairMenu_task(void* parameters) } -static void repairMenu_selectMenu(struct RepairMenu* self, char key) -{ - switch (self->menuState) - { - case MAINMENU: - { - repairMenu_printMenu(self); - break; - } - case REPAIRMENU: - { - break; - } - } -} - static void repairMenu_printMenu(struct RepairMenu* self) { - switch (self->menuState) + int loopCounter; + + // Always print Row1 (index0), ignoring the scrolling index + Display_write(self->display, menuArray[self->menuState].row[0].text, strlen(menuArray[self->menuState].row[0].text), 1, 1); + + for (loopCounter = 1 ; loopCounter < self->display->displayDevice->parameters.numberOfRows; loopCounter++) { - case MAINMENU: + Display_write(self->display, menuArray[self->menuState].row[loopCounter + self->scrollOffset].text, strlen(menuArray[self->menuState].row[loopCounter + self->scrollOffset].text), loopCounter + 1, 1); + } +} + + +static void repairMenu_printCursor(struct RepairMenu* self) +{ + if (menuArray[self->menuState].hasCursor) + { + Display_write(self->display, &cursorValue, 1, 1 + self->cursorIndex - self->scrollOffset, 1); + } +} + + +static void repairMenu_performAction(struct RepairMenu* self, char key) +{ + struct KeyActionBinding keyAction = repairMenu_findKeyAction(self, key); + LOGGER_DEBUG(mainLog, "Action: received key %c, action to perform %d,", key, keyAction.action); + + switch (keyAction.action) + { + case NO_ACTION: { - Display_write(self->display, PCBA_getInstance()->name, strlen(PCBA_getInstance()->name), 1, 1); + LOGGER_INFO(mainLog, "This button has no action"); break; } - case REPAIRMENU: + + case HOTKEY_SELECT: { + LOGGER_INFO(mainLog, "HOTKEY SELECT ITEM: char %c, argument %d - Going to state %d", keyAction.key, keyAction.argument, menuArray[self->menuState].row[keyAction.argument].newState); + if (menuArray[self->menuState].row[keyAction.argument].actionPointer != NULL) + { + menuArray[self->menuState].row[keyAction.argument].actionPointer(self, keyAction.argument); + } + self->menuState = menuArray[self->menuState].row[keyAction.argument].newState; + repairMenu_scrollIndexHandlerReset(self); + break; + } + + case SELECT: + { + LOGGER_INFO(mainLog, "SELECT ITEM %d - going to state %d", self->cursorIndex, menuArray[self->menuState].row[self->cursorIndex].newState); + if (menuArray[self->menuState].row[self->cursorIndex].actionPointer != NULL) + { + menuArray[self->menuState].row[self->cursorIndex].actionPointer(self, self->cursorIndex); + } + self->menuState = menuArray[self->menuState].row[self->cursorIndex].newState; + repairMenu_scrollIndexHandlerReset(self); + break; + } + + case SCROLL_UP: + { + LOGGER_INFO(mainLog, "Scrolling up"); + repairMenu_scrollUpIndexHandler(self); + break; + } + case SCROLL_DOWN: + { + LOGGER_INFO(mainLog, "Scrolling down"); + repairMenu_scrollDownIndexHandler(self); + break; + } + case DIGIT_INSERT: + { + LOGGER_INFO(mainLog, "Key is allowed as insert"); break; } } } + + +static struct KeyActionBinding repairMenu_findKeyAction(struct RepairMenu* self, char key) +{ + int loopCounter; + struct KeyActionBinding returnValue; + returnValue.action = NO_ACTION; + + for (loopCounter = 0; loopCounter < REPAIRMENU_MAX_NUMBER_OF_KEYS; loopCounter++) + { + if (menuArray[self->menuState].keyActionBinding[loopCounter].key == key) + { + returnValue = menuArray[self->menuState].keyActionBinding[loopCounter]; + break; + } + } + return returnValue; +} + + +static void repairMenu_scrollIndexHandlerReset (struct RepairMenu* self) +{ + self->cursorIndex = 1; + self->scrollOffset = 0; +} + +static void repairMenu_scrollUpIndexHandler(struct RepairMenu* self) +{ + if (self->cursorIndex - self->scrollOffset > 1) + { + if (self->cursorIndex > 1) + { + self->cursorIndex--; + } + } + else + { + if (self->cursorIndex > 1) + { + self->cursorIndex--; + } + + if (self->scrollOffset > 0) + { + self->scrollOffset--; + } + } +} + + +static void repairMenu_scrollDownIndexHandler(struct RepairMenu* self) +{ + if (self->cursorIndex < self->display->displayDevice->parameters.numberOfRows - 1) + { + if (self->cursorIndex < menuArray[self->menuState].numberOfRows - 1) + { + self->cursorIndex++; + } + } + else + { + if (self->cursorIndex < menuArray[self->menuState].numberOfRows - 1) + { + self->cursorIndex++; + } + + if (self->scrollOffset < (menuArray[self->menuState].numberOfRows - self->display->displayDevice->parameters.numberOfRows)) + { + self->scrollOffset++; + } + } +} + + +static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorIndex) +{ + self->rpParameters.adcRow1 = &adc1->channel[0]; + self->rpParameters.adcRow2 = &adc1->channel[1]; + self->rpParameters.adcRow3 = &adc1->channel[2]; + self->rpParameters.dacRow1 = &max5715->dac[0]; + self->rpParameters.dacRow2 = &max5715->dac[1]; + self->rpParameters.dacRow3 = &max5715->dac[2]; + + rp = &self->repairProcess; + Observable_addObserver(RTC_getObservable(rtc), repairMenu_feedProcessSecondsCounter); + repairProcess_construct(&self->repairProcess, &self->rpParameters, self->repairPreset, 2, 1024); +} + +static ErrorStatus repairMenu_feedProcessSecondsCounter(const void* const data) +{ + repairProcess_feedSecondsCounterFromISR(rp); + return SUCCESS; +} + + +static void repairMenu_selectPreset(struct RepairMenu* self, int cursorIndex) +{ + self->repairPreset = presetArray[cursorIndex - 1]; + LOGGER_INFO(mainLog, "Preset %d selected", cursorIndex); +} + + +static void repairMenu_createMenuPage (struct MenuPage* self, bool hasCursor, int numberOfRows) +{ + self->hasCursor = hasCursor; + if (numberOfRows <= REPAIRMENU_MAX_NUMBER_OF_ROWS) + { + self->numberOfRows = numberOfRows; + } +} + +static void repairMenu_addMenuPageRow (struct MenuPage* self, int rowIndex, char* text, int newState, RepairMenuFunctionCall actionCall) +{ + if (rowIndex < self->numberOfRows) + { + memcpy(self->row[rowIndex].text, text, 20); + self->row[rowIndex].newState = newState; + self->row[rowIndex].actionPointer = actionCall; + } +} + +static void repairMenu_addMenuPageKeyAction (struct MenuPage* self, int keyActionIndex, char key, T_KeyAction action, int argument) +{ + if (keyActionIndex < REPAIRMENU_MAX_NUMBER_OF_KEYS) + { + self->keyActionBinding[keyActionIndex].key = key; + self->keyActionBinding[keyActionIndex].argument = argument; + self->keyActionBinding[keyActionIndex].action = action; + } +} diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenus.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenus.c index 507eacd..7d64a5a 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenus.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairMenus.c @@ -33,6 +33,7 @@ #include "repairMenu.h" #include "platform.h" +#include "storm700.h" #include "Observable.h" #include "rtc.h" @@ -66,8 +67,6 @@ static ErrorStatus repairMenus_mainMenuObserverFromISR(const void* const data); // Function definitions // ----------------------------------------------------------------------------- -//TODO REMOVE -extern struct Display* display; ErrorStatus repairMenus_construct(void) { ErrorStatus returnValue = SUCCESS; @@ -75,7 +74,7 @@ ErrorStatus repairMenus_construct(void) if (returnValue == SUCCESS) { // Create first repair menu - returnValue = repairMenu_construct(mainMenu, mainDisplay, HSB_MAINMENU_TASK_PRIORITY, HSB_MAINMENU_TASK_STACKSIZE); + returnValue = repairMenu_construct(mainMenu, mainDisplay, &storm700->keyboardDevice, HSB_MAINMENU_TASK_PRIORITY, HSB_MAINMENU_TASK_STACKSIZE, PRESSED); } if (returnValue == SUCCESS) diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairProcess.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairProcess.c index eac205b..24edf81 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairProcess.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/repairProcess.c @@ -69,7 +69,7 @@ static int SignalProfileGenerator(struct RepairProcess* self); // ----------------------------------------------------------------------------- -ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairProcessParameters* parameters, int taskPriority, uint16_t stackSize) +ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairProcessParameters* parameters, const struct RepairPreset* preset, int taskPriority, uint16_t stackSize) { ErrorStatus returnValue = SUCCESS; @@ -90,6 +90,7 @@ ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairPro { self->runTask = true; self->initialized = true; + self->repairPreset = preset; self->currentState = PREPARE; self->adc[0] = parameters->adcRow1; @@ -104,9 +105,9 @@ ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairPro self->pid[2].initialized = false; - PID_construct(&self->pid[0], 5000, 3000, 0, 0, 10000000); - PID_construct(&self->pid[1], 5000, 3000, 0, 0, 100000000); - PID_construct(&self->pid[2], 5000, 3000, 0, 0, 10000000); + PID_construct(&self->pid[0], 5000, 3000, 5000, 0, 10000000); + PID_construct(&self->pid[1], 5000, 3000, 5000, 0, 100000000); + PID_construct(&self->pid[2], 5000, 3000, 5000, 0, 10000000); LOGGER_INFO(mainLog, "Repair Process task started"); }