123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include "mcc_generated_files/mcc.h"
- #include "serial.h"
- #include "rn4870/rn4870.h"
- #include "rn4870/hid_defs.h"
- #include <stdlib.h>
- static char cmd[48];
- static int idx;
- static void process_command(void) {
- if (!strncmp(cmd, "ble command mode", 16)) {
- serial_println("Trying to enter BLE command mode ...");
- rn4870_enter_command_mode();
- } else if (!strncmp(cmd, "ble list services", 17)) {
- serial_println("Retrieving a list of defined BLE services and their characteristics ...");
- rn4870_list_services();
- } else if (!strncmp(cmd, "ble reset services", 18)) {
- serial_println("Resetting defined BLE services ...");
- rn4870_reset_services();
- } else if (!strncmp(cmd, "ble add battery service", 23)) {
- serial_print("Trying to add service ...");
- rn4870_add_battery_service();
- } else if (!strncmp(cmd, "set battery level", 17)) {
- const char *p = cmd + 18;
- if (!p) {
- serial_print("You must specify the level!");
- return;
- }
- serial_print("Trying to set battery level to ");
- serial_println(p);
- uint8_t level = atoi(p);
- rn4870_set_battery_level(level);
- } else if (!strncmp(cmd, "ble add info service", 20)) {
- serial_println("Trying to add device info service ...");
- rn4870_add_device_info_service();
- } else if (!strncmp(cmd, "ble add hid service", 19)) {
- serial_println("Trying to add HID service ...");
- rn4870_add_hid_service();
- } else if (!strncmp(cmd, "ble set gap appearance", 22)) {
- const char *code = cmd + 23;
- if (!code) {
- serial_println("You must specify the code.");
- return;
- }
- serial_print("Setting GAP appearance to 0x");
- serial_println(code);
- rn4870_set_gap_appearance(code);
- } else if (!strncmp(cmd, "ble init hid", 12)) {
- serial_println("Trying to init HID service ...");
- rn4870_init_hid_param();
- } else if (!strncmp(cmd, "ble read characteristic", 23)) {
- char *handle = cmd + 24;
- serial_print("Trying to read characteristic ");
- serial_println(handle);
- rn4870_read_characteristic(handle);
- } else if (!strncmp(cmd, "mouse left click", 16)) {
- serial_println("Sending left click ...");
- rn4870_hid_mouse_click(MOUSE_LEFT_CLICK);
- } else if (!strncmp(cmd, "mouse right click", 17)) {
- serial_println("Sending right click ...");
- rn4870_hid_mouse_click(MOUSE_RIGHT_CLICK);
- } else {
- serial_print("Did not understand command: ");
- serial_println(cmd);
- }
- }
- static void process_rx_char(char ch) {
- if (ch == '\r') {
- } else if (ch == '\n') {
- cmd[idx] = '\0';
- idx = 0;
- process_command();
- } else {
- cmd[idx++] = ch;
- if (idx >= sizeof (cmd) - 1) idx = 0;
- }
- }
- void console_monitor(void) {
- if (EUSART1_is_rx_ready()) {
- char ch = EUSART1_Read();
- process_rx_char(ch);
- }
- }
|