4 errors
Dependencies: KS0108_PCF8574 mbed
menbed/menbedDisplayer.cpp@3:ec80bb6ff5da, 2012-09-11 (annotated)
- Committer:
- GuiTwo
- Date:
- Tue Sep 11 10:21:10 2012 +0000
- Revision:
- 3:ec80bb6ff5da
- Parent:
- 0:936f1c020120
4 errors on vector .cc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GuiTwo | 0:936f1c020120 | 1 | #include "mbed.h" |
GuiTwo | 0:936f1c020120 | 2 | #include "include/menbedMenuMessage.h" |
GuiTwo | 0:936f1c020120 | 3 | #include "include/menbedDisplayer.h" |
GuiTwo | 0:936f1c020120 | 4 | |
GuiTwo | 0:936f1c020120 | 5 | MenbedDisplayer::MenbedDisplayer (MenbedDisplay *display) : |
GuiTwo | 0:936f1c020120 | 6 | display(display) |
GuiTwo | 0:936f1c020120 | 7 | { |
GuiTwo | 0:936f1c020120 | 8 | } |
GuiTwo | 0:936f1c020120 | 9 | |
GuiTwo | 0:936f1c020120 | 10 | |
GuiTwo | 0:936f1c020120 | 11 | void MenbedDisplayer::update (MenbedMenuMessage *menuMessage) |
GuiTwo | 0:936f1c020120 | 12 | { |
GuiTwo | 0:936f1c020120 | 13 | char *text = new char[display->getLineLength()+1]; |
GuiTwo | 0:936f1c020120 | 14 | |
GuiTwo | 0:936f1c020120 | 15 | for (int i=0; i<display->getLines(); i++) |
GuiTwo | 0:936f1c020120 | 16 | { |
GuiTwo | 0:936f1c020120 | 17 | extractLine (menuMessage->text, i, text); |
GuiTwo | 0:936f1c020120 | 18 | display->writeLine (text, i); |
GuiTwo | 0:936f1c020120 | 19 | } |
GuiTwo | 0:936f1c020120 | 20 | |
GuiTwo | 0:936f1c020120 | 21 | // Print the up and down arrows if requested |
GuiTwo | 0:936f1c020120 | 22 | display->showUpArrow (menuMessage->showUpArrow); |
GuiTwo | 0:936f1c020120 | 23 | display->showDownArrow (menuMessage->showDownArrow); |
GuiTwo | 0:936f1c020120 | 24 | |
GuiTwo | 0:936f1c020120 | 25 | delete[] text; |
GuiTwo | 0:936f1c020120 | 26 | } |
GuiTwo | 0:936f1c020120 | 27 | |
GuiTwo | 0:936f1c020120 | 28 | |
GuiTwo | 0:936f1c020120 | 29 | void MenbedDisplayer::extractLine (char *catenatedText, uint8_t lineNum, |
GuiTwo | 0:936f1c020120 | 30 | char *extractedText) |
GuiTwo | 0:936f1c020120 | 31 | { |
GuiTwo | 0:936f1c020120 | 32 | char *subText, *endText; |
GuiTwo | 0:936f1c020120 | 33 | size_t bytesToCopy; |
GuiTwo | 0:936f1c020120 | 34 | |
GuiTwo | 0:936f1c020120 | 35 | extractedText[0] = '\0'; |
GuiTwo | 0:936f1c020120 | 36 | |
GuiTwo | 0:936f1c020120 | 37 | // Return with just a blank line if the line number to be extracted exceeds |
GuiTwo | 0:936f1c020120 | 38 | // the number of lines in the menu |
GuiTwo | 0:936f1c020120 | 39 | if (lineNum > display->getLines() - 1) |
GuiTwo | 0:936f1c020120 | 40 | return; |
GuiTwo | 0:936f1c020120 | 41 | |
GuiTwo | 0:936f1c020120 | 42 | // We loop through the catenatedString finding each \n. These \n |
GuiTwo | 0:936f1c020120 | 43 | // characters separate the substrings that we are trying to extract. |
GuiTwo | 0:936f1c020120 | 44 | subText = catenatedText; |
GuiTwo | 0:936f1c020120 | 45 | while (lineNum > 0) |
GuiTwo | 0:936f1c020120 | 46 | { |
GuiTwo | 0:936f1c020120 | 47 | subText = strchr (subText, '\n'); |
GuiTwo | 0:936f1c020120 | 48 | |
GuiTwo | 0:936f1c020120 | 49 | // If the \n character was not found, the catenatedText string does not |
GuiTwo | 0:936f1c020120 | 50 | // contain enough \n-separated substrings. |
GuiTwo | 0:936f1c020120 | 51 | if (subText == (char *)NULL) |
GuiTwo | 0:936f1c020120 | 52 | { |
GuiTwo | 0:936f1c020120 | 53 | extractedText[0] = '\0'; |
GuiTwo | 0:936f1c020120 | 54 | return; |
GuiTwo | 0:936f1c020120 | 55 | } |
GuiTwo | 0:936f1c020120 | 56 | |
GuiTwo | 0:936f1c020120 | 57 | // Increment the subText pointer because the strchr() command returned |
GuiTwo | 0:936f1c020120 | 58 | // a pointer to the \n character found, but next time through the loop |
GuiTwo | 0:936f1c020120 | 59 | // we want to find the next \n, not the same \n again. |
GuiTwo | 0:936f1c020120 | 60 | subText++; |
GuiTwo | 0:936f1c020120 | 61 | lineNum--; |
GuiTwo | 0:936f1c020120 | 62 | } |
GuiTwo | 0:936f1c020120 | 63 | |
GuiTwo | 0:936f1c020120 | 64 | // If there are strings following the one we are trying to extract, we |
GuiTwo | 0:936f1c020120 | 65 | // change the \n terminating the string to be extracted into a \0 so that |
GuiTwo | 0:936f1c020120 | 66 | // we can use the strlen function to determine the length of the string |
GuiTwo | 0:936f1c020120 | 67 | // we are trying to extract. If there are no additional \n-separated |
GuiTwo | 0:936f1c020120 | 68 | // strings following the one we are attempting to extract, strlen should |
GuiTwo | 0:936f1c020120 | 69 | // work on subText without modification. |
GuiTwo | 0:936f1c020120 | 70 | if ((endText = strchr (subText, '\n')) != (char *)NULL) |
GuiTwo | 0:936f1c020120 | 71 | bytesToCopy = endText - subText + 1; |
GuiTwo | 0:936f1c020120 | 72 | else |
GuiTwo | 0:936f1c020120 | 73 | bytesToCopy = strlen(subText); |
GuiTwo | 0:936f1c020120 | 74 | |
GuiTwo | 0:936f1c020120 | 75 | // Copy the string found in the \n-separated substring number specified by |
GuiTwo | 0:936f1c020120 | 76 | // the lineNum parameter to the extracted string. |
GuiTwo | 0:936f1c020120 | 77 | strncpy (extractedText, subText, bytesToCopy); |
GuiTwo | 0:936f1c020120 | 78 | |
GuiTwo | 0:936f1c020120 | 79 | // Replace the \n at the end of extractedText string with a \0 |
GuiTwo | 0:936f1c020120 | 80 | extractedText[bytesToCopy-1] = '\0'; |
GuiTwo | 0:936f1c020120 | 81 | } |