Minor fixes + optimizations - test success

This commit is contained in:
jonny_l480 2024-09-05 10:47:37 +02:00
parent 946fdd6c15
commit c19d053867
4 changed files with 33 additions and 15 deletions

View File

@ -182,9 +182,9 @@ void buttonCommands::action (uint8_t count, bool lastPressLong){
// when not in MENU_SETTINGS mode, repeatedly receives events from encoder button
// and takes the corresponding action
// this function has to be started once in a separate task
#define INPUT_TIMEOUT 500 // duration of no button events, after which action is run (implicitly also is 'long-press' time)
#define INPUT_TIMEOUT 600 // duration of no button events, after which action is run (implicitly also is 'long-press' time)
#define IGNORE_BUTTON_TIME_SINCE_LAST_ROTATE 800 // time that has to be passed since last encoder rotate click for button count command to be accepted (e.g. prevent long press action after PRESS+ROTATE was used)
#define IGNORE_ROTATE_COUNT 2 //amount of ignored clicks before action is actually taken (ignore accidental touches)
#define IGNORE_ROTATE_COUNT 1 //amount of ignored clicks before action is actually taken (ignore accidental touches)
void buttonCommands::startHandleLoop()
{
//-- variables --
@ -226,7 +226,7 @@ void buttonCommands::startHandleLoop()
break;
case RE_ET_CHANGED:
// ignore first clicks
if (++rotateCount < IGNORE_ROTATE_COUNT)
if (rotateCount++ < IGNORE_ROTATE_COUNT)
{
buzzer->beep(1, 60, 0);
break;
@ -245,8 +245,8 @@ void buttonCommands::startHandleLoop()
backRest->setTargetPercent(backRest->getTargetPercent() + 5);
// show temporary notification on display
char buf[8];
snprintf(buf, 8, "%.1f%%", backRest->getTargetPercent());
display_showNotification(1000, "moving Rest:", "LEG", buf);
snprintf(buf, 8, "%.0f%%", backRest->getTargetPercent());
display_showNotification(2500, "moving Rest:", "BACK", buf);
}
//### adjust leg support when ROTATED ###
else
@ -258,8 +258,8 @@ void buttonCommands::startHandleLoop()
legRest->setTargetPercent(legRest->getTargetPercent() + 5);
// show temporary notification on display
char buf[8];
snprintf(buf, 8, "%.1f%%", legRest->getTargetPercent());
display_showNotification(1000, "moving Rest:", "LEG", buf);
snprintf(buf, 8, "%.0f%%", legRest->getTargetPercent());
display_showNotification(2500, "moving Rest:", "LEG", buf);
}
buzzer->beep(1, 90, 0);
break;

View File

@ -596,6 +596,10 @@ void handleStatusScreen(display_task_parameters_t *objects)
// trigger custom notification that is shown in any mode for set amount of time
void display_showNotification(uint32_t showDurationMs, const char *line1, const char *line2Large, const char *line3Large)
{
// clear display when notification initially shown
if (notificationIsActive == false)
ssd1306_clear_screen(&dev, false);
// update state and timestamp for auto exit
timestampNotificationStop = esp_log_timestamp() + showDurationMs;
notificationIsActive = true;
// void displayTextLineCentered(SSD1306_t *display, int line, bool isLarge, bool inverted, const char *format, ...);

View File

@ -162,7 +162,7 @@ void createObjects()
// create objects for controlling the chair position
// gpio_up, gpio_down, travelDuration, name, defaultPosition
legRest = new cControlledRest(GPIO_NUM_2, GPIO_NUM_15, 12000, "legRest");
legRest = new cControlledRest(GPIO_NUM_2, GPIO_NUM_15, 11000, "legRest");
backRest = new cControlledRest(GPIO_NUM_16, GPIO_NUM_4, 12000, "backRest", 100); //default position "100% up"
// create control object (control.hpp)

View File

@ -95,11 +95,19 @@ void cControlledRest::updatePosition(){
//============================
void cControlledRest::setState(restState_t targetState)
{
//check if actually changed
if (targetState == state){
// TODO: drop this section?
// check if actually changed
if (targetState == state)
{
// update anyways when target is 0 or 100, to trigger movement threshold in case of position tracking is out of sync
if (positionTarget == 0 || positionTarget == 100)
ESP_LOGD(TAG, "[%s] state already at '%s', but updating anyway to trigger move to limit addition", name, restStateStr[state]);
else
{
ESP_LOGV(TAG, "[%s] state already at '%s', nothing to do", name, restStateStr[state]);
return;
}
}
// when switching direction without stop: update position first
if (state != REST_OFF)
@ -148,6 +156,12 @@ void cControlledRest::setTargetPercent(float targetPercent){
else if (positionTarget < 0)
positionTarget = 0;
// ignore if unchanged
//if (positionTarget == positionTargetPrev){
// ESP_LOGI(TAG, "[%s] Target position unchanged at %.2f%%", name, positionTarget);
// return;
//}
ESP_LOGI(TAG, "[%s] changed Target position from %.2f%% to %.2f%%", name, positionTargetPrev, positionTarget);
// start rest in required direction
@ -185,7 +199,7 @@ void cControlledRest::handle(){
// target reached
if (timeRan >= timeTarget){
ESP_LOGW(TAG, "[%s] reached target run-time (%dms/%dms) for position %.2f%% -> stopping", name, timeRan, timeTarget, positionTarget);
ESP_LOGW(TAG, "[%s] handle: reached target run-time (%dms/%dms) for position %.2f%% -> stopping", name, timeRan, timeTarget, positionTarget);
setState(REST_OFF);
}
}