From aab30abb80321c23e0f7d12d42d79d8e5f2903bc Mon Sep 17 00:00:00 2001 From: jonny_l480 Date: Mon, 26 Feb 2024 23:05:02 +0100 Subject: [PATCH] Display: Add Status screens 'Motors' and 'Joystick' Add new status screens that can be selected in menu (status screen = display content while not in MENU mode) - display: - Motors screen: shows Power usage, duty, speed - Joystick screen: shows all stick data and current control mode (similar to 'debug joystick' menu option - menu: - disable example menu items - add new status screens --- board_single/main/display.cpp | 69 ++++++++++++++++++++++++++++++----- board_single/main/display.hpp | 2 +- board_single/main/menu.cpp | 17 +++++---- 3 files changed, 71 insertions(+), 17 deletions(-) diff --git a/board_single/main/display.cpp b/board_single/main/display.cpp index 71b3d0d..e0c8a3a 100644 --- a/board_single/main/display.cpp +++ b/board_single/main/display.cpp @@ -190,9 +190,9 @@ float getBatteryPercent(){ -//----------------------------- -//---- showScreen Overview ---- -//----------------------------- +//############################# +//#### showScreen Overview #### +//############################# //shows overview on entire display: //Battery percentage, voltage, current, mode, rpm, speed #define STATUS_SCREEN_OVERVIEW_UPDATE_INTERVAL 500 @@ -228,9 +228,9 @@ void showStatusScreenOverview(display_task_parameters_t * objects) } -//---------------------------- -//----- showScreen Speed ----- -//---------------------------- +//############################ +//##### showScreen Speed ##### +//############################ // shows speed of each motor in km/h large in two lines and RPM in last line #define STATUS_SCREEN_SPEED_UPDATE_INTERVAL 300 void showStatusScreenSpeed(display_task_parameters_t * objects) @@ -248,9 +248,54 @@ void showStatusScreenSpeed(display_task_parameters_t * objects) } -//------------------------ -//---- showStartupMsg ---- -//------------------------ + +//############################# +//#### showScreen Joystick #### +//############################# +// shows speed of each motor in km/h large in two lines and RPM in last line +#define STATUS_SCREEN_JOYSTICK_UPDATE_INTERVAL 100 +void showStatusScreenJoystick(display_task_parameters_t * objects) +{ + // print all joystick data + joystickData_t data = objects->joystick->getData(); + displayTextLine(&dev, 0, false, false, "joystick status:"); + displayTextLine(&dev, 1, false, false, "x = %.3f ", data.x); + displayTextLine(&dev, 2, false, false, "y = %.3f ", data.y); + displayTextLine(&dev, 3, false, false, "radius = %.3f", data.radius); + displayTextLine(&dev, 4, false, false, "angle = %-06.3f ", data.angle); + displayTextLine(&dev, 5, false, false, "pos=%-12s ", joystickPosStr[(int)data.position]); + displayTextLine(&dev, 6, false, false, "adc: %d:%d ", objects->joystick->getRawX(), objects->joystick->getRawY()); + displayTextLine(&dev, 7, false, false, "mode=%s ", objects->control->getCurrentModeStr()); + vTaskDelay(STATUS_SCREEN_JOYSTICK_UPDATE_INTERVAL / portTICK_PERIOD_MS); +} + + +//############################# +//##### showScreen motors ##### +//############################# +// shows speed of each motor in km/h large in two lines and RPM in last line +#define STATUS_SCREEN_MOTORS_UPDATE_INTERVAL 150 +void showStatusScreenMotors(display_task_parameters_t *objects) +{ + // print all joystick data + joystickData_t data = objects->joystick->getData(); + displayTextLine(&dev, 0, true, false, "%-4.0fW ", fabs(objects->motorLeft->getCurrentA()) * getBatteryVoltage()); + displayTextLine(&dev, 3, true, false, "%-4.0fW ", fabs(objects->motorRight->getCurrentA()) * getBatteryVoltage()); + //displayTextLine(&dev, 0, true, false, "L:%02.0f%%", objects->motorLeft->getStatus().duty); + //displayTextLine(&dev, 3, true, false, "R:%02.0f%%", objects->motorRight->getStatus().duty); + displayTextLineCentered(&dev, 6, false, false, "%+03.0f%% | %+03.0f%% DTY", + objects->motorLeft->getStatus().duty, + objects->motorRight->getStatus().duty); + displayTextLineCentered(&dev, 7, false, false, "%+04.0f | %+04.0f RPM", + objects->speedLeft->getRpm(), + objects->speedRight->getRpm()); + vTaskDelay(STATUS_SCREEN_MOTORS_UPDATE_INTERVAL / portTICK_PERIOD_MS); +} + + +//######################## +//#### showStartupMsg #### +//######################## //shows welcome message and information about current version void showStartupMsg(){ const esp_app_desc_t * desc = esp_ota_get_app_description(); @@ -314,6 +359,12 @@ void display_task(void *pvParameters) case STATUS_SCREEN_SPEED: showStatusScreenSpeed(objects); break; + case STATUS_SCREEN_JOYSTICK: + showStatusScreenJoystick(objects); + break; + case STATUS_SCREEN_MOTORS: + showStatusScreenMotors(objects); + break; } } // TODO add pages and menus diff --git a/board_single/main/display.hpp b/board_single/main/display.hpp index 9dba7ee..6b64caa 100644 --- a/board_single/main/display.hpp +++ b/board_single/main/display.hpp @@ -49,7 +49,7 @@ typedef struct display_task_parameters_t { // enum for selecting the currently shown status page (display content when not in MENU mode) -typedef enum displayStatusPage_t {STATUS_SCREEN_OVERVIEW=0, STATUS_SCREEN_SPEED, STATUS_SCREEN_JOYSTICK} displayStatusPage_t; +typedef enum displayStatusPage_t {STATUS_SCREEN_OVERVIEW=0, STATUS_SCREEN_SPEED, STATUS_SCREEN_JOYSTICK, STATUS_SCREEN_MOTORS} displayStatusPage_t; // function to select one of the defined status screens which are shown on display when not in MENU mode void display_selectStatusPage(displayStatusPage_t newStatusPage); diff --git a/board_single/main/menu.cpp b/board_single/main/menu.cpp index 8f3d7a8..46100d4 100644 --- a/board_single/main/menu.cpp +++ b/board_single/main/menu.cpp @@ -381,9 +381,9 @@ menuItem_t item_reset = { }; -//##################### -//###### example ###### -//##################### +//############################### +//##### select statusScreen ##### +//############################### void item_statusScreen_action(display_task_parameters_t *objects, SSD1306_t *display, int value) { switch (value) @@ -398,6 +398,9 @@ void item_statusScreen_action(display_task_parameters_t *objects, SSD1306_t *dis case 3: display_selectStatusPage(STATUS_SCREEN_JOYSTICK); break; + case 4: + display_selectStatusPage(STATUS_SCREEN_MOTORS); + break; } } int item_statusScreen_value(display_task_parameters_t *objects) @@ -409,7 +412,7 @@ menuItem_t item_statusScreen = { item_statusScreen_value, // function get initial value or NULL(show in line 2) NULL, // function get default value or NULL(dont set value, show msg) 1, // valueMin - 3, // valueMax + 4, // valueMax 1, // valueIncrement "Status Screen ", // title " Select ", // line1 (above value) @@ -417,7 +420,7 @@ menuItem_t item_statusScreen = { "1: Overview", // line4 * (below value) "2: Speeds", // line5 * "3: Joystick", // line6 - " ", // line7 + "4: Motors", // line7 }; //##################### @@ -470,7 +473,7 @@ menuItem_t item_last = { //### store all configured menu items in one array ### //#################################################### const menuItem_t menuItems[] = {item_centerJoystick, item_calibrateJoystick, item_debugJoystick, item_maxDuty, item_accelLimit, item_decelLimit, item_statusScreen, item_reset, item_example, item_last}; -const int itemCount = 10; +const int itemCount = 8; @@ -496,7 +499,7 @@ void showItemList(SSD1306_t *display, int selectedItem) if (printItemIndex < 0 || printItemIndex >= itemCount) // out of range of available items { // no item in this line - displayTextLine(display, line, false, false, " -- empty -- "); + displayTextLineCentered(display, line, false, false, "---"); } else {