Release 1.01
Menu.cpp@7:d8673bb9fb6f, 2019-09-27 (annotated)
- Committer:
- foxbrianr
- Date:
- Fri Sep 27 13:20:32 2019 +0000
- Revision:
- 7:d8673bb9fb6f
- Parent:
- 5:9f4d4f8ffc00
- Child:
- 8:9d4e684d8eb8
Beta 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
foxbrianr | 5:9f4d4f8ffc00 | 1 | /************************************************************************** |
foxbrianr | 5:9f4d4f8ffc00 | 2 | * @file Menu.h |
foxbrianr | 5:9f4d4f8ffc00 | 3 | * @brief Base class for wrapping the interface with LCD Menu display |
foxbrianr | 5:9f4d4f8ffc00 | 4 | * @version: V1.0 |
foxbrianr | 5:9f4d4f8ffc00 | 5 | * @date: 9/17/2019 |
foxbrianr | 5:9f4d4f8ffc00 | 6 | |
foxbrianr | 5:9f4d4f8ffc00 | 7 | * |
foxbrianr | 5:9f4d4f8ffc00 | 8 | * @note |
foxbrianr | 5:9f4d4f8ffc00 | 9 | * Copyright (C) 2019 E3 Design. All rights reserved. |
foxbrianr | 5:9f4d4f8ffc00 | 10 | * |
foxbrianr | 5:9f4d4f8ffc00 | 11 | * @par |
foxbrianr | 5:9f4d4f8ffc00 | 12 | * E3 Designers LLC is supplying this software for use with Cortex-M3 LPC1768 |
foxbrianr | 5:9f4d4f8ffc00 | 13 | * processor based microcontroller for the ESCM 2000 Monitor and Display. |
foxbrianr | 5:9f4d4f8ffc00 | 14 | * * |
foxbrianr | 5:9f4d4f8ffc00 | 15 | * @par |
foxbrianr | 5:9f4d4f8ffc00 | 16 | * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED |
foxbrianr | 5:9f4d4f8ffc00 | 17 | * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF |
foxbrianr | 5:9f4d4f8ffc00 | 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. |
foxbrianr | 5:9f4d4f8ffc00 | 19 | * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR |
foxbrianr | 5:9f4d4f8ffc00 | 20 | * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. |
foxbrianr | 5:9f4d4f8ffc00 | 21 | * |
foxbrianr | 5:9f4d4f8ffc00 | 22 | ******************************************************************************/ |
foxbrianr | 5:9f4d4f8ffc00 | 23 | |
pyeh9 | 0:577f0ec71f4c | 24 | #include "mbed.h" |
pyeh9 | 0:577f0ec71f4c | 25 | #include "Menu.h" |
foxbrianr | 4:7226c43320b5 | 26 | #include "ESCMControlApp.h" |
foxbrianr | 4:7226c43320b5 | 27 | |
foxbrianr | 5:9f4d4f8ffc00 | 28 | /******************************************************************************/ |
foxbrianr | 4:7226c43320b5 | 29 | Menu* Menu::currentMenu = NULL; |
foxbrianr | 4:7226c43320b5 | 30 | |
foxbrianr | 4:7226c43320b5 | 31 | |
foxbrianr | 5:9f4d4f8ffc00 | 32 | /******************************************************************************/ |
foxbrianr | 4:7226c43320b5 | 33 | Menu * Menu::getCurrentMenu () |
foxbrianr | 4:7226c43320b5 | 34 | { |
foxbrianr | 4:7226c43320b5 | 35 | return currentMenu; |
foxbrianr | 4:7226c43320b5 | 36 | } |
foxbrianr | 4:7226c43320b5 | 37 | |
foxbrianr | 5:9f4d4f8ffc00 | 38 | /******************************************************************************/ |
foxbrianr | 4:7226c43320b5 | 39 | Menu * Menu::setCurrentMenu (Menu * value) |
foxbrianr | 4:7226c43320b5 | 40 | { |
foxbrianr | 4:7226c43320b5 | 41 | |
foxbrianr | 7:d8673bb9fb6f | 42 | //printf("\n Goto Menu :%s ", value->getText() ); |
foxbrianr | 4:7226c43320b5 | 43 | currentMenu = value; |
foxbrianr | 4:7226c43320b5 | 44 | currentMenu->init(); |
foxbrianr | 4:7226c43320b5 | 45 | return currentMenu; |
foxbrianr | 4:7226c43320b5 | 46 | } |
foxbrianr | 4:7226c43320b5 | 47 | |
pyeh9 | 0:577f0ec71f4c | 48 | |
foxbrianr | 5:9f4d4f8ffc00 | 49 | /******************************************************************************/ |
foxbrianr | 3:8395f7ab6d3e | 50 | Menu::Menu(char *id) : menuID(id), parent(NULL),update_needed(1) |
foxbrianr | 3:8395f7ab6d3e | 51 | { |
foxbrianr | 4:7226c43320b5 | 52 | children.clear(); |
foxbrianr | 4:7226c43320b5 | 53 | |
foxbrianr | 4:7226c43320b5 | 54 | selectedMenu = 0; // default menu |
foxbrianr | 4:7226c43320b5 | 55 | update_needed = 1; |
foxbrianr | 3:8395f7ab6d3e | 56 | } |
foxbrianr | 3:8395f7ab6d3e | 57 | |
foxbrianr | 5:9f4d4f8ffc00 | 58 | /******************************************************************************/ |
foxbrianr | 4:7226c43320b5 | 59 | void Menu::add(Menu *submenu) |
pyeh9 | 0:577f0ec71f4c | 60 | { |
foxbrianr | 4:7226c43320b5 | 61 | submenu->parent = this; |
foxbrianr | 4:7226c43320b5 | 62 | children.push_back(submenu); |
pyeh9 | 0:577f0ec71f4c | 63 | } |
pyeh9 | 0:577f0ec71f4c | 64 | |
foxbrianr | 4:7226c43320b5 | 65 | |
foxbrianr | 5:9f4d4f8ffc00 | 66 | /******************************************************************************/ |
foxbrianr | 4:7226c43320b5 | 67 | void Menu::init() |
pyeh9 | 0:577f0ec71f4c | 68 | { |
foxbrianr | 4:7226c43320b5 | 69 | update_needed=1; |
foxbrianr | 4:7226c43320b5 | 70 | } |
foxbrianr | 4:7226c43320b5 | 71 | |
foxbrianr | 5:9f4d4f8ffc00 | 72 | /******************************************************************************/ |
foxbrianr | 4:7226c43320b5 | 73 | void Menu::select(void) |
foxbrianr | 4:7226c43320b5 | 74 | { |
foxbrianr | 4:7226c43320b5 | 75 | Menu::setCurrentMenu ( children[selectedMenu]) ; |
pyeh9 | 0:577f0ec71f4c | 76 | } |
pyeh9 | 0:577f0ec71f4c | 77 | |
pyeh9 | 0:577f0ec71f4c | 78 | |
foxbrianr | 5:9f4d4f8ffc00 | 79 | /******************************************************************************/ |
foxbrianr | 4:7226c43320b5 | 80 | void Menu::back() |
foxbrianr | 4:7226c43320b5 | 81 | { |
foxbrianr | 4:7226c43320b5 | 82 | if (parent != NULL ) |
foxbrianr | 4:7226c43320b5 | 83 | { |
foxbrianr | 4:7226c43320b5 | 84 | Menu::setCurrentMenu (parent); |
foxbrianr | 4:7226c43320b5 | 85 | } |
foxbrianr | 4:7226c43320b5 | 86 | else |
foxbrianr | 4:7226c43320b5 | 87 | { |
foxbrianr | 4:7226c43320b5 | 88 | printf("ERROR: missing parent "); |
foxbrianr | 4:7226c43320b5 | 89 | } |
foxbrianr | 4:7226c43320b5 | 90 | } |
foxbrianr | 5:9f4d4f8ffc00 | 91 | |
foxbrianr | 5:9f4d4f8ffc00 | 92 | /******************************************************************************/ |
foxbrianr | 4:7226c43320b5 | 93 | void Menu::DrawDisplay(LCD * lcd) |
foxbrianr | 3:8395f7ab6d3e | 94 | { |
foxbrianr | 4:7226c43320b5 | 95 | this->lcd = lcd; |
foxbrianr | 4:7226c43320b5 | 96 | |
foxbrianr | 4:7226c43320b5 | 97 | static unsigned long time_max = 0 ; |
foxbrianr | 4:7226c43320b5 | 98 | unsigned long time_delta = 0; |
foxbrianr | 4:7226c43320b5 | 99 | unsigned long time_ms1 = us_ticker_read() / 1000L; |
foxbrianr | 4:7226c43320b5 | 100 | |
foxbrianr | 4:7226c43320b5 | 101 | |
foxbrianr | 4:7226c43320b5 | 102 | lock(); |
foxbrianr | 4:7226c43320b5 | 103 | display(lcd); |
foxbrianr | 4:7226c43320b5 | 104 | unlock(); |
foxbrianr | 4:7226c43320b5 | 105 | |
foxbrianr | 4:7226c43320b5 | 106 | unsigned long time_ms2 = us_ticker_read() / 1000L; |
foxbrianr | 4:7226c43320b5 | 107 | |
foxbrianr | 4:7226c43320b5 | 108 | time_delta = time_ms2-time_ms1; |
foxbrianr | 4:7226c43320b5 | 109 | if (time_max < time_delta ) |
foxbrianr | 4:7226c43320b5 | 110 | { |
foxbrianr | 4:7226c43320b5 | 111 | time_max = time_delta; |
foxbrianr | 4:7226c43320b5 | 112 | printf("Tmax=%d\n\r", time_max); |
foxbrianr | 4:7226c43320b5 | 113 | } |
foxbrianr | 4:7226c43320b5 | 114 | |
foxbrianr | 3:8395f7ab6d3e | 115 | } |
foxbrianr | 3:8395f7ab6d3e | 116 | |
foxbrianr | 5:9f4d4f8ffc00 | 117 | /******************************************************************************/ |
foxbrianr | 3:8395f7ab6d3e | 118 | void Menu::display(LCD * lcd) |
foxbrianr | 4:7226c43320b5 | 119 | { |
foxbrianr | 4:7226c43320b5 | 120 | static int top = 1; |
foxbrianr | 4:7226c43320b5 | 121 | static int bottom = 3; |
foxbrianr | 4:7226c43320b5 | 122 | static int size = children.size(); |
foxbrianr | 4:7226c43320b5 | 123 | |
foxbrianr | 4:7226c43320b5 | 124 | // paging |
foxbrianr | 4:7226c43320b5 | 125 | if (selectedMenu < top ) |
foxbrianr | 4:7226c43320b5 | 126 | { |
foxbrianr | 4:7226c43320b5 | 127 | top = selectedMenu ; |
foxbrianr | 4:7226c43320b5 | 128 | bottom = selectedMenu + 2; |
foxbrianr | 4:7226c43320b5 | 129 | update_needed=1; |
foxbrianr | 4:7226c43320b5 | 130 | } |
foxbrianr | 4:7226c43320b5 | 131 | else if (selectedMenu > bottom) |
foxbrianr | 4:7226c43320b5 | 132 | { |
foxbrianr | 4:7226c43320b5 | 133 | top = selectedMenu - 2; |
foxbrianr | 4:7226c43320b5 | 134 | bottom = selectedMenu; |
foxbrianr | 4:7226c43320b5 | 135 | update_needed=1; |
foxbrianr | 4:7226c43320b5 | 136 | } |
foxbrianr | 4:7226c43320b5 | 137 | else |
foxbrianr | 4:7226c43320b5 | 138 | { |
foxbrianr | 4:7226c43320b5 | 139 | |
foxbrianr | 4:7226c43320b5 | 140 | } |
foxbrianr | 4:7226c43320b5 | 141 | |
foxbrianr | 4:7226c43320b5 | 142 | if (update_needed) { |
foxbrianr | 4:7226c43320b5 | 143 | |
foxbrianr | 4:7226c43320b5 | 144 | lcd->cls(); |
foxbrianr | 4:7226c43320b5 | 145 | lcd->locate(0,0); |
foxbrianr | 4:7226c43320b5 | 146 | #if 1 |
foxbrianr | 4:7226c43320b5 | 147 | lcd->printf("ESCM Controller"); |
foxbrianr | 4:7226c43320b5 | 148 | #else |
foxbrianr | 4:7226c43320b5 | 149 | |
foxbrianr | 4:7226c43320b5 | 150 | lcd->printf("(%d,%d,%d)", top,selectedMenu,size); |
foxbrianr | 4:7226c43320b5 | 151 | #endif |
foxbrianr | 4:7226c43320b5 | 152 | displayVersion(lcd); |
foxbrianr | 4:7226c43320b5 | 153 | |
foxbrianr | 4:7226c43320b5 | 154 | for ( int i=0; i< 3;i++) |
foxbrianr | 4:7226c43320b5 | 155 | { |
foxbrianr | 4:7226c43320b5 | 156 | int index = top + i; |
foxbrianr | 4:7226c43320b5 | 157 | int line = (1+i); |
foxbrianr | 4:7226c43320b5 | 158 | int selected = (selectedMenu == index); |
foxbrianr | 4:7226c43320b5 | 159 | |
foxbrianr | 4:7226c43320b5 | 160 | lcd->locate(line,0); |
foxbrianr | 4:7226c43320b5 | 161 | |
foxbrianr | 4:7226c43320b5 | 162 | if (selected) |
foxbrianr | 4:7226c43320b5 | 163 | lcd->printf(">%s",children[index]->getText()); |
foxbrianr | 4:7226c43320b5 | 164 | else |
foxbrianr | 4:7226c43320b5 | 165 | lcd->printf(" %s",children[index]->getText()); |
foxbrianr | 4:7226c43320b5 | 166 | |
foxbrianr | 3:8395f7ab6d3e | 167 | } |
foxbrianr | 4:7226c43320b5 | 168 | |
foxbrianr | 4:7226c43320b5 | 169 | update_needed = 0; |
foxbrianr | 3:8395f7ab6d3e | 170 | } |
foxbrianr | 4:7226c43320b5 | 171 | |
foxbrianr | 4:7226c43320b5 | 172 | displayCurrentTime(lcd); |
foxbrianr | 4:7226c43320b5 | 173 | |
foxbrianr | 3:8395f7ab6d3e | 174 | } |
foxbrianr | 3:8395f7ab6d3e | 175 | |
foxbrianr | 3:8395f7ab6d3e | 176 | |
foxbrianr | 5:9f4d4f8ffc00 | 177 | /******************************************************************************/ |
foxbrianr | 3:8395f7ab6d3e | 178 | void Menu::moveUp() |
foxbrianr | 3:8395f7ab6d3e | 179 | { |
foxbrianr | 4:7226c43320b5 | 180 | |
foxbrianr | 3:8395f7ab6d3e | 181 | cursorLine--; |
foxbrianr | 4:7226c43320b5 | 182 | selectedMenu--; |
foxbrianr | 4:7226c43320b5 | 183 | |
foxbrianr | 4:7226c43320b5 | 184 | if(selectedMenu < 0) |
foxbrianr | 3:8395f7ab6d3e | 185 | { |
foxbrianr | 4:7226c43320b5 | 186 | selectedMenu = children.size()-1; |
foxbrianr | 4:7226c43320b5 | 187 | } |
foxbrianr | 3:8395f7ab6d3e | 188 | |
foxbrianr | 4:7226c43320b5 | 189 | if (cursorLine < 1 ) |
foxbrianr | 4:7226c43320b5 | 190 | cursorLine = 1; |
foxbrianr | 4:7226c43320b5 | 191 | |
foxbrianr | 4:7226c43320b5 | 192 | |
foxbrianr | 4:7226c43320b5 | 193 | update_needed = 1; |
foxbrianr | 3:8395f7ab6d3e | 194 | } |
foxbrianr | 5:9f4d4f8ffc00 | 195 | /******************************************************************************/ |
foxbrianr | 3:8395f7ab6d3e | 196 | void Menu::moveDown() |
foxbrianr | 3:8395f7ab6d3e | 197 | { |
foxbrianr | 4:7226c43320b5 | 198 | cursorLine++; |
foxbrianr | 4:7226c43320b5 | 199 | selectedMenu++; |
foxbrianr | 3:8395f7ab6d3e | 200 | |
foxbrianr | 4:7226c43320b5 | 201 | if(selectedMenu >= children.size()) |
foxbrianr | 4:7226c43320b5 | 202 | { |
foxbrianr | 4:7226c43320b5 | 203 | selectedMenu=0; |
foxbrianr | 3:8395f7ab6d3e | 204 | } |
foxbrianr | 3:8395f7ab6d3e | 205 | |
foxbrianr | 4:7226c43320b5 | 206 | if (cursorLine > 3 ) |
foxbrianr | 4:7226c43320b5 | 207 | cursorLine = 3; |
foxbrianr | 4:7226c43320b5 | 208 | |
foxbrianr | 4:7226c43320b5 | 209 | update_needed = 1; |
foxbrianr | 3:8395f7ab6d3e | 210 | |
foxbrianr | 3:8395f7ab6d3e | 211 | } |
foxbrianr | 3:8395f7ab6d3e | 212 | |
foxbrianr | 5:9f4d4f8ffc00 | 213 | /******************************************************************************/ |
foxbrianr | 3:8395f7ab6d3e | 214 | void Menu::pressMode() |
foxbrianr | 3:8395f7ab6d3e | 215 | { |
foxbrianr | 4:7226c43320b5 | 216 | select(); |
foxbrianr | 3:8395f7ab6d3e | 217 | } |
foxbrianr | 3:8395f7ab6d3e | 218 | |
foxbrianr | 5:9f4d4f8ffc00 | 219 | /******************************************************************************/ |
foxbrianr | 3:8395f7ab6d3e | 220 | void Menu::pressSet() |
foxbrianr | 3:8395f7ab6d3e | 221 | { |
foxbrianr | 4:7226c43320b5 | 222 | select(); |
foxbrianr | 3:8395f7ab6d3e | 223 | } |
foxbrianr | 3:8395f7ab6d3e | 224 | |
foxbrianr | 5:9f4d4f8ffc00 | 225 | /******************************************************************************/ |
foxbrianr | 3:8395f7ab6d3e | 226 | void Menu::pressUp() |
foxbrianr | 3:8395f7ab6d3e | 227 | { |
foxbrianr | 4:7226c43320b5 | 228 | moveUp(); |
foxbrianr | 3:8395f7ab6d3e | 229 | } |
foxbrianr | 3:8395f7ab6d3e | 230 | |
foxbrianr | 5:9f4d4f8ffc00 | 231 | /******************************************************************************/ |
foxbrianr | 3:8395f7ab6d3e | 232 | void Menu::pressDown() |
foxbrianr | 3:8395f7ab6d3e | 233 | { |
foxbrianr | 4:7226c43320b5 | 234 | moveDown(); |
foxbrianr | 3:8395f7ab6d3e | 235 | } |
foxbrianr | 3:8395f7ab6d3e | 236 | |
foxbrianr | 5:9f4d4f8ffc00 | 237 | /******************************************************************************/ |
foxbrianr | 3:8395f7ab6d3e | 238 | void Menu::pressClear() |
foxbrianr | 3:8395f7ab6d3e | 239 | { |
foxbrianr | 4:7226c43320b5 | 240 | back(); |
foxbrianr | 3:8395f7ab6d3e | 241 | } |
foxbrianr | 3:8395f7ab6d3e | 242 | |
foxbrianr | 5:9f4d4f8ffc00 | 243 | /******************************************************************************/ |
foxbrianr | 4:7226c43320b5 | 244 | void Menu::displayVersion (LCD * lcd) |
foxbrianr | 4:7226c43320b5 | 245 | { |
foxbrianr | 3:8395f7ab6d3e | 246 | |
foxbrianr | 4:7226c43320b5 | 247 | |
foxbrianr | 4:7226c43320b5 | 248 | lcd->locate(3,35); |
foxbrianr | 7:d8673bb9fb6f | 249 | lcd->printf("v1.01"); |
foxbrianr | 3:8395f7ab6d3e | 250 | } |
foxbrianr | 5:9f4d4f8ffc00 | 251 | /******************************************************************************/ |
foxbrianr | 4:7226c43320b5 | 252 | void Menu::displayCurrentTime (LCD * lcd) |
foxbrianr | 4:7226c43320b5 | 253 | { |
foxbrianr | 5:9f4d4f8ffc00 | 254 | #if 1 |
foxbrianr | 4:7226c43320b5 | 255 | time_t rawtime; |
foxbrianr | 4:7226c43320b5 | 256 | struct tm * timeinfo; |
foxbrianr | 4:7226c43320b5 | 257 | |
foxbrianr | 4:7226c43320b5 | 258 | int cur_hours,cur_mins,cur_secs,cur_year,cur_month,cur_day; |
foxbrianr | 4:7226c43320b5 | 259 | |
foxbrianr | 4:7226c43320b5 | 260 | time ( &rawtime ); |
foxbrianr | 4:7226c43320b5 | 261 | timeinfo = localtime ( &rawtime ); timeinfo = localtime (&rawtime); |
foxbrianr | 3:8395f7ab6d3e | 262 | |
foxbrianr | 4:7226c43320b5 | 263 | cur_hours = timeinfo->tm_hour; |
foxbrianr | 4:7226c43320b5 | 264 | cur_mins = timeinfo->tm_min; |
foxbrianr | 4:7226c43320b5 | 265 | cur_secs = timeinfo->tm_sec; |
foxbrianr | 4:7226c43320b5 | 266 | cur_year = timeinfo->tm_year+1900; |
foxbrianr | 4:7226c43320b5 | 267 | cur_month = timeinfo->tm_mon + 1; |
foxbrianr | 4:7226c43320b5 | 268 | cur_day = timeinfo->tm_mday; |
foxbrianr | 4:7226c43320b5 | 269 | |
foxbrianr | 4:7226c43320b5 | 270 | lcd->locate(0,20); |
foxbrianr | 4:7226c43320b5 | 271 | lcd->printf(" %02d:%02d:%02d %02d/%02d/%04d", cur_hours, cur_mins, cur_secs, cur_month, cur_day, cur_year); |
foxbrianr | 4:7226c43320b5 | 272 | |
foxbrianr | 4:7226c43320b5 | 273 | lcd->locate(1,33); |
foxbrianr | 4:7226c43320b5 | 274 | lcd->printf("Addr=%02d",escmController.cur_address); |
foxbrianr | 5:9f4d4f8ffc00 | 275 | #endif |
foxbrianr | 3:8395f7ab6d3e | 276 | } |
foxbrianr | 5:9f4d4f8ffc00 | 277 | /******************************************************************************/ |