Skip to content

Commit

Permalink
Partial implementation of hidraw commands added, to continue work on …
Browse files Browse the repository at this point in the history
…other branch
  • Loading branch information
mame82 committed Sep 2, 2019
1 parent 2901add commit 5109d26
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

companion.py
CMakeLists.txt
.idea
mdk/blank/armgcc/_build
Expand Down
41 changes: 40 additions & 1 deletion logitacker/logitacker_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#define NRF_LOG_MODULE_NAME LOGITACKER_USB
#include "nrf_log.h"
#include "logitacker_script_engine.h"


NRF_LOG_MODULE_REGISTER();
Expand All @@ -22,7 +23,7 @@ static void usbd_device_event_handler(app_usbd_event_type_t event);
static void usbd_hid_generic_event_handler(app_usbd_class_inst_t const *p_inst, app_usbd_hid_user_event_t event);
static void usbd_hid_keyboard_event_handler(app_usbd_class_inst_t const * p_inst, app_usbd_hid_user_event_t event);
static void usbd_hid_mouse_event_handler(app_usbd_class_inst_t const * p_inst, app_usbd_hid_user_event_t event);

uint32_t logitacker_usb_read_hidraw_output_report();

// created HID report descriptor with vendor define output / input report of max size in raw_desc
APP_USBD_HID_GENERIC_SUBCLASS_REPORT_DESC(raw_desc,APP_USBD_HID_RAW_REPORT_DSC_SIZE(LOGITACKER_USB_HID_GENERIC_OUT_REPORT_MAXSIZE));
Expand Down Expand Up @@ -151,6 +152,8 @@ static void usbd_hid_generic_event_handler(app_usbd_class_inst_t const *p_inst,
{
case APP_USBD_HID_USER_EVT_OUT_REPORT_READY:
{
logitacker_usb_read_hidraw_output_report();
/*
NRF_LOG_INFO("hid generic raw evt: APP_USBD_HID_USER_EVT_OUT_REPORT_READY");
size_t out_rep_size = LOGITACKER_USB_HID_GENERIC_OUT_REPORT_MAXSIZE;
const uint8_t* out_rep = app_usbd_hid_generic_out_report_get(&m_app_hid_generic, &out_rep_size);
Expand All @@ -159,6 +162,7 @@ static void usbd_hid_generic_event_handler(app_usbd_class_inst_t const *p_inst,
// memcpy(&hid_out_report, out_rep, LOGITACKER_USB_HID_GENERIC_OUT_REPORT_MAXSIZE);
// processing_hid_out_report = true;
*/
break;
}
case APP_USBD_HID_USER_EVT_IN_REPORT_DONE:
Expand Down Expand Up @@ -343,6 +347,41 @@ uint32_t logitacker_usb_write_mouse_input_report(const void * p_buf) {
return app_usbd_hid_generic_in_report_set(&m_app_hid_mouse, m_mouse_hid_input_report, LOGITACKER_USB_HID_MOUSE_IN_REPORT_MAXSIZE);
}

uint32_t logitacker_usb_read_hidraw_output_report() {
size_t len = LOGITACKER_USB_HID_GENERIC_OUT_REPORT_MAXSIZE;
const uint8_t * p_report = app_usbd_hid_generic_out_report_get(&m_app_hid_generic, &len);

NRF_LOG_HEXDUMP_INFO(p_report, len)
logitacker_usb_hidraw_report_type_t type = p_report[1];
loigtacker_usb_hidraw_command_t command = p_report[2];

NRF_LOG_INFO("type: %02x, command: %02x\n", type, command);

switch (type) {
case LOGITACKER_USB_HIDRAW_REPORT_TYPE_COMMAND:
{
switch (command) {
case LOGITACKER_USB_HIDRAW_COMMAND_SCRIPT_STRING:
{
size_t slen = p_report[3];
char buf[61] = {0};
if (slen > 60) slen = 60;
memcpy(buf,&p_report[4],slen);
logitacker_script_engine_append_task_type_string(buf);
}
break;
default:
NRF_LOG_WARNING("Unhandled raw report command %02x\n", type)
}
}
break;
default:
NRF_LOG_WARNING("Unhandled raw report type %02x\n", type)
}

return NRF_SUCCESS;
}

uint32_t logitacker_usb_write_hidraw_input_report(logitacker_mode_t logitacker_mode, logitacker_usb_hidraw_report_type_t type, size_t length, const void * data) {

//prepare data
Expand Down
9 changes: 9 additions & 0 deletions logitacker/logitacker_usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

typedef enum {
LOGITACKER_USB_HIDRAW_REPORT_TYPE_RF_FRAME = 0x01,
LOGITACKER_USB_HIDRAW_REPORT_TYPE_COMMAND = 0x02,
} logitacker_usb_hidraw_report_type_t;

typedef struct {
Expand All @@ -39,6 +40,14 @@ typedef struct {

} logitacker_usb_hidraw_rf_frame_representation_t;

typedef enum {
LOGITACKER_USB_HIDRAW_COMMAND_SCRIPT_STRING = 0x10,
LOGITACKER_USB_HIDRAW_COMMAND_SCRIPT_ALTSTRING = 0x11,
LOGITACKER_USB_HIDRAW_COMMAND_SCRIPT_PRESS = 0x12,
LOGITACKER_USB_HIDRAW_COMMAND_SCRIPT_DELAY = 0x13,
LOGITACKER_USB_HIDRAW_COMMAND_SCRIPT_CLEAR = 0x14,
} loigtacker_usb_hidraw_command_t;

/*
// custom commands
Expand Down

0 comments on commit 5109d26

Please sign in to comment.