This commit is contained in:
Willy-JL
2023-11-19 23:42:25 +00:00
parent 2b71789692
commit 91368a4538
7 changed files with 126 additions and 114 deletions

View File

@@ -1,10 +1,9 @@
#include "hex_viewer_haptic.h" #include "hex_viewer_haptic.h"
#include "../hex_viewer.h" #include "../hex_viewer.h"
void hex_viewer_play_happy_bump(void* context) { void hex_viewer_play_happy_bump(void* context) {
HexViewer* app = context; HexViewer* app = context;
if (app->haptic != 1) { if(app->haptic != 1) {
return; return;
} }
notification_message(app->notification, &sequence_set_vibro_on); notification_message(app->notification, &sequence_set_vibro_on);
@@ -14,7 +13,7 @@ void hex_viewer_play_happy_bump(void* context) {
void hex_viewer_play_bad_bump(void* context) { void hex_viewer_play_bad_bump(void* context) {
HexViewer* app = context; HexViewer* app = context;
if (app->haptic != 1) { if(app->haptic != 1) {
return; return;
} }
notification_message(app->notification, &sequence_set_vibro_on); notification_message(app->notification, &sequence_set_vibro_on);
@@ -24,10 +23,10 @@ void hex_viewer_play_bad_bump(void* context) {
void hex_viewer_play_long_bump(void* context) { void hex_viewer_play_long_bump(void* context) {
HexViewer* app = context; HexViewer* app = context;
if (app->haptic != 1) { if(app->haptic != 1) {
return; return;
} }
for (int i = 0; i < 4; i++) { for(int i = 0; i < 4; i++) {
notification_message(app->notification, &sequence_set_vibro_on); notification_message(app->notification, &sequence_set_vibro_on);
furi_thread_flags_wait(0, FuriFlagWaitAny, 50); furi_thread_flags_wait(0, FuriFlagWaitAny, 50);
notification_message(app->notification, &sequence_reset_vibro); notification_message(app->notification, &sequence_reset_vibro);

View File

@@ -5,4 +5,3 @@ void hex_viewer_play_happy_bump(void* context);
void hex_viewer_play_bad_bump(void* context); void hex_viewer_play_bad_bump(void* context);
void hex_viewer_play_long_bump(void* context); void hex_viewer_play_long_bump(void* context);

View File

@@ -1,11 +1,9 @@
#include "hex_viewer_led.h" #include "hex_viewer_led.h"
#include "../hex_viewer.h" #include "../hex_viewer.h"
void hex_viewer_led_set_rgb(void* context, int red, int green, int blue) { void hex_viewer_led_set_rgb(void* context, int red, int green, int blue) {
HexViewer* app = context; HexViewer* app = context;
if (app->led != 1) { if(app->led != 1) {
return; return;
} }
NotificationMessage notification_led_message_1; NotificationMessage notification_led_message_1;
@@ -26,7 +24,8 @@ void hex_viewer_led_set_rgb(void* context, int red, int green, int blue) {
NULL, NULL,
}; };
notification_message(app->notification, &notification_sequence); notification_message(app->notification, &notification_sequence);
furi_thread_flags_wait(0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set furi_thread_flags_wait(
0, FuriFlagWaitAny, 10); //Delay, prevent removal from RAM before LED value set
} }
void hex_viewer_led_reset(void* context) { void hex_viewer_led_reset(void* context) {
@@ -34,6 +33,7 @@ void hex_viewer_led_reset(void* context) {
notification_message(app->notification, &sequence_reset_red); notification_message(app->notification, &sequence_reset_red);
notification_message(app->notification, &sequence_reset_green); notification_message(app->notification, &sequence_reset_green);
notification_message(app->notification, &sequence_reset_blue); notification_message(app->notification, &sequence_reset_blue);
furi_thread_flags_wait(0, FuriFlagWaitAny, 300); //Delay, prevent removal from RAM before LED value set furi_thread_flags_wait(
0, FuriFlagWaitAny, 300); //Delay, prevent removal from RAM before LED value set
} }

View File

@@ -3,4 +3,3 @@
void hex_viewer_led_set_rgb(void* context, int red, int green, int blue); void hex_viewer_led_set_rgb(void* context, int red, int green, int blue);
void hex_viewer_led_reset(void* context); void hex_viewer_led_reset(void* context);

View File

@@ -5,19 +5,18 @@
void hex_viewer_play_input_sound(void* context) { void hex_viewer_play_input_sound(void* context) {
HexViewer* app = context; HexViewer* app = context;
if (app->speaker != 1) { if(app->speaker != 1) {
return; return;
} }
float volume = 1.0f; float volume = 1.0f;
if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) { if(furi_hal_speaker_is_mine() || furi_hal_speaker_acquire(30)) {
furi_hal_speaker_start(NOTE_INPUT, volume); furi_hal_speaker_start(NOTE_INPUT, volume);
} }
} }
void hex_viewer_stop_all_sound(void* context) { void hex_viewer_stop_all_sound(void* context) {
HexViewer* app = context; HexViewer* app = context;
if (app->speaker != 1) { if(app->speaker != 1) {
return; return;
} }
if(furi_hal_speaker_is_mine()) { if(furi_hal_speaker_is_mine()) {

View File

@@ -43,7 +43,6 @@ const uint32_t settings_value[2] = {
HexViewerSettingsOn, HexViewerSettingsOn,
}; };
static void hex_viewer_scene_settings_set_haptic(VariableItem* item) { static void hex_viewer_scene_settings_set_haptic(VariableItem* item) {
HexViewer* app = variable_item_get_context(item); HexViewer* app = variable_item_get_context(item);
uint8_t index = variable_item_get_current_value_index(item); uint8_t index = variable_item_get_current_value_index(item);
@@ -85,33 +84,21 @@ void hex_viewer_scene_settings_on_enter(void* context) {
// Vibro on/off // Vibro on/off
item = variable_item_list_add( item = variable_item_list_add(
app->variable_item_list, app->variable_item_list, "Vibro/Haptic:", 2, hex_viewer_scene_settings_set_haptic, app);
"Vibro/Haptic:",
2,
hex_viewer_scene_settings_set_haptic,
app);
value_index = value_index_uint32(app->haptic, haptic_value, 2); value_index = value_index_uint32(app->haptic, haptic_value, 2);
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, haptic_text[value_index]); variable_item_set_current_value_text(item, haptic_text[value_index]);
// Sound on/off // Sound on/off
item = variable_item_list_add( item = variable_item_list_add(
app->variable_item_list, app->variable_item_list, "Sound:", 2, hex_viewer_scene_settings_set_speaker, app);
"Sound:",
2,
hex_viewer_scene_settings_set_speaker,
app);
value_index = value_index_uint32(app->speaker, speaker_value, 2); value_index = value_index_uint32(app->speaker, speaker_value, 2);
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, speaker_text[value_index]); variable_item_set_current_value_text(item, speaker_text[value_index]);
// LED Effects on/off // LED Effects on/off
item = variable_item_list_add( item = variable_item_list_add(
app->variable_item_list, app->variable_item_list, "LED FX:", 2, hex_viewer_scene_settings_set_led, app);
"LED FX:",
2,
hex_viewer_scene_settings_set_led,
app);
value_index = value_index_uint32(app->led, led_value, 2); value_index = value_index_uint32(app->led, led_value, 2);
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, led_text[value_index]); variable_item_set_current_value_text(item, led_text[value_index]);
@@ -126,7 +113,7 @@ void hex_viewer_scene_settings_on_enter(void* context) {
value_index = value_index_uint32(app->save_settings, settings_value, 2); value_index = value_index_uint32(app->save_settings, settings_value, 2);
variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_index(item, value_index);
variable_item_set_current_value_text(item, settings_text[value_index]); variable_item_set_current_value_text(item, settings_text[value_index]);
view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerViewIdSettings); view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerViewIdSettings);
} }
@@ -135,7 +122,6 @@ bool hex_viewer_scene_settings_on_event(void* context, SceneManagerEvent event)
UNUSED(app); UNUSED(app);
bool consumed = false; bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) { if(event.type == SceneManagerEventTypeCustom) {
} }
return consumed; return consumed;
} }

View File

@@ -68,11 +68,12 @@ static void hid_ptt_draw_callback(Canvas* canvas, void* context) {
const uint8_t y_os = 88; const uint8_t y_os = 88;
const uint8_t x_os = 7; const uint8_t x_os = 7;
// elements_slightly_rounded_box(canvas, model->is_mac_os ? 0 : 26, y_os, model->is_mac_os ? 21 : 26, 11); // elements_slightly_rounded_box(canvas, model->is_mac_os ? 0 : 26, y_os, model->is_mac_os ? 21 : 26, 11);
elements_slightly_rounded_box(canvas, model->is_mac_os ? x_os : x_os + 26, y_os, model->is_mac_os ? 21 : 26, 11); elements_slightly_rounded_box(
canvas, model->is_mac_os ? x_os : x_os + 26, y_os, model->is_mac_os ? 21 : 26, 11);
canvas_set_color(canvas, model->is_mac_os ? ColorWhite : ColorBlack); canvas_set_color(canvas, model->is_mac_os ? ColorWhite : ColorBlack);
elements_multiline_text_aligned(canvas, x_os + 2, y_os + 1, AlignLeft, AlignTop, "Mac"); elements_multiline_text_aligned(canvas, x_os + 2, y_os + 1, AlignLeft, AlignTop, "Mac");
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
if (model->appIndex != HidPttAppIndexFaceTime) { if(model->appIndex != HidPttAppIndexFaceTime) {
elements_multiline_text_aligned(canvas, x_os + 23, y_os + 2, AlignLeft, AlignTop, "|"); elements_multiline_text_aligned(canvas, x_os + 23, y_os + 2, AlignLeft, AlignTop, "|");
canvas_set_color(canvas, model->is_mac_os ? ColorBlack : ColorWhite); canvas_set_color(canvas, model->is_mac_os ? ColorBlack : ColorWhite);
elements_multiline_text_aligned(canvas, x_os + 28, y_os + 2, AlignLeft, AlignTop, "Linux"); elements_multiline_text_aligned(canvas, x_os + 28, y_os + 2, AlignLeft, AlignTop, "Linux");
@@ -83,7 +84,7 @@ static void hid_ptt_draw_callback(Canvas* canvas, void* context) {
const uint8_t y_mic = 102; const uint8_t y_mic = 102;
canvas_draw_icon(canvas, 19, y_mic - 1, &I_Pin_back_arrow_rotated_8x10); canvas_draw_icon(canvas, 19, y_mic - 1, &I_Pin_back_arrow_rotated_8x10);
elements_multiline_text_aligned(canvas, 0, y_mic, AlignLeft, AlignTop, "Hold to sync"); elements_multiline_text_aligned(canvas, 0, y_mic, AlignLeft, AlignTop, "Hold to sync");
elements_multiline_text_aligned(canvas, 20, y_mic+10, AlignLeft, AlignTop, "mic status"); elements_multiline_text_aligned(canvas, 20, y_mic + 10, AlignLeft, AlignTop, "mic status");
// Exit label // Exit label
canvas_draw_icon(canvas, 20, 121, &I_ButtonLeft_4x7); canvas_draw_icon(canvas, 20, 121, &I_ButtonLeft_4x7);
@@ -104,7 +105,7 @@ static void hid_ptt_draw_callback(Canvas* canvas, void* context) {
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
} }
if(model->ptt_pressed) { if(model->ptt_pressed) {
if (model->appIndex != HidPttAppIndexFaceTime) { if(model->appIndex != HidPttAppIndexFaceTime) {
elements_multiline_text_aligned(canvas, x_2 + 4, y_1 + 5, AlignLeft, AlignTop, "OS"); elements_multiline_text_aligned(canvas, x_2 + 4, y_1 + 5, AlignLeft, AlignTop, "OS");
} }
} else { } else {
@@ -125,13 +126,13 @@ static void hid_ptt_draw_callback(Canvas* canvas, void* context) {
// Left // Left
canvas_draw_icon(canvas, x_1, y_2, &I_Button_18x18); canvas_draw_icon(canvas, x_1, y_2, &I_Button_18x18);
if(model->left_pressed) { if(model->left_pressed) {
elements_slightly_rounded_box(canvas, x_1 + 3, y_2 + 2, 13, 13); elements_slightly_rounded_box(canvas, x_1 + 3, y_2 + 2, 13, 13);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
} }
if (model->ptt_pressed) { if(model->ptt_pressed) {
canvas_draw_icon(canvas, x_1 + 7, y_2 + 5, &I_ButtonLeft_4x7); canvas_draw_icon(canvas, x_1 + 7, y_2 + 5, &I_ButtonLeft_4x7);
} else { } else {
canvas_draw_icon(canvas, x_1 + 4, y_2 + 5, &I_Pin_back_arrow_10x8); canvas_draw_icon(canvas, x_1 + 4, y_2 + 5, &I_Pin_back_arrow_10x8);
} }
canvas_set_color(canvas, ColorBlack); canvas_set_color(canvas, ColorBlack);
@@ -143,7 +144,7 @@ static void hid_ptt_draw_callback(Canvas* canvas, void* context) {
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
} }
if(!model->ptt_pressed) { if(!model->ptt_pressed) {
if (model->appIndex != HidPttAppIndexFaceTime) { if(model->appIndex != HidPttAppIndexFaceTime) {
canvas_draw_icon(canvas, x_3 + 11, y_2 + 5, &I_ButtonLeft_4x7); canvas_draw_icon(canvas, x_3 + 11, y_2 + 5, &I_ButtonLeft_4x7);
canvas_draw_box(canvas, x_3 + 4, y_2 + 5, 7, 7); canvas_draw_box(canvas, x_3 + 4, y_2 + 5, 7, 7);
} }
@@ -161,8 +162,8 @@ static void hid_ptt_draw_callback(Canvas* canvas, void* context) {
} }
canvas_draw_icon(canvas, x_mic + 5, 0 + 4, &I_Mic_btn_8x10); canvas_draw_icon(canvas, x_mic + 5, 0 + 4, &I_Mic_btn_8x10);
if(model->muted && !model->ptt_pressed) { if(model->muted && !model->ptt_pressed) {
canvas_draw_line(canvas, x_mic + 3, 2 , x_mic + 3 + 13, 2 + 13); canvas_draw_line(canvas, x_mic + 3, 2, x_mic + 3 + 13, 2 + 13);
canvas_draw_line(canvas, x_mic + 2, 2 , x_mic + 2 + 13, 2 + 13); canvas_draw_line(canvas, x_mic + 2, 2, x_mic + 2 + 13, 2 + 13);
canvas_draw_line(canvas, x_mic + 3, 2 + 13, x_mic + 3 + 13, 2); canvas_draw_line(canvas, x_mic + 3, 2 + 13, x_mic + 3 + 13, 2);
canvas_draw_line(canvas, x_mic + 2, 2 + 13, x_mic + 2 + 13, 2); canvas_draw_line(canvas, x_mic + 2, 2 + 13, x_mic + 2 + 13, 2);
} }
@@ -172,102 +173,125 @@ static void hid_ptt_draw_callback(Canvas* canvas, void* context) {
const uint8_t x_ptt_margin = 4; const uint8_t x_ptt_margin = 4;
const uint8_t x_ptt_width = 17; const uint8_t x_ptt_width = 17;
const uint8_t x_ptt = x_1 + 19; const uint8_t x_ptt = x_1 + 19;
canvas_draw_icon(canvas, x_ptt , y_2 , &I_BtnFrameLeft_3x18); canvas_draw_icon(canvas, x_ptt, y_2, &I_BtnFrameLeft_3x18);
canvas_draw_icon(canvas, x_ptt + x_ptt_width + 3 + x_ptt_margin, y_2 , &I_BtnFrameRight_2x18); canvas_draw_icon(canvas, x_ptt + x_ptt_width + 3 + x_ptt_margin, y_2, &I_BtnFrameRight_2x18);
canvas_draw_line(canvas, x_ptt + 3 , y_2 , x_ptt + x_ptt_width + 2 + x_ptt_margin, y_2); canvas_draw_line(canvas, x_ptt + 3, y_2, x_ptt + x_ptt_width + 2 + x_ptt_margin, y_2);
canvas_draw_line(canvas, x_ptt + 3 , y_2 + 16, x_ptt + x_ptt_width + 2 + x_ptt_margin, y_2 + 16); canvas_draw_line(
canvas_draw_line(canvas, x_ptt + 3 , y_2 + 17, x_ptt + x_ptt_width + 2 + x_ptt_margin, y_2 + 17); canvas, x_ptt + 3, y_2 + 16, x_ptt + x_ptt_width + 2 + x_ptt_margin, y_2 + 16);
canvas_draw_line(
canvas, x_ptt + 3, y_2 + 17, x_ptt + x_ptt_width + 2 + x_ptt_margin, y_2 + 17);
if(model->ptt_pressed) { if(model->ptt_pressed) {
elements_slightly_rounded_box(canvas, x_ptt + 3, y_2 + 2, x_ptt_width + x_ptt_margin, 13); elements_slightly_rounded_box(canvas, x_ptt + 3, y_2 + 2, x_ptt_width + x_ptt_margin, 13);
canvas_set_color(canvas, ColorWhite); canvas_set_color(canvas, ColorWhite);
} }
canvas_set_font(canvas, FontPrimary); canvas_set_font(canvas, FontPrimary);
elements_multiline_text_aligned(canvas, x_ptt + 2 + x_ptt_margin / 2, y_2 + 13, AlignLeft, AlignBottom, "PTT"); elements_multiline_text_aligned(
canvas, x_ptt + 2 + x_ptt_margin / 2, y_2 + 13, AlignLeft, AlignBottom, "PTT");
canvas_set_font(canvas, FontSecondary); canvas_set_font(canvas, FontSecondary);
} }
static void hid_ptt_trigger_mute(HidPtt* hid_ptt, HidPttModel * model) { static void hid_ptt_trigger_mute(HidPtt* hid_ptt, HidPttModel* model) {
if(model->appIndex == HidPttAppIndexGoogleMeet && model->is_mac_os) { if(model->appIndex == HidPttAppIndexGoogleMeet && model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_D); hid_hal_keyboard_press(hid_ptt->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_D);
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_D ); hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_D);
} else if(model->appIndex == HidPttAppIndexGoogleMeet && !model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexGoogleMeet && !model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_D); hid_hal_keyboard_press(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_D);
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_D ); hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_D);
} else if(model->appIndex == HidPttAppIndexZoom && model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexZoom && model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_A); hid_hal_keyboard_press(
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_A ); hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_A);
hid_hal_keyboard_release(
hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_A);
} else if(model->appIndex == HidPttAppIndexFaceTime) { } else if(model->appIndex == HidPttAppIndexFaceTime) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M); hid_hal_keyboard_press(
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M ); hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
hid_hal_keyboard_release(
hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
} else if(model->appIndex == HidPttAppIndexSkype && model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexSkype && model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M); hid_hal_keyboard_press(
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M ); hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
hid_hal_keyboard_release(
hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
} else if(model->appIndex == HidPttAppIndexSkype && !model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexSkype && !model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M); hid_hal_keyboard_press(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M);
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M ); hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M);
} }
} }
static void hid_ptt_trigger_camera(HidPtt* hid_ptt, HidPttModel * model) { static void hid_ptt_trigger_camera(HidPtt* hid_ptt, HidPttModel* model) {
if(model->appIndex == HidPttAppIndexGoogleMeet && model->is_mac_os) { if(model->appIndex == HidPttAppIndexGoogleMeet && model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_E); hid_hal_keyboard_press(hid_ptt->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_E);
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_E ); hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI | HID_KEYBOARD_E);
} else if(model->appIndex == HidPttAppIndexGoogleMeet && !model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexGoogleMeet && !model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_E); hid_hal_keyboard_press(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_E);
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_E ); hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_E);
} else if(model->appIndex == HidPttAppIndexZoom && model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexZoom && model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_V); hid_hal_keyboard_press(
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_V ); hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_V);
hid_hal_keyboard_release(
hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_V);
} else if(model->appIndex == HidPttAppIndexZoom && !model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexZoom && !model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_ALT | HID_KEYBOARD_V); hid_hal_keyboard_press(hid_ptt->hid, KEY_MOD_LEFT_ALT | HID_KEYBOARD_V);
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_ALT | HID_KEYBOARD_V ); hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_ALT | HID_KEYBOARD_V);
} else if(model->appIndex == HidPttAppIndexSkype && model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexSkype && model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_K); hid_hal_keyboard_press(
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_K ); hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_K);
hid_hal_keyboard_release(
hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_K);
} else if(model->appIndex == HidPttAppIndexSkype && !model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexSkype && !model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_CTRL| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_K); hid_hal_keyboard_press(
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_CTRL| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_K ); hid_ptt->hid, KEY_MOD_LEFT_CTRL | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_K);
hid_hal_keyboard_release(
hid_ptt->hid, KEY_MOD_LEFT_CTRL | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_K);
} }
} }
static void hid_ptt_start_ptt(HidPtt* hid_ptt, HidPttModel * model) { static void hid_ptt_start_ptt(HidPtt* hid_ptt, HidPttModel* model) {
if(model->appIndex == HidPttAppIndexGoogleMeet) { if(model->appIndex == HidPttAppIndexGoogleMeet) {
hid_hal_keyboard_press(hid_ptt->hid, HID_KEYBOARD_SPACEBAR); hid_hal_keyboard_press(hid_ptt->hid, HID_KEYBOARD_SPACEBAR);
} else if(model->appIndex == HidPttAppIndexZoom) { } else if(model->appIndex == HidPttAppIndexZoom) {
hid_hal_keyboard_press(hid_ptt->hid, HID_KEYBOARD_SPACEBAR); hid_hal_keyboard_press(hid_ptt->hid, HID_KEYBOARD_SPACEBAR);
} else if(model->appIndex == HidPttAppIndexFaceTime) { } else if(model->appIndex == HidPttAppIndexFaceTime) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M); hid_hal_keyboard_press(
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M ); hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
hid_hal_keyboard_release(
hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
} else if(model->appIndex == HidPttAppIndexSkype && model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexSkype && model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M); hid_hal_keyboard_press(
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M ); hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
hid_hal_keyboard_release(
hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
} else if(model->appIndex == HidPttAppIndexSkype && !model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexSkype && !model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M); hid_hal_keyboard_press(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M);
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M ); hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M);
} }
} }
static void hid_ptt_stop_ptt(HidPtt* hid_ptt, HidPttModel * model) { static void hid_ptt_stop_ptt(HidPtt* hid_ptt, HidPttModel* model) {
if(model->appIndex == HidPttAppIndexGoogleMeet) { if(model->appIndex == HidPttAppIndexGoogleMeet) {
hid_hal_keyboard_release(hid_ptt->hid, HID_KEYBOARD_SPACEBAR); hid_hal_keyboard_release(hid_ptt->hid, HID_KEYBOARD_SPACEBAR);
} else if(model->appIndex == HidPttAppIndexZoom) { } else if(model->appIndex == HidPttAppIndexZoom) {
hid_hal_keyboard_release(hid_ptt->hid, HID_KEYBOARD_SPACEBAR); hid_hal_keyboard_release(hid_ptt->hid, HID_KEYBOARD_SPACEBAR);
} else if(model->appIndex == HidPttAppIndexFaceTime) { } else if(model->appIndex == HidPttAppIndexFaceTime) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M); hid_hal_keyboard_press(
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M ); hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
hid_hal_keyboard_release(
hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
} else if(model->appIndex == HidPttAppIndexSkype && model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexSkype && model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M); hid_hal_keyboard_press(
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_GUI| KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M ); hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
hid_hal_keyboard_release(
hid_ptt->hid, KEY_MOD_LEFT_GUI | KEY_MOD_LEFT_SHIFT | HID_KEYBOARD_M);
} else if(model->appIndex == HidPttAppIndexSkype && !model->is_mac_os) { } else if(model->appIndex == HidPttAppIndexSkype && !model->is_mac_os) {
hid_hal_keyboard_press( hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M); hid_hal_keyboard_press(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M);
hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M ); hid_hal_keyboard_release(hid_ptt->hid, KEY_MOD_LEFT_CTRL | HID_KEYBOARD_M);
} }
} }
// Supports only ±1 // Supports only ±1
static void hid_ptt_shift_app(HidPttModel * model, int shift) { static void hid_ptt_shift_app(HidPttModel* model, int shift) {
int i = (short) model->appIndex; int i = (short)model->appIndex;
if (i + shift >= HidPttAppIndexSize) { if(i + shift >= HidPttAppIndexSize) {
model->appIndex = 0; model->appIndex = 0;
} else if(i + shift <= 0) { } else if(i + shift <= 0) {
model->appIndex = HidPttAppIndexSize - 1; model->appIndex = HidPttAppIndexSize - 1;
@@ -275,7 +299,7 @@ static void hid_ptt_shift_app(HidPttModel * model, int shift) {
model->appIndex += shift; model->appIndex += shift;
} }
// Avoid showing facetime if not macos // Avoid showing facetime if not macos
if (model->appIndex == HidPttAppIndexFaceTime && !model->is_mac_os) { if(model->appIndex == HidPttAppIndexFaceTime && !model->is_mac_os) {
hid_ptt_shift_app(model, shift); hid_ptt_shift_app(model, shift);
} }
} }
@@ -288,37 +312,38 @@ static void hid_ptt_process(HidPtt* hid_ptt, InputEvent* event) {
if(event->type == InputTypePress) { if(event->type == InputTypePress) {
if(event->key == InputKeyUp) { if(event->key == InputKeyUp) {
model->up_pressed = true; model->up_pressed = true;
if (!model->ptt_pressed){ if(!model->ptt_pressed) {
hid_hal_consumer_key_press(hid_ptt->hid, HID_CONSUMER_VOLUME_INCREMENT); hid_hal_consumer_key_press(hid_ptt->hid, HID_CONSUMER_VOLUME_INCREMENT);
} else { } else {
if (model->appIndex != HidPttAppIndexFaceTime) { if(model->appIndex != HidPttAppIndexFaceTime) {
model->is_mac_os = !model->is_mac_os; model->is_mac_os = !model->is_mac_os;
notification_message(hid_ptt->hid->notifications, &sequence_single_vibro); notification_message(
hid_ptt->hid->notifications, &sequence_single_vibro);
} }
} }
} else if(event->key == InputKeyDown) { } else if(event->key == InputKeyDown) {
model->down_pressed = true; model->down_pressed = true;
if (!model->ptt_pressed){ if(!model->ptt_pressed) {
hid_hal_consumer_key_press(hid_ptt->hid, HID_CONSUMER_VOLUME_DECREMENT); hid_hal_consumer_key_press(hid_ptt->hid, HID_CONSUMER_VOLUME_DECREMENT);
} else { } else {
hid_ptt_shift_app(model, - 1); hid_ptt_shift_app(model, -1);
notification_message(hid_ptt->hid->notifications, &sequence_single_vibro); notification_message(hid_ptt->hid->notifications, &sequence_single_vibro);
} }
} else if(event->key == InputKeyLeft) { } else if(event->key == InputKeyLeft) {
model->left_pressed = true; model->left_pressed = true;
if (model->ptt_pressed){ if(model->ptt_pressed) {
hid_ptt_shift_app(model, 1); hid_ptt_shift_app(model, 1);
notification_message(hid_ptt->hid->notifications, &sequence_single_vibro); notification_message(hid_ptt->hid->notifications, &sequence_single_vibro);
} }
} else if(event->key == InputKeyRight) { } else if(event->key == InputKeyRight) {
model->right_pressed = true; model->right_pressed = true;
if (model->ptt_pressed){ if(model->ptt_pressed) {
hid_ptt_shift_app(model, - 1); hid_ptt_shift_app(model, -1);
notification_message(hid_ptt->hid->notifications, &sequence_single_vibro); notification_message(hid_ptt->hid->notifications, &sequence_single_vibro);
} }
} else if(event->key == InputKeyOk) { } else if(event->key == InputKeyOk) {
model->ptt_pressed = true; model->ptt_pressed = true;
if (model->muted) { if(model->muted) {
hid_ptt_start_ptt(hid_ptt, model); hid_ptt_start_ptt(hid_ptt, model);
} }
} else if(event->key == InputKeyBack) { } else if(event->key == InputKeyBack) {
@@ -327,12 +352,12 @@ static void hid_ptt_process(HidPtt* hid_ptt, InputEvent* event) {
} else if(event->type == InputTypeRelease) { } else if(event->type == InputTypeRelease) {
if(event->key == InputKeyUp) { if(event->key == InputKeyUp) {
model->up_pressed = false; model->up_pressed = false;
if (!model->ptt_pressed){ if(!model->ptt_pressed) {
hid_hal_consumer_key_release(hid_ptt->hid, HID_CONSUMER_VOLUME_INCREMENT); hid_hal_consumer_key_release(hid_ptt->hid, HID_CONSUMER_VOLUME_INCREMENT);
} }
} else if(event->key == InputKeyDown) { } else if(event->key == InputKeyDown) {
model->down_pressed = false; model->down_pressed = false;
if (!model->ptt_pressed){ if(!model->ptt_pressed) {
hid_hal_consumer_key_release(hid_ptt->hid, HID_CONSUMER_VOLUME_DECREMENT); hid_hal_consumer_key_release(hid_ptt->hid, HID_CONSUMER_VOLUME_DECREMENT);
} }
} else if(event->key == InputKeyLeft) { } else if(event->key == InputKeyLeft) {
@@ -342,7 +367,7 @@ static void hid_ptt_process(HidPtt* hid_ptt, InputEvent* event) {
} else if(event->key == InputKeyOk) { } else if(event->key == InputKeyOk) {
model->ptt_pressed = false; model->ptt_pressed = false;
if (model->muted) { if(model->muted) {
hid_ptt_stop_ptt(hid_ptt, model); hid_ptt_stop_ptt(hid_ptt, model);
} else { } else {
hid_ptt_trigger_mute(hid_ptt, model); hid_ptt_trigger_mute(hid_ptt, model);
@@ -352,31 +377,33 @@ static void hid_ptt_process(HidPtt* hid_ptt, InputEvent* event) {
model->mic_pressed = false; model->mic_pressed = false;
} }
} else if(event->type == InputTypeShort) { } else if(event->type == InputTypeShort) {
if(event->key == InputKeyBack && !model->ptt_pressed ) { // no changes if PTT is pressed if(event->key == InputKeyBack &&
!model->ptt_pressed) { // no changes if PTT is pressed
model->muted = !model->muted; model->muted = !model->muted;
hid_ptt_trigger_mute(hid_ptt, model); hid_ptt_trigger_mute(hid_ptt, model);
} else if(event->key == InputKeyRight) { } else if(event->key == InputKeyRight) {
if (!model->ptt_pressed){ if(!model->ptt_pressed) {
hid_ptt_trigger_camera(hid_ptt, model); hid_ptt_trigger_camera(hid_ptt, model);
} }
} }
} else if(event->type == InputTypeLong) { } else if(event->type == InputTypeLong) {
if(event->key == InputKeyLeft) { if(event->key == InputKeyLeft) {
model->left_pressed = false; model->left_pressed = false;
if (!model->ptt_pressed){ if(!model->ptt_pressed) {
hid_hal_keyboard_release_all(hid_ptt->hid); hid_hal_keyboard_release_all(hid_ptt->hid);
view_dispatcher_switch_to_view(hid_ptt->hid->view_dispatcher, HidViewSubmenu); view_dispatcher_switch_to_view(
hid_ptt->hid->view_dispatcher, HidViewSubmenu);
// sequence_double_vibro to notify that we quit PTT // sequence_double_vibro to notify that we quit PTT
notification_message(hid_ptt->hid->notifications, &sequence_double_vibro); notification_message(hid_ptt->hid->notifications, &sequence_double_vibro);
} }
} else if(event->key == InputKeyBack && !model->ptt_pressed ) { // no changes if PTT is pressed } else if(event->key == InputKeyBack && !model->ptt_pressed) { // no changes if PTT is pressed
// Change local mic status // Change local mic status
model->muted = !model->muted; model->muted = !model->muted;
notification_message(hid_ptt->hid->notifications, &sequence_single_vibro); notification_message(hid_ptt->hid->notifications, &sequence_single_vibro);
} }
} }
//LED //LED
if (model->muted && !model->ptt_pressed) { if(model->muted && !model->ptt_pressed) {
notification_message(hid_ptt->hid->notifications, &sequence_reset_red); notification_message(hid_ptt->hid->notifications, &sequence_reset_red);
} else { } else {
notification_message(hid_ptt->hid->notifications, &sequence_set_red_255); notification_message(hid_ptt->hid->notifications, &sequence_set_red_255);
@@ -404,11 +431,14 @@ HidPtt* hid_ptt_alloc(Hid* hid) {
view_set_orientation(hid_ptt->view, ViewOrientationVerticalFlip); view_set_orientation(hid_ptt->view, ViewOrientationVerticalFlip);
with_view_model( with_view_model(
hid_ptt->view, HidPttModel * model, { hid_ptt->view,
HidPttModel * model,
{
model->transport = hid->transport; model->transport = hid->transport;
model->muted = true; // assume we're muted model->muted = true; // assume we're muted
model->is_mac_os = true; model->is_mac_os = true;
}, true); },
true);
return hid_ptt; return hid_ptt;
} }