-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afa2068
commit d45816b
Showing
16 changed files
with
483 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
#include "apps/ble/hid_device/hid_module.h" | ||
#include "apps/ble/hid_device/hid_screens.h" | ||
#include "ble_hidd_demo_main.h" | ||
#include "esp_log.h" | ||
#include "menu_screens_modules.h" | ||
|
||
static uint16_t current_item = 0; | ||
|
||
static void hid_module_cb_event(uint8_t button_name, uint8_t button_event); | ||
static void hid_module_cb_event_volumen(uint8_t button_name, | ||
uint8_t button_event); | ||
static void hid_module_cb_connection_handler(bool connection); | ||
|
||
static void hid_module_increment_item() { | ||
current_item++; | ||
} | ||
|
||
static void hid_module_decrement_item() { | ||
current_item--; | ||
} | ||
|
||
static void hid_module_cb_connection_handler(bool connection) { | ||
hid_module_display_device_connection(connection); | ||
if (!connection) { | ||
esp_restart(); | ||
} | ||
} | ||
|
||
static void hid_module_cb_event_volumen(uint8_t button_name, | ||
uint8_t button_event) { | ||
if (button_event != BUTTON_PRESS_DOWN) { | ||
return; | ||
} | ||
switch (button_name) { | ||
case BUTTON_UP: | ||
hid_module_decrement_item(); | ||
if (current_item < 0) { | ||
current_item = HID_DEVICE_COUNT - 1; | ||
} | ||
hid_module_display_menu(current_item); | ||
break; | ||
case BUTTON_DOWN: | ||
hid_module_increment_item(); | ||
if (current_item > HID_DEVICE_COUNT - 1) { | ||
current_item = 0; | ||
} | ||
hid_module_display_menu(current_item); | ||
break; | ||
case BUTTON_LEFT: | ||
current_item = 0; | ||
hid_module_register_menu(HID_TREE_MENU); | ||
hid_module_display_menu(current_item); | ||
menu_screens_set_app_state(true, hid_module_cb_event); | ||
break; | ||
case BUTTON_RIGHT: | ||
if (current_item == HID_DEVICE_VOL_UP) { | ||
ble_hid_volume_up(true); | ||
ble_hid_volume_up(false); | ||
hid_module_display_notify_volumen_up(); | ||
} else if (current_item == HID_DEVICE_VOL_DOWN) { | ||
ble_hid_volume_down(true); | ||
ble_hid_volume_down(false); | ||
hid_module_display_notify_volumen_down(); | ||
} else if (current_item == HID_DEVICE_PLAY) { | ||
ble_hid_play(true); | ||
ble_hid_play(false); | ||
hid_module_display_notify_play_pause(); | ||
} | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
static void hid_module_cb_event(uint8_t button_name, uint8_t button_event) { | ||
if (button_event != BUTTON_PRESS_DOWN) { | ||
return; | ||
} | ||
switch (button_name) { | ||
case BUTTON_UP: | ||
hid_module_decrement_item(); | ||
if (current_item < 0) { | ||
current_item = HID_MENU_COUNT - 1; | ||
} | ||
hid_module_display_menu(current_item); | ||
break; | ||
case BUTTON_DOWN: | ||
hid_module_increment_item(); | ||
if (current_item > HID_MENU_COUNT - 1) { | ||
current_item = 0; | ||
} | ||
hid_module_display_menu(current_item); | ||
break; | ||
case BUTTON_RIGHT: | ||
if (current_item == HID_CONFIG_NAME) { | ||
current_item = 0; | ||
hid_module_display_device_name(); | ||
} else if (current_item == HID_CONFIG_MAC) { | ||
current_item = 0; | ||
hid_module_display_device_mac(); | ||
} else if (current_item == HID_CONFIG_START) { | ||
current_item = 0; | ||
hid_module_register_menu(HID_TREE_DEVICE); | ||
hid_module_display_device_pairing(); | ||
ble_hid_register_callback(hid_module_cb_connection_handler); | ||
ble_hid_begin(); | ||
menu_screens_set_app_state(true, hid_module_cb_event_volumen); | ||
} | ||
break; | ||
case BUTTON_LEFT: | ||
current_item = 0; | ||
hid_module_register_menu(HID_TREE_MENU); | ||
hid_module_display_menu(current_item); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
void hid_module_begin() { | ||
hid_module_register_menu(HID_TREE_MENU); | ||
hid_module_display_menu(current_item); | ||
menu_screens_set_app_state(true, hid_module_cb_event); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <stdint.h> | ||
#ifndef HID_MODULE_H | ||
#define HID_MODULE_H | ||
void hid_module_begin(); | ||
#endif // HID_MODULE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#include "hid_screens.h" | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include "animations_task.h" | ||
#include "freertos/FreeRTOS.h" | ||
#include "general/bitmaps_general.h" | ||
#include "general/general_screens.h" | ||
#include "led_events.h" | ||
#include "oled_screen.h" | ||
|
||
static uint16_t hid_current_item = 0; | ||
|
||
static const general_menu_t hid_menu = { | ||
.menu_items = hid_menu_items, | ||
.menu_count = HID_MENU_COUNT, | ||
.menu_level = GENERAL_MENU_MAIN, | ||
}; | ||
|
||
static const general_menu_t hid_device_menu = { | ||
.menu_items = hid_device_items, | ||
.menu_count = HID_DEVICE_COUNT, | ||
.menu_level = GENERAL_MENU_SUBMENU, | ||
}; | ||
|
||
void hid_module_register_menu(hid_menu_t menu) { | ||
switch (menu) { | ||
case HID_TREE_MENU: | ||
general_register_menu(&hid_menu); | ||
break; | ||
case HID_TREE_DEVICE: | ||
general_register_menu(&hid_device_menu); | ||
break; | ||
default: | ||
general_register_menu(&hid_menu); | ||
break; | ||
} | ||
} | ||
|
||
void hid_module_display_notify_volumen_up() { | ||
led_control_run_effect(led_control_pulse_led_right); | ||
genera_screen_display_notify_information("Notify", "Volumen Up"); | ||
vTaskDelay(500 / portTICK_PERIOD_MS); | ||
general_screen_display_menu(hid_current_item); | ||
} | ||
|
||
void hid_module_display_notify_volumen_down() { | ||
led_control_run_effect(led_control_pulse_led_left); | ||
genera_screen_display_notify_information("Notify", "Volumen Down"); | ||
vTaskDelay(500 / portTICK_PERIOD_MS); | ||
general_screen_display_menu(hid_current_item); | ||
} | ||
|
||
void hid_module_display_notify_play_pause() { | ||
led_control_run_effect(led_control_ble_tracking); | ||
genera_screen_display_notify_information("Notify", "Play/Pause"); | ||
vTaskDelay(500 / portTICK_PERIOD_MS); | ||
general_screen_display_menu(hid_current_item); | ||
} | ||
|
||
void hid_module_display_device_pairing() { | ||
led_control_run_effect(led_control_ble_spam_breathing); | ||
genera_screen_display_notify_information("Pairing", "Waiting for connection"); | ||
} | ||
|
||
void hid_module_display_device_connection(bool status) { | ||
led_control_stop(); | ||
if (status) { | ||
genera_screen_display_notify_information("Notify", "Connected"); | ||
} else { | ||
general_register_menu(&hid_menu); | ||
genera_screen_display_notify_information("Notify", "Disconnected"); | ||
} | ||
vTaskDelay(1000 / portTICK_PERIOD_MS); | ||
hid_current_item = 0; | ||
general_screen_display_menu(hid_current_item); | ||
} | ||
|
||
void hid_module_display_device_name() { | ||
led_control_run_effect(led_control_pulse_leds); | ||
genera_screen_display_card_information("HID Device", "HIDNAME"); | ||
} | ||
void hid_module_display_device_mac() { | ||
led_control_run_effect(led_control_pulse_leds); | ||
genera_screen_display_card_information("HID Device", "MACADDD"); | ||
} | ||
|
||
void hid_module_display_menu(uint16_t current_item) { | ||
led_control_run_effect(led_control_pulse_leds); | ||
hid_current_item = current_item; | ||
general_screen_display_menu(current_item); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <stdbool.h> | ||
#include <stdint.h> | ||
#ifndef HID_SCREENS_H | ||
#define HID_SCREENS_H | ||
|
||
typedef enum { HID_TREE_MENU, HID_TREE_DEVICE, HID_TREE_COUNT } hid_menu_t; | ||
|
||
enum { | ||
HID_CONFIG_NAME, | ||
HID_CONFIG_MAC, | ||
HID_CONFIG_START, | ||
HID_MENU_COUNT | ||
} hid_menu_item = HID_CONFIG_NAME; | ||
const char* hid_menu_items[HID_MENU_COUNT] = {"Device name", "Device MAC", | ||
"Start"}; | ||
|
||
enum { | ||
HID_DEVICE_VOL_UP, | ||
HID_DEVICE_VOL_DOWN, | ||
HID_DEVICE_PLAY, | ||
HID_DEVICE_COUNT | ||
} hid_device_item = HID_DEVICE_VOL_UP; | ||
const char* hid_device_items[HID_DEVICE_COUNT] = { | ||
"Volumen Up", | ||
"Volumen Down", | ||
"Play/Pause", | ||
}; | ||
|
||
void hid_module_register_menu(hid_menu_t menu); | ||
void hid_clear_screen(); | ||
void hid_module_display_menu(uint16_t current_item); | ||
void hid_module_display_device_name(); | ||
void hid_module_display_device_mac(); | ||
void hid_module_display_notify_volumen_up(); | ||
void hid_module_display_notify_volumen_down(); | ||
void hid_module_display_notify_play_pause(); | ||
void hid_module_display_device_connection(bool status); | ||
void hid_module_display_device_pairing(); | ||
#endif // HID_SCREENS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.