Skip to content
Snippets Groups Projects
Commit 9b256c80 authored by schneider's avatar schneider
Browse files

feat(ble): Basic HID support for pycardium

parent b9311d11
No related branches found
No related tags found
1 merge request!382HID over BLE
import hid
import buttons
BUTTON_VOLUME_UP = 1
BUTTON_VOLUME_DOWN = 2
BUTTON_PLAY = 8
b_old = buttons.read()
while True:
b_new = buttons.read()
if not b_old == b_new:
print(b_new)
b_old = b_new
if b_new == buttons.TOP_RIGHT:
hid.set_button(BUTTON_PLAY)
elif b_new == buttons.BOTTOM_RIGHT:
hid.set_button(BUTTON_VOLUME_UP)
elif b_new == buttons.BOTTOM_LEFT:
hid.set_button(BUTTON_VOLUME_DOWN)
else:
hid.set_button(0)
......@@ -7,6 +7,7 @@ modsrc = files(
'modules/fat_file.c',
'modules/fat_reader_import.c',
'modules/gpio.c',
'modules/hid.c',
'modules/interrupt.c',
'modules/light_sensor.c',
'modules/max30001-sys.c',
......
#include "epicardium.h"
#include "py/builtin.h"
#include "py/obj.h"
#include "py/runtime.h"
static mp_obj_t mp_hid_set_button(mp_obj_t button_id)
{
int id = mp_obj_get_int(button_id);
epic_hid_remote_report_event(id);
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_1(hid_set_button_obj, mp_hid_set_button);
static const mp_rom_map_elem_t hid_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hid) },
{ MP_ROM_QSTR(MP_QSTR_set_button), MP_ROM_PTR(&hid_set_button_obj) },
};
static MP_DEFINE_CONST_DICT(hid_module_globals, hid_module_globals_table);
const mp_obj_module_t hid_module = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&hid_module_globals,
};
/* clang-format off */
MP_REGISTER_MODULE(MP_QSTR_hid, hid_module, MODULE_HID_ENABLED);
......@@ -211,6 +211,8 @@ Q(EVENT_HANDLE_NUMERIC_COMPARISON)
Q(EVENT_PAIRING_COMPLETE)
Q(EVENT_PAIRING_FAILED)
Q(EVENT_SCAN_REPORT)
Q(hid)
Q(set_button)
/* SpO2 */
Q(spo2_algo)
......
......@@ -61,6 +61,7 @@ int mp_hal_csprng_read_int(void);
#define MODULE_BUTTONS_ENABLED (1)
#define MODULE_DISPLAY_ENABLED (1)
#define MODULE_GPIO_ENABLED (1)
#define MODULE_HID_ENABLED (1)
#define MODULE_INTERRUPT_ENABLED (1)
#define MODULE_LEDS_ENABLED (1)
#define MODULE_LIGHT_SENSOR_ENABLED (1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment