Update cookie clicker with updated Bluetooth API.

This commit is contained in:
Derek Jamison 2024-04-01 12:44:44 -05:00
parent 9c944be2e6
commit 9006626231
4 changed files with 47 additions and 18 deletions

View File

@ -1,11 +1,16 @@
App( App(
appid="cookie_bt", appid="cookie_clicker",
name="Cookie Clicker", name="Cookie Clicker",
apptype=FlipperAppType.EXTERNAL, apptype=FlipperAppType.EXTERNAL,
entry_point="hid_cookie_ble_app", entry_point="hid_cookie_ble_app",
stack_size=1 * 1024, stack_size=1 * 1024,
fap_libs=["ble_profile"],
fap_category="Bluetooth", fap_category="Bluetooth",
fap_icon="hid_cookie_ble_10px.png", fap_icon="hid_cookie_ble_10px.png",
fap_icon_assets="assets", fap_icon_assets="assets",
fap_icon_assets_symbol="hid", fap_icon_assets_symbol="hid",
fap_author="jamisonderek",
fap_weburl="https://github.com/jamisonderek/flipper-zero-tutorials/tree/main/hid/hid_cookie",
fap_version=(1, 1),
fap_description="The goal of this application is use the Flipper Zero's bluetooth connectivity to send mouse clicks to your phone at a given frequency. If you are playing a game, such as Cookie Clicker 2, this will result in a 'screen tap' being simulated. Only connect to phones you own (unless your friends ask you to connect your Flipper Zero to their phone, so they can unlock more achievements in their games!)",
) )

View File

@ -1,7 +1,8 @@
#include "hid.h" #include "hid.h"
#include <extra_profiles/hid_profile.h>
#include <profiles/serial_profile.h>
#include "views.h" #include "views.h"
#include <notification/notification_messages.h> #include <notification/notification_messages.h>
#include <dolphin/dolphin.h>
#define TAG "CookieClickerApp" #define TAG "CookieClickerApp"
@ -9,9 +10,20 @@ enum HidDebugSubmenuIndex {
HidSubmenuIndexInstructions, HidSubmenuIndexInstructions,
HidSubmenuConfigure, HidSubmenuConfigure,
HidSubmenuIndexClicker, HidSubmenuIndexClicker,
HidSubmenuIndexRemovePairing,
HidSubmenuIndexCredits, HidSubmenuIndexCredits,
}; };
static void bt_hid_remove_pairing(Hid* hid) {
bt_disconnect(hid->bt);
furi_delay_ms(200);
furi_hal_bt_stop_advertising();
bt_forget_bonded_devices(hid->bt);
furi_hal_bt_start_advertising();
hid->ble = NULL;
notification_message(hid->notifications, &sequence_success);
}
static void hid_submenu_callback(void* context, uint32_t index) { static void hid_submenu_callback(void* context, uint32_t index) {
furi_assert(context); furi_assert(context);
Hid* app = context; Hid* app = context;
@ -24,6 +36,8 @@ 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 == HidSubmenuIndexRemovePairing) {
bt_hid_remove_pairing(app);
} else if(index == HidSubmenuConfigure) { } else if(index == HidSubmenuConfigure) {
app->view_id = BtHidViewConfigure; app->view_id = BtHidViewConfigure;
view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id); view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id);
@ -78,6 +92,8 @@ Hid* hid_alloc() {
app->submenu, "Configuration", HidSubmenuConfigure, hid_submenu_callback, app); 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, "Remove Pairing", HidSubmenuIndexRemovePairing, 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);
view_set_previous_callback(submenu_get_view(app->submenu), hid_exit); view_set_previous_callback(submenu_get_view(app->submenu), hid_exit);
view_dispatcher_add_view(app->view_dispatcher, HidViewSubmenu, submenu_get_view(app->submenu)); view_dispatcher_add_view(app->view_dispatcher, HidViewSubmenu, submenu_get_view(app->submenu));
@ -198,8 +214,8 @@ Hid* hid_app_alloc_view(void* context) {
app->offset_y = 80; app->offset_y = 80;
item = variable_item_list_add( item = variable_item_list_add(
app->variable_item_list, "Multiplier", 20, hid_setting_change_repeat, app); 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_index(item, 0); // 1,2,3,4,...
variable_item_set_current_value_text(item, "3"); variable_item_set_current_value_text(item, "1");
app->offset_repeat = 3; app->offset_repeat = 3;
item = variable_item_list_add( item = variable_item_list_add(
app->variable_item_list, "CursorSpeed", 50, hid_setting_change_speed, app); app->variable_item_list, "CursorSpeed", 50, hid_setting_change_speed, app);
@ -276,22 +292,30 @@ void hid_free(Hid* app) {
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) {
furi_assert(instance); furi_assert(instance);
furi_hal_bt_hid_mouse_move(dx, dy); if(instance->ble) {
ble_profile_hid_mouse_move(instance->ble, dx, dy);
}
} }
void hid_hal_mouse_press(Hid* instance, uint16_t event) { void hid_hal_mouse_press(Hid* instance, uint16_t event) {
furi_assert(instance); furi_assert(instance);
furi_hal_bt_hid_mouse_press(event); if(instance->ble) {
ble_profile_hid_mouse_press(instance->ble, event);
}
} }
void hid_hal_mouse_release(Hid* instance, uint16_t event) { void hid_hal_mouse_release(Hid* instance, uint16_t event) {
furi_assert(instance); furi_assert(instance);
furi_hal_bt_hid_mouse_release(event); if(instance->ble) {
ble_profile_hid_mouse_release(instance->ble, event);
}
} }
void hid_hal_mouse_release_all(Hid* instance) { void hid_hal_mouse_release_all(Hid* instance) {
furi_assert(instance); furi_assert(instance);
furi_hal_bt_hid_mouse_release_all(); if(instance->ble) {
ble_profile_hid_mouse_release_all(instance->ble);
}
} }
int32_t hid_cookie_ble_app(void* p) { int32_t hid_cookie_ble_app(void* p) {
@ -309,22 +333,21 @@ int32_t hid_cookie_ble_app(void* p) {
storage_common_migrate( storage_common_migrate(
storage, storage,
EXT_PATH("apps/Tools/" HID_BT_KEYS_STORAGE_NAME), EXT_PATH("apps/Bluetooth/" HID_BT_KEYS_STORAGE_NAME),
APP_DATA_PATH(HID_BT_KEYS_STORAGE_NAME)); APP_DATA_PATH(HID_BT_KEYS_STORAGE_NAME));
bt_keys_storage_set_storage_path(app->bt, APP_DATA_PATH(HID_BT_KEYS_STORAGE_NAME)); bt_keys_storage_set_storage_path(app->bt, APP_DATA_PATH(HID_BT_KEYS_STORAGE_NAME));
furi_record_close(RECORD_STORAGE); furi_record_close(RECORD_STORAGE);
if(!bt_set_profile(app->bt, BtProfileHidKeyboard)) { app->ble = bt_profile_start(app->bt, ble_profile_hid, NULL);
FURI_LOG_E(TAG, "Failed to switch to HID profile"); if(!app->ble) {
FURI_LOG_E(TAG, "Failed to start BLE profile");
} }
furi_hal_bt_start_advertising(); furi_hal_bt_start_advertising();
bt_set_status_changed_callback(app->bt, bt_hid_connection_status_changed_callback, app); bt_set_status_changed_callback(app->bt, bt_hid_connection_status_changed_callback, app);
// dolphin_deed(DolphinDeedPluginStart);
view_dispatcher_run(app->view_dispatcher); view_dispatcher_run(app->view_dispatcher);
bt_set_status_changed_callback(app->bt, NULL, NULL); bt_set_status_changed_callback(app->bt, NULL, NULL);
@ -336,7 +359,7 @@ int32_t hid_cookie_ble_app(void* p) {
bt_keys_storage_set_default_path(app->bt); bt_keys_storage_set_default_path(app->bt);
if(!bt_set_profile(app->bt, BtProfileSerial)) { if(!bt_profile_restore_default(app->bt)) {
FURI_LOG_E(TAG, "Failed to switch to Serial profile"); FURI_LOG_E(TAG, "Failed to switch to Serial profile");
} }

View File

@ -2,9 +2,9 @@
#include <furi.h> #include <furi.h>
#include <furi_hal_bt.h> #include <furi_hal_bt.h>
#include <furi_hal_bt_hid.h>
#include <furi_hal_usb.h> #include <furi_hal_usb.h>
#include <furi_hal_usb_hid.h> #include <furi_hal_usb_hid.h>
#include <extra_profiles/hid_profile.h>
#include <bt/bt_service/bt.h> #include <bt/bt_service/bt.h>
#include <gui/gui.h> #include <gui/gui.h>
@ -26,6 +26,7 @@ typedef struct Hid Hid;
struct Hid { struct Hid {
Bt* bt; Bt* bt;
FuriHalBleProfileBase* ble;
Gui* gui; Gui* gui;
NotificationApp* notifications; NotificationApp* notifications;
ViewDispatcher* view_dispatcher; ViewDispatcher* view_dispatcher;

View File

@ -2,7 +2,7 @@
#include "../hid.h" #include "../hid.h"
#include <gui/elements.h> #include <gui/elements.h>
#include "hid_icons.h" #include <hid_icons.h>
#define TAG "HidCC" #define TAG "HidCC"
@ -40,7 +40,7 @@ static void hid_cc_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, "Cookie\nClicker"); elements_multiline_text_aligned(canvas, 17, 3, AlignLeft, AlignTop, "Cookie\nClicker");
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
FuriString* buffer = furi_string_alloc(32); FuriString* buffer = furi_string_alloc();
furi_string_printf(buffer, "%0.1f ms\r\n", (double)model->timer_duration); furi_string_printf(buffer, "%0.1f ms\r\n", (double)model->timer_duration);
if(model->timer_click_enabled) { if(model->timer_click_enabled) {
furi_string_cat(buffer, "Clicking"); furi_string_cat(buffer, "Clicking");