#11 wrong spot - Make click location configurable.
This commit is contained in:
parent
554e36a4f2
commit
d922892bea
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
enum HidDebugSubmenuIndex {
|
enum HidDebugSubmenuIndex {
|
||||||
HidSubmenuIndexInstructions,
|
HidSubmenuIndexInstructions,
|
||||||
|
HidSubmenuConfigure,
|
||||||
HidSubmenuIndexClicker,
|
HidSubmenuIndexClicker,
|
||||||
HidSubmenuIndexCredits,
|
HidSubmenuIndexCredits,
|
||||||
};
|
};
|
||||||
@ -23,6 +24,9 @@ static void hid_submenu_callback(void* context, uint32_t index) {
|
|||||||
} else if(index == HidSubmenuIndexCredits) {
|
} else if(index == HidSubmenuIndexCredits) {
|
||||||
app->view_id = BtHidViewCredits;
|
app->view_id = BtHidViewCredits;
|
||||||
view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id);
|
view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id);
|
||||||
|
} else if(index == HidSubmenuConfigure) {
|
||||||
|
app->view_id = BtHidViewConfigure;
|
||||||
|
view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +74,8 @@ Hid* hid_alloc() {
|
|||||||
submenu_set_header(app->submenu, "Cookie clicker");
|
submenu_set_header(app->submenu, "Cookie clicker");
|
||||||
submenu_add_item(
|
submenu_add_item(
|
||||||
app->submenu, "Instructions", HidSubmenuIndexInstructions, hid_submenu_callback, app);
|
app->submenu, "Instructions", HidSubmenuIndexInstructions, hid_submenu_callback, app);
|
||||||
|
submenu_add_item(
|
||||||
|
app->submenu, "Configuration", HidSubmenuConfigure, hid_submenu_callback, app);
|
||||||
submenu_add_item(
|
submenu_add_item(
|
||||||
app->submenu, "BT Phone Clicker", HidSubmenuIndexClicker, hid_submenu_callback, app);
|
app->submenu, "BT Phone Clicker", HidSubmenuIndexClicker, hid_submenu_callback, app);
|
||||||
submenu_add_item(app->submenu, "Credits", HidSubmenuIndexCredits, hid_submenu_callback, app);
|
submenu_add_item(app->submenu, "Credits", HidSubmenuIndexCredits, hid_submenu_callback, app);
|
||||||
@ -80,6 +86,44 @@ Hid* hid_alloc() {
|
|||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hid_setting_changed(Hid* instance) {
|
||||||
|
hid_cc_set_cursor_position(
|
||||||
|
instance->hid_cc, instance->offset_x, instance->offset_y, instance->offset_repeat);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_setting_change_x(VariableItem* item) {
|
||||||
|
FuriString* str = furi_string_alloc();
|
||||||
|
Hid* instance = variable_item_get_context(item);
|
||||||
|
uint8_t index = variable_item_get_current_value_index(item);
|
||||||
|
instance->offset_x = index * 10;
|
||||||
|
furi_string_cat_printf(str, "%d", instance->offset_x);
|
||||||
|
variable_item_set_current_value_text(item, furi_string_get_cstr(str));
|
||||||
|
furi_string_free(str);
|
||||||
|
hid_setting_changed(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_setting_change_y(VariableItem* item) {
|
||||||
|
FuriString* str = furi_string_alloc();
|
||||||
|
Hid* instance = variable_item_get_context(item);
|
||||||
|
uint8_t index = variable_item_get_current_value_index(item);
|
||||||
|
instance->offset_y = index * 10;
|
||||||
|
furi_string_cat_printf(str, "%d", instance->offset_y);
|
||||||
|
variable_item_set_current_value_text(item, furi_string_get_cstr(str));
|
||||||
|
furi_string_free(str);
|
||||||
|
hid_setting_changed(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
void hid_setting_change_repeat(VariableItem* item) {
|
||||||
|
FuriString* str = furi_string_alloc();
|
||||||
|
Hid* instance = variable_item_get_context(item);
|
||||||
|
uint8_t index = variable_item_get_current_value_index(item);
|
||||||
|
instance->offset_repeat = index + 1;
|
||||||
|
furi_string_cat_printf(str, "%d", instance->offset_repeat);
|
||||||
|
variable_item_set_current_value_text(item, furi_string_get_cstr(str));
|
||||||
|
furi_string_free(str);
|
||||||
|
hid_setting_changed(instance);
|
||||||
|
}
|
||||||
|
|
||||||
Hid* hid_app_alloc_view(void* context) {
|
Hid* hid_app_alloc_view(void* context) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
Hid* app = context;
|
Hid* app = context;
|
||||||
@ -112,11 +156,38 @@ Hid* hid_app_alloc_view(void* context) {
|
|||||||
"speed. Click the OK button on\n"
|
"speed. Click the OK button on\n"
|
||||||
"the Flipper to enable/\n"
|
"the Flipper to enable/\n"
|
||||||
"disable the clicker.\n"
|
"disable the clicker.\n"
|
||||||
|
"Use the configuration setting\n"
|
||||||
|
"to change the location of the\n"
|
||||||
|
"clicking!\n"
|
||||||
"Enjoy!\n");
|
"Enjoy!\n");
|
||||||
view_set_previous_callback(widget_get_view(app->widget_instructions), hid_submenu_view);
|
view_set_previous_callback(widget_get_view(app->widget_instructions), hid_submenu_view);
|
||||||
view_dispatcher_add_view(
|
view_dispatcher_add_view(
|
||||||
app->view_dispatcher, BtHidViewInstructions, widget_get_view(app->widget_instructions));
|
app->view_dispatcher, BtHidViewInstructions, widget_get_view(app->widget_instructions));
|
||||||
|
|
||||||
|
app->variable_item_list = variable_item_list_alloc();
|
||||||
|
variable_item_list_reset(app->variable_item_list);
|
||||||
|
VariableItem* item =
|
||||||
|
variable_item_list_add(app->variable_item_list, "X offset", 13, hid_setting_change_x, app);
|
||||||
|
variable_item_set_current_value_index(item, 3); // 0,10,20,30,...
|
||||||
|
variable_item_set_current_value_text(item, "30");
|
||||||
|
app->offset_x = 10;
|
||||||
|
item =
|
||||||
|
variable_item_list_add(app->variable_item_list, "Y offset", 13, hid_setting_change_y, app);
|
||||||
|
variable_item_set_current_value_index(item, 8); // 0,10,20,30,...
|
||||||
|
variable_item_set_current_value_text(item, "80");
|
||||||
|
app->offset_y = 100;
|
||||||
|
item = variable_item_list_add(
|
||||||
|
app->variable_item_list, "Multiplier", 20, hid_setting_change_repeat, app);
|
||||||
|
variable_item_set_current_value_index(item, 2); // 1,2,3,4,...
|
||||||
|
variable_item_set_current_value_text(item, "3");
|
||||||
|
app->offset_repeat = 2;
|
||||||
|
view_set_previous_callback(
|
||||||
|
variable_item_list_get_view(app->variable_item_list), hid_submenu_view);
|
||||||
|
view_dispatcher_add_view(
|
||||||
|
app->view_dispatcher,
|
||||||
|
BtHidViewConfigure,
|
||||||
|
variable_item_list_get_view(app->variable_item_list));
|
||||||
|
|
||||||
// Clicker view
|
// Clicker view
|
||||||
app->hid_cc = hid_cc_alloc(app);
|
app->hid_cc = hid_cc_alloc(app);
|
||||||
view_set_previous_callback(hid_cc_get_view(app->hid_cc), hid_submenu_view);
|
view_set_previous_callback(hid_cc_get_view(app->hid_cc), hid_submenu_view);
|
||||||
@ -157,6 +228,8 @@ void hid_free(Hid* app) {
|
|||||||
hid_cc_free(app->hid_cc);
|
hid_cc_free(app->hid_cc);
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, BtHidViewCredits);
|
view_dispatcher_remove_view(app->view_dispatcher, BtHidViewCredits);
|
||||||
widget_free(app->widget_credits);
|
widget_free(app->widget_credits);
|
||||||
|
view_dispatcher_remove_view(app->view_dispatcher, BtHidViewConfigure);
|
||||||
|
variable_item_list_free(app->variable_item_list);
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, BtHidViewInstructions);
|
view_dispatcher_remove_view(app->view_dispatcher, BtHidViewInstructions);
|
||||||
widget_free(app->widget_instructions);
|
widget_free(app->widget_instructions);
|
||||||
view_dispatcher_remove_view(app->view_dispatcher, HidViewSubmenu);
|
view_dispatcher_remove_view(app->view_dispatcher, HidViewSubmenu);
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <gui/modules/dialog_ex.h>
|
#include <gui/modules/dialog_ex.h>
|
||||||
#include <gui/modules/popup.h>
|
#include <gui/modules/popup.h>
|
||||||
#include <gui/modules/widget.h>
|
#include <gui/modules/widget.h>
|
||||||
|
#include <gui/modules/variable_item_list.h>
|
||||||
#include "views/hid_cc.h"
|
#include "views/hid_cc.h"
|
||||||
|
|
||||||
#define HID_BT_KEYS_STORAGE_NAME ".bt_hid.keys"
|
#define HID_BT_KEYS_STORAGE_NAME ".bt_hid.keys"
|
||||||
@ -30,9 +31,13 @@ struct Hid {
|
|||||||
ViewDispatcher* view_dispatcher;
|
ViewDispatcher* view_dispatcher;
|
||||||
Submenu* submenu;
|
Submenu* submenu;
|
||||||
Widget* widget_instructions;
|
Widget* widget_instructions;
|
||||||
|
VariableItemList* variable_item_list;
|
||||||
Widget* widget_credits;
|
Widget* widget_credits;
|
||||||
HidCC* hid_cc;
|
HidCC* hid_cc;
|
||||||
uint32_t view_id;
|
uint32_t view_id;
|
||||||
|
uint8_t offset_repeat;
|
||||||
|
uint8_t offset_x;
|
||||||
|
uint8_t offset_y;
|
||||||
};
|
};
|
||||||
|
|
||||||
void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy);
|
void hid_hal_mouse_move(Hid* instance, int8_t dx, int8_t dy);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
HidViewSubmenu,
|
HidViewSubmenu,
|
||||||
BtHidViewInstructions,
|
BtHidViewInstructions,
|
||||||
|
BtHidViewConfigure,
|
||||||
BtHidViewClicker,
|
BtHidViewClicker,
|
||||||
BtHidViewCredits,
|
BtHidViewCredits,
|
||||||
} HidView;
|
} HidView;
|
@ -20,6 +20,9 @@ typedef struct {
|
|||||||
bool is_cursor_set;
|
bool is_cursor_set;
|
||||||
float timer_duration;
|
float timer_duration;
|
||||||
bool timer_click_enabled;
|
bool timer_click_enabled;
|
||||||
|
uint8_t click_x;
|
||||||
|
uint8_t click_y;
|
||||||
|
uint8_t click_loop;
|
||||||
} HidCCModel;
|
} HidCCModel;
|
||||||
|
|
||||||
static void hid_cc_draw_callback(Canvas* canvas, void* context) {
|
static void hid_cc_draw_callback(Canvas* canvas, void* context) {
|
||||||
@ -114,9 +117,18 @@ static void hid_cc_reset_cursor(HidCC* hid_cc) {
|
|||||||
hid_hal_mouse_move(hid_cc->hid, -127, -127);
|
hid_hal_mouse_move(hid_cc->hid, -127, -127);
|
||||||
furi_delay_ms(50);
|
furi_delay_ms(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move cursor from the corner
|
// Move cursor from the corner
|
||||||
hid_hal_mouse_move(hid_cc->hid, 20, 120);
|
with_view_model(
|
||||||
furi_delay_ms(50);
|
hid_cc->view,
|
||||||
|
HidCCModel * model,
|
||||||
|
{
|
||||||
|
for(size_t i = 0; i < model->click_loop; i++) {
|
||||||
|
hid_hal_mouse_move(hid_cc->hid, model->click_x, model->click_y);
|
||||||
|
furi_delay_ms(50);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hid_cc_process_press(HidCC* hid_cc, HidCCModel* model, InputEvent* event) {
|
static void hid_cc_process_press(HidCC* hid_cc, HidCCModel* model, InputEvent* event) {
|
||||||
@ -195,6 +207,19 @@ static bool hid_cc_input_callback(InputEvent* event, void* context) {
|
|||||||
return consumed;
|
return consumed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void hid_cc_set_cursor_position(HidCC* hid_cc, uint8_t x, uint8_t y, uint8_t repeat) {
|
||||||
|
furi_assert(hid_cc);
|
||||||
|
with_view_model(
|
||||||
|
hid_cc->view,
|
||||||
|
HidCCModel * model,
|
||||||
|
{
|
||||||
|
model->click_x = x;
|
||||||
|
model->click_y = y;
|
||||||
|
model->click_loop = repeat;
|
||||||
|
},
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
HidCC* hid_cc_alloc(Hid* bt_hid) {
|
HidCC* hid_cc_alloc(Hid* bt_hid) {
|
||||||
HidCC* hid_cc = malloc(sizeof(HidCC));
|
HidCC* hid_cc = malloc(sizeof(HidCC));
|
||||||
hid_cc->hid = bt_hid;
|
hid_cc->hid = bt_hid;
|
||||||
|
@ -12,3 +12,5 @@ void hid_cc_free(HidCC* hid_cc);
|
|||||||
View* hid_cc_get_view(HidCC* hid_cc);
|
View* hid_cc_get_view(HidCC* hid_cc);
|
||||||
|
|
||||||
void hid_cc_set_connected_status(HidCC* hid_cc, bool connected);
|
void hid_cc_set_connected_status(HidCC* hid_cc, bool connected);
|
||||||
|
|
||||||
|
void hid_cc_set_cursor_position(HidCC* hid_cc, uint8_t x, uint8_t y, uint8_t repeat);
|
Loading…
Reference in New Issue
Block a user