Skip to content

Commit

Permalink
moved 'reboot' screen into configuration menus
Browse files Browse the repository at this point in the history
  • Loading branch information
barry-ha committed Mar 30, 2023
1 parent d9554f3 commit a773007
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 66 deletions.
61 changes: 29 additions & 32 deletions Griduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
#include "view_date.h" // counting days to/from special event
#include "view_grid_crossings.h" // list of time spent in each grid
#include "view_help.h" // help screen
#include "view_reboot.h" // confirm reboot operation // moved reboot to settings
#include "view_screen1.h" // starting screen animation
#include "view_splash.h" // splash screen
#include "view_status.h" // status screen
Expand All @@ -102,6 +101,7 @@
#include "cfg_audio_type.h" // config audio Morse/speech
#include "cfg_crossing.h" // config 4/6 digit crossing
#include "cfg_gps.h" // config GPS (alphabetical order)
#include "cfg_reboot.h" // show firmware update option
#include "cfg_rotation.h" // config screen rotation
#include "cfg_units.h" // config english/metric
#include "cfg_volume.h" // config volume level
Expand Down Expand Up @@ -200,17 +200,14 @@ const int howLongToWait = 6; // max number of seconds at startup waitin

// 2. Helper Functions
// ============== Touchable spots on all screens ===============
Rect areaGear { {0, 0}, {gScreenWidth * 4/10, gScreenHeight * 5/10}};
Rect areaArrow{ {gScreenWidth *5/10, 0}, {gScreenWidth * 5/10, gScreenHeight * 5/10}};
//ct areaReboot{{0, gScreenHeight *7/10}, {gScreenWidth * 3/10, gScreenHeight * 3/10}};
//ct areaBrite{ {gScreenWidth *4/10,gScreenHeight *6/10}, {gScreenWidth *6/10, (gScreenHeight * 4/10)-1}};
Rect areaBrite{ {0,gScreenHeight *2/3}, {gScreenWidth, (gScreenHeight * 1/3)-1}};
Rect areaGear { {0, 0}, {gScreenWidth * 4/10, gScreenHeight * 5/10}};
Rect areaArrow{ {gScreenWidth *5/10, 0}, {gScreenWidth * 5/10, gScreenHeight * 5/10}};
Rect areaBrite{ {0, gScreenHeight *2/3}, {gScreenWidth, (gScreenHeight * 1/3)-1}};

void showDefaultTouchTargets() {
if (showTouchTargets) {
tft.drawRect(areaGear.ul.x,areaGear.ul.y, areaGear.size.x, areaGear.size.y, ILI9341_MAGENTA);
tft.drawRect(areaArrow.ul.x,areaArrow.ul.y, areaArrow.size.x,areaArrow.size.y, ILI9341_MAGENTA);
//t.drawRect(areaReboot.ul.x,areaReboot.ul.y, areaReboot.size.x,areaReboot.size.y, ILI9341_MAGENTA); // moved reboot to settings
tft.drawRect(areaBrite.ul.x,areaBrite.ul.y, areaBrite.size.x,areaBrite.size.y, ILI9341_MAGENTA);
}
}
Expand Down Expand Up @@ -319,23 +316,23 @@ BarometerModel baroModel; // create instance of the model

// alias names for all views - MUST be in same order as "viewTable" array below, alphabetical by class name
enum VIEW_INDEX {
GRID_VIEW = 0,
GRID_CROSSINGS_VIEW, // log of time in each grid
ALTIMETER_VIEW, // altimeter
ALTIMETER_VIEW = 0, // altimeter
BARO_VIEW, // barometer graph
HELP_VIEW, // hints at startup
CFG_GPS, // gps/simulator
CFG_UNITS, // english/metric
CFG_CROSSING, // announce grid crossing 4/6 digit boundaries
CFG_AUDIO_TYPE, // audio output Morse/speech
CFG_CROSSING, // announce grid crossing 4/6 digit boundaries
CFG_GPS, // gps/simulator
CFG_REBOOT, // confirm reboot
CFG_ROTATION, // screen rotation
REBOOT_VIEW, // confirm reboot
CFG_UNITS, // english/metric
DATE_VIEW, // Groundhog Day, Halloween, or other day-counting screen
GRID_VIEW,
GRID_CROSSINGS_VIEW, // log of time in each grid
HELP_VIEW, // hints at startup
SCREEN1_VIEW, // first bootup screen
SPLASH_VIEW, // startup
STATUS_VIEW, // size and scale of this grid
TEN_MILE_ALERT_VIEW, // microwave rover view
TIME_VIEW, //
DATE_VIEW, // Groundhog Day, Halloween, or other day-counting screen
CFG_VOLUME, //
GOTO_SETTINGS, // command the state machine to show control panel
GOTO_NEXT_VIEW, // command the state machine to show next screen
Expand All @@ -346,23 +343,24 @@ enum VIEW_INDEX {
/*const*/ int screen1_view = SCREEN1_VIEW;
/*const*/ int grid_view = GRID_VIEW;
/*const*/ int goto_next_view = GOTO_NEXT_VIEW;
/*const*/ int goto_next_cfg = GOTO_SETTINGS;

// list of objects derived from "class View", in alphabetical order
// clang-format off
View* pView; // pointer to a derived class

// vvv sort vvv
ViewAltimeter altimeterView(&tft, ALTIMETER_VIEW); // alphabetical order by class name
ViewBaro baroView(&tft, BARO_VIEW); // instantiate derived classes
ViewCfgAudioType cfgAudioType(&tft, CFG_AUDIO_TYPE);
ViewCfgCrossing cfgCrossing(&tft, CFG_CROSSING);
ViewCfgGPS cfgGPS(&tft, CFG_GPS);
ViewCfgReboot cfgReboot(&tft, CFG_REBOOT);
ViewCfgRotation cfgRotation(&tft, CFG_ROTATION);
ViewCfgUnits cfgUnits(&tft, CFG_UNITS);
ViewDate dateView(&tft, DATE_VIEW);
ViewGrid gridView(&tft, GRID_VIEW);
ViewGridCrossings gridCrossingsView(&tft, GRID_CROSSINGS_VIEW);
ViewHelp helpView(&tft, HELP_VIEW);
ViewReboot rebootView(&tft, REBOOT_VIEW);
ViewScreen1 screen1View(&tft, SCREEN1_VIEW);
ViewSplash splashView(&tft, SPLASH_VIEW);
ViewStatus statusView(&tft, STATUS_VIEW);
Expand All @@ -376,29 +374,29 @@ void selectNewView(int cmd) {
// this is a state machine to select next view, given current view and type of command
View *viewTable[] = {
// vvv same order as enum vvv
&gridView, // [GRID_VIEW]
&gridCrossingsView, // [GRID_CROSSINGS_VIEW]
&altimeterView, // [ALTIMETER_VIEW]
&baroView, // [BARO_VIEW]
&helpView, // [HELP_VIEW]
&cfgGPS, // [CFG_GPS]
&cfgUnits, // [CFG_UNITS]
&cfgCrossing, // [CFG_CROSSING]
&cfgAudioType, // [CFG_AUDIO_TYPE]
&cfgCrossing, // [CFG_CROSSING]
&cfgGPS, // [CFG_GPS]
&cfgReboot, // [CFG_REBOOT]
&cfgRotation, // [CFG_ROTATION]
&rebootView, // [REBOOT_VIEW]
&cfgUnits, // [CFG_UNITS]
&dateView, // [DATE_VIEW]
&gridView, // [GRID_VIEW]
&gridCrossingsView, // [GRID_CROSSINGS_VIEW]
&helpView, // [HELP_VIEW]
&screen1View, // [SCREEN1_VIEW]
&splashView, // [SPLASH_VIEW]
&statusView, // [STATUS_VIEW]
&tenMileAlertView, // [TEN_MILE_ALERT_VIEW]
&timeView, // [TIME_VIEW]
&dateView, // [DATE_VIEW]
&volumeView, // [CFG_VOLUME]
};

int currentView = pView->screenID;
int nextView = BARO_VIEW; // GRID_VIEW; // default
// clang-format off
int currentView = pView->screenID;
int nextView = BARO_VIEW; // GRID_VIEW; // default
// clang-format off
if (cmd == GOTO_NEXT_VIEW) {
// operator requested the next NORMAL user view
switch (currentView) {
Expand All @@ -424,7 +422,8 @@ int nextView = BARO_VIEW; // GRID_VIEW; // default
case CFG_CROSSING: nextView = CFG_GPS; break;
case CFG_GPS: nextView = CFG_UNITS; break;
case CFG_UNITS: nextView = CFG_ROTATION; break;
case CFG_ROTATION: nextView = CFG_VOLUME; break;
case CFG_ROTATION: nextView = CFG_REBOOT; break;
case CFG_REBOOT: nextView = CFG_VOLUME; break;
// none of above: we must be showing some normal user view, so go to the first settings view
default: nextView = CFG_VOLUME; break;
}
Expand Down Expand Up @@ -966,8 +965,6 @@ void loop() {
selectNewView(GOTO_SETTINGS); // advance to next settings view
} else if (areaArrow.contains(touch)) {
selectNewView(GOTO_NEXT_VIEW); // advance to next normal user view
// } else if (areaReboot.contains(touch)) {
// selectNewView(REBOOT_VIEW);
} else if (areaBrite.contains(touch)) {
adjustBrightness(); // change brightness
} else {
Expand Down
69 changes: 35 additions & 34 deletions view_reboot.h → cfg_reboot.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#pragma once // Please format this file with clang before check-in to GitHub
/*
File: view_reboot.h (based on view_status.h)
File: cfg_reboot.h
Version history:
2022-12-12 written for rp2040
2023-03-30 moved 'reboot' from 'view' to a configuration screen
2022-12-12 written for rp2040 (feature is only available of rp2040, not Feather M4)
Software: Barry Hansen, K7BWH, barry@k7bwh.com, Seattle, WA
Hardware: John Vanderbeck, KM7O, Seattle, WA
Purpose: Ask operator to confirm reboot.
+-----------------------------------------+
| * Griduino Reboot > |... yRow1
| * 7. Griduino Reboot > |... yRow1
| |
| Use this option to update firmware. |... yRow2
| Do you have a UF2 file? |... yRow3
Expand All @@ -22,7 +23,7 @@
| | | | | |
| +=============+ +-------------+ |
| |
| v1.11, Dec 13 2022 |... yRow9
| v1.12, Mar 30 2023 |... yRow9
+-----------------------------------------+
*/

Expand All @@ -34,22 +35,23 @@

// ========== extern ===========================================
#if defined(ARDUINO_ADAFRUIT_FEATHER_RP2040)
extern "C" {
#include <hardware/watchdog.h>
#include <hardware/resets.h>
#include <pico/bootrom.h>
}
extern "C" {
#include <hardware/watchdog.h>
#include <hardware/resets.h>
#include <pico/bootrom.h>
}
#endif
extern Logger logger; // Griduino.ino
extern void showDefaultTouchTargets(); // Griduino.ino
void selectNewView(int cmd); // extern declaration
extern void selectNewView(int cmd); // Griduino.ino
extern int goto_next_cfg; // Griduino.ino

// ========== class ViewReboot ===================================
class ViewReboot : public View {
// ========== class ViewCfgReboot ================================
class ViewCfgReboot : public View {
public:
// ---------- public interface ----------
// This derived class must implement the public interface:
ViewReboot(Adafruit_ILI9341 *vtft, int vid) // ctor
ViewCfgReboot(Adafruit_ILI9341 *vtft, int vid) // ctor
: View{vtft, vid} {
background = cBACKGROUND; // every view can have its own background color
}
Expand All @@ -67,12 +69,12 @@ class ViewReboot : public View {
const int space = 30;
const int half = space / 2;

const int yRow1 = 20; // title "Confirm reboot"
const int yRow2 = yRow1 + space; // "Use this option to update firmware."
const int yRow1 = 20; // title "Firmware Update"
const int yRow2 = yRow1 + space; // "This option starts bootloader mode."
const int yRow3 = yRow2 + space; // "Do you have a UF2 file?"
const int yRow4 = yRow3 + space; // "Do you want to install it?""
const int yRow5 = yRow4 + half; // "Cancel", "Install UF2" buttons
const int yRow9 = gScreenHeight - 4; // "v1.11, Dec 13 2022"
const int yRow9 = gScreenHeight - 4; // "v1.12, Mar 30 2023"

// ----- screen text
// names for the array indexes, must be named in same order as array below
Expand All @@ -91,12 +93,12 @@ class ViewReboot : public View {
// clang-format off
#define nRebootValues 5
TextField txtValues[nRebootValues] = {
// text x,y color, alignment, font size
{"Confirm Reboot", -1, yRow1, cHIGHLIGHT, ALIGNCENTER, eFONTSMALLEST}, // [TITLE] centered
{"Use this option to update firmware.", -1, yRow2, cLABEL, ALIGNCENTER, eFONTSMALLEST}, // [LINE1] centered
{"Do you have a UF2 file?", left, yRow3, cVALUE, ALIGNLEFT, eFONTSMALL}, // [LINE2]
{"Do you want to install it?", left, yRow4, cVALUE, ALIGNLEFT, eFONTSMALL}, // [LINE3]
{PROGRAM_VERSION ", " __DATE__, -1, yRow9, cLABEL, ALIGNCENTER, eFONTSMALLEST}, // [COMPILED]
// text x,y color, alignment, font size
{"7. Firmware Update", -1, yRow1, cHIGHLIGHT, ALIGNCENTER, eFONTSMALLEST}, // [TITLE] centered
{"This option starts bootloader mode.", -1, yRow2, cLABEL, ALIGNCENTER, eFONTSMALLEST}, // [LINE1] centered
{"Do you have a UF2 file?", left, yRow3, cVALUE, ALIGNLEFT, eFONTSMALL}, // [LINE2]
{"Do you want to install it?", left, yRow4, cVALUE, ALIGNLEFT, eFONTSMALL}, // [LINE3]
{PROGRAM_VERSION ", " __DATE__, -1, yRow9, cLABEL, ALIGNCENTER, eFONTSMALLEST}, // [COMPILED]
};

enum buttonID {
Expand All @@ -115,11 +117,11 @@ enum buttonID {
// ---------- local functions for this derived class ----------
void rebootGriduino() { // operator confirmed: reboot to USB for software update
// Do The Thing!
Serial.println("---> REBOOTING"); // the end of our world is nigh
delay(100); // allow time for Serial to send message
logger.info("---> REBOOTING"); // the end of our world is nigh
delay(100); // allow time for Serial to send message

this->clearScreen(this->background); // clear screen and post message

this->clearScreen(this->background); // clear screen
// post message
const int left = 28; // x: left text edge
const int top = 40; // y: top text row
setFontSize(eFONTSMALLEST);
Expand Down Expand Up @@ -151,28 +153,27 @@ enum buttonID {
reset_usb_boot(0, 0);
#else
// todo: try to discover a way to put Feather M4 into bootloader mode
// todo: for now
// todo: for now, display a message
#endif
}
void fCancel() {
logger.info("->->-> Clicked CANCEL button.");
extern /*const*/ int grid_view; // see "Griduino.ino"
selectNewView(grid_view);
selectNewView(goto_next_cfg);
}
void fReboot() {
logger.info("->->-> Clicked REBOOT button.");
rebootGriduino();
}

}; // end class ViewReboot
}; // end class ViewCfgReboot

// ============== implement public interface ================
void ViewReboot::updateScreen() {
void ViewCfgReboot::updateScreen() {
// called on every pass through main()
// nothing to do in the main loop - this screen has no dynamic items
} // end updateScreen

void ViewReboot::startScreen() {
void ViewCfgReboot::startScreen() {
// called once each time this view becomes active
this->clearScreen(this->background); // clear screen
txtValues[0].setBackground(this->background); // set background for all TextFields in this view
Expand Down Expand Up @@ -207,7 +208,7 @@ void ViewReboot::startScreen() {
updateScreen(); // update UI immediately, don't wait for the main loop to eventually get around to it
} // end startScreen()

bool ViewReboot::onTouch(Point touch) {
bool ViewCfgReboot::onTouch(Point touch) {
logger.info("->->-> Touched reboot screen.");
bool handled = false; // assume a touch target was not hit
for (int ii = 0; ii < nRebootButtons; ii++) {
Expand All @@ -223,7 +224,7 @@ bool ViewReboot::onTouch(Point touch) {
fReboot();
break;
default:
logger.error("Error, unknown function ", item.functionIndex);
logger.error("Internal error, unknown function ", item.functionIndex);
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions view_screen1.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
// ========== extern ===========================================
extern Logger logger; // Griduino.ino
extern void showDefaultTouchTargets(); // Griduino.ino
extern void selectNewView(int cmd); // Griduino.ino
extern int goto_next_view; // Griduino.ino

// ========== class ViewScreen1 =================================
Expand Down

0 comments on commit a773007

Please sign in to comment.