Progress on the menu

- Debounced the interlocks
- Created a specified screen for pre-compliance tests

ADCs must be averaged
menu handling of screens is not OK
destructing tasks is not OK

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@257 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-10-18 15:26:05 +00:00
parent 97a42de2ea
commit 51ffde94d7
20 changed files with 649 additions and 215 deletions

View File

@@ -29,6 +29,7 @@
#include "string.h"
#include "repairMenu.h"
#include "repairProcess.h"
#include "repairProcesses.h"
#include "Display.h"
#include "Error.h"
@@ -41,6 +42,7 @@
#include "KeyboardDevice.h"
#include "PCBA.h"
#include "rtc.h"
#include "storm700.h"
// -----------------------------------------------------------------------------
@@ -61,8 +63,6 @@
// File-scope variables
// -----------------------------------------------------------------------------
//TODO THIS IS UGLY
static struct RepairProcess* rp = NULL;
static const char cursorValue = 0x7E;
@@ -87,6 +87,9 @@ 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_printAskPause(struct RepairMenu* self);
static void repairMenu_printPause(struct RepairMenu* self);
static void repairMenu_printFinish(struct RepairMenu* self);
static void repairMenu_printMenu(struct RepairMenu* self);
static void repairMenu_printCursor(struct RepairMenu* self);
static ErrorStatus repairMenu_performAction(struct RepairMenu* self, char key, Keypad_KeyState keyState);
@@ -94,13 +97,12 @@ static struct KeyActionBinding repairMenu_findKeyAction(struct RepairMenu* self,
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 void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorIndex);
static void repairMenu_stopRepairProcess(struct RepairMenu* self, int cursorIndex);
static ErrorStatus repairMenu_createMenu(struct RepairMenu* self);
static ErrorStatus repairMenu_createMenuPage (struct MenuPage* self, bool hasCursor, int maxNumberOfRows);
@@ -118,7 +120,7 @@ static ErrorStatus repairMenu_addKeyAction_SCROLLDOWN (struct MenuPage* self, ch
// -----------------------------------------------------------------------------
ErrorStatus repairMenu_construct(struct RepairMenu* self, struct Display* display, struct KeyboardDevice* keyboardDevice, int taskPriority, uint16_t stackSize, Keypad_KeyState keyStateTrigger)
ErrorStatus repairMenu_construct(struct RepairMenu* self, struct Display* display, struct KeyboardDevice* keyboardDevice, int taskPriority, uint16_t stackSize, Observer repairScreenUpdateObserver)
{
ErrorStatus returnValue = SUCCESS;
@@ -165,7 +167,10 @@ ErrorStatus repairMenu_construct(struct RepairMenu* self, struct Display* displa
}
else
{
vSemaphoreCreateBinary(self->repairScreenUpdateSemaphore);
self->observer = repairScreenUpdateObserver;
self->initialized = true;
self->repairPreset = presetArray[0];
self->cursorIndex = 1;
self->scrollOffset = 0;
LOGGER_INFO(mainLog, "Repair Menu task started");
@@ -183,6 +188,8 @@ ErrorStatus repairMenu_construct(struct RepairMenu* self, struct Display* displa
void repairMenu_destruct (struct RepairMenu* self)
{
repairProcesses_abortMainRepairProcess();
self->runTask = false;
self->initialized = false;
}
@@ -223,7 +230,7 @@ static void repairMenu_task(void* parameters)
// Show ERROR message
repairMenu_printError(self);
// Handle error
repairMenu_abortRepairProcess(self);
repairMenu_stopRepairProcess(self, 0);
}
else if (self->menuState == WARNING_STATE)
{
@@ -231,8 +238,31 @@ static void repairMenu_task(void* parameters)
}
else if (self->menuState == REPAIR_RUNNING)
{
// Create the repair screen
repairMenu_printRepair(self);
// Check the remaining repair time
struct Time remainingTime = repairProcess_getRemainingRepairTime(repairProcesses_getMainRepairProcess());
if ((remainingTime.hours == 0) && (remainingTime.minutes == 0) && (remainingTime.seconds == 0))
{
// repair is finished
repairMenu_changeState(self, FINISH);
}
else
{
// Create the repair screen
repairMenu_printRepair(self);
}
}
else if (self->menuState == REPAIR_ASK_PAUSE)
{
repairMenu_printAskPause(self);
}
else if (self->menuState == REPAIR_PAUSE)
{
repairMenu_printPause(self);
}
else if (self->menuState == FINISH)
{
repairMenu_stopRepairProcess(self, 0);
repairMenu_printFinish(self);
}
if (KeyboardDevice_read(&storm700->keyboardDevice, &key, &keyState) == SUCCESS)
@@ -278,44 +308,64 @@ static void repairMenu_printWarning(struct RepairMenu* self)
static void repairMenu_printRepair(struct RepairMenu* self)
{
uint32_t rpSecondsCounter;
int hoursToRemain;
int minutesToRemain;
int secondsToRemain;
int loopCounter = 0;
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)
if (xSemaphoreTake(self->repairScreenUpdateSemaphore, 0) != pdTRUE)
{
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);
// Taking semaphore failed - no update on the screen
}
else if ((PCBA_getInstance()->pcba == Anode) || (PCBA_getInstance()->pcba == CathodeMCP))
else
{
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);
struct Time remainingTime = repairProcess_getRemainingRepairTime(repairProcesses_getMainRepairProcess());
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);
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), " %02d:%02d:%02d remain", remainingTime.hours, remainingTime.minutes, remainingTime.seconds);
Display_write(self->display, buffer, strlen(buffer), 1, 1);
// Regulation is unique for each row
// For TESLA repair only row 1 (out of 0,1,2) is used
// For ANODE and Cathode/MCP, all 3 rows are used
for (loopCounter = ((PCBA_getInstance()->pcba == Tesla) ? 1 : 0); loopCounter <= ((PCBA_getInstance()->pcba == Tesla) ? 1 : 2); loopCounter++)
{
struct RepairProcessRow* row;
row = repairProcess_getRowInformation(repairProcesses_getMainRepairProcess(), loopCounter);
snprintf (buffer, sizeof(buffer) / sizeof(buffer[0]), "R%d", loopCounter + 1);
Display_write(self->display, buffer, strlen(buffer), 2, ((loopCounter * (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS)) + (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS) / strlen(buffer)));
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%05dV", row->lastADCValue);
Display_write(self->display, buffer, strlen(buffer), 3, (loopCounter + (loopCounter * (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS)) + (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS) / strlen(buffer)));
snprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), "%04dER", row->pidError);
Display_write(self->display, buffer, strlen(buffer), 4, (loopCounter + (loopCounter * (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS)) + (self->display->displayDevice->parameters.numberOfColumns / REPAIRPROCESS_NUMBER_OF_ROWS) / strlen(buffer)));
}
}
}
static void repairMenu_printAskPause(struct RepairMenu* self)
{
Display_write(self->display, "REPAIR BUSY", strlen("REPAIR BUSY"), 2, 6);
Display_write(self->display, "Hit X to RESET", strlen("Hit X to RESET"), 3, 2);
}
static void repairMenu_printPause(struct RepairMenu* self)
{
Display_write(self->display, "!!PAUSE!!", strlen("!!PAUSE!!"), 2, 6);
Display_write(self->display, "Hit ENT to continue", strlen("Hit ENT to continue"), 3, 2);
Display_write(self->display, "Hit X to RESET", strlen("Hit X to RESET"), 4, 2);
}
static void repairMenu_printFinish(struct RepairMenu* self)
{
Display_write(self->display, "REPAIR FINISHED", strlen("REPAIR FINISHED"), 2, 6);
Display_write(self->display, "Hit ENT to continue", strlen("Hit ENT to continue"), 4, 2);
}
static void repairMenu_printMenu(struct RepairMenu* self)
{
int loopCounter;
@@ -492,6 +542,25 @@ static void repairMenu_scrollDownIndexHandler(struct RepairMenu* self)
}
static void repairMenu_selectPreset(struct RepairMenu* self, int cursorIndex)
{
self->repairPreset = presetArray[cursorIndex - 1];
LOGGER_INFO(mainLog, "Preset %d selected", cursorIndex);
}
static void repairMenu_solenoidLock(struct RepairMenu* self, int cursorIndex)
{
hsb_solenoidLock();
}
static void repairMenu_solenoidUnlock(struct RepairMenu* self, int cursorIndex)
{
hsb_solenoidUnlock();
}
static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorIndex)
{
ErrorStatus returnValue = SUCCESS;
@@ -502,7 +571,6 @@ static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorInd
self->rpParameters.dacRow2 = &max5715->dac[1];
self->rpParameters.dacRow3 = &max5715->dac[2];
// First, Lock the cover
if (returnValue == SUCCESS)
{
@@ -536,8 +604,8 @@ static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorInd
}
else
{
// Error_postError(INTERLOCK_TESLA_FAIL);
// returnValue = ERROR;
Error_postError(INTERLOCK_TESLA_FAIL);
returnValue = ERROR;
}
}
}
@@ -546,7 +614,7 @@ static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorInd
if (returnValue == SUCCESS)
{
// Power the circuit
if (GPIO_setValue(power6v5Enable, true) != SUCCESS)
if (GPIO_setValue(power6v5Enable, false) != SUCCESS)
{
Error_postError(POWERENABLE_FAIL);
}
@@ -561,9 +629,11 @@ static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorInd
// 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);
returnValue = repairProcesses_startMainRepairProcess(self->repairPreset, &self->rpParameters);
}
if (returnValue == SUCCESS)
{
returnValue = repairProcesses_mainRepairProcessAddObserver(self->observer);
if (returnValue == SUCCESS)
{
@@ -578,40 +648,10 @@ static void repairMenu_startRepairProcess(struct RepairMenu* self, int cursorInd
}
static void repairMenu_abortRepairProcess(struct RepairMenu* self)
static void repairMenu_stopRepairProcess(struct RepairMenu* self, int cursorIndex)
{
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)
{
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_solenoidLock(struct RepairMenu* self, int cursorIndex)
{
hsb_solenoidLock();
}
static void repairMenu_solenoidUnlock(struct RepairMenu* self, int cursorIndex)
{
hsb_solenoidUnlock();
repairProcesses_mainRepairProcessRemoveObserver(self->observer);
repairProcesses_abortMainRepairProcess();
}
@@ -693,11 +733,13 @@ static ErrorStatus repairMenu_createMenu(struct RepairMenu* self)
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_addKeyAction_GOTOSTATE(&self->menuArray[REPAIR_PAUSE], 'E', PRESSED, REPAIR_RUNNING);
repairMenu_createMenuPage(&self->menuArray[FINISH], MENU_HAS_NO_CURSOR, 4);
repairMenu_addKeyAction_GOTOSTATE(&self->menuArray[FINISH], 'E', PRESSED, MAINMENU);
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;
}