mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-24 05:48:08 +03:00
Merge pull request #303 from DocKuro/mouse_jiggler_interval_selction_added
Added movement interval in mouse_jiggler USB & BLE
This commit is contained in:
commit
a0d5aa0c7b
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#define TAG "HidMouseJiggler"
|
#define TAG "HidMouseJiggler"
|
||||||
|
|
||||||
|
#define LENGTH(x) (int)(sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
struct HidMouseJiggler {
|
struct HidMouseJiggler {
|
||||||
View* view;
|
View* view;
|
||||||
Hid* hid;
|
Hid* hid;
|
||||||
@ -15,10 +17,13 @@ struct HidMouseJiggler {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
bool connected;
|
bool connected;
|
||||||
bool running;
|
bool running;
|
||||||
|
int interval_idx;
|
||||||
uint8_t counter;
|
uint8_t counter;
|
||||||
HidTransport transport;
|
HidTransport transport;
|
||||||
} HidMouseJigglerModel;
|
} HidMouseJigglerModel;
|
||||||
|
|
||||||
|
const int intervals[6] = {500, 2000, 5000, 10000, 30000, 60000};
|
||||||
|
|
||||||
static void hid_mouse_jiggler_draw_callback(Canvas* canvas, void* context) {
|
static void hid_mouse_jiggler_draw_callback(Canvas* canvas, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
HidMouseJigglerModel* model = context;
|
HidMouseJigglerModel* model = context;
|
||||||
@ -33,29 +38,39 @@ static void hid_mouse_jiggler_draw_callback(Canvas* canvas, void* context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "Mouse Jiggler");
|
elements_multiline_text_aligned(canvas, 17, 2, AlignLeft, AlignTop, "Mouse Jiggler");
|
||||||
|
|
||||||
|
// Timeout
|
||||||
|
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 != LENGTH(intervals) - 1)
|
||||||
|
canvas_draw_icon(canvas, 80, 19, &I_ButtonRight_4x7);
|
||||||
|
FuriString* interval_str = furi_string_alloc_printf("%d", intervals[model->interval_idx]);
|
||||||
|
elements_multiline_text(canvas, 91, 26, furi_furi_string_get_cstr(interval_str));
|
||||||
|
furi_string_free(interval_str);
|
||||||
|
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
elements_multiline_text(canvas, AlignLeft, 35, "Press Start\nto jiggle");
|
elements_multiline_text(canvas, AlignLeft, 40, "Press Start\nto jiggle");
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
|
||||||
// Ok
|
// Ok
|
||||||
canvas_draw_icon(canvas, 63, 25, &I_Space_65x18);
|
canvas_draw_icon(canvas, 63, 30, &I_Space_65x18);
|
||||||
if(model->running) {
|
if(model->running) {
|
||||||
elements_slightly_rounded_box(canvas, 66, 27, 60, 13);
|
elements_slightly_rounded_box(canvas, 66, 32, 60, 13);
|
||||||
canvas_set_color(canvas, ColorWhite);
|
canvas_set_color(canvas, ColorWhite);
|
||||||
}
|
}
|
||||||
canvas_draw_icon(canvas, 74, 29, &I_Ok_btn_9x9);
|
canvas_draw_icon(canvas, 74, 34, &I_Ok_btn_9x9);
|
||||||
if(model->running) {
|
if(model->running) {
|
||||||
elements_multiline_text_aligned(canvas, 91, 36, AlignLeft, AlignBottom, "Stop");
|
elements_multiline_text_aligned(canvas, 91, 41, AlignLeft, AlignBottom, "Stop");
|
||||||
} else {
|
} else {
|
||||||
elements_multiline_text_aligned(canvas, 91, 36, AlignLeft, AlignBottom, "Start");
|
elements_multiline_text_aligned(canvas, 91, 41, AlignLeft, AlignBottom, "Start");
|
||||||
}
|
}
|
||||||
canvas_set_color(canvas, ColorBlack);
|
canvas_set_color(canvas, ColorBlack);
|
||||||
|
|
||||||
// Back
|
// Back
|
||||||
canvas_draw_icon(canvas, 74, 49, &I_Pin_back_arrow_10x8);
|
canvas_draw_icon(canvas, 74, 54, &I_Pin_back_arrow_10x8);
|
||||||
elements_multiline_text_aligned(canvas, 91, 57, AlignLeft, AlignBottom, "Quit");
|
elements_multiline_text_aligned(canvas, 91, 62, AlignLeft, AlignBottom, "Quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hid_mouse_jiggler_timer_callback(void* context) {
|
static void hid_mouse_jiggler_timer_callback(void* context) {
|
||||||
@ -76,13 +91,6 @@ static void hid_mouse_jiggler_timer_callback(void* context) {
|
|||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hid_mouse_jiggler_enter_callback(void* context) {
|
|
||||||
furi_assert(context);
|
|
||||||
HidMouseJiggler* hid_mouse_jiggler = context;
|
|
||||||
|
|
||||||
furi_timer_start(hid_mouse_jiggler->timer, 500);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void hid_mouse_jiggler_exit_callback(void* context) {
|
static void hid_mouse_jiggler_exit_callback(void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
HidMouseJiggler* hid_mouse_jiggler = context;
|
HidMouseJiggler* hid_mouse_jiggler = context;
|
||||||
@ -95,14 +103,30 @@ static bool hid_mouse_jiggler_input_callback(InputEvent* event, void* context) {
|
|||||||
|
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
|
|
||||||
if(event->key == InputKeyOk) {
|
|
||||||
with_view_model(
|
with_view_model(
|
||||||
hid_mouse_jiggler->view,
|
hid_mouse_jiggler->view,
|
||||||
HidMouseJigglerModel * model,
|
HidMouseJigglerModel * model,
|
||||||
{ model->running = !model->running; },
|
{
|
||||||
true);
|
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;
|
consumed = true;
|
||||||
}
|
}
|
||||||
|
if(event->type == InputTypePress && event->key == InputKeyRight && !model->running &&
|
||||||
|
model->interval_idx < LENGTH(intervals) - 1) {
|
||||||
|
model->interval_idx++;
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
if(event->type == InputTypePress && event->key == InputKeyLeft && !model->running &&
|
||||||
|
model->interval_idx > 0) {
|
||||||
|
model->interval_idx--;
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
|
||||||
return consumed;
|
return consumed;
|
||||||
}
|
}
|
||||||
@ -116,7 +140,6 @@ HidMouseJiggler* hid_mouse_jiggler_alloc(Hid* hid) {
|
|||||||
hid_mouse_jiggler->view, ViewModelTypeLocking, sizeof(HidMouseJigglerModel));
|
hid_mouse_jiggler->view, ViewModelTypeLocking, sizeof(HidMouseJigglerModel));
|
||||||
view_set_draw_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_draw_callback);
|
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_input_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_input_callback);
|
||||||
view_set_enter_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_enter_callback);
|
|
||||||
view_set_exit_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_exit_callback);
|
view_set_exit_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_exit_callback);
|
||||||
|
|
||||||
hid_mouse_jiggler->hid = hid;
|
hid_mouse_jiggler->hid = hid;
|
||||||
@ -127,7 +150,10 @@ HidMouseJiggler* hid_mouse_jiggler_alloc(Hid* hid) {
|
|||||||
with_view_model(
|
with_view_model(
|
||||||
hid_mouse_jiggler->view,
|
hid_mouse_jiggler->view,
|
||||||
HidMouseJigglerModel * model,
|
HidMouseJigglerModel * model,
|
||||||
{ model->transport = hid->transport; },
|
{
|
||||||
|
model->transport = hid->transport;
|
||||||
|
model->interval_idx = 2;
|
||||||
|
},
|
||||||
true);
|
true);
|
||||||
|
|
||||||
return hid_mouse_jiggler;
|
return hid_mouse_jiggler;
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#define TAG "HidMouseJiggler"
|
#define TAG "HidMouseJiggler"
|
||||||
|
|
||||||
|
#define LENGTH(x) (int)(sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
struct HidMouseJiggler {
|
struct HidMouseJiggler {
|
||||||
View* view;
|
View* view;
|
||||||
FuriTimer* timer;
|
FuriTimer* timer;
|
||||||
@ -14,38 +16,51 @@ struct HidMouseJiggler {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool running;
|
bool running;
|
||||||
|
int interval_idx;
|
||||||
uint8_t counter;
|
uint8_t counter;
|
||||||
} HidMouseJigglerModel;
|
} HidMouseJigglerModel;
|
||||||
|
|
||||||
|
const int intervals[6] = {500, 2000, 5000, 10000, 30000, 60000};
|
||||||
|
|
||||||
static void hid_mouse_jiggler_draw_callback(Canvas* canvas, void* context) {
|
static void hid_mouse_jiggler_draw_callback(Canvas* canvas, void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
HidMouseJigglerModel* model = context;
|
HidMouseJigglerModel* model = context;
|
||||||
|
|
||||||
// Header
|
// Header
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "Mouse Jiggler");
|
elements_multiline_text_aligned(canvas, 17, 2, AlignLeft, AlignTop, "Mouse Jiggler");
|
||||||
|
|
||||||
|
// Timeout
|
||||||
|
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 != LENGTH(intervals) - 1)
|
||||||
|
canvas_draw_icon(canvas, 80, 19, &I_ButtonRight_4x7);
|
||||||
|
FuriString* interval_str = furi_string_alloc_printf("%d", intervals[model->interval_idx]);
|
||||||
|
elements_multiline_text(canvas, 91, 26, furi_string_get_cstr(interval_str));
|
||||||
|
furi_string_free(interval_str);
|
||||||
|
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
elements_multiline_text(canvas, AlignLeft, 35, "Press Start\nto jiggle");
|
elements_multiline_text(canvas, AlignLeft, 40, "Press Start\nto jiggle");
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
|
|
||||||
// Ok
|
// Ok
|
||||||
canvas_draw_icon(canvas, 63, 25, &I_Space_65x18);
|
canvas_draw_icon(canvas, 63, 30, &I_Space_65x18);
|
||||||
if(model->running) {
|
if(model->running) {
|
||||||
elements_slightly_rounded_box(canvas, 66, 27, 60, 13);
|
elements_slightly_rounded_box(canvas, 66, 32, 60, 13);
|
||||||
canvas_set_color(canvas, ColorWhite);
|
canvas_set_color(canvas, ColorWhite);
|
||||||
}
|
}
|
||||||
canvas_draw_icon(canvas, 74, 29, &I_Ok_btn_9x9);
|
canvas_draw_icon(canvas, 74, 34, &I_Ok_btn_9x9);
|
||||||
if(model->running) {
|
if(model->running) {
|
||||||
elements_multiline_text_aligned(canvas, 91, 36, AlignLeft, AlignBottom, "Stop");
|
elements_multiline_text_aligned(canvas, 91, 41, AlignLeft, AlignBottom, "Stop");
|
||||||
} else {
|
} else {
|
||||||
elements_multiline_text_aligned(canvas, 91, 36, AlignLeft, AlignBottom, "Start");
|
elements_multiline_text_aligned(canvas, 91, 41, AlignLeft, AlignBottom, "Start");
|
||||||
}
|
}
|
||||||
canvas_set_color(canvas, ColorBlack);
|
canvas_set_color(canvas, ColorBlack);
|
||||||
|
|
||||||
// Back
|
// Back
|
||||||
canvas_draw_icon(canvas, 74, 49, &I_Pin_back_arrow_10x8);
|
canvas_draw_icon(canvas, 74, 54, &I_Pin_back_arrow_10x8);
|
||||||
elements_multiline_text_aligned(canvas, 91, 57, AlignLeft, AlignBottom, "Quit");
|
elements_multiline_text_aligned(canvas, 91, 62, AlignLeft, AlignBottom, "Quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hid_mouse_jiggler_timer_callback(void* context) {
|
static void hid_mouse_jiggler_timer_callback(void* context) {
|
||||||
@ -64,13 +79,6 @@ static void hid_mouse_jiggler_timer_callback(void* context) {
|
|||||||
false);
|
false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hid_mouse_jiggler_enter_callback(void* context) {
|
|
||||||
furi_assert(context);
|
|
||||||
HidMouseJiggler* hid_mouse_jiggler = context;
|
|
||||||
|
|
||||||
furi_timer_start(hid_mouse_jiggler->timer, 500);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void hid_mouse_jiggler_exit_callback(void* context) {
|
static void hid_mouse_jiggler_exit_callback(void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
HidMouseJiggler* hid_mouse_jiggler = context;
|
HidMouseJiggler* hid_mouse_jiggler = context;
|
||||||
@ -83,14 +91,30 @@ static bool hid_mouse_jiggler_input_callback(InputEvent* event, void* context) {
|
|||||||
|
|
||||||
bool consumed = false;
|
bool consumed = false;
|
||||||
|
|
||||||
if(event->key == InputKeyOk) {
|
|
||||||
with_view_model(
|
with_view_model(
|
||||||
hid_mouse_jiggler->view,
|
hid_mouse_jiggler->view,
|
||||||
HidMouseJigglerModel * model,
|
HidMouseJigglerModel * model,
|
||||||
{ model->running = !model->running; },
|
{
|
||||||
true);
|
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;
|
consumed = true;
|
||||||
}
|
}
|
||||||
|
if(event->type == InputTypePress && event->key == InputKeyRight && !model->running &&
|
||||||
|
model->interval_idx < LENGTH(intervals) - 1) {
|
||||||
|
model->interval_idx++;
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
if(event->type == InputTypePress && event->key == InputKeyLeft && !model->running &&
|
||||||
|
model->interval_idx > 0) {
|
||||||
|
model->interval_idx--;
|
||||||
|
consumed = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
|
||||||
return consumed;
|
return consumed;
|
||||||
}
|
}
|
||||||
@ -104,12 +128,14 @@ HidMouseJiggler* hid_mouse_jiggler_alloc() {
|
|||||||
hid_mouse_jiggler->view, ViewModelTypeLocking, sizeof(HidMouseJigglerModel));
|
hid_mouse_jiggler->view, ViewModelTypeLocking, sizeof(HidMouseJigglerModel));
|
||||||
view_set_draw_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_draw_callback);
|
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_input_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_input_callback);
|
||||||
view_set_enter_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_enter_callback);
|
|
||||||
view_set_exit_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_exit_callback);
|
view_set_exit_callback(hid_mouse_jiggler->view, hid_mouse_jiggler_exit_callback);
|
||||||
|
|
||||||
hid_mouse_jiggler->timer = furi_timer_alloc(
|
hid_mouse_jiggler->timer = furi_timer_alloc(
|
||||||
hid_mouse_jiggler_timer_callback, FuriTimerTypePeriodic, hid_mouse_jiggler);
|
hid_mouse_jiggler_timer_callback, FuriTimerTypePeriodic, hid_mouse_jiggler);
|
||||||
|
|
||||||
|
with_view_model(
|
||||||
|
hid_mouse_jiggler->view, HidMouseJigglerModel * model, { model->interval_idx = 2; }, true);
|
||||||
|
|
||||||
return hid_mouse_jiggler;
|
return hid_mouse_jiggler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user