2022-12-12 09:47:22 +00:00
|
|
|
#include "hid_mouse_jiggler.h"
|
|
|
|
#include <gui/elements.h>
|
2023-01-26 14:31:54 +00:00
|
|
|
#include <m-string.h>
|
2022-12-12 09:47:22 +00:00
|
|
|
#include "../hid.h"
|
|
|
|
|
|
|
|
#include "hid_icons.h"
|
|
|
|
|
|
|
|
#define TAG "HidMouseJiggler"
|
|
|
|
|
2023-01-26 14:31:54 +00:00
|
|
|
#define LENGTH(x) (int)(sizeof(x) / sizeof((x)[0]))
|
|
|
|
|
2022-12-12 09:47:22 +00:00
|
|
|
struct HidMouseJiggler {
|
|
|
|
View* view;
|
|
|
|
Hid* hid;
|
|
|
|
FuriTimer* timer;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
bool connected;
|
|
|
|
bool running;
|
2023-01-26 14:31:54 +00:00
|
|
|
int interval_idx;
|
2022-12-12 09:47:22 +00:00
|
|
|
uint8_t counter;
|
2022-12-27 08:03:56 +00:00
|
|
|
HidTransport transport;
|
2022-12-12 09:47:22 +00:00
|
|
|
} HidMouseJigglerModel;
|
|
|
|
|
2023-01-26 14:31:54 +00:00
|
|
|
const int intervals[6] = {500, 2000, 5000, 10000, 30000, 60000};
|
|
|
|
|
2022-12-12 09:47:22 +00:00
|
|
|
static void hid_mouse_jiggler_draw_callback(Canvas* canvas, void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
HidMouseJigglerModel* model = context;
|
|
|
|
|
|
|
|
// Header
|
2022-12-27 08:03:56 +00:00
|
|
|
if(model->transport == HidTransportBle) {
|
|
|
|
if(model->connected) {
|
|
|
|
canvas_draw_icon(canvas, 0, 0, &I_Ble_connected_15x15);
|
|
|
|
} else {
|
|
|
|
canvas_draw_icon(canvas, 0, 0, &I_Ble_disconnected_15x15);
|
|
|
|
}
|
2022-12-12 09:47:22 +00:00
|
|
|
}
|
2022-12-27 08:03:56 +00:00
|
|
|
|
2022-12-12 09:47:22 +00:00
|
|
|
canvas_set_font(canvas, FontPrimary);
|
2023-01-26 14:31:54 +00:00
|
|
|
elements_multiline_text_aligned(canvas, 17, 2, AlignLeft, AlignTop, "Mouse Jiggler");
|
|
|
|
|
|
|
|
// Timeout
|
|
|
|
string_t interval_str;
|
|
|
|
string_init(interval_str);
|
|
|
|
string_printf(interval_str, "%d", intervals[model->interval_idx]);
|
|
|
|
elements_multiline_text(canvas, AlignLeft, 26, "Interval (ms):");
|
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
if(model->interval_idx != 0) canvas_draw_icon(canvas, 74, 19, &I_ButtonLeft_4x7);
|
|
|
|
if(model->interval_idx != 5) canvas_draw_icon(canvas, 80, 19, &I_ButtonRight_4x7);
|
|
|
|
elements_multiline_text(canvas, 91, 26, string_get_cstr(interval_str));
|
2022-12-12 09:47:22 +00:00
|
|
|
|
|
|
|
canvas_set_font(canvas, FontPrimary);
|
2023-01-26 14:31:54 +00:00
|
|
|
elements_multiline_text(canvas, AlignLeft, 40, "Press Start\nto jiggle");
|
2022-12-12 09:47:22 +00:00
|
|
|
canvas_set_font(canvas, FontSecondary);
|
|
|
|
|
|
|
|
// Ok
|
2023-01-26 14:31:54 +00:00
|
|
|
canvas_draw_icon(canvas, 63, 30, &I_Space_65x18);
|
2022-12-12 09:47:22 +00:00
|
|
|
if(model->running) {
|
2023-01-26 14:31:54 +00:00
|
|
|
elements_slightly_rounded_box(canvas, 66, 32, 60, 13);
|
2022-12-12 09:47:22 +00:00
|
|
|
canvas_set_color(canvas, ColorWhite);
|
|
|
|
}
|
2023-01-26 14:31:54 +00:00
|
|
|
canvas_draw_icon(canvas, 74, 34, &I_Ok_btn_9x9);
|
2022-12-12 09:47:22 +00:00
|
|
|
if(model->running) {
|
2023-01-26 14:31:54 +00:00
|
|
|
elements_multiline_text_aligned(canvas, 91, 41, AlignLeft, AlignBottom, "Stop");
|
2022-12-12 09:47:22 +00:00
|
|
|
} else {
|
2023-01-26 14:31:54 +00:00
|
|
|
elements_multiline_text_aligned(canvas, 91, 41, AlignLeft, AlignBottom, "Start");
|
2022-12-12 09:47:22 +00:00
|
|
|
}
|
|
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
|
|
|
|
// Back
|
2023-01-26 14:31:54 +00:00
|
|
|
canvas_draw_icon(canvas, 74, 54, &I_Pin_back_arrow_10x8);
|
|
|
|
elements_multiline_text_aligned(canvas, 91, 62, AlignLeft, AlignBottom, "Quit");
|
2022-12-12 09:47:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hid_mouse_jiggler_timer_callback(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
HidMouseJiggler* hid_mouse_jiggler = context;
|
|
|
|
with_view_model(
|
|
|
|
hid_mouse_jiggler->view,
|
|
|
|
HidMouseJigglerModel * model,
|
|
|
|
{
|
|
|
|
if(model->running) {
|
|
|
|
model->counter++;
|
|
|
|
hid_hal_mouse_move(
|
|
|
|
hid_mouse_jiggler->hid,
|
|
|
|
(model->counter % 2 == 0) ? MOUSE_MOVE_SHORT : -MOUSE_MOVE_SHORT,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hid_mouse_jiggler_exit_callback(void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
HidMouseJiggler* hid_mouse_jiggler = context;
|
|
|
|
furi_timer_stop(hid_mouse_jiggler->timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool hid_mouse_jiggler_input_callback(InputEvent* event, void* context) {
|
|
|
|
furi_assert(context);
|
|
|
|
HidMouseJiggler* hid_mouse_jiggler = context;
|
|
|
|
|
|
|
|
bool consumed = false;
|
|
|
|
|
2023-01-26 14:31:54 +00:00
|
|
|
with_view_model(
|
|
|
|
hid_mouse_jiggler->view,
|
|
|
|
HidMouseJigglerModel * model,
|
|
|
|
{
|
|
|
|
if(event->type == InputTypePress && event->key == InputKeyOk) {
|
|
|
|
model->running = !model->running;
|
|
|
|
if(model->running) {
|
|
|
|
furi_timer_stop(hid_mouse_jiggler->timer);
|
|
|
|
furi_timer_start(hid_mouse_jiggler->timer, intervals[model->interval_idx]);
|
|
|
|
};
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
if(event->type == InputTypePress && event->key == InputKeyRight && !model->running &&
|
2023-01-26 14:55:15 +00:00
|
|
|
model->interval_idx < LENGTH(intervals) - 1) {
|
2023-01-26 14:31:54 +00:00
|
|
|
model->interval_idx++;
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
if(event->type == InputTypePress && event->key == InputKeyLeft && !model->running &&
|
|
|
|
model->interval_idx > 0) {
|
|
|
|
model->interval_idx--;
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
true);
|
2022-12-12 09:47:22 +00:00
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
|
|
|
HidMouseJiggler* hid_mouse_jiggler_alloc(Hid* hid) {
|
|
|
|
HidMouseJiggler* hid_mouse_jiggler = malloc(sizeof(HidMouseJiggler));
|
|
|
|
|
|
|
|
hid_mouse_jiggler->view = view_alloc();
|
|
|
|
view_set_context(hid_mouse_jiggler->view, hid_mouse_jiggler);
|
|
|
|
view_allocate_model(
|
|
|
|
hid_mouse_jiggler->view, ViewModelTypeLocking, sizeof(HidMouseJigglerModel));
|
|
|
|
view_set_draw_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_draw_callback);
|
|
|
|
view_set_input_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_input_callback);
|
|
|
|
view_set_exit_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_exit_callback);
|
|
|
|
|
|
|
|
hid_mouse_jiggler->hid = hid;
|
|
|
|
|
|
|
|
hid_mouse_jiggler->timer = furi_timer_alloc(
|
|
|
|
hid_mouse_jiggler_timer_callback, FuriTimerTypePeriodic, hid_mouse_jiggler);
|
|
|
|
|
2022-12-27 08:03:56 +00:00
|
|
|
with_view_model(
|
|
|
|
hid_mouse_jiggler->view,
|
|
|
|
HidMouseJigglerModel * model,
|
2023-01-26 14:31:54 +00:00
|
|
|
{
|
|
|
|
model->transport = hid->transport;
|
|
|
|
model->interval_idx = 2;
|
|
|
|
},
|
2022-12-27 08:03:56 +00:00
|
|
|
true);
|
|
|
|
|
2022-12-12 09:47:22 +00:00
|
|
|
return hid_mouse_jiggler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hid_mouse_jiggler_free(HidMouseJiggler* hid_mouse_jiggler) {
|
|
|
|
furi_assert(hid_mouse_jiggler);
|
|
|
|
|
|
|
|
furi_timer_stop(hid_mouse_jiggler->timer);
|
|
|
|
furi_timer_free(hid_mouse_jiggler->timer);
|
|
|
|
|
|
|
|
view_free(hid_mouse_jiggler->view);
|
|
|
|
|
|
|
|
free(hid_mouse_jiggler);
|
|
|
|
}
|
|
|
|
|
|
|
|
View* hid_mouse_jiggler_get_view(HidMouseJiggler* hid_mouse_jiggler) {
|
|
|
|
furi_assert(hid_mouse_jiggler);
|
|
|
|
return hid_mouse_jiggler->view;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hid_mouse_jiggler_set_connected_status(HidMouseJiggler* hid_mouse_jiggler, bool connected) {
|
|
|
|
furi_assert(hid_mouse_jiggler);
|
|
|
|
with_view_model(
|
|
|
|
hid_mouse_jiggler->view,
|
|
|
|
HidMouseJigglerModel * model,
|
|
|
|
{ model->connected = connected; },
|
|
|
|
true);
|
|
|
|
}
|