Button: Scroll through status screens with rotating encoder
In any mode except MENU the encoder rotateion selects status screens Add functions to rotate through available status screens Aandle rotate encoder event in button menu
This commit is contained in:
parent
a839d61f65
commit
bff6175fb0
@ -9,6 +9,7 @@ extern "C"
|
|||||||
|
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
#include "encoder.hpp"
|
#include "encoder.hpp"
|
||||||
|
#include "display.hpp"
|
||||||
|
|
||||||
// tag for logging
|
// tag for logging
|
||||||
static const char *TAG = "button";
|
static const char *TAG = "button";
|
||||||
@ -164,7 +165,7 @@ void buttonCommands::startHandleLoop()
|
|||||||
{
|
{
|
||||||
//-- variables --
|
//-- variables --
|
||||||
bool isPressed = false;
|
bool isPressed = false;
|
||||||
static rotary_encoder_event_t ev; // store event data
|
static rotary_encoder_event_t event; // store event data
|
||||||
// int count = 0; (from class)
|
// int count = 0; (from class)
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
@ -180,10 +181,10 @@ void buttonCommands::startHandleLoop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-- get events from encoder --
|
//-- get events from encoder --
|
||||||
if (xQueueReceive(encoderQueue, &ev, INPUT_TIMEOUT / portTICK_PERIOD_MS))
|
if (xQueueReceive(encoderQueue, &event, INPUT_TIMEOUT / portTICK_PERIOD_MS))
|
||||||
{
|
{
|
||||||
control->resetTimeout(); // user input -> reset switch to IDLE timeout
|
control->resetTimeout(); // user input -> reset switch to IDLE timeout
|
||||||
switch (ev.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
case RE_ET_BTN_PRESSED:
|
case RE_ET_BTN_PRESSED:
|
||||||
@ -196,9 +197,20 @@ void buttonCommands::startHandleLoop()
|
|||||||
ESP_LOGD(TAG, "Button released");
|
ESP_LOGD(TAG, "Button released");
|
||||||
isPressed = false; // rest stored state
|
isPressed = false; // rest stored state
|
||||||
break;
|
break;
|
||||||
|
case RE_ET_CHANGED: // scroll through status pages when simply rotating encoder
|
||||||
|
if (event.diff > 0)
|
||||||
|
{
|
||||||
|
display_rotateStatusPage(true, true); //select NEXT status screen, stau at last element (dont rotate to first)
|
||||||
|
buzzer->beep(1, 65, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
display_rotateStatusPage(false, true); //select PREVIOUS status screen, stay at first element (dont rotate to last)
|
||||||
|
buzzer->beep(1, 65, 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case RE_ET_BTN_LONG_PRESSED:
|
case RE_ET_BTN_LONG_PRESSED:
|
||||||
case RE_ET_BTN_CLICKED:
|
case RE_ET_BTN_CLICKED:
|
||||||
case RE_ET_CHANGED:
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -441,6 +441,13 @@ void showStartupMsg(){
|
|||||||
//============================
|
//============================
|
||||||
void display_selectStatusPage(displayStatusPage_t newStatusPage)
|
void display_selectStatusPage(displayStatusPage_t newStatusPage)
|
||||||
{
|
{
|
||||||
|
// get number of available screens
|
||||||
|
const displayStatusPage_t max = STATUS_SCREEN_SCREENSAVER;
|
||||||
|
const uint8_t maxItems = (uint8_t)max;
|
||||||
|
// limit to available pages
|
||||||
|
if (newStatusPage > maxItems) newStatusPage = (displayStatusPage_t)(maxItems);
|
||||||
|
else if (newStatusPage < 0) newStatusPage = (displayStatusPage_t)0;
|
||||||
|
|
||||||
//-- run commands when switching FROM certain mode --
|
//-- run commands when switching FROM certain mode --
|
||||||
switch (selectedStatusPage)
|
switch (selectedStatusPage)
|
||||||
{
|
{
|
||||||
@ -470,6 +477,41 @@ void display_selectStatusPage(displayStatusPage_t newStatusPage)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//============================
|
||||||
|
//===== rotateStatusPage =====
|
||||||
|
//============================
|
||||||
|
// select next/previous status screen and rotate to start/end (uses all available in struct)
|
||||||
|
void display_rotateStatusPage(bool reverseDirection, bool noRotate)
|
||||||
|
{
|
||||||
|
// get number of available screens
|
||||||
|
const displayStatusPage_t max = STATUS_SCREEN_SCREENSAVER;
|
||||||
|
const uint8_t maxItems = (uint8_t)max - 1; // screensaver is not relevant
|
||||||
|
|
||||||
|
if (reverseDirection == false) // rotate next
|
||||||
|
{
|
||||||
|
if (selectedStatusPage >= maxItems) // already at last item
|
||||||
|
{
|
||||||
|
if (noRotate)
|
||||||
|
return; // stay at last item when rotating disabled
|
||||||
|
display_selectStatusPage((displayStatusPage_t)0); // rotate to first item
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// select next screen
|
||||||
|
display_selectStatusPage((displayStatusPage_t)((int)selectedStatusPage + 1));
|
||||||
|
}
|
||||||
|
else // rotate back
|
||||||
|
{
|
||||||
|
if (selectedStatusPage <= 0) // already at first item
|
||||||
|
{
|
||||||
|
if (noRotate)
|
||||||
|
return; // stay at first item when rotating disabled
|
||||||
|
display_selectStatusPage((displayStatusPage_t)(maxItems)); // rotate to last item
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// select previous screen
|
||||||
|
display_selectStatusPage((displayStatusPage_t)((int)selectedStatusPage - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//============================
|
//============================
|
||||||
|
@ -54,7 +54,7 @@ typedef struct display_task_parameters_t {
|
|||||||
|
|
||||||
|
|
||||||
// enum for selecting the currently shown status page (display content when not in MENU mode)
|
// 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, STATUS_SCREEN_MOTORS, STATUS_SCREEN_SCREENSAVER} displayStatusPage_t;
|
typedef enum displayStatusPage_t {STATUS_SCREEN_OVERVIEW=0, STATUS_SCREEN_SPEED, STATUS_SCREEN_JOYSTICK, STATUS_SCREEN_MOTORS, STATUS_SCREEN_SCREENSAVER, __NUMBER_OF_AVAILABLE_SCREENS} displayStatusPage_t; //note: SCREENSAVER has to be last one since it is ignored by rotate and used to determine count
|
||||||
|
|
||||||
// get precise battery voltage (using lookup table)
|
// get precise battery voltage (using lookup table)
|
||||||
float getBatteryVoltage();
|
float getBatteryVoltage();
|
||||||
@ -64,6 +64,8 @@ float getBatteryPercent();
|
|||||||
|
|
||||||
// function to select one of the defined status screens which are shown on display when not in MENU mode
|
// 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);
|
void display_selectStatusPage(displayStatusPage_t newStatusPage);
|
||||||
|
// select next/previous status screen to be shown, when noRotate is set is stays at first/last screen
|
||||||
|
void display_rotateStatusPage(bool reverseDirection = false, bool noRotate = false);
|
||||||
|
|
||||||
//task that inititialized the display, displays welcome message
|
//task that inititialized the display, displays welcome message
|
||||||
//and releatedly updates the display with certain content
|
//and releatedly updates the display with certain content
|
||||||
|
Loading…
x
Reference in New Issue
Block a user