This commit is contained in:
RogueMaster
2022-10-12 00:18:03 -04:00
parent 60a9f61bb7
commit 778ba72707
8 changed files with 224 additions and 119 deletions
+4 -2
View File
@@ -150,12 +150,14 @@ static void render_callback(Canvas* const canvas, void* ctx) {
furi_string_reset(tempStr);
furi_string_printf(tempStr, "x2 %.2f /2 %.2f", bpm_state->bpm * 2, bpm_state->bpm / 2);
canvas_draw_str_aligned(canvas, 64, 60, AlignCenter, AlignCenter, furi_string_get_cstr(tempStr));
canvas_draw_str_aligned(
canvas, 64, 60, AlignCenter, AlignCenter, furi_string_get_cstr(tempStr));
furi_string_reset(tempStr);
furi_string_printf(tempStr, "%.2f", bpm_state->bpm);
canvas_set_font(canvas, FontBigNumbers);
canvas_draw_str_aligned(canvas, 64, 40, AlignCenter, AlignCenter, furi_string_get_cstr(tempStr));
canvas_draw_str_aligned(
canvas, 64, 40, AlignCenter, AlignCenter, furi_string_get_cstr(tempStr));
furi_string_reset(tempStr);
furi_string_free(tempStr);
@@ -21,126 +21,127 @@ typedef struct {
} PluginEvent;
typedef struct {
ViewDispatcher* view_dispatcher;
TextInput* text_input;
TextBox* text_box;
char input[TEXT_BUFFER_SIZE];
char output[(TEXT_BUFFER_SIZE*26) + (26)]; // linebreaks
ViewDispatcher* view_dispatcher;
TextInput* text_input;
TextBox* text_box;
char input[TEXT_BUFFER_SIZE];
char output[(TEXT_BUFFER_SIZE * 26) + (26)]; // linebreaks
} CaesarState;
static void string_to_uppercase(char* input) {
int i;
for (i=0; input[i] != '\0'; i++) {
if (input[i] >= 'a' && input[i] <= 'z') {
input[i] = input[i] - 32;
} else {
input[i] = input[i];
int i;
for(i = 0; input[i] != '\0'; i++) {
if(input[i] >= 'a' && input[i] <= 'z') {
input[i] = input[i] - 32;
} else {
input[i] = input[i];
}
}
}
}
static void build_output(char* input, char* output) {
int out = 0;
for ( int rot = 1; rot < 26; rot++) {
int in;
for(in = 0; input[in] != '\0'; in++){
if (input[in] >= 'A' && input[in] <= 'Z') {
output[out] = 65 + ( ((input[in] - 65) + rot ) % 26);
} else {
output[out] = input[in];
}
out++;
int out = 0;
for(int rot = 1; rot < 26; rot++) {
int in;
for(in = 0; input[in] != '\0'; in++) {
if(input[in] >= 'A' && input[in] <= 'Z') {
output[out] = 65 + (((input[in] - 65) + rot) % 26);
} else {
output[out] = input[in];
}
out++;
}
output[out] = '\n';
out++;
}
output[out]= '\n';
out++;
}
output[out]='\0';
output[out] = '\0';
}
static void text_input_callback(void* ctx) {
CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25);
FURI_LOG_D("caesar_cipher", "Input text: %s", caesar_state->input);
// this is where we build the output.
string_to_uppercase(caesar_state->input);
FURI_LOG_D("caesar_cipher", "Upper text: %s", caesar_state->input);
build_output(caesar_state->input, caesar_state->output);
text_box_set_text(caesar_state->text_box, caesar_state->output);
view_dispatcher_switch_to_view(caesar_state->view_dispatcher, 1);
CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25);
FURI_LOG_D("caesar_cipher", "Input text: %s", caesar_state->input);
// this is where we build the output.
string_to_uppercase(caesar_state->input);
FURI_LOG_D("caesar_cipher", "Upper text: %s", caesar_state->input);
build_output(caesar_state->input, caesar_state->output);
text_box_set_text(caesar_state->text_box, caesar_state->output);
view_dispatcher_switch_to_view(caesar_state->view_dispatcher, 1);
release_mutex((ValueMutex*)ctx, caesar_state);
release_mutex((ValueMutex*)ctx, caesar_state);
}
static bool back_event_callback(void* ctx) {
const CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25);
view_dispatcher_stop(caesar_state->view_dispatcher);
release_mutex((ValueMutex*)ctx, caesar_state);
return true;
const CaesarState* caesar_state = acquire_mutex((ValueMutex*)ctx, 25);
view_dispatcher_stop(caesar_state->view_dispatcher);
release_mutex((ValueMutex*)ctx, caesar_state);
return true;
}
static void caesar_cipher_state_init(CaesarState* const caesar_state) {
caesar_state->view_dispatcher = view_dispatcher_alloc();
caesar_state->text_input = text_input_alloc();
caesar_state->text_box = text_box_alloc();
text_box_set_font(caesar_state->text_box, TextBoxFontText);
caesar_state->view_dispatcher = view_dispatcher_alloc();
caesar_state->text_input = text_input_alloc();
caesar_state->text_box = text_box_alloc();
text_box_set_font(caesar_state->text_box, TextBoxFontText);
}
static void caesar_cipher_state_free(CaesarState* const caesar_state) {
text_input_free(caesar_state->text_input);
text_box_free(caesar_state->text_box);
view_dispatcher_remove_view(caesar_state->view_dispatcher, 0);
view_dispatcher_remove_view(caesar_state->view_dispatcher, 1);
view_dispatcher_free(caesar_state->view_dispatcher);
free(caesar_state);
text_input_free(caesar_state->text_input);
text_box_free(caesar_state->text_box);
view_dispatcher_remove_view(caesar_state->view_dispatcher, 0);
view_dispatcher_remove_view(caesar_state->view_dispatcher, 1);
view_dispatcher_free(caesar_state->view_dispatcher);
free(caesar_state);
}
int32_t caesar_cipher_app() {
CaesarState* caesar_state = malloc(sizeof(CaesarState));
CaesarState* caesar_state = malloc(sizeof(CaesarState));
FURI_LOG_D("caesar_cipher", "Running caesar_cipher_state_init");
caesar_cipher_state_init(caesar_state);
FURI_LOG_D("caesar_cipher", "Running caesar_cipher_state_init");
caesar_cipher_state_init(caesar_state);
ValueMutex state_mutex;
if(!init_mutex(&state_mutex, caesar_state, sizeof(CaesarState))) {
FURI_LOG_E("caesar_cipher", "cannot create mutex\r\n");
free(caesar_state);
return 255;
}
ValueMutex state_mutex;
if(!init_mutex(&state_mutex, caesar_state, sizeof(CaesarState))) {
FURI_LOG_E("caesar_cipher", "cannot create mutex\r\n");
free(caesar_state);
return 255;
}
FURI_LOG_D("caesar_cipher", "Assigning text input callback");
text_input_set_result_callback(
caesar_state->text_input,
text_input_callback,
&state_mutex,
caesar_state->input,
TEXT_BUFFER_SIZE,
//clear default text
true
);
text_input_set_header_text(caesar_state->text_input, "Input");
FURI_LOG_D("caesar_cipher", "Assigning text input callback");
text_input_set_result_callback(
caesar_state->text_input,
text_input_callback,
&state_mutex,
caesar_state->input,
TEXT_BUFFER_SIZE,
//clear default text
true);
text_input_set_header_text(caesar_state->text_input, "Input");
// Open GUI and register view_port
Gui* gui = furi_record_open("gui");
//gui_add_view_port(gui, view_port, GuiLayerFullscreen);
FURI_LOG_D("caesar_cipher", "Enabling view dispatcher queue");
view_dispatcher_enable_queue(caesar_state->view_dispatcher);
// Open GUI and register view_port
Gui* gui = furi_record_open("gui");
//gui_add_view_port(gui, view_port, GuiLayerFullscreen);
FURI_LOG_D("caesar_cipher", "Adding text input view to dispatcher");
view_dispatcher_add_view(caesar_state->view_dispatcher, 0, text_input_get_view(caesar_state->text_input));
view_dispatcher_add_view(caesar_state->view_dispatcher, 1, text_box_get_view(caesar_state->text_box));
FURI_LOG_D("caesar_cipher", "Attaching view dispatcher to GUI");
view_dispatcher_attach_to_gui(caesar_state->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
FURI_LOG_D("ceasar_cipher", "starting view dispatcher");
view_dispatcher_set_navigation_event_callback(caesar_state->view_dispatcher, back_event_callback);
view_dispatcher_set_event_callback_context(caesar_state->view_dispatcher, &state_mutex);
view_dispatcher_switch_to_view(caesar_state->view_dispatcher, 0);
view_dispatcher_run(caesar_state->view_dispatcher);
FURI_LOG_D("caesar_cipher", "Enabling view dispatcher queue");
view_dispatcher_enable_queue(caesar_state->view_dispatcher);
furi_record_close("gui");
delete_mutex(&state_mutex);
caesar_cipher_state_free(caesar_state);
FURI_LOG_D("caesar_cipher", "Adding text input view to dispatcher");
view_dispatcher_add_view(
caesar_state->view_dispatcher, 0, text_input_get_view(caesar_state->text_input));
view_dispatcher_add_view(
caesar_state->view_dispatcher, 1, text_box_get_view(caesar_state->text_box));
FURI_LOG_D("caesar_cipher", "Attaching view dispatcher to GUI");
view_dispatcher_attach_to_gui(
caesar_state->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
FURI_LOG_D("ceasar_cipher", "starting view dispatcher");
view_dispatcher_set_navigation_event_callback(
caesar_state->view_dispatcher, back_event_callback);
view_dispatcher_set_event_callback_context(caesar_state->view_dispatcher, &state_mutex);
view_dispatcher_switch_to_view(caesar_state->view_dispatcher, 0);
view_dispatcher_run(caesar_state->view_dispatcher);
return 0;
furi_record_close("gui");
delete_mutex(&state_mutex);
caesar_cipher_state_free(caesar_state);
return 0;
}
@@ -40,13 +40,16 @@ bool storage_DolphinBackup_perform(void) {
for(uint32_t i = 0; i < COUNT_OF(app_dirsDolphinBackup); i++) {
if(i > 5) {
furi_string_printf(path_src, "%s/%s", MOVE_SRC, app_dirsDolphinBackup[i]);
furi_string_printf(path_dst, "%s/dolphin_restorer/%s", MOVE_DST, app_dirsDolphinBackup[i]);
furi_string_printf(
path_dst, "%s/dolphin_restorer/%s", MOVE_DST, app_dirsDolphinBackup[i]);
storage_simply_remove_recursive(storage, furi_string_get_cstr(path_dst));
storage_common_copy(storage, furi_string_get_cstr(path_src), furi_string_get_cstr(path_dst));
storage_common_copy(
storage, furi_string_get_cstr(path_src), furi_string_get_cstr(path_dst));
} else {
furi_string_printf(path_src, "%s/%s", MOVE_SRC, app_dirsDolphinBackup[i]);
furi_string_printf(path_dst, "%s/%s", MOVE_DST, app_dirsDolphinBackup[i]);
storage_common_merge(storage, furi_string_get_cstr(path_src), furi_string_get_cstr(path_dst));
storage_common_merge(
storage, furi_string_get_cstr(path_src), furi_string_get_cstr(path_dst));
storage_simply_remove_recursive(storage, furi_string_get_cstr(path_src));
}
}
@@ -30,7 +30,8 @@ bool drestorer_perform(void) {
furi_string_printf(path_src, "%s/%s", MOVE_SRC, app_dirs[i]);
furi_string_printf(path_dst, "%s/%s", MOVE_DST, app_dirs[i]);
storage_simply_remove_recursive(storage, furi_string_get_cstr(path_dst));
storage_common_copy(storage, furi_string_get_cstr(path_src), furi_string_get_cstr(path_dst));
storage_common_copy(
storage, furi_string_get_cstr(path_src), furi_string_get_cstr(path_dst));
}
furi_string_free(path_src);
@@ -191,7 +191,7 @@ static bool dtmf_dolphin_dialer_process_up(DTMFDolphinDialer* dtmf_dolphin_diale
if(span != 0) {
model->row = cursor;
}
},
},
true);
return true;
}
@@ -268,8 +268,8 @@ static bool
bool consumed = false;
with_view_model(
dtmf_dolphin_dialer->view,
DTMFDolphinDialerModel * model,
dtmf_dolphin_dialer->view,
DTMFDolphinDialerModel * model,
{
if(event->type == InputTypePress) {
model->playing = dtmf_dolphin_audio_play_tones(model->freq1, model->freq2);
@@ -287,7 +287,7 @@ static void dtmf_dolphin_dialer_enter_callback(void* context) {
DTMFDolphinDialer* dtmf_dolphin_dialer = context;
with_view_model(
dtmf_dolphin_dialer->view,
dtmf_dolphin_dialer->view,
DTMFDolphinDialerModel * model,
{
model->col = 0;
@@ -309,8 +309,8 @@ DTMFDolphinDialer* dtmf_dolphin_dialer_alloc() {
with_view_model(
dtmf_dolphin_dialer->view,
DTMFDolphinDialerModel * model
,{
DTMFDolphinDialerModel * model,
{
model->col = 0;
model->row = 0;
model->section = 0;
+6 -3
View File
@@ -65,14 +65,17 @@ static void render_callback(Canvas* const canvas, void* ctx) {
canvas_set_font(canvas, FontPrimary);
// draw bars/beat
furi_string_printf(tempStr, "%d/%d", metronome_state->beats_per_bar, metronome_state->note_length);
canvas_draw_str_aligned(canvas, 64, 8, AlignCenter, AlignCenter, furi_string_get_cstr(tempStr));
furi_string_printf(
tempStr, "%d/%d", metronome_state->beats_per_bar, metronome_state->note_length);
canvas_draw_str_aligned(
canvas, 64, 8, AlignCenter, AlignCenter, furi_string_get_cstr(tempStr));
furi_string_reset(tempStr);
// draw BPM value
furi_string_printf(tempStr, "%.2f", metronome_state->bpm);
canvas_set_font(canvas, FontBigNumbers);
canvas_draw_str_aligned(canvas, 64, 24, AlignCenter, AlignCenter, furi_string_get_cstr(tempStr));
canvas_draw_str_aligned(
canvas, 64, 24, AlignCenter, AlignCenter, furi_string_get_cstr(tempStr));
furi_string_reset(tempStr);
// draw volume indicator
+108 -12
View File
@@ -1,48 +1,144 @@
#define tile_0_width 8
#define tile_0_height 8
static uint8_t tile_0_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
};
#define tile_1_width 8
#define tile_1_height 8
static uint8_t tile_1_bits[] = {
0x00, 0x10, 0x18, 0x10, 0x10, 0x10, 0x10, 0x00, };
0x00,
0x10,
0x18,
0x10,
0x10,
0x10,
0x10,
0x00,
};
#define tile_2_width 8
#define tile_2_height 8
static uint8_t tile_2_bits[] = {
0x00, 0x1C, 0x20, 0x20, 0x18, 0x04, 0x3C, 0x00, };
0x00,
0x1C,
0x20,
0x20,
0x18,
0x04,
0x3C,
0x00,
};
#define tile_3_width 8
#define tile_3_height 8
static uint8_t tile_3_bits[] = {
0x00, 0x1C, 0x20, 0x20, 0x18, 0x20, 0x1C, 0x00, };
0x00,
0x1C,
0x20,
0x20,
0x18,
0x20,
0x1C,
0x00,
};
#define tile_4_width 8
#define tile_4_height 8
static uint8_t tile_4_bits[] = {
0x00, 0x04, 0x14, 0x14, 0x3C, 0x10, 0x10, 0x00, };
0x00,
0x04,
0x14,
0x14,
0x3C,
0x10,
0x10,
0x00,
};
#define tile_5_width 8
#define tile_5_height 8
static uint8_t tile_5_bits[] = {
0x00, 0x3C, 0x04, 0x1C, 0x20, 0x20, 0x1C, 0x00, };
0x00,
0x3C,
0x04,
0x1C,
0x20,
0x20,
0x1C,
0x00,
};
#define tile_6_width 8
#define tile_6_height 8
static uint8_t tile_6_bits[] = {
0x00, 0x18, 0x24, 0x04, 0x1C, 0x24, 0x18, 0x00, };
0x00,
0x18,
0x24,
0x04,
0x1C,
0x24,
0x18,
0x00,
};
#define tile_7_width 8
#define tile_7_height 8
static uint8_t tile_7_bits[] = {
0x00, 0x3C, 0x20, 0x20, 0x10, 0x08, 0x08, 0x00, };
0x00,
0x3C,
0x20,
0x20,
0x10,
0x08,
0x08,
0x00,
};
#define tile_8_width 8
#define tile_8_height 8
static uint8_t tile_8_bits[] = {
0x00, 0x18, 0x24, 0x18, 0x24, 0x24, 0x18, 0x00, };
0x00,
0x18,
0x24,
0x18,
0x24,
0x24,
0x18,
0x00,
};
#define tile_flag_width 8
#define tile_flag_height 8
static uint8_t tile_flag_bits[] = {
0xFF, 0x81, 0xB9, 0x89, 0x89, 0x9D, 0x81, 0xFF, };
0xFF,
0x81,
0xB9,
0x89,
0x89,
0x9D,
0x81,
0xFF,
};
#define tile_mine_width 8
#define tile_mine_height 8
static uint8_t tile_mine_bits[] = {
0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, };
0x55,
0xAA,
0x55,
0xAA,
0x55,
0xAA,
0x55,
0xAA,
};
#define tile_uncleared_width 8
#define tile_uncleared_height 8
static uint8_t tile_uncleared_bits[] = {
0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF, };
0xFF,
0x81,
0x81,
0x81,
0x81,
0x81,
0x81,
0xFF,
};
@@ -241,7 +241,6 @@ static uint8_t usb_hid_keyboard_get_selected_key(UsbHidKeyboardModel* model) {
return key.value;
}
static void
usb_hid_keyboard_get_select_key(UsbHidKeyboardModel* model, UsbHidKeyboardPoint delta) {
// Keep going until a valid spot is found, this allows for nulls and zero width keys in the map