Skip to content

Commit

Permalink
fix some buttons snafu & power off led on suspend
Browse files Browse the repository at this point in the history
  • Loading branch information
philippe44 committed Sep 17, 2023
1 parent bb185d7 commit 66b88d1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
7 changes: 4 additions & 3 deletions components/services/audio_controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ static void control_handler(void *client, button_event_e event, button_press_e p

// in raw mode, we just do normal action press *and* release, there is no longpress nor shift
if (current_raw_controls && action_detail.action != ACTRLS_SLEEP) {
ESP_LOGD(TAG, "calling action %u in raw mode", key->normal[0].action);
if (current_controls[key->normal[0].action]) (*current_controls[key->normal[0].action])(event == BUTTON_PRESSED);
actrls_action_e action = key->normal[0].action != ACTRLS_NONE ? key->normal[0].action : key->normal[1].action;
ESP_LOGD(TAG, "calling action %u in raw mode", action);
if (action != ACTRLS_NONE && current_controls[action]) current_controls[action](event == BUTTON_PRESSED);
return;
}

Expand All @@ -218,7 +219,7 @@ static void control_handler(void *client, button_event_e event, button_press_e p
ESP_LOGE(TAG,"Invalid profile name %s. Cannot remap buttons",action_detail.name);
}
} else if (action_detail.action == ACTRLS_SLEEP) {
ESP_LOGI(TAG, "Sleep button pressed");
ESP_LOGI(TAG, "special sleep button pressed");
services_sleep_activate(SLEEP_ONKEY);
} else if (action_detail.action != ACTRLS_NONE) {
ESP_LOGD(TAG, "calling action %u", action_detail.action);
Expand Down
3 changes: 2 additions & 1 deletion components/services/audio_controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ typedef enum { ACTRLS_NONE = -1, ACTRLS_POWER, ACTRLS_VOLUP, ACTRLS_VOLDOWN, AC
BCTRLS_UP, BCTRLS_DOWN, BCTRLS_LEFT, BCTRLS_RIGHT,
BCTRLS_PS0,BCTRLS_PS1,BCTRLS_PS2,BCTRLS_PS3,BCTRLS_PS4,BCTRLS_PS5,BCTRLS_PS6,BCTRLS_PS7,BCTRLS_PS8,BCTRLS_PS9,
KNOB_LEFT, KNOB_RIGHT, KNOB_PUSH,
ACTRLS_REMAP, ACTRLS_SLEEP, ACTRLS_MAX
ACTRLS_SLEEP,
ACTRLS_REMAP, ACTRLS_MAX
} actrls_action_e;

typedef void (*actrls_handler)(bool pressed);
Expand Down
12 changes: 12 additions & 0 deletions components/services/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "led.h"
#include "globdefs.h"
#include "accessors.h"
#include "services.h"

#define MAX_LED 8
#define BLOCKTIME 10 // up to portMAX_DELAY
Expand Down Expand Up @@ -276,6 +277,14 @@ bool led_config(int idx, gpio_num_t gpio, int color, int bright, led_type_t type
return true;
}

/****************************************************************************************
*
*/
static void led_suspend(void) {
led_off(LED_GREEN);
led_off(LED_RED);
}

/****************************************************************************************
*
*/
Expand Down Expand Up @@ -326,6 +335,9 @@ void led_svc_init(void) {

led_config(LED_GREEN, green.gpio, green.color, green.bright, green.type);
led_config(LED_RED, red.gpio, red.color, red.bright, red.type);

// make sure we switch off all leds (useful for gpio expanders)
services_sleep_setsuspend(led_suspend);

ESP_LOGI(TAG,"Configuring LEDs green:%d (on:%d rmt:%d %d%% ), red:%d (on:%d rmt:%d %d%% )",
green.gpio, green.color, green.type, green.bright,
Expand Down
2 changes: 1 addition & 1 deletion components/squeezelite/controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void sendBUTN(int code, bool pressed) {
pkt_header.jiffies = htonl(gettime_ms());
pkt_header.button = htonl(code + (pressed ? DOWN_OFS : UP_OFS));

LOG_INFO("sending BUTN code %04x %s", code, pressed ? "down" : "up");
LOG_DEBUG("sending BUTN code %04x %s", code, pressed ? "down" : "up");

LOCK_P;
send_packet((uint8_t *) &pkt_header, sizeof(pkt_header));
Expand Down

0 comments on commit 66b88d1

Please sign in to comment.