Skip to content

Commit 7483069

Browse files
LordMZTEhedger
andauthored
hid_app mouse clicker: make mouse button selectable (#4270)
* hid_app mouse clicker: make mouse button selectable * hid_app: fixed uninit var warning --------- Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: hedger <hedger@nanode.su>
1 parent 7554b32 commit 7483069

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

applications/system/hid_app/views/hid_mouse_clicker.c

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ typedef struct {
1919
bool connected;
2020
bool running;
2121
int rate;
22+
enum HidMouseButtons btn;
2223
} HidMouseClickerModel;
2324

2425
static void hid_mouse_clicker_start_or_restart_timer(void* context) {
@@ -61,6 +62,26 @@ static void hid_mouse_clicker_draw_callback(Canvas* canvas, void* context) {
6162
// Ok
6263
canvas_draw_icon(canvas, 58, 25, &I_Space_65x18);
6364

65+
canvas_draw_icon(canvas, 61, 50, &I_ButtonLeft_4x7);
66+
canvas_draw_icon(canvas, 117, 50, &I_ButtonRight_4x7);
67+
68+
const char* btn_label;
69+
switch(model->btn) {
70+
case HID_MOUSE_BTN_LEFT:
71+
btn_label = "Left";
72+
break;
73+
case HID_MOUSE_BTN_WHEEL:
74+
btn_label = "Middle";
75+
break;
76+
case HID_MOUSE_BTN_RIGHT:
77+
btn_label = "Right";
78+
break;
79+
default:
80+
furi_crash();
81+
}
82+
83+
elements_multiline_text_aligned(canvas, 89, 57, AlignCenter, AlignBottom, btn_label);
84+
6485
if(model->running) {
6586
elements_slightly_rounded_box(canvas, 61, 27, 60, 13);
6687
canvas_set_color(canvas, ColorWhite);
@@ -100,8 +121,8 @@ static void hid_mouse_clicker_timer_callback(void* context) {
100121
HidMouseClickerModel * model,
101122
{
102123
if(model->running) {
103-
hid_hal_mouse_press(hid_mouse_clicker->hid, HID_MOUSE_BTN_LEFT);
104-
hid_hal_mouse_release(hid_mouse_clicker->hid, HID_MOUSE_BTN_LEFT);
124+
hid_hal_mouse_press(hid_mouse_clicker->hid, model->btn);
125+
hid_hal_mouse_release(hid_mouse_clicker->hid, model->btn);
105126
}
106127
},
107128
false);
@@ -154,6 +175,34 @@ static bool hid_mouse_clicker_input_callback(InputEvent* event, void* context) {
154175
case InputKeyBack:
155176
model->running = false;
156177
break;
178+
case InputKeyLeft:
179+
switch(model->btn) {
180+
case HID_MOUSE_BTN_LEFT:
181+
model->btn = HID_MOUSE_BTN_RIGHT;
182+
break;
183+
case HID_MOUSE_BTN_WHEEL:
184+
model->btn = HID_MOUSE_BTN_LEFT;
185+
break;
186+
case HID_MOUSE_BTN_RIGHT:
187+
model->btn = HID_MOUSE_BTN_WHEEL;
188+
break;
189+
}
190+
consumed = true;
191+
break;
192+
case InputKeyRight:
193+
switch(model->btn) {
194+
case HID_MOUSE_BTN_LEFT:
195+
model->btn = HID_MOUSE_BTN_WHEEL;
196+
break;
197+
case HID_MOUSE_BTN_WHEEL:
198+
model->btn = HID_MOUSE_BTN_RIGHT;
199+
break;
200+
case HID_MOUSE_BTN_RIGHT:
201+
model->btn = HID_MOUSE_BTN_LEFT;
202+
break;
203+
}
204+
consumed = true;
205+
break;
157206
default:
158207
consumed = true;
159208
break;
@@ -188,7 +237,10 @@ HidMouseClicker* hid_mouse_clicker_alloc(Hid* hid) {
188237
with_view_model(
189238
hid_mouse_clicker->view,
190239
HidMouseClickerModel * model,
191-
{ model->rate = DEFAULT_CLICK_RATE; },
240+
{
241+
model->rate = DEFAULT_CLICK_RATE;
242+
model->btn = HID_MOUSE_BTN_LEFT;
243+
},
192244
true);
193245

194246
return hid_mouse_clicker;

0 commit comments

Comments
 (0)