fix initialization. add speed.

This commit is contained in:
Derek Jamison 2023-06-11 15:16:07 -05:00
parent 6fad46cfb2
commit 052f4f8679
5 changed files with 50 additions and 24 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View File

@ -88,7 +88,11 @@ Hid* hid_alloc() {
void hid_setting_changed(Hid* instance) {
hid_cc_set_cursor_position(
instance->hid_cc, instance->offset_x, instance->offset_y, instance->offset_repeat);
instance->hid_cc,
instance->offset_x,
instance->offset_y,
instance->offset_repeat,
instance->offset_speed);
}
void hid_setting_change_x(VariableItem* item) {
@ -124,6 +128,17 @@ void hid_setting_change_repeat(VariableItem* item) {
hid_setting_changed(instance);
}
void hid_setting_change_speed(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_speed = index * 10 + 1;
furi_string_cat_printf(str, "%d", instance->offset_speed);
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) {
furi_assert(context);
Hid* app = context;
@ -168,19 +183,24 @@ Hid* hid_app_alloc_view(void* context) {
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;
variable_item_set_current_value_index(item, 5); // 0,10,20,30,...
variable_item_set_current_value_text(item, "40");
app->offset_x = 40;
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;
app->offset_y = 80;
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;
app->offset_repeat = 3;
item = variable_item_list_add(
app->variable_item_list, "CursorSpeed", 50, hid_setting_change_speed, app);
variable_item_set_current_value_index(item, 5); // 1,2,3,4,...
variable_item_set_current_value_text(item, "50");
app->offset_speed = 50;
view_set_previous_callback(
variable_item_list_get_view(app->variable_item_list), hid_submenu_view);
view_dispatcher_add_view(
@ -192,6 +212,7 @@ Hid* hid_app_alloc_view(void* context) {
app->hid_cc = hid_cc_alloc(app);
view_set_previous_callback(hid_cc_get_view(app->hid_cc), hid_submenu_view);
view_dispatcher_add_view(app->view_dispatcher, BtHidViewClicker, hid_cc_get_view(app->hid_cc));
hid_setting_changed(app);
// Credits view
app->widget_credits = widget_alloc();

View File

@ -36,6 +36,7 @@ struct Hid {
HidCC* hid_cc;
uint32_t view_id;
uint8_t offset_repeat;
uint8_t offset_speed;
uint8_t offset_x;
uint8_t offset_y;
};

View File

@ -20,9 +20,10 @@ typedef struct {
bool is_cursor_set;
float timer_duration;
bool timer_click_enabled;
uint8_t click_x;
uint8_t click_y;
uint8_t click_loop;
uint8_t move_x;
uint8_t move_y;
uint8_t move_loop;
uint8_t move_speed;
} HidCCModel;
static void hid_cc_draw_callback(Canvas* canvas, void* context) {
@ -111,21 +112,23 @@ static void hid_cc_tick_callback(void* context) {
}
static void hid_cc_reset_cursor(HidCC* hid_cc) {
// Set cursor to the phone's left up corner
// Delays to guarantee one packet per connection interval
for(size_t i = 0; i < 8; i++) {
hid_hal_mouse_move(hid_cc->hid, -127, -127);
furi_delay_ms(50);
}
FURI_LOG_I("HID", "Reset cursor!");
// Move cursor from the corner
with_view_model(
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);
// Set cursor to the phone's left up corner
// Delays to guarantee one packet per connection interval
for(size_t i = 0; i < 20; i++) {
hid_hal_mouse_move(hid_cc->hid, -127, -127);
furi_delay_ms(model->move_speed);
}
FURI_LOG_I("HID", "%d %d", model->move_x, model->move_y);
for(size_t i = 0; i < model->move_loop; i++) {
hid_hal_mouse_move(hid_cc->hid, model->move_x, model->move_y);
furi_delay_ms(model->move_speed);
}
},
true);
@ -207,15 +210,16 @@ static bool hid_cc_input_callback(InputEvent* event, void* context) {
return consumed;
}
void hid_cc_set_cursor_position(HidCC* hid_cc, uint8_t x, uint8_t y, uint8_t repeat) {
void hid_cc_set_cursor_position(HidCC* hid_cc, uint8_t x, uint8_t y, uint8_t repeat, uint8_t speed) {
furi_assert(hid_cc);
with_view_model(
hid_cc->view,
HidCCModel * model,
{
model->click_x = x;
model->click_y = y;
model->click_loop = repeat;
model->move_x = x;
model->move_y = y;
model->move_loop = repeat;
model->move_speed = speed;
},
true);
}

View File

@ -13,4 +13,4 @@ View* hid_cc_get_view(HidCC* hid_cc);
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);
void hid_cc_set_cursor_position(HidCC* hid_cc, uint8_t x, uint8_t y, uint8_t repeat, uint8_t speed);