From 088ce81dc78e3e1837108b49024186482731f46b Mon Sep 17 00:00:00 2001 From: mmi Date: Tue, 17 Oct 2017 15:23:56 +0000 Subject: [PATCH] Most parts of the menu structure are functional. Error handler added Screens for warning, pause, FINISH etc yet to be added git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@255 05563f52-14a8-4384-a975-3d1654cca0fa --- .../0 - Code/HAL/inc/Interlock.h | 10 +- .../0 - Code/HAL/src/Interlock.c | 13 +- .../0 - Code/Platform/inc/keypadMatrix.h | 3 +- .../0 - Code/Platform/src/oli_stm32_h107.c | 6 +- .../0 - Code/hsb-mrts/Makefile | 1 + .../0 - Code/hsb-mrts/inc/Error.h | 119 ++++ .../0 - Code/hsb-mrts/inc/Warning.h | 52 ++ .../0 - Code/hsb-mrts/inc/hsb-mrts.h | 31 + .../0 - Code/hsb-mrts/inc/repairMenu.h | 36 +- .../0 - Code/hsb-mrts/inc/repairProcess.h | 19 +- .../0 - Code/hsb-mrts/src/Error.c | 89 +++ .../0 - Code/hsb-mrts/src/hsb-mrts.c | 12 + .../0 - Code/hsb-mrts/src/main.c | 6 - .../0 - Code/hsb-mrts/src/repairMenu.c | 586 ++++++++++++++---- .../0 - Code/hsb-mrts/src/repairMenus.c | 30 +- .../0 - Code/hsb-mrts/src/repairProcess.c | 22 +- .../0 - Code/hsb-mrts/src/stm32f10x_it.c | 9 +- 17 files changed, 883 insertions(+), 161 deletions(-) create mode 100644 S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Error.h create mode 100644 S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Warning.h create mode 100644 S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Error.c diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/Interlock.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/Interlock.h index dd30fc2..ddfd3c0 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/Interlock.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/inc/Interlock.h @@ -44,11 +44,16 @@ // ----------------------------------------------------------------------------- - // ----------------------------------------------------------------------------- // Type definitions. // ----------------------------------------------------------------------------- +typedef enum +{ + COMMON_INTERLOCK = 0, + TESLA_INTERLOCK = !COMMON_INTERLOCK +} T_INTERLOCK_ID; + struct InterlockElement { struct Gpio* io; @@ -60,6 +65,7 @@ struct Interlock struct InterlockElement NO; struct InterlockElement NC; bool initialized; + T_INTERLOCK_ID ID; }; // ----------------------------------------------------------------------------- @@ -82,7 +88,7 @@ struct Interlock * @todo * ----------------------------------------------------------------------------- */ -extern ErrorStatus Interlock_construct(struct Interlock* self, struct Gpio* NO, EXTI_InitTypeDef NOEXTI, struct Gpio* NC, EXTI_InitTypeDef NCEXTI); +extern ErrorStatus Interlock_construct(struct Interlock* self, T_INTERLOCK_ID ID, struct Gpio* NO, EXTI_InitTypeDef NOEXTI, struct Gpio* NC, EXTI_InitTypeDef NCEXTI); /** ---------------------------------------------------------------------------- diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/Interlock.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/Interlock.c index d93145a..7b4f789 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/Interlock.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/Interlock.c @@ -54,11 +54,12 @@ // Function definitions // ----------------------------------------------------------------------------- -ErrorStatus Interlock_construct(struct Interlock* self, struct Gpio* NO, EXTI_InitTypeDef NOEXTI, struct Gpio* NC, EXTI_InitTypeDef NCEXTI) +ErrorStatus Interlock_construct(struct Interlock* self, T_INTERLOCK_ID ID, struct Gpio* NO, EXTI_InitTypeDef NOEXTI, struct Gpio* NC, EXTI_InitTypeDef NCEXTI) { ErrorStatus returnValue = SUCCESS; if (!self->initialized) { + self->ID = ID; self->NO.io = NO; self->NO.ioEXTI = NOEXTI; self->NC.io = NC; @@ -77,8 +78,9 @@ void Interlock_getStatus(struct Interlock* self, FunctionalState* command, int* { *command = self->NO.ioEXTI.EXTI_LineCmd; - IODevice_read((struct IODevice*)self->NO.io, (char*)NO, 1, NULL); - IODevice_read((struct IODevice*)self->NC.io, (char*)NC, 1, NULL); + size_t actualLength; + IODevice_read((struct IODevice*)self->NO.io, (char*)NO, 1, &actualLength); + IODevice_read((struct IODevice*)self->NC.io, (char*)NC, 1, &actualLength); } @@ -88,9 +90,10 @@ bool Interlock_isClosed(struct Interlock* self) char no; char nc; + size_t actualLength; - IODevice_read((struct IODevice*)self->NO.io, &no, 1, NULL); - IODevice_read((struct IODevice*)self->NC.io, &nc, 1, NULL); + IODevice_read((struct IODevice*)self->NO.io, &no, 1, &actualLength); + IODevice_read((struct IODevice*)self->NC.io, &nc, 1, &actualLength); if ((no != 0) && (nc == 0)) { diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/keypadMatrix.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/keypadMatrix.h index e328cd9..3c40502 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/keypadMatrix.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/Platform/inc/keypadMatrix.h @@ -58,7 +58,8 @@ typedef enum { RELEASED = 0, - PRESSED = (!RELEASED) + PRESSED = (!RELEASED), + NUMBER_OF_KEY_EVENTS } Keypad_KeyState; struct KeypadQueueItem 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 b72f77c..1809478 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 @@ -712,11 +712,11 @@ static ErrorStatus initPeriphery(void) EXTI_InitTypeDef intNCEXTI = configureEXTI(EXTI_Line1, EXTI_Mode_Interrupt, EXTI_Trigger_Rising_Falling, DISABLE); GPIO_construct(interlockNC, INPUT, interlockNC->gpio); - Interlock_construct(interlock, interlockNO, intNOEXTI, interlockNC, intNCEXTI); - + Interlock_construct(interlock, COMMON_INTERLOCK, interlockNO, intNOEXTI, interlockNC, intNCEXTI); // Solenoid GPIO_construct(solenoid, OUTPUT, solenoid->gpio); + if (PCBA_getInstance()->pcba == CathodeMCP) { // MCP0Relay @@ -742,7 +742,7 @@ static ErrorStatus initPeriphery(void) EXTI_InitTypeDef teslaNCEXTI = configureEXTI(EXTI_Line10, EXTI_Mode_Interrupt, EXTI_Trigger_Rising_Falling, DISABLE); GPIO_construct(teslaNC, INPUT, teslaNC->gpio); - Interlock_construct(teslalock, teslaNO, teslaNOEXTI, teslaNC, teslaNCEXTI); + Interlock_construct(teslalock, TESLA_INTERLOCK, teslaNO, teslaNOEXTI, teslaNC, teslaNCEXTI); } return returnValue; diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/Makefile b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/Makefile index aad27f1..2c6e676 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/Makefile +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/Makefile @@ -14,6 +14,7 @@ startup_stm32f10x_cl.o \ \ Display.o \ Displays.o \ +Error.o \ FreeRTOSFixes.o \ hwValidationMenu.o \ repairMenu.o \ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Error.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Error.h new file mode 100644 index 0000000..5cdef5d --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Error.h @@ -0,0 +1,119 @@ +// ----------------------------------------------------------------------------- +/// @file Error.h +/// @brief File description +// ----------------------------------------------------------------------------- +// Micro-Key bv +// Industrieweg 28, 9804 TG Noordhorn +// Postbus 92, 9800 AB Zuidhorn +// The Netherlands +// Tel: +31 594 503020 +// Fax: +31 594 505825 +// Email: support@microkey.nl +// Web: www.microkey.nl +// ----------------------------------------------------------------------------- +/// $Revision$ +/// $Author$ +/// $Date$ +// (c) 2015 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @defgroup {group_name} {group_description} +/// Description + +/// @file Error.h +/// @ingroup {group_name} + +#ifndef ERROR_H_ +#define ERROR_H_ + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + +#include "stm32f10x.h" + +#include "Observable.h" + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Type definitions. +// ----------------------------------------------------------------------------- + +typedef enum +{ + GPIO_FAIL, + INTERLOCK_COMMON_FAIL, + INTERLOCK_TESLA_FAIL, + POWERENABLE_FAIL, + REPAIR_FAIL, +} T_ErrorCode; + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + + +/** ---------------------------------------------------------------------------- + * Error_construct + * Constructs the error handler + * + * @return ErrorStatus SUCCESS if construction was successful + * ERROR otherwise + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern ErrorStatus Error_construct(void); + + +/** ---------------------------------------------------------------------------- + * Error_getObservable + * Returns the observable of the Error handler + * + * @return struct Observable* Observable of the ERROR handler + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern struct Observable* Error_getObservable(void); + + +/** ---------------------------------------------------------------------------- + * Error_postError + * Posts a new error + * + * @param errorCode ERROR CODE + * + * @return void + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern void Error_postError(T_ErrorCode errorCode); + + +/** ---------------------------------------------------------------------------- + * Error_postErrorFromISR + * Posts a new error from an ISR context + * + * @param errorCode ERROR CODE + * + * @return void + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern void Error_postErrorFromISR(T_ErrorCode errorCode); + + + + + + +#endif /* ERROR_H_ */ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Warning.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Warning.h new file mode 100644 index 0000000..606ed8b --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/Warning.h @@ -0,0 +1,52 @@ +// ----------------------------------------------------------------------------- +/// @file Warning.h +/// @brief File description +// ----------------------------------------------------------------------------- +// Micro-Key bv +// Industrieweg 28, 9804 TG Noordhorn +// Postbus 92, 9800 AB Zuidhorn +// The Netherlands +// Tel: +31 594 503020 +// Fax: +31 594 505825 +// Email: support@microkey.nl +// Web: www.microkey.nl +// ----------------------------------------------------------------------------- +/// $Revision$ +/// $Author$ +/// $Date$ +// (c) 2015 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @defgroup {group_name} {group_description} +/// Description + +/// @file Warning.h +/// @ingroup {group_name} + +#ifndef WARNING_H_ +#define WARNING_H_ + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Type definitions. +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + + +#endif /* WARNING_H_ */ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/hsb-mrts.h b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/hsb-mrts.h index 71554b2..775045d 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/hsb-mrts.h +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/inc/hsb-mrts.h @@ -33,6 +33,8 @@ #include "stm32f10x.h" +#include "gpio.h" + // ----------------------------------------------------------------------------- // Constant and macro definitions // ----------------------------------------------------------------------------- @@ -69,4 +71,33 @@ extern struct Display* const mainDisplay; * ----------------------------------------------------------------------------- */ extern ErrorStatus hsb_generateStartScreen(struct Display* Display); + + +/** ---------------------------------------------------------------------------- + * hsb_solenoidLock + * Locks the solenoid + * + * + * @return ErrorStatus SUCCESS if locking was successful + * ERROR otherwise + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern ErrorStatus hsb_solenoidLock (void); + + +/** ---------------------------------------------------------------------------- + * hsb_solenoidUnlock + * Unlocks the solenoid + * + * + * @return ErrorStatus SUCCESS if locking was successful + * ERROR otherwise + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern ErrorStatus hsb_solenoidUnlock (void); + #endif /* HSB_MRTS_H_ */ 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 9203aae..b2b4307 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 @@ -41,6 +41,7 @@ #include "repairPreset.h" #include "repairProcess.h" +#include "Interlock.h" #include "keypadMatrix.h" #include "Observable.h" #include "rtc.h" @@ -67,6 +68,11 @@ typedef enum CALIBRATIONMENU, PRESETMENU, START_REPAIR, + REPAIR_RUNNING, + REPAIR_ASK_PAUSE, + REPAIR_PAUSE, + ERROR_STATE, + WARNING_STATE, NO_MENU, NUMBER_OF_MENUS } T_MenuState; @@ -79,6 +85,8 @@ typedef enum NO_ACTION = 0, HOTKEY_SELECT, SELECT, + GOTO_STATE, + EXECUTE_FUNCTION, SCROLL_UP, SCROLL_DOWN, DIGIT_INSERT @@ -91,11 +99,14 @@ struct MenuRow RepairMenuFunctionCall actionPointer; }; + struct KeyActionBinding { char key; + Keypad_KeyState keyState; T_KeyAction action; int argument; + RepairMenuFunctionCall actionPointer; }; @@ -103,8 +114,11 @@ struct MenuPage { bool hasCursor; int numberOfRows; + int maxNumberOfRows; + int numberOfKeys; + int maxNumberOfKeys; struct MenuRow row[REPAIRMENU_MAX_NUMBER_OF_ROWS]; - struct KeyActionBinding keyActionBinding[REPAIRMENU_MAX_NUMBER_OF_KEYS]; + struct KeyActionBinding keyActionBinding[NUMBER_OF_KEY_EVENTS * REPAIRMENU_MAX_NUMBER_OF_KEYS]; }; struct RepairMenu @@ -113,18 +127,18 @@ struct RepairMenu int TaskPriority; uint16_t stackSize; bool runTask; - 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; struct MenuPage menuArray[NUMBER_OF_MENUS]; + char errorMessage[20]; + char warningMessage[20]; }; // ----------------------------------------------------------------------------- @@ -197,4 +211,20 @@ extern void repairMenu_feedSecondsCounter(struct RepairMenu* self); */ extern void repairMenu_feedSecondsCounterFromISR(struct RepairMenu* self); + +/** ---------------------------------------------------------------------------- + * repairMenu_interlockFailed + * Interlock verification failed + * + * @param self The repair menu object + * @param interlockID 0 for common interlock + * !0 for the tesla interlock + * + * @return void + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern void repairMenu_interlockFailed(struct RepairMenu* self, T_INTERLOCK_ID interlockID); + #endif /* INC_REPAIRMENU_H_ */ 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 88f9cac..9f4fd46 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 @@ -118,6 +118,20 @@ struct RepairProcess extern ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairProcessParameters* parameters, const struct RepairPreset* preset, int taskPriority, uint16_t stackSize); +/** ---------------------------------------------------------------------------- + * repairProcess_construct + * Destructor for repair process + * + * @param self The process object + * + * @return void + * + * @todo + * ----------------------------------------------------------------------------- + */ +extern void repairProcess_destruct(struct RepairProcess* self); + + /** ---------------------------------------------------------------------------- * repairProcess_feedSecondsCounter * Feeds the seconds counter of the repair process. @@ -157,12 +171,15 @@ extern void repairProcess_feedSecondsCounterFromISR(struct RepairProcess* self); * * @param self * @param repairTime + * @param hours + * @param minutes + * @param seconds * * @return ErrorStatus * * @todo * ----------------------------------------------------------------------------- */ -extern ErrorStatus repairProcess_getRepairTime(const struct RepairProcess* self, uint32_t* repairTime); +extern ErrorStatus repairProcess_getRepairTime(const struct RepairProcess* self, uint32_t* repairTime, int* hours, int* minutes, int* seconds); #endif /* REPAIRPROCESS_H_ */ diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Error.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Error.c new file mode 100644 index 0000000..80758bc --- /dev/null +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/Error.c @@ -0,0 +1,89 @@ +// ----------------------------------------------------------------------------- +/// @file Error.c +/// @brief Description +// ----------------------------------------------------------------------------- +// Micro-Key bv +// Industrieweg 28, 9804 TG Noordhorn +// Postbus 92, 9800 AB Zuidhorn +// The Netherlands +// Tel: +31 594 503020 +// Fax: +31 594 505825 +// Email: support@microkey.nl +// Web: www.microkey.nl +// ----------------------------------------------------------------------------- +/// $Revision$ +/// $Author$ +/// $Date$ +// (c) 2017 Micro-Key bv +// ----------------------------------------------------------------------------- + +/// @file Error.c +/// @ingroup {group_name} + + +// ----------------------------------------------------------------------------- +// Include files +// ----------------------------------------------------------------------------- + +#include "Error.h" + +#include "platform.h" +#include "Logger.h" + +// ----------------------------------------------------------------------------- +// Constant and macro definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Type definitions +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// File-scope variables +// ----------------------------------------------------------------------------- + +static struct Observable observable; + +// ----------------------------------------------------------------------------- +// Function declarations +// ----------------------------------------------------------------------------- + + + +// ----------------------------------------------------------------------------- +// Function definitions +// ----------------------------------------------------------------------------- + + +ErrorStatus Error_construct(void) +{ + Observable_construct(&observable); + + return SUCCESS; +} + + +struct Observable* Error_getObservable(void) +{ + return &observable; +} + + +void Error_postError(T_ErrorCode errorCode) +{ + LOGGER_ERROR(mainLog, "ERROR POSTED WITH CODE %d", errorCode); + Observable_notifyObservers(&observable, (const void* const)errorCode); +} + + +void Error_postErrorFromISR(T_ErrorCode errorCode) +{ + portBASE_TYPE higherPriorityTaskWoken = pdFALSE; + LOGGER_ERROR_ISR(mainLog, "ERROR POSTED FROM ISR"); + Observable_notifyObservers(&observable, (const void* const)errorCode); + portEND_SWITCHING_ISR(higherPriorityTaskWoken); +} diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/hsb-mrts.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/hsb-mrts.c index 3dc78f2..e36cf0e 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/hsb-mrts.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/hsb-mrts.c @@ -32,6 +32,7 @@ #include "Display.h" #include "platform.h" +#include "Logger.h" #include "PCBA.h" #include "Version.h" @@ -92,3 +93,14 @@ ErrorStatus hsb_generateStartScreen(struct Display* Display) } return returnValue; } + + +ErrorStatus hsb_solenoidLock (void) +{ + return GPIO_setValue(solenoid, false); +} + +ErrorStatus hsb_solenoidUnlock (void) +{ + return GPIO_setValue(solenoid, true); +} 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 2b060df..5933218 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 @@ -210,12 +210,6 @@ static void initTask(void* parameters) // EEPROM TO BE DONE // HwValidationMenu_construct(hwValidation, &uart1->device, &hwTestItems, 1, 1024); - Interlock_setEXTI(interlock, ENABLE); - if (PCBA_getInstance()->pcba == Tesla) - { - Interlock_setEXTI(teslalock, ENABLE); - } - // Construct the repair menu repairMenus_construct(); 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 2ac13e7..dd9b41e 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 @@ -31,8 +31,11 @@ #include "repairProcess.h" #include "Display.h" +#include "Error.h" +#include "hsb-mrts.h" #include "Logger.h" +#include "Interlock.h" #include "internalADC.h" #include "MAX5715.h" @@ -64,8 +67,8 @@ static const char cursorValue = 0x7E; // 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 preset1 = {.numberOfStages = 1, .preset[0].softstartDuration = 100, .preset[0].duration = 200, .preset[0].voltage = 1000}; +static const struct RepairPreset preset2 = {.numberOfStages = 1, .preset[0].softstartDuration = 200, .preset[0].duration = 400, .preset[0].voltage = 3000}; 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}; @@ -80,24 +83,35 @@ static const struct RepairPreset* presetArray[9] = {&preset1, &preset2, &preset3 // ----------------------------------------------------------------------------- static void repairMenu_task(void* parameters); - +static void repairMenu_changeState(struct RepairMenu* self, T_MenuState newState); +static void repairMenu_printError(struct RepairMenu* self); +static void repairMenu_printWarning(struct RepairMenu* self); +static void repairMenu_printRepair(struct RepairMenu* self); 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 ErrorStatus repairMenu_performAction(struct RepairMenu* self, char key, Keypad_KeyState keyState); +static struct KeyActionBinding repairMenu_findKeyAction(struct RepairMenu* self, char key, Keypad_KeyState keyState); 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 void repairMenu_abortRepairProcess(struct RepairMenu* self); static ErrorStatus repairMenu_feedProcessSecondsCounter(const void* const data); static void repairMenu_selectPreset(struct RepairMenu* self, int cursorIndex); - +static void repairMenu_solenoidLock(struct RepairMenu* self, int cursorIndex); +static void repairMenu_solenoidUnlock(struct RepairMenu* self, int cursorIndex); static ErrorStatus repairMenu_createMenu(struct RepairMenu* self); -static ErrorStatus repairMenu_createMenuPage (struct MenuPage* self, bool hasCursor, int numberOfRows); -static ErrorStatus repairMenu_addMenuPageRow (struct MenuPage* self, int rowIndex, char* text, int newState, RepairMenuFunctionCall actionCall); -static ErrorStatus repairMenu_addMenuPageKeyAction (struct MenuPage* self, int keyActionIndex, char key, T_KeyAction action, int argument); +static ErrorStatus repairMenu_createMenuPage (struct MenuPage* self, bool hasCursor, int maxNumberOfRows); +static ErrorStatus repairMenu_addMenuPageRow (struct MenuPage* self, char* text, int newState, RepairMenuFunctionCall actionCall); +static ErrorStatus repairMenu_addKeyAction_HOTKEYSELECT (struct MenuPage* self, char key, Keypad_KeyState keyState, int rowToSelect); +static ErrorStatus repairMenu_addKeyAction_SELECT (struct MenuPage* self, char key, Keypad_KeyState keyState); +static ErrorStatus repairMenu_addKeyAction_GOTOSTATE (struct MenuPage* self, char key, Keypad_KeyState keyState, T_MenuState state); +static ErrorStatus repairMenu_addKeyAction_EXECUTEFUNCTION (struct MenuPage* self, char key, Keypad_KeyState keyState, RepairMenuFunctionCall actionPointer); +static ErrorStatus repairMenu_addKeyAction_SCROLLUP (struct MenuPage* self, char key, Keypad_KeyState keyState); +static ErrorStatus repairMenu_addKeyAction_SCROLLDOWN (struct MenuPage* self, char key, Keypad_KeyState keyState); + // ----------------------------------------------------------------------------- // Function definitions @@ -136,15 +150,11 @@ ErrorStatus repairMenu_construct(struct RepairMenu* self, struct Display* displa if (returnValue == SUCCESS) { - // Create a semaphore to sync access to the display shadow - vSemaphoreCreateBinary(self->secondsSyncronisation); - xSemaphoreGive(self->secondsSyncronisation); - // Construct the menu based on PCBA information returnValue = repairMenu_createMenu(self); - self->menuState = MAINMENU; + repairMenu_changeState(self, MAINMENU); self->runTask = true; BaseType_t rv = xTaskCreate(repairMenu_task, "RepairMenu", stackSize, self, taskPriority, &self->taskHandle); @@ -177,27 +187,17 @@ void repairMenu_destruct (struct RepairMenu* self) } -void repairMenu_feedSecondsCounter(struct RepairMenu* self) +void repairMenu_interlockFailed(struct RepairMenu* self, T_INTERLOCK_ID interlockID) { - if (self->initialized) + repairMenu_changeState(self, ERROR_STATE); + if (interlockID == COMMON_INTERLOCK) { - xSemaphoreGive(self->secondsSyncronisation); + snprintf(self->errorMessage, sizeof(self->errorMessage) / sizeof(self->errorMessage[0]), "COVER OPEN"); } - -} - - -void repairMenu_feedSecondsCounterFromISR(struct RepairMenu* self) -{ - portBASE_TYPE higherPriorityTaskWoken = pdFALSE; - - if (self->initialized) + else if (interlockID == TESLA_INTERLOCK) { - xSemaphoreGiveFromISR(self->secondsSyncronisation, &higherPriorityTaskWoken); + snprintf(self->errorMessage, sizeof(self->errorMessage) / sizeof(self->errorMessage[0]), "SAFETY TUBE MISSING"); } - - portEND_SWITCHING_ISR(higherPriorityTaskWoken); - } @@ -205,30 +205,51 @@ static void repairMenu_task(void* parameters) { struct RepairMenu* self = (struct RepairMenu*)parameters; + // 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(self->runTask) { char key; Keypad_KeyState keyState; - // 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) + // Catch ERROR state + if (self->menuState == ERROR_STATE) { - vTaskDelay(10); + // Show ERROR message + repairMenu_printError(self); + // Handle error + repairMenu_abortRepairProcess(self); + } + else if (self->menuState == WARNING_STATE) + { + + } + else if (self->menuState == REPAIR_RUNNING) + { + // Create the repair screen + repairMenu_printRepair(self); } - if (keyState == self->keyStateTrigger) + if (KeyboardDevice_read(&storm700->keyboardDevice, &key, &keyState) == SUCCESS) { - repairMenu_performAction(self, key); + if (repairMenu_performAction(self, key, keyState) == SUCCESS) + { + // The key had an action + // 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); + LOGGER_WARNING(mainLog, "menu index is %d", self->menuState); + } } - - + vTaskDelay(50); } LOGGER_INFO(mainLog, "Deleting RepairMenu task"); @@ -236,6 +257,64 @@ static void repairMenu_task(void* parameters) } +static void repairMenu_changeState(struct RepairMenu* self, T_MenuState newState) +{ + Display_clearScreen(self->display); + self->menuState = newState; +} + +static void repairMenu_printError(struct RepairMenu* self) +{ + Display_write(self->display, "!!ERROR!!", strlen("!!ERROR!!"), 2, 6); + Display_write(self->display, self->errorMessage, strlen(self->errorMessage), 3, 1 + ((self->display->displayDevice->parameters.numberOfColumns - strlen(self->errorMessage)) / 2)); +} + + +static void repairMenu_printWarning(struct RepairMenu* self) +{ + +} + + +static void repairMenu_printRepair(struct RepairMenu* self) +{ + uint32_t rpSecondsCounter; + int hoursToRemain; + int minutesToRemain; + int secondsToRemain; + char buffer[20]; + repairProcess_getRepairTime(&self->repairProcess, &rpSecondsCounter, &hoursToRemain, &minutesToRemain, &secondsToRemain); + + snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), " %02d:%02d:%02d remain", hoursToRemain, minutesToRemain, secondsToRemain); + Display_write(self->display, buffer, strlen(buffer), 2, 1); + + if (PCBA_getInstance()->pcba == Tesla) + { + Display_write(self->display, "R2", strlen("R2"), 3, 10); + uint16_t value; + ADCChannel_read(self->repairProcess.adc[1], &value); + snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%05dV", value); + Display_write(self->display, buffer, strlen(buffer), 4, 8); + } + else if ((PCBA_getInstance()->pcba == Anode) || (PCBA_getInstance()->pcba == CathodeMCP)) + { + Display_write(self->display, "R1", strlen("R1"), 3, 3); + Display_write(self->display, "R2", strlen("R2"), 3, 10); + Display_write(self->display, "R3", strlen("R3"), 3, 17); + + uint16_t value; + ADCChannel_read(self->repairProcess.adc[0], &value); + snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%05dV", value); + Display_write(self->display, buffer, strlen(buffer), 4, 1); + ADCChannel_read(self->repairProcess.adc[1], &value); + snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%05dV", value); + Display_write(self->display, buffer, strlen(buffer), 4, 8); + ADCChannel_read(self->repairProcess.adc[2], &value); + snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%05dV", value); + Display_write(self->display, buffer, strlen(buffer), 4, 15); + } +} + static void repairMenu_printMenu(struct RepairMenu* self) { @@ -260,9 +339,11 @@ static void repairMenu_printCursor(struct RepairMenu* self) } -static void repairMenu_performAction(struct RepairMenu* self, char key) +static ErrorStatus repairMenu_performAction(struct RepairMenu* self, char key, Keypad_KeyState keyState) { - struct KeyActionBinding keyAction = repairMenu_findKeyAction(self, key); + ErrorStatus returnValue = SUCCESS; + + struct KeyActionBinding keyAction = repairMenu_findKeyAction(self, key, keyState); LOGGER_DEBUG(mainLog, "Action: received key %c, action to perform %d,", key, keyAction.action); switch (keyAction.action) @@ -270,17 +351,19 @@ static void repairMenu_performAction(struct RepairMenu* self, char key) case NO_ACTION: { LOGGER_INFO(mainLog, "This button has no action"); + returnValue = ERROR; break; } case HOTKEY_SELECT: { LOGGER_INFO(mainLog, "HOTKEY SELECT ITEM: char %c, argument %d - Going to state %d", keyAction.key, keyAction.argument, self->menuArray[self->menuState].row[keyAction.argument].newState); - if (self->menuArray[self->menuState].row[keyAction.argument].actionPointer != NULL) + T_MenuState tempState = self->menuState; + repairMenu_changeState(self, self->menuArray[self->menuState].row[keyAction.argument].newState); + if (self->menuArray[tempState].row[keyAction.argument].actionPointer != NULL) { - self->menuArray[self->menuState].row[keyAction.argument].actionPointer(self, keyAction.argument); + self->menuArray[tempState].row[keyAction.argument].actionPointer(self, keyAction.argument); } - self->menuState = self->menuArray[self->menuState].row[keyAction.argument].newState; repairMenu_scrollIndexHandlerReset(self); break; } @@ -288,15 +371,33 @@ static void repairMenu_performAction(struct RepairMenu* self, char key) case SELECT: { LOGGER_INFO(mainLog, "SELECT ITEM %d - going to state %d", self->cursorIndex, self->menuArray[self->menuState].row[self->cursorIndex].newState); - if (self->menuArray[self->menuState].row[self->cursorIndex].actionPointer != NULL) + T_MenuState tempState = self->menuState; + repairMenu_changeState(self, self->menuArray[self->menuState].row[self->cursorIndex].newState); + if (self->menuArray[tempState].row[self->cursorIndex].actionPointer != NULL) { - self->menuArray[self->menuState].row[self->cursorIndex].actionPointer(self, self->cursorIndex); + self->menuArray[tempState].row[self->cursorIndex].actionPointer(self, self->cursorIndex); } - self->menuState = self->menuArray[self->menuState].row[self->cursorIndex].newState; repairMenu_scrollIndexHandlerReset(self); break; } + case GOTO_STATE: + { + LOGGER_INFO(mainLog, "Going to new state %d directly", keyAction.argument); + repairMenu_changeState(self, keyAction.argument); + break; + } + + case EXECUTE_FUNCTION: + { + LOGGER_INFO(mainLog, "Executing function directly"); + if (keyAction.actionPointer != NULL) + { + keyAction.actionPointer(self, 0); + } + break; + } + case SCROLL_UP: { LOGGER_INFO(mainLog, "Scrolling up"); @@ -315,10 +416,11 @@ static void repairMenu_performAction(struct RepairMenu* self, char key) break; } } + return returnValue; } -static struct KeyActionBinding repairMenu_findKeyAction(struct RepairMenu* self, char key) +static struct KeyActionBinding repairMenu_findKeyAction(struct RepairMenu* self, char key, Keypad_KeyState keyState) { int loopCounter; struct KeyActionBinding returnValue; @@ -326,7 +428,7 @@ static struct KeyActionBinding repairMenu_findKeyAction(struct RepairMenu* self, for (loopCounter = 0; loopCounter < REPAIRMENU_MAX_NUMBER_OF_KEYS; loopCounter++) { - if (self->menuArray[self->menuState].keyActionBinding[loopCounter].key == key) + if ((self->menuArray[self->menuState].keyActionBinding[loopCounter].key == key) && (self->menuArray[self->menuState].keyActionBinding[loopCounter].keyState == keyState)) { returnValue = self->menuArray[self->menuState].keyActionBinding[loopCounter]; break; @@ -392,6 +494,7 @@ static void repairMenu_scrollDownIndexHandler(struct RepairMenu* self) static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorIndex) { + ErrorStatus returnValue = SUCCESS; self->rpParameters.adcRow1 = &adc1->channel[0]; self->rpParameters.adcRow2 = &adc1->channel[1]; self->rpParameters.adcRow3 = &adc1->channel[2]; @@ -399,9 +502,91 @@ static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorInd 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); + + // First, Lock the cover + if (returnValue == SUCCESS) + { + hsb_solenoidLock(); + } + + if (returnValue == SUCCESS) + { + // Check for INTERLOCK CLOSE + if (Interlock_isClosed(interlock)) + { + // Enable Interrupt for interlock switch + Interlock_setEXTI(interlock, ENABLE); + } + else + { + Error_postError(INTERLOCK_COMMON_FAIL); + returnValue = ERROR; + } + } + + if (returnValue == SUCCESS) + { + // TESLA has a second interlock that must be closed + if (PCBA_getInstance()->pcba == Tesla) + { + if (Interlock_isClosed(teslalock)) + { + // Enable Interrupt for tesla interlock switch + Interlock_setEXTI(teslalock, ENABLE); + } + else + { +// Error_postError(INTERLOCK_TESLA_FAIL); +// returnValue = ERROR; + } + } + } + + // if Interlock(s) closed, continue procedure + if (returnValue == SUCCESS) + { + // Power the circuit + if (GPIO_setValue(power6v5Enable, true) != SUCCESS) + { + Error_postError(POWERENABLE_FAIL); + } + } + + if (returnValue == SUCCESS) + { + // For MCP/Cathode, the right settings must be made + ///TODO + } + + // If all is OK, start the repair process + if (returnValue == SUCCESS) + { + rp = &self->repairProcess; + Observable_addObserver(RTC_getObservable(rtc), repairMenu_feedProcessSecondsCounter); + returnValue = repairProcess_construct(&self->repairProcess, &self->rpParameters, self->repairPreset, 2, 1024); + + if (returnValue == SUCCESS) + { + // repair process is running + repairMenu_changeState(self, REPAIR_RUNNING); + } + else + { + Error_postError(REPAIR_FAIL); + } + } +} + + +static void repairMenu_abortRepairProcess(struct RepairMenu* self) +{ + Interlock_setEXTI(interlock, DISABLE); + if (PCBA_getInstance()->pcba == Tesla) + { + Interlock_setEXTI(teslalock, ENABLE); + } + + repairProcess_destruct(&self->repairProcess); } static ErrorStatus repairMenu_feedProcessSecondsCounter(const void* const data) @@ -418,85 +603,117 @@ static void repairMenu_selectPreset(struct RepairMenu* self, int cursorIndex) } +static void repairMenu_solenoidLock(struct RepairMenu* self, int cursorIndex) +{ + hsb_solenoidLock(); +} + + +static void repairMenu_solenoidUnlock(struct RepairMenu* self, int cursorIndex) +{ + hsb_solenoidUnlock(); +} + + static ErrorStatus repairMenu_createMenu(struct RepairMenu* self) { ErrorStatus returnValue = SUCCESS; repairMenu_createMenuPage(&self->menuArray[MAINMENU], MENU_HAS_CURSOR, 4); - repairMenu_addMenuPageRow(&self->menuArray[MAINMENU], 0, PCBA_getInstance()->name, MAINMENU, NULL); - repairMenu_addMenuPageRow(&self->menuArray[MAINMENU], 1, " 1.Tube repair", REPAIRMENU, NULL); - repairMenu_addMenuPageRow(&self->menuArray[MAINMENU], 2, " 2.Administrator", ADMINMENU, NULL); - repairMenu_addMenuPageRow(&self->menuArray[MAINMENU], 3, " 3.Calibration", CALIBRATIONMENU, NULL); - repairMenu_addMenuPageKeyAction(&self->menuArray[MAINMENU], 0, 'U', SCROLL_UP, 0); - repairMenu_addMenuPageKeyAction(&self->menuArray[MAINMENU], 1, 'D', SCROLL_DOWN, 0); - repairMenu_addMenuPageKeyAction(&self->menuArray[MAINMENU], 2, 'E', SELECT, 0); - repairMenu_addMenuPageKeyAction(&self->menuArray[MAINMENU], 3, '1', HOTKEY_SELECT, 1); - repairMenu_addMenuPageKeyAction(&self->menuArray[MAINMENU], 4, '2', HOTKEY_SELECT, 2); - repairMenu_addMenuPageKeyAction(&self->menuArray[MAINMENU], 5, '3', HOTKEY_SELECT, 3); + repairMenu_addMenuPageRow(&self->menuArray[MAINMENU], PCBA_getInstance()->name, MAINMENU, NULL); + repairMenu_addMenuPageRow(&self->menuArray[MAINMENU], " 1.Tube repair", REPAIRMENU, NULL); + repairMenu_addMenuPageRow(&self->menuArray[MAINMENU], " 2.Administrator", ADMINMENU, NULL); + repairMenu_addMenuPageRow(&self->menuArray[MAINMENU], " 3.Calibration", CALIBRATIONMENU, NULL); + repairMenu_addKeyAction_SCROLLUP(&self->menuArray[MAINMENU], 'U', PRESSED); + repairMenu_addKeyAction_SCROLLDOWN(&self->menuArray[MAINMENU], 'D', PRESSED); + repairMenu_addKeyAction_SELECT(&self->menuArray[MAINMENU], 'E', PRESSED); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[MAINMENU], '1', PRESSED, 1); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[MAINMENU], '2', PRESSED, 2); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[MAINMENU], '3', PRESSED, 3); + repairMenu_addKeyAction_EXECUTEFUNCTION(&self->menuArray[MAINMENU], '0', PRESSED, repairMenu_solenoidUnlock); + repairMenu_addKeyAction_EXECUTEFUNCTION(&self->menuArray[MAINMENU], '0', RELEASED, repairMenu_solenoidLock); + repairMenu_createMenuPage(&self->menuArray[REPAIRMENU], MENU_HAS_CURSOR, 4); - repairMenu_addMenuPageRow(&self->menuArray[REPAIRMENU], 0, "Tube repair", REPAIRMENU, NULL); - repairMenu_addMenuPageRow(&self->menuArray[REPAIRMENU], 1, " 1.Select preset", PRESETMENU, NULL); - repairMenu_addMenuPageRow(&self->menuArray[REPAIRMENU], 2, " 2.Start", START_REPAIR, repairMenu_startRepairProcess); - repairMenu_addMenuPageRow(&self->menuArray[REPAIRMENU], 3, " 3.To main menu", MAINMENU, NULL); - repairMenu_addMenuPageKeyAction(&self->menuArray[REPAIRMENU], 0, 'U', SCROLL_UP, 0); - repairMenu_addMenuPageKeyAction(&self->menuArray[REPAIRMENU], 1, 'D', SCROLL_DOWN, 0); - repairMenu_addMenuPageKeyAction(&self->menuArray[REPAIRMENU], 2, 'E', SELECT, 0); - repairMenu_addMenuPageKeyAction(&self->menuArray[REPAIRMENU], 3, '1', HOTKEY_SELECT, 1); - repairMenu_addMenuPageKeyAction(&self->menuArray[REPAIRMENU], 4, '2', HOTKEY_SELECT, 2); - repairMenu_addMenuPageKeyAction(&self->menuArray[REPAIRMENU], 5, 'X', HOTKEY_SELECT, 3); + repairMenu_addMenuPageRow(&self->menuArray[REPAIRMENU], "Tube repair", REPAIRMENU, NULL); + repairMenu_addMenuPageRow(&self->menuArray[REPAIRMENU], " 1.Select preset", PRESETMENU, NULL); + repairMenu_addMenuPageRow(&self->menuArray[REPAIRMENU], " 2.Start", START_REPAIR, repairMenu_startRepairProcess); + repairMenu_addKeyAction_SCROLLUP(&self->menuArray[REPAIRMENU], 'U', PRESSED); + repairMenu_addKeyAction_SCROLLDOWN(&self->menuArray[REPAIRMENU], 'D', PRESSED); + repairMenu_addKeyAction_SELECT(&self->menuArray[REPAIRMENU], 'E', PRESSED); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[REPAIRMENU], '1', PRESSED, 1); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[REPAIRMENU], '2', PRESSED, 2); + repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[REPAIRMENU], 'X', PRESSED, MAINMENU); + repairMenu_addKeyAction_EXECUTEFUNCTION(&self->menuArray[REPAIRMENU], '0', PRESSED, repairMenu_solenoidUnlock); + repairMenu_addKeyAction_EXECUTEFUNCTION(&self->menuArray[REPAIRMENU], '0', RELEASED, repairMenu_solenoidLock); + repairMenu_createMenuPage(&self->menuArray[ADMINMENU], MENU_HAS_NO_CURSOR, 2); - repairMenu_addMenuPageRow(&self->menuArray[ADMINMENU], 0, "Administration", ADMINMENU, NULL); - repairMenu_addMenuPageRow(&self->menuArray[ADMINMENU], 1, " 1.To main menu", MAINMENU, NULL); - repairMenu_addMenuPageKeyAction(&self->menuArray[ADMINMENU], 0, 'E', SELECT, 0); - repairMenu_addMenuPageKeyAction(&self->menuArray[ADMINMENU], 1, '1', HOTKEY_SELECT, 1); - repairMenu_addMenuPageKeyAction(&self->menuArray[ADMINMENU], 2, 'X', HOTKEY_SELECT, 1); + repairMenu_addMenuPageRow(&self->menuArray[ADMINMENU], "Administration", ADMINMENU, NULL); + repairMenu_addMenuPageRow(&self->menuArray[ADMINMENU], " 1.Nothing", ADMINMENU, NULL); + repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[ADMINMENU], 'X', PRESSED, MAINMENU); repairMenu_createMenuPage(&self->menuArray[CALIBRATIONMENU], MENU_HAS_NO_CURSOR, 2); - repairMenu_addMenuPageRow(&self->menuArray[CALIBRATIONMENU], 0, "Calibration", CALIBRATIONMENU, NULL); - repairMenu_addMenuPageRow(&self->menuArray[CALIBRATIONMENU], 1, " 1.To main menu", MAINMENU, NULL); - repairMenu_addMenuPageKeyAction(&self->menuArray[CALIBRATIONMENU], 0, 'E', SELECT, 0); - repairMenu_addMenuPageKeyAction(&self->menuArray[CALIBRATIONMENU], 1, '1', HOTKEY_SELECT, 1); - repairMenu_addMenuPageKeyAction(&self->menuArray[CALIBRATIONMENU], 2, 'X', HOTKEY_SELECT, 1); + repairMenu_addMenuPageRow(&self->menuArray[CALIBRATIONMENU], "Calibration", CALIBRATIONMENU, NULL); + repairMenu_addMenuPageRow(&self->menuArray[CALIBRATIONMENU], " 1.Nothing", CALIBRATIONMENU, NULL); + repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[CALIBRATIONMENU], 'X', PRESSED, MAINMENU); - repairMenu_createMenuPage(&self->menuArray[PRESETMENU], MENU_HAS_CURSOR, 11); - repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], 0, "Select preset", PRESETMENU, NULL); - repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], 1, " 1.Preset1", REPAIRMENU, repairMenu_selectPreset); - repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], 2, " 2.Preset2", REPAIRMENU, repairMenu_selectPreset); - repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], 3, " 3.Preset3", REPAIRMENU, repairMenu_selectPreset); - repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], 4, " 4.Preset4", REPAIRMENU, repairMenu_selectPreset); - repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], 5, " 5.Preset5", REPAIRMENU, repairMenu_selectPreset); - repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], 6, " 6.Preset6", REPAIRMENU, repairMenu_selectPreset); - repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], 7, " 7.Preset7", REPAIRMENU, repairMenu_selectPreset); - repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], 8, " 8.Preset8", REPAIRMENU, repairMenu_selectPreset); - repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], 9, " 9.Preset9", REPAIRMENU, repairMenu_selectPreset); - repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], 10, " 10.To repair menu", REPAIRMENU, NULL); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 0, 'U', SCROLL_UP, 0); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 1, 'D', SCROLL_DOWN, 0); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 2, 'E', SELECT, 0); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 3, '1', HOTKEY_SELECT, 1); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 4, '2', HOTKEY_SELECT, 2); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 5, '3', HOTKEY_SELECT, 3); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 6, '4', HOTKEY_SELECT, 4); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 7, '5', HOTKEY_SELECT, 5); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 8, '6', HOTKEY_SELECT, 6); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 9, '7', HOTKEY_SELECT, 7); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 10, '8', HOTKEY_SELECT, 8); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 11, '9', HOTKEY_SELECT, 9); - repairMenu_addMenuPageKeyAction(&self->menuArray[PRESETMENU], 12, 'X', HOTKEY_SELECT, 10); + repairMenu_createMenuPage(&self->menuArray[PRESETMENU], MENU_HAS_CURSOR, 10); + repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], "Select preset", PRESETMENU, NULL); + repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], " 1.Preset1", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], " 2.Preset2", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], " 3.Preset3", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], " 4.Preset4", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], " 5.Preset5", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], " 6.Preset6", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], " 7.Preset7", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], " 8.Preset8", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addMenuPageRow(&self->menuArray[PRESETMENU], " 9.Preset9", REPAIRMENU, repairMenu_selectPreset); + repairMenu_addKeyAction_SCROLLUP(&self->menuArray[PRESETMENU], 'U', PRESSED); + repairMenu_addKeyAction_SCROLLDOWN(&self->menuArray[PRESETMENU], 'D', PRESSED); + repairMenu_addKeyAction_SELECT(&self->menuArray[PRESETMENU], 'E', PRESSED); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[PRESETMENU], '1', PRESSED, 1); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[PRESETMENU], '2', PRESSED, 2); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[PRESETMENU], '3', PRESSED, 3); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[PRESETMENU], '4', PRESSED, 4); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[PRESETMENU], '5', PRESSED, 5); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[PRESETMENU], '6', PRESSED, 6); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[PRESETMENU], '7', PRESSED, 7); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[PRESETMENU], '8', PRESSED, 8); + repairMenu_addKeyAction_HOTKEYSELECT(&self->menuArray[PRESETMENU], '9', PRESSED, 9); + repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[PRESETMENU], 'X', PRESSED, REPAIRMENU); + repairMenu_addKeyAction_EXECUTEFUNCTION(&self->menuArray[PRESETMENU], '0', PRESSED, repairMenu_solenoidUnlock); + repairMenu_addKeyAction_EXECUTEFUNCTION(&self->menuArray[PRESETMENU], '0', RELEASED, repairMenu_solenoidLock); + + repairMenu_createMenuPage(&self->menuArray[REPAIR_RUNNING], MENU_HAS_NO_CURSOR, 4); + repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[REPAIR_RUNNING], 'X', PRESSED, REPAIR_ASK_PAUSE); + + repairMenu_createMenuPage(&self->menuArray[REPAIR_ASK_PAUSE], MENU_HAS_NO_CURSOR, 4); + repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[REPAIR_ASK_PAUSE], 'X', PRESSED, REPAIR_PAUSE); + + repairMenu_createMenuPage(&self->menuArray[REPAIR_PAUSE], MENU_HAS_NO_CURSOR, 4); + repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[REPAIR_PAUSE], 'X', PRESSED, REPAIR_PAUSE); + + repairMenu_createMenuPage(&self->menuArray[ERROR_STATE], MENU_HAS_NO_CURSOR, 4); + repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[ERROR_STATE], 'X', PRESSED, MAINMENU); + repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[ERROR_STATE], 'E', PRESSED, REPAIR_RUNNING); return returnValue; } -static ErrorStatus repairMenu_createMenuPage (struct MenuPage* self, bool hasCursor, int numberOfRows) +static ErrorStatus repairMenu_createMenuPage (struct MenuPage* self, bool hasCursor, int maxNumberOfRows) { ErrorStatus returnValue = SUCCESS; - self->hasCursor = hasCursor; - if (numberOfRows <= REPAIRMENU_MAX_NUMBER_OF_ROWS) + + + if (maxNumberOfRows <= REPAIRMENU_MAX_NUMBER_OF_ROWS) { - self->numberOfRows = numberOfRows; + self->maxNumberOfKeys = NUMBER_OF_KEY_EVENTS * REPAIRMENU_MAX_NUMBER_OF_KEYS; + self->numberOfRows = 0; + self->numberOfKeys = 0; + self->maxNumberOfRows = maxNumberOfRows; + self->hasCursor = hasCursor; } else { @@ -505,14 +722,15 @@ static ErrorStatus repairMenu_createMenuPage (struct MenuPage* self, bool hasCur return returnValue; } -static ErrorStatus repairMenu_addMenuPageRow (struct MenuPage* self, int rowIndex, char* text, int newState, RepairMenuFunctionCall actionCall) +static ErrorStatus repairMenu_addMenuPageRow (struct MenuPage* self, char* text, int newState, RepairMenuFunctionCall actionCall) { ErrorStatus returnValue = SUCCESS; - if (rowIndex < self->numberOfRows) + if (self->numberOfRows < self->maxNumberOfRows) { - memcpy(self->row[rowIndex].text, text, 20); - self->row[rowIndex].newState = newState; - self->row[rowIndex].actionPointer = actionCall; + memcpy(self->row[self->numberOfRows].text, text, 20); + self->row[self->numberOfRows].newState = newState; + self->row[self->numberOfRows].actionPointer = actionCall; + self->numberOfRows++; } else { @@ -521,18 +739,136 @@ static ErrorStatus repairMenu_addMenuPageRow (struct MenuPage* self, int rowInde return returnValue; } -static ErrorStatus repairMenu_addMenuPageKeyAction (struct MenuPage* self, int keyActionIndex, char key, T_KeyAction action, int argument) + +static ErrorStatus repairMenu_addKeyAction_HOTKEYSELECT (struct MenuPage* self, char key, Keypad_KeyState keyState, int rowToSelect) { ErrorStatus returnValue = SUCCESS; - if (keyActionIndex < REPAIRMENU_MAX_NUMBER_OF_KEYS) + + if (self->numberOfKeys < self->maxNumberOfKeys) { - self->keyActionBinding[keyActionIndex].key = key; - self->keyActionBinding[keyActionIndex].argument = argument; - self->keyActionBinding[keyActionIndex].action = action; + self->keyActionBinding[self->numberOfKeys].key = key; + self->keyActionBinding[self->numberOfKeys].keyState = keyState; + self->keyActionBinding[self->numberOfKeys].action = HOTKEY_SELECT; + self->keyActionBinding[self->numberOfKeys].argument = rowToSelect; + self->keyActionBinding[self->numberOfKeys].actionPointer = NULL; + self->numberOfKeys++; } else { returnValue = ERROR; } + return returnValue; } + + +static ErrorStatus repairMenu_addKeyAction_SELECT (struct MenuPage* self, char key, Keypad_KeyState keyState) +{ + ErrorStatus returnValue = SUCCESS; + + if (self->numberOfKeys < self->maxNumberOfKeys) + { + self->keyActionBinding[self->numberOfKeys].key = key; + self->keyActionBinding[self->numberOfKeys].keyState = keyState; + self->keyActionBinding[self->numberOfKeys].action = SELECT; + self->keyActionBinding[self->numberOfKeys].argument = 0; + self->keyActionBinding[self->numberOfKeys].actionPointer = NULL; + self->numberOfKeys++; + } + else + { + returnValue = ERROR; + } + + return returnValue; +} + + +static ErrorStatus repairMenu_addKeyAction_GOTOSTATE (struct MenuPage* self, char key, Keypad_KeyState keyState, T_MenuState state) +{ + ErrorStatus returnValue = SUCCESS; + + if (self->numberOfKeys < self->maxNumberOfKeys) + { + self->keyActionBinding[self->numberOfKeys].key = key; + self->keyActionBinding[self->numberOfKeys].keyState = keyState; + self->keyActionBinding[self->numberOfKeys].action = GOTO_STATE; + self->keyActionBinding[self->numberOfKeys].argument = state; + self->keyActionBinding[self->numberOfKeys].actionPointer = NULL; + self->numberOfKeys++; + } + else + { + returnValue = ERROR; + } + + return returnValue; +} + + +static ErrorStatus repairMenu_addKeyAction_EXECUTEFUNCTION (struct MenuPage* self, char key, Keypad_KeyState keyState, RepairMenuFunctionCall actionPointer) +{ + ErrorStatus returnValue = SUCCESS; + + if (self->numberOfKeys < self->maxNumberOfKeys) + { + self->keyActionBinding[self->numberOfKeys].key = key; + self->keyActionBinding[self->numberOfKeys].keyState = keyState; + self->keyActionBinding[self->numberOfKeys].action = EXECUTE_FUNCTION; + self->keyActionBinding[self->numberOfKeys].argument = 0; + self->keyActionBinding[self->numberOfKeys].actionPointer = actionPointer; + self->numberOfKeys++; + } + else + { + returnValue = ERROR; + } + + return returnValue; +} + + +static ErrorStatus repairMenu_addKeyAction_SCROLLUP (struct MenuPage* self, char key, Keypad_KeyState keyState) +{ + ErrorStatus returnValue = SUCCESS; + + if (self->numberOfKeys < self->maxNumberOfKeys) + { + self->keyActionBinding[self->numberOfKeys].key = key; + self->keyActionBinding[self->numberOfKeys].keyState = keyState; + self->keyActionBinding[self->numberOfKeys].action = SCROLL_UP; + self->keyActionBinding[self->numberOfKeys].argument = 0; + self->keyActionBinding[self->numberOfKeys].actionPointer = NULL; + self->numberOfKeys++; + } + else + { + returnValue = ERROR; + } + + return returnValue; +} + + +static ErrorStatus repairMenu_addKeyAction_SCROLLDOWN (struct MenuPage* self, char key, Keypad_KeyState keyState) +{ + ErrorStatus returnValue = SUCCESS; + + if (self->numberOfKeys < self->maxNumberOfKeys) + { + self->keyActionBinding[self->numberOfKeys].key = key; + self->keyActionBinding[self->numberOfKeys].keyState = keyState; + self->keyActionBinding[self->numberOfKeys].action = SCROLL_DOWN; + self->keyActionBinding[self->numberOfKeys].argument = 0; + self->keyActionBinding[self->numberOfKeys].actionPointer = NULL; + self->numberOfKeys++; + } + else + { + returnValue = ERROR; + } + + return returnValue; +} + + 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 7d64a5a..6e917e7 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 @@ -29,6 +29,7 @@ #include "hsb-mrts.h" +#include "Error.h" #include "repairMenus.h" #include "repairMenu.h" @@ -61,7 +62,7 @@ struct RepairMenu* const mainMenu = &_mainMenu; // Function declarations // ----------------------------------------------------------------------------- -static ErrorStatus repairMenus_mainMenuObserverFromISR(const void* const data); +static ErrorStatus repairMenu_errorReceive(const void* const data); // ----------------------------------------------------------------------------- // Function definitions @@ -79,7 +80,7 @@ ErrorStatus repairMenus_construct(void) if (returnValue == SUCCESS) { - returnValue = Observable_addObserver(RTC_getObservable(rtc), repairMenus_mainMenuObserverFromISR); + returnValue = Observable_addObserver(Error_getObservable(), repairMenu_errorReceive); } return returnValue; @@ -88,13 +89,30 @@ ErrorStatus repairMenus_construct(void) void repairMenus_destruct(void) { - Observable_deleteObserver(RTC_getObservable(rtc), repairMenus_mainMenuObserverFromISR); + Observable_deleteObserver(Error_getObservable(), repairMenu_errorReceive); repairMenu_destruct(mainMenu); } -static ErrorStatus repairMenus_mainMenuObserverFromISR(const void* const data) +static ErrorStatus repairMenu_errorReceive(const void* const data) { - repairMenu_feedSecondsCounterFromISR(mainMenu); - return SUCCESS; + T_ErrorCode errorCode = (T_ErrorCode)data; + // Only respond to the errors necessary + if (errorCode == INTERLOCK_COMMON_FAIL) + { + repairMenu_interlockFailed(mainMenu, COMMON_INTERLOCK); + } + else if (errorCode == INTERLOCK_TESLA_FAIL) + { + repairMenu_interlockFailed(mainMenu, TESLA_INTERLOCK); + } + else if (errorCode == POWERENABLE_FAIL) + { + + } + else if (errorCode == REPAIR_FAIL) + { + + } + return 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 f61514b..3fa7fe6 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 @@ -105,9 +105,9 @@ ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairPro self->pid[2].initialized = false; - PID_construct(&self->pid[0], 5000, 3000, 1000, 0, 10000000); - PID_construct(&self->pid[1], 5000, 3000, 1000, 0, 10000000); - PID_construct(&self->pid[2], 5000, 3000, 1000, 0, 10000000); + PID_construct(&self->pid[0], 3000, 2000, 0, 0, 10000000); + PID_construct(&self->pid[1], 3000, 2000, 0, 0, 10000000); + PID_construct(&self->pid[2], 3000, 2000, 0, 0, 10000000); LOGGER_INFO(mainLog, "Repair Process task started"); } @@ -125,6 +125,13 @@ ErrorStatus repairProcess_construct(struct RepairProcess* self, struct RepairPro } +void repairProcess_destruct(struct RepairProcess* self) +{ + self->runTask = false; + self->initialized = false; +} + + void repairProcess_feedSecondsCounter(struct RepairProcess* self) { if (self->initialized) @@ -146,13 +153,18 @@ void repairProcess_feedSecondsCounterFromISR(struct RepairProcess* self) } -ErrorStatus repairProcess_getRepairTime(const struct RepairProcess* self, uint32_t* repairTime) +ErrorStatus repairProcess_getRepairTime(const struct RepairProcess* self, uint32_t* repairTime, int* hours, int* minutes, int* seconds) { ErrorStatus returnValue = SUCCESS; if (self->initialized) { *repairTime = self->secondsCounter; + + uint32_t timeToRemain = self->voltageHoldTimer - self->secondsCounter; + *hours = (timeToRemain / (60 * 60)); + *minutes = (timeToRemain - (*hours * 60 * 60)) / 60; + *seconds = (timeToRemain - (*hours * 60 * 60) - (*minutes * 60)); } else { @@ -257,7 +269,7 @@ static int SignalProfileGenerator(struct RepairProcess* self) // If first preset, start voltage is 0 if (self->currentPresetIndex == 0) { - startVoltage = 0; + startVoltage = 450; } else { diff --git a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c index 3b522f5..a33bccb 100644 --- a/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c +++ b/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/hsb-mrts/src/stm32f10x_it.c @@ -39,6 +39,7 @@ #include "stm32f10x_usart.h" #include "Display.h" +#include "Error.h" #include "repairMenu.h" #include "repairProcess.h" @@ -237,7 +238,7 @@ void EXTI0_IRQHandler(void) static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE; EXTI_ClearITPendingBit(EXTI_Line0); - LOGGER_ERROR_ISR(mainLog, "EXTI0 IRQ TRIGGERED"); + Error_postErrorFromISR(INTERLOCK_COMMON_FAIL); portEND_SWITCHING_ISR(higherPriorityTaskWoken); } @@ -248,7 +249,7 @@ void EXTI1_IRQHandler(void) static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE; EXTI_ClearITPendingBit(EXTI_Line1); - LOGGER_ERROR_ISR(mainLog, "EXTI1 IRQ TRIGGERED"); + Error_postErrorFromISR(INTERLOCK_COMMON_FAIL); portEND_SWITCHING_ISR(higherPriorityTaskWoken); } @@ -294,7 +295,7 @@ void EXTI9_5_IRQHandler (void) else if (EXTI_GetITStatus(EXTI_Line9) != RESET) { EXTI_ClearITPendingBit(EXTI_Line9); - LOGGER_ERROR_ISR(mainLog, "EXTI9 IRQ TRIGGERED"); + Error_postErrorFromISR(INTERLOCK_TESLA_FAIL); } portEND_SWITCHING_ISR(higherPriorityTaskWoken); @@ -308,7 +309,7 @@ void EXTI15_10_IRQHandler (void) if (EXTI_GetITStatus(EXTI_Line10) != RESET) { EXTI_ClearITPendingBit(EXTI_Line10); - LOGGER_ERROR_ISR(mainLog, "EXTI10 IRQ TRIGGERED"); + Error_postErrorFromISR(INTERLOCK_TESLA_FAIL); } else if (EXTI_GetITStatus(EXTI_Line11) != RESET) {