Year Two Project ELEC 2645: Embedded Systems Project Portable Weather Station
Dependencies: BMP180 ConfigFile N5110 PowerControl beep mbed
ListController.h@0:da2b8c7a1ec1, 2015-05-11 (annotated)
- Committer:
- OHstin
- Date:
- Mon May 11 15:25:52 2015 +0000
- Revision:
- 0:da2b8c7a1ec1
Completed Weather Station
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OHstin | 0:da2b8c7a1ec1 | 1 | /** |
OHstin | 0:da2b8c7a1ec1 | 2 | @file ListController.h |
OHstin | 0:da2b8c7a1ec1 | 3 | |
OHstin | 0:da2b8c7a1ec1 | 4 | */ |
OHstin | 0:da2b8c7a1ec1 | 5 | |
OHstin | 0:da2b8c7a1ec1 | 6 | #ifndef LISTCONTROLLER_H |
OHstin | 0:da2b8c7a1ec1 | 7 | #define LISTCONTROLLER_H |
OHstin | 0:da2b8c7a1ec1 | 8 | |
OHstin | 0:da2b8c7a1ec1 | 9 | #include "mbed.h" |
OHstin | 0:da2b8c7a1ec1 | 10 | #include "Outputs.h" |
OHstin | 0:da2b8c7a1ec1 | 11 | |
OHstin | 0:da2b8c7a1ec1 | 12 | /** |
OHstin | 0:da2b8c7a1ec1 | 13 | @brief Manages the display of upto 4 possible options on LCD that the user can select.\n |
OHstin | 0:da2b8c7a1ec1 | 14 | @brief also has a scrolling feature that allows user to browse the options\n |
OHstin | 0:da2b8c7a1ec1 | 15 | @author Augustine Kizito K |
OHstin | 0:da2b8c7a1ec1 | 16 | @date April 2015 |
OHstin | 0:da2b8c7a1ec1 | 17 | */ |
OHstin | 0:da2b8c7a1ec1 | 18 | class ListController |
OHstin | 0:da2b8c7a1ec1 | 19 | { |
OHstin | 0:da2b8c7a1ec1 | 20 | private: |
OHstin | 0:da2b8c7a1ec1 | 21 | char title[32]; // title of the list |
OHstin | 0:da2b8c7a1ec1 | 22 | char option1[32]; // option 1 on the list |
OHstin | 0:da2b8c7a1ec1 | 23 | char option2[32]; // option 2 on the list |
OHstin | 0:da2b8c7a1ec1 | 24 | char option3[32]; // option 3 on the list |
OHstin | 0:da2b8c7a1ec1 | 25 | char option4[32]; // option 4 on the list |
OHstin | 0:da2b8c7a1ec1 | 26 | int numberOfOptions; // available number of options |
OHstin | 0:da2b8c7a1ec1 | 27 | int currentOption; // tracks position of current cell |
OHstin | 0:da2b8c7a1ec1 | 28 | |
OHstin | 0:da2b8c7a1ec1 | 29 | void invertPixels(int option); // inverts pixels in a given bank i.e highlighting an option |
OHstin | 0:da2b8c7a1ec1 | 30 | |
OHstin | 0:da2b8c7a1ec1 | 31 | protected: |
OHstin | 0:da2b8c7a1ec1 | 32 | /** |
OHstin | 0:da2b8c7a1ec1 | 33 | Creates a List Controller instance |
OHstin | 0:da2b8c7a1ec1 | 34 | |
OHstin | 0:da2b8c7a1ec1 | 35 | @param t - string title of list |
OHstin | 0:da2b8c7a1ec1 | 36 | @param op1 - option 1 on the list |
OHstin | 0:da2b8c7a1ec1 | 37 | @param op2 - option 2 on the list |
OHstin | 0:da2b8c7a1ec1 | 38 | @param op3 - option 3 on the list |
OHstin | 0:da2b8c7a1ec1 | 39 | @param op4 - option 4 on the list |
OHstin | 0:da2b8c7a1ec1 | 40 | @param nOO 0 - available number of options |
OHstin | 0:da2b8c7a1ec1 | 41 | |
OHstin | 0:da2b8c7a1ec1 | 42 | */ |
OHstin | 0:da2b8c7a1ec1 | 43 | ListController( char t[], char op1[], char op2[], char op3[], char op4[], int nOO); |
OHstin | 0:da2b8c7a1ec1 | 44 | |
OHstin | 0:da2b8c7a1ec1 | 45 | /** |
OHstin | 0:da2b8c7a1ec1 | 46 | Populates the LCD screen with the a list of browse-able and selectable options |
OHstin | 0:da2b8c7a1ec1 | 47 | |
OHstin | 0:da2b8c7a1ec1 | 48 | */ |
OHstin | 0:da2b8c7a1ec1 | 49 | void showInfo(); // populate the screen with controller data |
OHstin | 0:da2b8c7a1ec1 | 50 | |
OHstin | 0:da2b8c7a1ec1 | 51 | /** |
OHstin | 0:da2b8c7a1ec1 | 52 | Scrolls to the previous option |
OHstin | 0:da2b8c7a1ec1 | 53 | |
OHstin | 0:da2b8c7a1ec1 | 54 | */ |
OHstin | 0:da2b8c7a1ec1 | 55 | void scrollUp(); |
OHstin | 0:da2b8c7a1ec1 | 56 | |
OHstin | 0:da2b8c7a1ec1 | 57 | /** |
OHstin | 0:da2b8c7a1ec1 | 58 | Scrolls to the next option |
OHstin | 0:da2b8c7a1ec1 | 59 | |
OHstin | 0:da2b8c7a1ec1 | 60 | */ |
OHstin | 0:da2b8c7a1ec1 | 61 | void scrollDown(); |
OHstin | 0:da2b8c7a1ec1 | 62 | |
OHstin | 0:da2b8c7a1ec1 | 63 | /** |
OHstin | 0:da2b8c7a1ec1 | 64 | Gets the current/highlighted option and returns is to the calling function |
OHstin | 0:da2b8c7a1ec1 | 65 | |
OHstin | 0:da2b8c7a1ec1 | 66 | @returns the currentt option 0 - 3 |
OHstin | 0:da2b8c7a1ec1 | 67 | */ |
OHstin | 0:da2b8c7a1ec1 | 68 | int getCurrentOption(); // returns the highlighted Option 0-3 |
OHstin | 0:da2b8c7a1ec1 | 69 | |
OHstin | 0:da2b8c7a1ec1 | 70 | }; |
OHstin | 0:da2b8c7a1ec1 | 71 | |
OHstin | 0:da2b8c7a1ec1 | 72 | |
OHstin | 0:da2b8c7a1ec1 | 73 | |
OHstin | 0:da2b8c7a1ec1 | 74 | |
OHstin | 0:da2b8c7a1ec1 | 75 | |
OHstin | 0:da2b8c7a1ec1 | 76 | |
OHstin | 0:da2b8c7a1ec1 | 77 | |
OHstin | 0:da2b8c7a1ec1 | 78 | ListController::ListController( char t[], char op1[], char op2[], char op3[], char op4[],int nOO) |
OHstin | 0:da2b8c7a1ec1 | 79 | { |
OHstin | 0:da2b8c7a1ec1 | 80 | // initialisations |
OHstin | 0:da2b8c7a1ec1 | 81 | strcpy(title,t); |
OHstin | 0:da2b8c7a1ec1 | 82 | strcpy(option1,op1); |
OHstin | 0:da2b8c7a1ec1 | 83 | strcpy(option2,op2); |
OHstin | 0:da2b8c7a1ec1 | 84 | strcpy(option3,op3); |
OHstin | 0:da2b8c7a1ec1 | 85 | strcpy(option4,op4); |
OHstin | 0:da2b8c7a1ec1 | 86 | numberOfOptions = nOO; |
OHstin | 0:da2b8c7a1ec1 | 87 | currentOption = 0; |
OHstin | 0:da2b8c7a1ec1 | 88 | |
OHstin | 0:da2b8c7a1ec1 | 89 | } |
OHstin | 0:da2b8c7a1ec1 | 90 | |
OHstin | 0:da2b8c7a1ec1 | 91 | void ListController::showInfo() |
OHstin | 0:da2b8c7a1ec1 | 92 | { |
OHstin | 0:da2b8c7a1ec1 | 93 | lcd.printString(title,15,1); // print title |
OHstin | 0:da2b8c7a1ec1 | 94 | lcd.printString(option1,0,2); // print option1 |
OHstin | 0:da2b8c7a1ec1 | 95 | lcd.printString(option2,0,3); // print option2 |
OHstin | 0:da2b8c7a1ec1 | 96 | lcd.printString(option3,0,4); // print option3 |
OHstin | 0:da2b8c7a1ec1 | 97 | lcd.printString(option4,0,5); // print option4 |
OHstin | 0:da2b8c7a1ec1 | 98 | |
OHstin | 0:da2b8c7a1ec1 | 99 | invertPixels(currentOption); // highlight the current option |
OHstin | 0:da2b8c7a1ec1 | 100 | } |
OHstin | 0:da2b8c7a1ec1 | 101 | |
OHstin | 0:da2b8c7a1ec1 | 102 | void ListController::scrollUp() |
OHstin | 0:da2b8c7a1ec1 | 103 | { |
OHstin | 0:da2b8c7a1ec1 | 104 | playSound(); // buzzer makes sound |
OHstin | 0:da2b8c7a1ec1 | 105 | invertPixels(currentOption); // UN invert/highlight current option |
OHstin | 0:da2b8c7a1ec1 | 106 | currentOption--; // current position is less by 1 |
OHstin | 0:da2b8c7a1ec1 | 107 | |
OHstin | 0:da2b8c7a1ec1 | 108 | if (currentOption < 0) { // prevents from inverting a non existent option |
OHstin | 0:da2b8c7a1ec1 | 109 | |
OHstin | 0:da2b8c7a1ec1 | 110 | currentOption = 0; |
OHstin | 0:da2b8c7a1ec1 | 111 | invertPixels(currentOption); // invert all pixels in current bank |
OHstin | 0:da2b8c7a1ec1 | 112 | |
OHstin | 0:da2b8c7a1ec1 | 113 | } else { |
OHstin | 0:da2b8c7a1ec1 | 114 | invertPixels(currentOption); // invert all pixels in current bank |
OHstin | 0:da2b8c7a1ec1 | 115 | } |
OHstin | 0:da2b8c7a1ec1 | 116 | |
OHstin | 0:da2b8c7a1ec1 | 117 | |
OHstin | 0:da2b8c7a1ec1 | 118 | } |
OHstin | 0:da2b8c7a1ec1 | 119 | |
OHstin | 0:da2b8c7a1ec1 | 120 | void ListController::scrollDown() |
OHstin | 0:da2b8c7a1ec1 | 121 | { |
OHstin | 0:da2b8c7a1ec1 | 122 | playSound(); // buzzer makes sound |
OHstin | 0:da2b8c7a1ec1 | 123 | invertPixels(currentOption); // UN-invert/highlight the current option |
OHstin | 0:da2b8c7a1ec1 | 124 | currentOption++; // current option is more by 1 |
OHstin | 0:da2b8c7a1ec1 | 125 | |
OHstin | 0:da2b8c7a1ec1 | 126 | if (currentOption > numberOfOptions-1) { // prevents from inverting a non existant option |
OHstin | 0:da2b8c7a1ec1 | 127 | |
OHstin | 0:da2b8c7a1ec1 | 128 | currentOption = numberOfOptions-1; |
OHstin | 0:da2b8c7a1ec1 | 129 | invertPixels(currentOption); // invert all pixels in current option |
OHstin | 0:da2b8c7a1ec1 | 130 | } else { |
OHstin | 0:da2b8c7a1ec1 | 131 | invertPixels(currentOption); // invert all pixels in current option |
OHstin | 0:da2b8c7a1ec1 | 132 | } |
OHstin | 0:da2b8c7a1ec1 | 133 | } |
OHstin | 0:da2b8c7a1ec1 | 134 | |
OHstin | 0:da2b8c7a1ec1 | 135 | |
OHstin | 0:da2b8c7a1ec1 | 136 | int ListController::getCurrentOption() |
OHstin | 0:da2b8c7a1ec1 | 137 | { |
OHstin | 0:da2b8c7a1ec1 | 138 | return currentOption; |
OHstin | 0:da2b8c7a1ec1 | 139 | |
OHstin | 0:da2b8c7a1ec1 | 140 | } |
OHstin | 0:da2b8c7a1ec1 | 141 | |
OHstin | 0:da2b8c7a1ec1 | 142 | void ListController::invertPixels(int option) |
OHstin | 0:da2b8c7a1ec1 | 143 | { |
OHstin | 0:da2b8c7a1ec1 | 144 | |
OHstin | 0:da2b8c7a1ec1 | 145 | |
OHstin | 0:da2b8c7a1ec1 | 146 | int onset; // x coordinate where inversion starts |
OHstin | 0:da2b8c7a1ec1 | 147 | |
OHstin | 0:da2b8c7a1ec1 | 148 | // first bank consists of status bar showing time and battery icon |
OHstin | 0:da2b8c7a1ec1 | 149 | // second bank consists of the title |
OHstin | 0:da2b8c7a1ec1 | 150 | |
OHstin | 0:da2b8c7a1ec1 | 151 | if (option == 0) { // invert third bank |
OHstin | 0:da2b8c7a1ec1 | 152 | onset = 15; |
OHstin | 0:da2b8c7a1ec1 | 153 | } else if ( option == 1) { // invert fourth bank |
OHstin | 0:da2b8c7a1ec1 | 154 | onset = 23; |
OHstin | 0:da2b8c7a1ec1 | 155 | } else if ( option == 2) { // invert fifth bank |
OHstin | 0:da2b8c7a1ec1 | 156 | onset = 31; |
OHstin | 0:da2b8c7a1ec1 | 157 | } else { |
OHstin | 0:da2b8c7a1ec1 | 158 | onset = 39; // invert sixth bank |
OHstin | 0:da2b8c7a1ec1 | 159 | } |
OHstin | 0:da2b8c7a1ec1 | 160 | |
OHstin | 0:da2b8c7a1ec1 | 161 | int termination = onset + 9; // bank's length height is 9 pixels |
OHstin | 0:da2b8c7a1ec1 | 162 | |
OHstin | 0:da2b8c7a1ec1 | 163 | for ( int m = onset; m < termination; m++) { |
OHstin | 0:da2b8c7a1ec1 | 164 | |
OHstin | 0:da2b8c7a1ec1 | 165 | for ( int n = 0; n < 84; n++) { |
OHstin | 0:da2b8c7a1ec1 | 166 | |
OHstin | 0:da2b8c7a1ec1 | 167 | if((lcd.getPixel(n,m)) == 0) { // if the pixel is clear |
OHstin | 0:da2b8c7a1ec1 | 168 | lcd.setPixel(n,m); // set the pixel |
OHstin | 0:da2b8c7a1ec1 | 169 | } else { |
OHstin | 0:da2b8c7a1ec1 | 170 | lcd.clearPixel(n,m); // else clear the pixel |
OHstin | 0:da2b8c7a1ec1 | 171 | } |
OHstin | 0:da2b8c7a1ec1 | 172 | |
OHstin | 0:da2b8c7a1ec1 | 173 | } |
OHstin | 0:da2b8c7a1ec1 | 174 | } |
OHstin | 0:da2b8c7a1ec1 | 175 | |
OHstin | 0:da2b8c7a1ec1 | 176 | lcd.refresh(); // refresh the lcd screen |
OHstin | 0:da2b8c7a1ec1 | 177 | |
OHstin | 0:da2b8c7a1ec1 | 178 | } |
OHstin | 0:da2b8c7a1ec1 | 179 | |
OHstin | 0:da2b8c7a1ec1 | 180 | #endif |