send button event to ESP Insights
Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
@@ -11,7 +11,7 @@ void analytics_init(void)
|
|||||||
.log_type = ESP_DIAG_LOG_TYPE_ERROR | ESP_DIAG_LOG_TYPE_EVENT | ESP_DIAG_LOG_TYPE_WARNING,
|
.log_type = ESP_DIAG_LOG_TYPE_ERROR | ESP_DIAG_LOG_TYPE_EVENT | ESP_DIAG_LOG_TYPE_WARNING,
|
||||||
.node_id = NULL,
|
.node_id = NULL,
|
||||||
.auth_key = insights_auth_key_start,
|
.auth_key = insights_auth_key_start,
|
||||||
.alloc_ext_ram = false,
|
.alloc_ext_ram = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
esp_insights_init(&config);
|
esp_insights_init(&config);
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ LightMenu::LightMenu(menu_options_t *options) : Menu(options), m_options(options
|
|||||||
variants.emplace_back("1");
|
variants.emplace_back("1");
|
||||||
variants.emplace_back("2");
|
variants.emplace_back("2");
|
||||||
variants.emplace_back("3");
|
variants.emplace_back("3");
|
||||||
int variant_value = 2;
|
int variant_value = 3;
|
||||||
if (m_options && m_options->persistenceManager)
|
if (m_options && m_options->persistenceManager)
|
||||||
{
|
{
|
||||||
variant_value = m_options->persistenceManager->GetValue(LightMenuOptions::LIGHT_VARIANT, variant_value);
|
variant_value = m_options->persistenceManager->GetValue(LightMenuOptions::LIGHT_VARIANT, variant_value) - 1;
|
||||||
}
|
}
|
||||||
addSelection(LightMenuItem::VARIANT, "Variante", variants, variant_value);
|
addSelection(LightMenuItem::VARIANT, "Variante", variants, variant_value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,12 @@
|
|||||||
static const char *TAG = "button_handling";
|
static const char *TAG = "button_handling";
|
||||||
|
|
||||||
const uint8_t gpios[] = {BUTTON_DOWN, BUTTON_UP, BUTTON_LEFT, BUTTON_RIGHT, BUTTON_SELECT, BUTTON_BACK};
|
const uint8_t gpios[] = {BUTTON_DOWN, BUTTON_UP, BUTTON_LEFT, BUTTON_RIGHT, BUTTON_SELECT, BUTTON_BACK};
|
||||||
|
static const char *button_names[] = {"DOWN", "UP", "LEFT", "RIGHT", "SELECT", "BACK"};
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t gpio;
|
uint8_t gpio;
|
||||||
|
uint8_t index;
|
||||||
} button_user_data_t;
|
} button_user_data_t;
|
||||||
|
|
||||||
static button_user_data_t button_data[6];
|
static button_user_data_t button_data[6];
|
||||||
@@ -35,8 +37,9 @@ static void button_event_cb(void *arg, void *usr_data)
|
|||||||
}
|
}
|
||||||
button_user_data_t *data = (button_user_data_t *)usr_data;
|
button_user_data_t *data = (button_user_data_t *)usr_data;
|
||||||
uint8_t gpio_num = data->gpio;
|
uint8_t gpio_num = data->gpio;
|
||||||
|
const char *button_name = button_names[data->index];
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Button pressed on GPIO %d", gpio_num);
|
ESP_DIAG_EVENT(TAG, "Button %s pressed (GPIO %d)", button_name, gpio_num);
|
||||||
|
|
||||||
if (xQueueSend(buttonQueue, &gpio_num, 0) != pdTRUE)
|
if (xQueueSend(buttonQueue, &gpio_num, 0) != pdTRUE)
|
||||||
{
|
{
|
||||||
@@ -60,6 +63,7 @@ static void init_button(uint8_t gpio, int index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
button_data[index].gpio = gpio;
|
button_data[index].gpio = gpio;
|
||||||
|
button_data[index].index = index;
|
||||||
iot_button_register_cb(gpio_btn, BUTTON_SINGLE_CLICK, NULL, button_event_cb, &button_data[index]);
|
iot_button_register_cb(gpio_btn, BUTTON_SINGLE_CLICK, NULL, button_event_cb, &button_data[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user