HID Rotate report can be turned off

This commit is contained in:
whowechina
2025-11-22 14:43:18 +08:00
parent 9e5bffcaa2
commit e3d60f830e
5 changed files with 36 additions and 7 deletions
Binary file not shown.
+21
View File
@@ -49,6 +49,7 @@ static void disp_hid()
{
printf("[HID]\n");
printf(" Rotate: %d degree\n", (ju_cfg->hid.rotate % 4) * 90);
printf(" Report Rotate: %s\n", ju_cfg->hid.report_rotate ? "on" : "off");
}
#define ARRAYSIZE(x) (sizeof(x) / sizeof(x[0]))
@@ -129,6 +130,25 @@ static void handle_rotate(int argc, char *argv[])
config_changed();
}
static void handle_report_rotate(int argc, char *argv[])
{
const char *usage = "Usage: report_rotate <on|off>\n";
if (argc != 1) {
printf(usage);
return;
}
const char *choicses[] = {"on", "off"};
int axis = cli_match_prefix(choicses, ARRAYSIZE(choicses), argv[0]);
if (axis < 0) {
printf(usage);
return;
}
ju_cfg->hid.report_rotate = (axis == 0);
config_changed();
}
static void handle_stat(int argc, char *argv[])
{
printf("[STAT]\n");
@@ -148,6 +168,7 @@ void commands_init()
cli_register("display", handle_display, "Display all config.");
cli_register("level", handle_level, "Set LED brightness level.");
cli_register("rotate", handle_rotate, "Set button rotate angle.");
cli_register("report_rotate", handle_report_rotate, "Set rotate report on axis.");
cli_register("stat", handle_stat, "Display statistics.");
cli_register("save", handle_save, "Save config to flash.");
cli_register("factory", config_factory_reset, "Reset everything to default.");
+1
View File
@@ -25,6 +25,7 @@ static ju_cfg_t default_cfg = {
},
.hid = {
.rotate = 0,
.report_rotate = true,
},
};
+1
View File
@@ -25,6 +25,7 @@ typedef struct __attribute__((packed)) {
} sense;
struct {
uint8_t rotate;
bool report_rotate;
} hid;
uint8_t reserved[8];
} ju_cfg_t;
+13 -7
View File
@@ -46,14 +46,20 @@ static void report_usb_hid()
hid_report.buttons = do_rotate(button_read() & 0xffff);
hid_report.aux = button_read() >> 16;
const struct {
uint8_t x;
uint8_t y;
} dirs[] = { {0, 127}, {127, 0}, {255, 127}, {127, 255}};
if (ju_cfg->hid.report_rotate) {
const struct {
uint8_t x;
uint8_t y;
} dirs[] = { {0, 127}, {127, 0}, {255, 127}, {127, 255}};
uint8_t rotate = ju_cfg->hid.rotate % 4;
hid_report.axis[0] = dirs[rotate].x;
hid_report.axis[1] = dirs[rotate].y;
uint8_t rotate = ju_cfg->hid.rotate % 4;
hid_report.axis[0] = dirs[rotate].x;
hid_report.axis[1] = dirs[rotate].y;
}
else {
hid_report.axis[0] = 127;
hid_report.axis[1] = 127;
}
uint64_t now = time_us_64();
if ((memcmp(&hid_reported, &hid_report, sizeof(hid_report)) != 0) ||