Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
Diff: GCStateAndFaultCodes.cpp
- Revision:
- 2:6e94a7fd1e37
- Parent:
- 1:a5258871b33d
--- a/GCStateAndFaultCodes.cpp Thu Jul 20 08:42:29 2017 +0000 +++ b/GCStateAndFaultCodes.cpp Thu Jul 20 15:31:28 2017 +0000 @@ -2,6 +2,16 @@ #include <string.h> + +/* + Passed three 8-bit colour components - red, green and blue. + Returns the corresponding 16-bit colour value (5 bits for red, 6 bits for green, 5 bits for blue). + + Defined in main.cpp +*/ +extern GuiConst_INTCOLOR SixteenBitColorValue(GuiConst_INT8U red, GuiConst_INT8U green, GuiConst_INT8U blue); + + /* Classes that match state or fault code integer values to the corresponding strings */ @@ -85,6 +95,81 @@ return GC_FAULTED; } +/* + Static member function to draw a message over the Run button location on the Home page, + showing the GC state. + + Args: the GC state, as a value in the "GCStateSimplified" enumeration + + No return code +*/ +void GCStateOrFaultCode::DrawSimplifiedStateMessageOnHomePageRunButton(GCStateSimplified simplifiedState) +{ + switch (simplifiedState) { + case GC_STABILISING: + DrawTextOnRunButton("Stabilising", SixteenBitColorValue(0, 0xFF, 0), SixteenBitColorValue(0, 0, 0), GuiFont_Helv36Bold); + break; + case GC_EQUILIBRATING: + DrawTextOnRunButton("Equilibrating", SixteenBitColorValue(255, 255, 50), SixteenBitColorValue(0, 0, 0), GuiFont_Helv36Bold); + break; + case GC_COOLING: + DrawTextOnRunButton("Cooling", SixteenBitColorValue(0, 243, 255), SixteenBitColorValue(0, 0, 0), GuiFont_Helv36Bold); + break; + case GC_READY_TO_RUN: +// DrawTextOnRunButton("Ready", SixteenBitColorValue(0, 0xFF, 0), SixteenBitColorValue(0, 0, 0), GuiFont_Helv36Bold); +// Test - don't display "Ready" message on top of green, enabled, Run button + break; + case GC_IDLE: + DrawTextOnRunButton("Idle", SixteenBitColorValue(192, 0, 0), SixteenBitColorValue(0, 0, 0), GuiFont_Helv36Bold); + break; + case GC_WAIT_READY_IO: + DrawTextOnRunButton("Waiting IO", SixteenBitColorValue(192, 192, 0), SixteenBitColorValue(0, 0, 0), GuiFont_Helv36Bold); + break; + case GC_FAULTED: + DrawTextOnRunButton("Faulted", SixteenBitColorValue(255, 0, 0), SixteenBitColorValue(0, 0, 0), GuiFont_Helv36Bold); + break; + default: + // Some other state - do nothing + break; + } +} + +/* + Draws the specified text on top of the Run button in the centre of the Home page, + in the specified colour. + + It is up to the caller to display the Home page before calling this function. + + Args: pointer to the (null-terminated) text + the foregound (i.e. text) colour + the background colour + the font ID (from the GuiFont_xxx list at the bottom of GuiFont.h) + (caller may want to e.g. use a larger font for shorter strings) + + No return code. +*/ +void GCStateOrFaultCode::DrawTextOnRunButton(char* text, GuiConst_INTCOLOR foreColor, GuiConst_INTCOLOR backColor, GuiConst_INT16U fontNo) +{ + const GuiConst_INT16S X = 400; // Approx centre of Run button + const GuiConst_INT16S Y = 220; + + GuiLib_DrawStr( + X, //GuiConst_INT16S X, + Y, //GuiConst_INT16S Y, + fontNo, //GuiConst_INT16U FontNo, + text, //GuiConst_TEXT PrefixLocate *String, + GuiLib_ALIGN_CENTER, //GuiConst_INT8U Alignment, + GuiLib_PS_ON, //GuiConst_INT8U PsWriting, + GuiLib_TRANSPARENT_ON, //GuiConst_INT8U Transparent, + GuiLib_UNDERLINE_OFF, //GuiConst_INT8U Underlining, + 0, //GuiConst_INT16S BackBoxSizeX, + 0, //GuiConst_INT16S BackBoxSizeY1, + 0, //GuiConst_INT16S BackBoxSizeY2, + GuiLib_BBP_NONE, //GuiConst_INT8U BackBorderPixels, + foreColor, //GuiConst_INTCOLOR ForeColor, + backColor //GuiConst_INTCOLOR BackColor + ); +} /* @@ -283,14 +368,14 @@ } /* - Given an integer code representing a simplified state, returns the associated descriptive string. + Given a simplified state value, returns the associated descriptive string. - Args: simplified state code (an int, not an enum, to keep things simple for the compiler) + Args: simplified state code pointer to the buffer to contain the associated string (if found) Returns true if the state code is valid, false if not */ -bool GCStateAndFaultCodes::GetSimplifiedStateCodeString(int simplifiedStateCode, char *buff) +bool GCStateAndFaultCodes::GetSimplifiedStateCodeString(GCStateSimplified simplifiedStateCode, char *buff) { for (int i = 0; i < GC_STATE_SIMPLIFIED_COUNT; ++i) { if(simplifiedStateCodeArray[i]->GetCodeNumber() == simplifiedStateCode) {