Skip to content

Commit

Permalink
Updated for upstream flipperzero 0.69. Nice.
Browse files Browse the repository at this point in the history
  • Loading branch information
litui committed Oct 16, 2022
1 parent a2b5ccc commit 90cc9b0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 28 deletions.
2 changes: 2 additions & 0 deletions application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ App(
entry_point="dtmf_dolphin_app",
cdefines=["DTMF_DOLPHIN"],
requires=[
"storage",
"gui",
"dialogs",
],
stack_size=8 * 1024,
order=20,
fap_category="Tools",
)
68 changes: 40 additions & 28 deletions views/dtmf_dolphin_dialer.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,26 @@ static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) {

draw_dialer(canvas, model);

string_t output;
string_init(output);
FuriString *output = furi_string_alloc();

if (model->freq1 && model->freq2) {
string_cat_printf(
furi_string_cat_printf(
output,
"Dual Tone\nF1: %u Hz\nF2: %u Hz\n",
(unsigned int) model->freq1,
(unsigned int) model->freq2);
} else if (model->freq1) {
string_cat_printf(
furi_string_cat_printf(
output,
"Single Tone\nF: %u Hz\n",
(unsigned int) model->freq1);
}

canvas_set_font(canvas, FontSecondary);
canvas_set_color(canvas, ColorBlack);
elements_multiline_text(canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 21, string_get_cstr(output));
elements_multiline_text(canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 21, furi_string_get_cstr(output));

string_clear(output);
furi_string_free(output);
}

static bool dtmf_dolphin_dialer_input_callback(InputEvent* event, void* context) {
Expand Down Expand Up @@ -175,7 +174,9 @@ static bool dtmf_dolphin_dialer_input_callback(InputEvent* event, void* context)

static bool dtmf_dolphin_dialer_process_up(DTMFDolphinDialer* dtmf_dolphin_dialer) {
with_view_model(
dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) {
dtmf_dolphin_dialer->view,
DTMFDolphinDialerModel * model,
{
uint8_t span = 0;
uint8_t cursor = model->row;
while (span == 0 && cursor > 0) {
Expand All @@ -185,8 +186,8 @@ static bool dtmf_dolphin_dialer_process_up(DTMFDolphinDialer* dtmf_dolphin_diale
if (span != 0) {
model->row = cursor;
}
return true;
});
},
true);
return true;
}

Expand All @@ -197,7 +198,9 @@ static bool dtmf_dolphin_dialer_process_down(DTMFDolphinDialer* dtmf_dolphin_dia
dtmf_dolphin_tone_get_max_pos(&max_rows, &max_cols, &max_span);

with_view_model(
dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) {
dtmf_dolphin_dialer->view,
DTMFDolphinDialerModel * model,
{
uint8_t span = 0;
uint8_t cursor = model->row;
while(span == 0 && cursor < max_rows - 1) {
Expand All @@ -207,14 +210,16 @@ static bool dtmf_dolphin_dialer_process_down(DTMFDolphinDialer* dtmf_dolphin_dia
if (span != 0) {
model->row = cursor;
}
return true;
});
},
true);
return true;
}

static bool dtmf_dolphin_dialer_process_left(DTMFDolphinDialer* dtmf_dolphin_dialer) {
with_view_model(
dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) {
dtmf_dolphin_dialer->view,
DTMFDolphinDialerModel * model,
{
uint8_t span = 0;
uint8_t cursor = model->col;
while (span == 0 && cursor > 0) {
Expand All @@ -224,8 +229,8 @@ static bool dtmf_dolphin_dialer_process_left(DTMFDolphinDialer* dtmf_dolphin_dia
if (span != 0) {
model->col = cursor;
}
return true;
});
},
true);
return true;
}

Expand All @@ -236,7 +241,9 @@ static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_di
dtmf_dolphin_tone_get_max_pos(&max_rows, &max_cols, &max_span);

with_view_model(
dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) {
dtmf_dolphin_dialer->view,
DTMFDolphinDialerModel * model,
{
uint8_t span = 0;
uint8_t cursor = model->col;
while(span == 0 && cursor < max_cols - 1) {
Expand All @@ -246,24 +253,25 @@ static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_di
if (span != 0) {
model->col = cursor;
}
return true;
});
},
true);
return true;
}

static bool dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event) {
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);
} else if (event->type == InputTypeRelease) {
model->playing = !dtmf_dolphin_audio_stop_tones();
}

return true;
});
},
true);

return consumed;
}
Expand All @@ -273,15 +281,17 @@ static void dtmf_dolphin_dialer_enter_callback(void* context) {
DTMFDolphinDialer* dtmf_dolphin_dialer = context;

with_view_model(
dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) {
dtmf_dolphin_dialer->view,
DTMFDolphinDialerModel * model,
{
model->col = 0;
model->row = 0;
model->section = 0;
model->freq1 = 0.0;
model->freq2 = 0.0;
model->playing = false;
return true;
}
},
true
);
}

Expand All @@ -292,15 +302,17 @@ DTMFDolphinDialer* dtmf_dolphin_dialer_alloc() {
view_allocate_model(dtmf_dolphin_dialer->view, ViewModelTypeLocking, sizeof(DTMFDolphinDialerModel));

with_view_model(
dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) {
dtmf_dolphin_dialer->view,
DTMFDolphinDialerModel * model,
{
model->col = 0;
model->row = 0;
model->section = 0;
model->freq1 = 0.0;
model->freq2 = 0.0;
model->playing = false;
return true;
}
},
true
);

view_set_context(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer);
Expand Down

0 comments on commit 90cc9b0

Please sign in to comment.