./fbt format

This commit is contained in:
RogueMaster
2022-09-21 14:28:03 -04:00
parent 3f3258d9f3
commit 32e18d5500
37 changed files with 2764 additions and 2572 deletions
@@ -7,4 +7,4 @@
#define DTMF_DOLPHIN_NUMPAD_Y 14
#define DTMF_DOLPHIN_BUTTON_WIDTH 13
#define DTMF_DOLPHIN_BUTTON_HEIGHT 13
#define DTMF_DOLPHIN_BUTTON_PADDING 1 // all sides
#define DTMF_DOLPHIN_BUTTON_PADDING 1 // all sides
@@ -21,53 +21,55 @@ static bool dtmf_dolphin_dialer_process_up(DTMFDolphinDialer* dtmf_dolphin_diale
static bool dtmf_dolphin_dialer_process_down(DTMFDolphinDialer* dtmf_dolphin_dialer);
static bool dtmf_dolphin_dialer_process_left(DTMFDolphinDialer* dtmf_dolphin_dialer);
static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_dialer);
static bool dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event);
static bool
dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event);
void draw_button(Canvas* canvas, uint8_t row, uint8_t col, bool invert) {
uint8_t left = DTMF_DOLPHIN_NUMPAD_X + \
// ((col + 1) * DTMF_DOLPHIN_BUTTON_PADDING) +
(col * DTMF_DOLPHIN_BUTTON_WIDTH);
// (col * DTMF_DOLPHIN_BUTTON_PADDING);
uint8_t top = DTMF_DOLPHIN_NUMPAD_Y + \
// ((row + 1) * DTMF_DOLPHIN_BUTTON_PADDING) +
(row * DTMF_DOLPHIN_BUTTON_HEIGHT);
// (row * DTMF_DOLPHIN_BUTTON_PADDING);
uint8_t left = DTMF_DOLPHIN_NUMPAD_X + // ((col + 1) * DTMF_DOLPHIN_BUTTON_PADDING) +
(col * DTMF_DOLPHIN_BUTTON_WIDTH);
// (col * DTMF_DOLPHIN_BUTTON_PADDING);
uint8_t top = DTMF_DOLPHIN_NUMPAD_Y + // ((row + 1) * DTMF_DOLPHIN_BUTTON_PADDING) +
(row * DTMF_DOLPHIN_BUTTON_HEIGHT);
// (row * DTMF_DOLPHIN_BUTTON_PADDING);
uint8_t span = dtmf_dolphin_get_tone_span(row, col);
if (span == 0) {
if(span == 0) {
return;
}
canvas_set_color(canvas, ColorBlack);
if (invert)
canvas_draw_rbox(canvas, left, top,
if(invert)
canvas_draw_rbox(
canvas,
left,
top,
(DTMF_DOLPHIN_BUTTON_WIDTH * span) - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
DTMF_DOLPHIN_BUTTON_HEIGHT - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
2);
else
canvas_draw_rframe(canvas, left, top,
canvas_draw_rframe(
canvas,
left,
top,
(DTMF_DOLPHIN_BUTTON_WIDTH * span) - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
DTMF_DOLPHIN_BUTTON_HEIGHT- (DTMF_DOLPHIN_BUTTON_PADDING * 2),
DTMF_DOLPHIN_BUTTON_HEIGHT - (DTMF_DOLPHIN_BUTTON_PADDING * 2),
2);
if (invert)
canvas_invert_color(canvas);
if(invert) canvas_invert_color(canvas);
canvas_set_font(canvas, FontSecondary);
// canvas_set_color(canvas, invert ? ColorWhite : ColorBlack);
canvas_draw_str_aligned(canvas,
left - 1 + (int) ((DTMF_DOLPHIN_BUTTON_WIDTH * span) / 2),
top + (int) (DTMF_DOLPHIN_BUTTON_HEIGHT / 2),
canvas_draw_str_aligned(
canvas,
left - 1 + (int)((DTMF_DOLPHIN_BUTTON_WIDTH * span) / 2),
top + (int)(DTMF_DOLPHIN_BUTTON_HEIGHT / 2),
AlignCenter,
AlignCenter,
dtmf_dolphin_data_get_tone_name(row, col));
if (invert)
canvas_invert_color(canvas);
if(invert) canvas_invert_color(canvas);
}
void draw_dialer(Canvas* canvas, void* _model) {
@@ -79,9 +81,9 @@ void draw_dialer(Canvas* canvas, void* _model) {
canvas_set_font(canvas, FontSecondary);
for (int r = 0; r < max_rows; r++) {
for (int c = 0; c < max_cols; c++) {
if (model->row == r && model->col == c)
for(int r = 0; r < max_rows; r++) {
for(int c = 0; c < max_cols; c++) {
if(model->row == r && model->col == c)
draw_button(canvas, r, c, true);
else
draw_button(canvas, r, c, false);
@@ -89,20 +91,20 @@ void draw_dialer(Canvas* canvas, void* _model) {
}
}
void update_frequencies(DTMFDolphinDialerModel *model) {
void update_frequencies(DTMFDolphinDialerModel* model) {
dtmf_dolphin_data_get_tone_frequencies(&model->freq1, &model->freq2, model->row, model->col);
}
static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) {
DTMFDolphinDialerModel* model = _model;
if (model->playing) {
if(model->playing) {
// Leverage the prioritized draw callback to handle
// the DMA so that it doesn't skip.
dtmf_dolphin_audio_handle_tick();
// Don't do any drawing if audio is playing.
canvas_set_font(canvas, FontPrimary);
elements_multiline_text_aligned(
canvas,
canvas,
canvas_width(canvas) / 2,
canvas_height(canvas) / 2,
AlignCenter,
@@ -118,11 +120,15 @@ static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) {
canvas_set_font(canvas, FontPrimary);
elements_multiline_text(canvas, 2, 10, dtmf_dolphin_data_get_current_section_name());
canvas_draw_line(canvas,
(max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1, 0,
(max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1, canvas_height(canvas));
canvas_draw_line(
canvas,
(max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1,
0,
(max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 1,
canvas_height(canvas));
elements_multiline_text(canvas, (max_span * DTMF_DOLPHIN_BUTTON_WIDTH) + 4, 10, "Detail");
canvas_draw_line(canvas, 0, DTMF_DOLPHIN_NUMPAD_Y - 3, canvas_width(canvas), DTMF_DOLPHIN_NUMPAD_Y - 3);
canvas_draw_line(
canvas, 0, DTMF_DOLPHIN_NUMPAD_Y - 3, canvas_width(canvas), DTMF_DOLPHIN_NUMPAD_Y - 3);
// elements_multiline_text_aligned(canvas, 64, 2, AlignCenter, AlignTop, "Dialer Mode");
draw_dialer(canvas, model);
@@ -130,22 +136,20 @@ static void dtmf_dolphin_dialer_draw_callback(Canvas* canvas, void* _model) {
string_t output;
string_init(output);
if (model->freq1 && model->freq2) {
if(model->freq1 && model->freq2) {
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(
output,
"Single Tone\nF: %u Hz\n",
(unsigned int) model->freq1);
(unsigned int)model->freq1,
(unsigned int)model->freq2);
} else if(model->freq1) {
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, string_get_cstr(output));
string_clear(output);
}
@@ -178,11 +182,11 @@ static bool dtmf_dolphin_dialer_process_up(DTMFDolphinDialer* dtmf_dolphin_diale
dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) {
uint8_t span = 0;
uint8_t cursor = model->row;
while (span == 0 && cursor > 0) {
while(span == 0 && cursor > 0) {
cursor--;
span = dtmf_dolphin_get_tone_span(cursor, model->col);
}
if (span != 0) {
if(span != 0) {
model->row = cursor;
}
return true;
@@ -204,7 +208,7 @@ static bool dtmf_dolphin_dialer_process_down(DTMFDolphinDialer* dtmf_dolphin_dia
cursor++;
span = dtmf_dolphin_get_tone_span(cursor, model->col);
}
if (span != 0) {
if(span != 0) {
model->row = cursor;
}
return true;
@@ -217,11 +221,11 @@ static bool dtmf_dolphin_dialer_process_left(DTMFDolphinDialer* dtmf_dolphin_dia
dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) {
uint8_t span = 0;
uint8_t cursor = model->col;
while (span == 0 && cursor > 0) {
while(span == 0 && cursor > 0) {
cursor--;
span = dtmf_dolphin_get_tone_span(model->row, cursor);
}
if (span != 0) {
if(span != 0) {
model->col = cursor;
}
return true;
@@ -243,7 +247,7 @@ static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_di
cursor++;
span = dtmf_dolphin_get_tone_span(model->row, cursor);
}
if (span != 0) {
if(span != 0) {
model->col = cursor;
}
return true;
@@ -251,14 +255,15 @@ static bool dtmf_dolphin_dialer_process_right(DTMFDolphinDialer* dtmf_dolphin_di
return true;
}
static bool dtmf_dolphin_dialer_process_ok(DTMFDolphinDialer* dtmf_dolphin_dialer, InputEvent* event) {
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) {
if (event->type == InputTypePress) {
if(event->type == InputTypePress) {
model->playing = dtmf_dolphin_audio_play_tones(model->freq1, model->freq2);
} else if (event->type == InputTypeRelease) {
} else if(event->type == InputTypeRelease) {
model->playing = !dtmf_dolphin_audio_stop_tones();
}
@@ -281,15 +286,15 @@ static void dtmf_dolphin_dialer_enter_callback(void* context) {
model->freq2 = 0.0;
model->playing = false;
return true;
}
);
});
}
DTMFDolphinDialer* dtmf_dolphin_dialer_alloc() {
DTMFDolphinDialer* dtmf_dolphin_dialer = malloc(sizeof(DTMFDolphinDialer));
dtmf_dolphin_dialer->view = view_alloc();
view_allocate_model(dtmf_dolphin_dialer->view, ViewModelTypeLocking, sizeof(DTMFDolphinDialerModel));
view_allocate_model(
dtmf_dolphin_dialer->view, ViewModelTypeLocking, sizeof(DTMFDolphinDialerModel));
with_view_model(
dtmf_dolphin_dialer->view, (DTMFDolphinDialerModel * model) {
@@ -300,8 +305,7 @@ DTMFDolphinDialer* dtmf_dolphin_dialer_alloc() {
model->freq2 = 0.0;
model->playing = false;
return true;
}
);
});
view_set_context(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer);
view_set_draw_callback(dtmf_dolphin_dialer->view, dtmf_dolphin_dialer_draw_callback);
@@ -320,4 +324,3 @@ View* dtmf_dolphin_dialer_get_view(DTMFDolphinDialer* dtmf_dolphin_dialer) {
furi_assert(dtmf_dolphin_dialer);
return dtmf_dolphin_dialer->view;
}
@@ -12,4 +12,7 @@ void dtmf_dolphin_dialer_free(DTMFDolphinDialer* dtmf_dolphin_dialer);
View* dtmf_dolphin_dialer_get_view(DTMFDolphinDialer* dtmf_dolphin_dialer);
void dtmf_dolphin_dialer_set_ok_callback(DTMFDolphinDialer* dtmf_dolphin_dialer, DTMFDolphinDialerOkCallback callback, void* context);
void dtmf_dolphin_dialer_set_ok_callback(
DTMFDolphinDialer* dtmf_dolphin_dialer,
DTMFDolphinDialerOkCallback callback,
void* context);