mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-20 04:54:45 -07:00
formatted, attempt to fix rfid fuzzer crash
crash doesn’t fixed with this commit
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
App(
|
App(
|
||||||
appid="flipfrid",
|
appid="flipfrid",
|
||||||
name="Rfid Fuzzer",
|
name="RFID Fuzzer",
|
||||||
apptype=FlipperAppType.PLUGIN,
|
apptype=FlipperAppType.PLUGIN,
|
||||||
entry_point="flipfrid_start",
|
entry_point="flipfrid_start",
|
||||||
cdefines=["APP_FLIP_FRID"],
|
cdefines=["APP_FLIP_FRID"],
|
||||||
|
|||||||
@@ -114,7 +114,10 @@ int32_t flipfrid_start(void* p) {
|
|||||||
if(!init_mutex(&flipfrid_state_mutex, flipfrid_state, sizeof(FlipFridState))) {
|
if(!init_mutex(&flipfrid_state_mutex, flipfrid_state, sizeof(FlipFridState))) {
|
||||||
FURI_LOG_E(TAG, "cannot create mutex\r\n");
|
FURI_LOG_E(TAG, "cannot create mutex\r\n");
|
||||||
furi_message_queue_free(event_queue);
|
furi_message_queue_free(event_queue);
|
||||||
|
furi_record_close(RECORD_NOTIFICATION);
|
||||||
|
furi_record_close(RECORD_DIALOGS);
|
||||||
free(flipfrid_state);
|
free(flipfrid_state);
|
||||||
|
return 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure view port
|
// Configure view port
|
||||||
@@ -228,6 +231,7 @@ int32_t flipfrid_start(void* p) {
|
|||||||
view_port_free(view_port);
|
view_port_free(view_port);
|
||||||
furi_message_queue_free(event_queue);
|
furi_message_queue_free(event_queue);
|
||||||
furi_record_close(RECORD_GUI);
|
furi_record_close(RECORD_GUI);
|
||||||
|
furi_record_close(RECORD_NOTIFICATION);
|
||||||
flipfrid_free(flipfrid_state);
|
flipfrid_free(flipfrid_state);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ void flipfrid_scene_entrypoint_on_event(FlipFridEvent event, FlipFridState* cont
|
|||||||
break;
|
break;
|
||||||
case InputKeyLeft:
|
case InputKeyLeft:
|
||||||
case InputKeyRight:
|
case InputKeyRight:
|
||||||
|
break;
|
||||||
case InputKeyOk:
|
case InputKeyOk:
|
||||||
flipfrid_scene_entrypoint_menu_callback(context, context->menu_index);
|
flipfrid_scene_entrypoint_menu_callback(context, context->menu_index);
|
||||||
break;
|
break;
|
||||||
@@ -84,14 +85,27 @@ void flipfrid_scene_entrypoint_on_draw(Canvas* canvas, FlipFridState* context) {
|
|||||||
|
|
||||||
if(context->menu_index > FlipFridAttackDefaultValues) {
|
if(context->menu_index > FlipFridAttackDefaultValues) {
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
canvas_draw_str_aligned(canvas, 64, 24, AlignCenter, AlignTop, string_get_cstr(menu_items[context->menu_index - 1]));
|
canvas_draw_str_aligned(
|
||||||
|
canvas,
|
||||||
|
64,
|
||||||
|
24,
|
||||||
|
AlignCenter,
|
||||||
|
AlignTop,
|
||||||
|
string_get_cstr(menu_items[context->menu_index - 1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
canvas_draw_str_aligned(canvas, 64, 36, AlignCenter, AlignTop, string_get_cstr(menu_items[context->menu_index]));
|
canvas_draw_str_aligned(
|
||||||
|
canvas, 64, 36, AlignCenter, AlignTop, string_get_cstr(menu_items[context->menu_index]));
|
||||||
|
|
||||||
if(context->menu_index < FlipFridAttackLoadFile) {
|
if(context->menu_index < FlipFridAttackLoadFile) {
|
||||||
canvas_set_font(canvas, FontSecondary);
|
canvas_set_font(canvas, FontSecondary);
|
||||||
canvas_draw_str_aligned(canvas, 64, 48, AlignCenter, AlignTop, string_get_cstr(menu_items[context->menu_index + 1]));
|
canvas_draw_str_aligned(
|
||||||
|
canvas,
|
||||||
|
64,
|
||||||
|
48,
|
||||||
|
AlignCenter,
|
||||||
|
AlignTop,
|
||||||
|
string_get_cstr(menu_items[context->menu_index + 1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,6 @@ bool flipfrid_load(FlipFridState* context, const char* file_path) {
|
|||||||
temp_str2[2] = '\0';
|
temp_str2[2] = '\0';
|
||||||
context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16);
|
context->data[i] = (uint8_t)strtol(temp_str2, NULL, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result = true;
|
result = true;
|
||||||
@@ -130,7 +129,7 @@ bool flipfrid_load_protocol_from_file(FlipFridState* context) {
|
|||||||
context->file_path,
|
context->file_path,
|
||||||
LFRFID_APP_EXTENSION,
|
LFRFID_APP_EXTENSION,
|
||||||
true,
|
true,
|
||||||
&I_sub1_10px,
|
&I_125_10px,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
if(res) {
|
if(res) {
|
||||||
|
|||||||
@@ -57,6 +57,10 @@ void flipfrid_scene_run_attack_on_tick(FlipFridState* context) {
|
|||||||
|
|
||||||
if(context->attack_step == 15) {
|
if(context->attack_step == 15) {
|
||||||
context->attack_step = 0;
|
context->attack_step = 0;
|
||||||
|
counter = 0;
|
||||||
|
context->is_attacking = false;
|
||||||
|
notification_message(context->notify, &sequence_blink_stop);
|
||||||
|
notification_message(context->notify, &sequence_single_vibro);
|
||||||
} else {
|
} else {
|
||||||
context->attack_step++;
|
context->attack_step++;
|
||||||
}
|
}
|
||||||
@@ -71,6 +75,10 @@ void flipfrid_scene_run_attack_on_tick(FlipFridState* context) {
|
|||||||
|
|
||||||
if(context->attack_step == 255) {
|
if(context->attack_step == 255) {
|
||||||
context->attack_step = 0;
|
context->attack_step = 0;
|
||||||
|
counter = 0;
|
||||||
|
context->is_attacking = false;
|
||||||
|
notification_message(context->notify, &sequence_blink_stop);
|
||||||
|
notification_message(context->notify, &sequence_single_vibro);
|
||||||
} else {
|
} else {
|
||||||
context->attack_step++;
|
context->attack_step++;
|
||||||
}
|
}
|
||||||
@@ -86,6 +94,10 @@ void flipfrid_scene_run_attack_on_tick(FlipFridState* context) {
|
|||||||
|
|
||||||
if(context->attack_step == 255) {
|
if(context->attack_step == 255) {
|
||||||
context->attack_step = 0;
|
context->attack_step = 0;
|
||||||
|
counter = 0;
|
||||||
|
context->is_attacking = false;
|
||||||
|
notification_message(context->notify, &sequence_blink_stop);
|
||||||
|
notification_message(context->notify, &sequence_single_vibro);
|
||||||
} else {
|
} else {
|
||||||
context->attack_step++;
|
context->attack_step++;
|
||||||
}
|
}
|
||||||
@@ -109,6 +121,7 @@ void flipfrid_scene_run_attack_on_event(FlipFridEvent event, FlipFridState* cont
|
|||||||
case InputKeyUp:
|
case InputKeyUp:
|
||||||
case InputKeyLeft:
|
case InputKeyLeft:
|
||||||
case InputKeyRight:
|
case InputKeyRight:
|
||||||
|
break;
|
||||||
case InputKeyOk:
|
case InputKeyOk:
|
||||||
counter = 0;
|
counter = 0;
|
||||||
if(!context->is_attacking) {
|
if(!context->is_attacking) {
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ void flipfrid_center_displayed_key(FlipFridState* context, uint8_t index) {
|
|||||||
const char* key_cstr = string_get_cstr(context->data_str);
|
const char* key_cstr = string_get_cstr(context->data_str);
|
||||||
uint8_t str_index = (index * 3);
|
uint8_t str_index = (index * 3);
|
||||||
|
|
||||||
char display_menu[17] = {'X', 'X', ' ', 'X', 'X', ' ', '<', 'X', 'X', '>', ' ', 'X', 'X', ' ', 'X', 'X', '\0'};
|
char display_menu[17] = {
|
||||||
|
'X', 'X', ' ', 'X', 'X', ' ', '<', 'X', 'X', '>', ' ', 'X', 'X', ' ', 'X', 'X', '\0'};
|
||||||
|
|
||||||
if(index > 1) {
|
if(index > 1) {
|
||||||
display_menu[0] = key_cstr[str_index - 6];
|
display_menu[0] = key_cstr[str_index - 6];
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ App(
|
|||||||
provides=[
|
provides=[
|
||||||
"snake_game",
|
"snake_game",
|
||||||
"tetris_game",
|
"tetris_game",
|
||||||
"arkanoid_game",
|
#"arkanoid_game",
|
||||||
"tictactoe_game",
|
#"tictactoe_game",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ App(
|
|||||||
apptype=FlipperAppType.METAPACKAGE,
|
apptype=FlipperAppType.METAPACKAGE,
|
||||||
provides=[
|
provides=[
|
||||||
"picopass",
|
"picopass",
|
||||||
"barcode_generator",
|
#"barcode_generator",
|
||||||
"mouse_jacker",
|
"mouse_jacker",
|
||||||
"nrf_sniff",
|
"nrf_sniff",
|
||||||
"sentry_safe",
|
"sentry_safe",
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
#include "multi_converter_mode_select.h"
|
#include "multi_converter_mode_select.h"
|
||||||
|
|
||||||
static void multi_converter_render_callback(Canvas* const canvas, void* ctx) {
|
static void multi_converter_render_callback(Canvas* const canvas, void* ctx) {
|
||||||
|
|
||||||
const MultiConverterState* multi_converter_state = acquire_mutex((ValueMutex*)ctx, 25);
|
const MultiConverterState* multi_converter_state = acquire_mutex((ValueMutex*)ctx, 25);
|
||||||
if(multi_converter_state == NULL) {
|
if(multi_converter_state == NULL) {
|
||||||
return;
|
return;
|
||||||
@@ -23,7 +22,8 @@ static void multi_converter_render_callback(Canvas* const canvas, void* ctx) {
|
|||||||
release_mutex((ValueMutex*)ctx, multi_converter_state);
|
release_mutex((ValueMutex*)ctx, multi_converter_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void multi_converter_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
|
static void
|
||||||
|
multi_converter_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
|
||||||
furi_assert(event_queue);
|
furi_assert(event_queue);
|
||||||
|
|
||||||
MultiConverterEvent event = {.type = EventTypeKey, .input = *input_event};
|
MultiConverterEvent event = {.type = EventTypeKey, .input = *input_event};
|
||||||
@@ -65,6 +65,7 @@ int32_t multi_converter_app(void* p) {
|
|||||||
ValueMutex state_mutex;
|
ValueMutex state_mutex;
|
||||||
if(!init_mutex(&state_mutex, multi_converter_state, sizeof(multi_converter_state))) {
|
if(!init_mutex(&state_mutex, multi_converter_state, sizeof(multi_converter_state))) {
|
||||||
FURI_LOG_E("MultiConverter", "cannot create mutex\r\n");
|
FURI_LOG_E("MultiConverter", "cannot create mutex\r\n");
|
||||||
|
furi_message_queue_free(event_queue);
|
||||||
free(multi_converter_state);
|
free(multi_converter_state);
|
||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
@@ -84,27 +85,31 @@ int32_t multi_converter_app(void* p) {
|
|||||||
MultiConverterEvent event;
|
MultiConverterEvent event;
|
||||||
for(bool processing = true; processing;) {
|
for(bool processing = true; processing;) {
|
||||||
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
|
||||||
MultiConverterState* multi_converter_state = (MultiConverterState*)acquire_mutex_block(&state_mutex);
|
MultiConverterState* multi_converter_state =
|
||||||
|
(MultiConverterState*)acquire_mutex_block(&state_mutex);
|
||||||
|
|
||||||
if(event_status == FuriStatusOk) {
|
if(event_status == FuriStatusOk) {
|
||||||
// press events
|
// press events
|
||||||
if(event.type == EventTypeKey && !multi_converter_state->keyboard_lock) {
|
if(event.type == EventTypeKey && !multi_converter_state->keyboard_lock) {
|
||||||
if(multi_converter_state->mode == ModeDisplay) {
|
if(multi_converter_state->mode == ModeDisplay) {
|
||||||
|
|
||||||
if(event.input.key == InputKeyBack) {
|
if(event.input.key == InputKeyBack) {
|
||||||
if(event.input.type == InputTypePress) processing = false;
|
if(event.input.type == InputTypePress) processing = false;
|
||||||
} else if(event.input.key == InputKeyOk) { // the "ok" press can be short or long
|
} else if(event.input.key == InputKeyOk) { // the "ok" press can be short or long
|
||||||
MultiConverterModeTrigger t = None;
|
MultiConverterModeTrigger t = None;
|
||||||
|
|
||||||
if (event.input.type == InputTypeLong) t = multi_converter_mode_display_ok(1, multi_converter_state);
|
if(event.input.type == InputTypeLong)
|
||||||
else if (event.input.type == InputTypeShort) t = multi_converter_mode_display_ok(0, multi_converter_state);
|
t = multi_converter_mode_display_ok(1, multi_converter_state);
|
||||||
|
else if(event.input.type == InputTypeShort)
|
||||||
|
t = multi_converter_mode_display_ok(0, multi_converter_state);
|
||||||
|
|
||||||
if(t == Reset) {
|
if(t == Reset) {
|
||||||
multi_converter_mode_select_reset(multi_converter_state);
|
multi_converter_mode_select_reset(multi_converter_state);
|
||||||
multi_converter_state->mode = ModeSelector;
|
multi_converter_state->mode = ModeSelector;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (event.input.type == InputTypePress) multi_converter_mode_display_navigation(event.input.key, multi_converter_state);
|
if(event.input.type == InputTypePress)
|
||||||
|
multi_converter_mode_display_navigation(
|
||||||
|
event.input.key, multi_converter_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else { // ModeSelect
|
} else { // ModeSelect
|
||||||
@@ -114,7 +119,8 @@ int32_t multi_converter_app(void* p) {
|
|||||||
break;
|
break;
|
||||||
case InputKeyBack:
|
case InputKeyBack:
|
||||||
case InputKeyOk: {
|
case InputKeyOk: {
|
||||||
MultiConverterModeTrigger t = multi_converter_mode_select_exit(event.input.key == InputKeyOk ? 1 : 0, multi_converter_state);
|
MultiConverterModeTrigger t = multi_converter_mode_select_exit(
|
||||||
|
event.input.key == InputKeyOk ? 1 : 0, multi_converter_state);
|
||||||
|
|
||||||
if(t == Reset) {
|
if(t == Reset) {
|
||||||
multi_converter_mode_display_reset(multi_converter_state);
|
multi_converter_mode_display_reset(multi_converter_state);
|
||||||
|
|||||||
@@ -16,41 +16,52 @@
|
|||||||
#define MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN 3
|
#define MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN 3
|
||||||
#define MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT 8
|
#define MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT 8
|
||||||
|
|
||||||
|
|
||||||
void multi_converter_mode_display_convert(MultiConverterState* const multi_converter_state) {
|
void multi_converter_mode_display_convert(MultiConverterState* const multi_converter_state) {
|
||||||
|
|
||||||
// 1.- if origin == destination (in theory user won't be allowed to choose the same options, but it's kinda "valid"...)
|
// 1.- if origin == destination (in theory user won't be allowed to choose the same options, but it's kinda "valid"...)
|
||||||
// just copy buffer_orig to buffer_dest and that's it
|
// just copy buffer_orig to buffer_dest and that's it
|
||||||
|
|
||||||
if(multi_converter_state->unit_type_orig == multi_converter_state->unit_type_dest) {
|
if(multi_converter_state->unit_type_orig == multi_converter_state->unit_type_dest) {
|
||||||
memcpy(multi_converter_state->buffer_dest, multi_converter_state->buffer_orig, MULTI_CONVERTER_NUMBER_DIGITS);
|
memcpy(
|
||||||
|
multi_converter_state->buffer_dest,
|
||||||
|
multi_converter_state->buffer_orig,
|
||||||
|
MULTI_CONVERTER_NUMBER_DIGITS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2.- origin_buffer has not null functions
|
// 2.- origin_buffer has not null functions
|
||||||
if (multi_converter_get_unit(multi_converter_state->unit_type_orig).convert_function == NULL || multi_converter_get_unit(multi_converter_state->unit_type_orig).allowed_function == NULL) return;
|
if(multi_converter_get_unit(multi_converter_state->unit_type_orig).convert_function == NULL ||
|
||||||
|
multi_converter_get_unit(multi_converter_state->unit_type_orig).allowed_function == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
// 3.- valid destination type (using allowed_destinations function)
|
// 3.- valid destination type (using allowed_destinations function)
|
||||||
if (!multi_converter_get_unit(multi_converter_state->unit_type_orig).allowed_function(multi_converter_state->unit_type_dest)) return;
|
if(!multi_converter_get_unit(multi_converter_state->unit_type_orig)
|
||||||
|
.allowed_function(multi_converter_state->unit_type_dest))
|
||||||
multi_converter_get_unit(multi_converter_state->unit_type_orig).convert_function(multi_converter_state);
|
return;
|
||||||
|
|
||||||
|
multi_converter_get_unit(multi_converter_state->unit_type_orig)
|
||||||
|
.convert_function(multi_converter_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void multi_converter_mode_display_draw(Canvas* const canvas, const MultiConverterState* multi_converter_state) {
|
void multi_converter_mode_display_draw(
|
||||||
|
Canvas* const canvas,
|
||||||
|
const MultiConverterState* multi_converter_state) {
|
||||||
canvas_set_color(canvas, ColorBlack);
|
canvas_set_color(canvas, ColorBlack);
|
||||||
|
|
||||||
// ORIGIN
|
// ORIGIN
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
canvas_draw_str(canvas, 2, 10, multi_converter_get_unit(multi_converter_state->unit_type_orig).mini_name);
|
canvas_draw_str(
|
||||||
|
canvas, 2, 10, multi_converter_get_unit(multi_converter_state->unit_type_orig).mini_name);
|
||||||
|
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
canvas_draw_str(canvas, 2 + 30, 10, multi_converter_state->buffer_orig);
|
canvas_draw_str(canvas, 2 + 30, 10, multi_converter_state->buffer_orig);
|
||||||
|
|
||||||
// DESTINATION
|
// DESTINATION
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
canvas_draw_str(canvas, 2, 10 + 12, multi_converter_get_unit(multi_converter_state->unit_type_dest).mini_name);
|
canvas_draw_str(
|
||||||
|
canvas,
|
||||||
|
2,
|
||||||
|
10 + 12,
|
||||||
|
multi_converter_get_unit(multi_converter_state->unit_type_dest).mini_name);
|
||||||
|
|
||||||
canvas_set_font(canvas, FontPrimary);
|
canvas_set_font(canvas, FontPrimary);
|
||||||
canvas_draw_str(canvas, 2 + 30, 10 + 12, multi_converter_state->buffer_dest);
|
canvas_draw_str(canvas, 2 + 30, 10 + 12, multi_converter_state->buffer_dest);
|
||||||
@@ -63,16 +74,21 @@ void multi_converter_mode_display_draw(Canvas* const canvas, const MultiConverte
|
|||||||
uint8_t _y = 25 + 15; // line + 10
|
uint8_t _y = 25 + 15; // line + 10
|
||||||
|
|
||||||
for(int i = 0; i < MULTI_CONVERTER_DISPLAY_KEYS; i++) {
|
for(int i = 0; i < MULTI_CONVERTER_DISPLAY_KEYS; i++) {
|
||||||
|
|
||||||
char g;
|
char g;
|
||||||
if (i < 10) g = (i + '0');
|
if(i < 10)
|
||||||
else if (i < 16) g = ((i - 10) + 'A');
|
g = (i + '0');
|
||||||
else if (i == MULTI_CONVERTER_DISPLAY_KEY_DEL) g = MULTI_CONVERTER_DISPLAY_CHAR_DEL;
|
else if(i < 16)
|
||||||
else g = MULTI_CONVERTER_DISPLAY_CHAR_SELECT;
|
g = ((i - 10) + 'A');
|
||||||
|
else if(i == MULTI_CONVERTER_DISPLAY_KEY_DEL)
|
||||||
|
g = MULTI_CONVERTER_DISPLAY_CHAR_DEL;
|
||||||
|
else
|
||||||
|
g = MULTI_CONVERTER_DISPLAY_CHAR_SELECT;
|
||||||
|
|
||||||
uint8_t g_w = canvas_glyph_width(canvas, g);
|
uint8_t g_w = canvas_glyph_width(canvas, g);
|
||||||
|
|
||||||
if (i < 16 && i > multi_converter_get_unit(multi_converter_state->unit_type_orig).max_number_keys-1) {
|
if(i < 16 &&
|
||||||
|
i > multi_converter_get_unit(multi_converter_state->unit_type_orig).max_number_keys -
|
||||||
|
1) {
|
||||||
// some units won't use the full [0] - [F] keyboard, in those situations just hide the char
|
// some units won't use the full [0] - [F] keyboard, in those situations just hide the char
|
||||||
// (won't be selectable anyway, so no worries here; this is just about drawing stuff)
|
// (won't be selectable anyway, so no worries here; this is just about drawing stuff)
|
||||||
g = MULTI_CONVERTER_DISPLAY_CHAR_BLANK;
|
g = MULTI_CONVERTER_DISPLAY_CHAR_BLANK;
|
||||||
@@ -80,20 +96,26 @@ void multi_converter_mode_display_draw(Canvas* const canvas, const MultiConverte
|
|||||||
|
|
||||||
// currently hover key is highlighted
|
// currently hover key is highlighted
|
||||||
if((multi_converter_state->display).key == i) {
|
if((multi_converter_state->display).key == i) {
|
||||||
canvas_draw_box(canvas,
|
canvas_draw_box(
|
||||||
|
canvas,
|
||||||
_x - MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN,
|
_x - MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN,
|
||||||
_y - (MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN),
|
_y - (MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT +
|
||||||
MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN + g_w + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN,
|
MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN),
|
||||||
MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN * 2
|
MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN + g_w +
|
||||||
);
|
MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN,
|
||||||
|
MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT +
|
||||||
|
MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN * 2);
|
||||||
canvas_set_color(canvas, ColorWhite);
|
canvas_set_color(canvas, ColorWhite);
|
||||||
} else {
|
} else {
|
||||||
canvas_draw_frame(canvas,
|
canvas_draw_frame(
|
||||||
|
canvas,
|
||||||
_x - MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN,
|
_x - MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN,
|
||||||
_y - (MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN),
|
_y - (MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT +
|
||||||
MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN + g_w + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN,
|
MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN),
|
||||||
MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN * 2
|
MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN + g_w +
|
||||||
);
|
MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN,
|
||||||
|
MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT +
|
||||||
|
MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw key
|
// draw key
|
||||||
@@ -101,19 +123,19 @@ void multi_converter_mode_display_draw(Canvas* const canvas, const MultiConverte
|
|||||||
|
|
||||||
// certain keys have long_press features, draw whatever they're using there too
|
// certain keys have long_press features, draw whatever they're using there too
|
||||||
if(i == MULTI_CONVERTER_DISPLAY_KEY_NEGATIVE) {
|
if(i == MULTI_CONVERTER_DISPLAY_KEY_NEGATIVE) {
|
||||||
canvas_draw_box(canvas,
|
canvas_draw_box(
|
||||||
|
canvas,
|
||||||
_x + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN + g_w - 4,
|
_x + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN + g_w - 4,
|
||||||
_y + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN - 2,
|
_y + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN - 2,
|
||||||
4,
|
4,
|
||||||
2
|
2);
|
||||||
);
|
|
||||||
} else if(i == MULTI_CONVERTER_DISPLAY_KEY_COMMA) {
|
} else if(i == MULTI_CONVERTER_DISPLAY_KEY_COMMA) {
|
||||||
canvas_draw_box(canvas,
|
canvas_draw_box(
|
||||||
|
canvas,
|
||||||
_x + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN + g_w - 2,
|
_x + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN + g_w - 2,
|
||||||
_y + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN - 2,
|
_y + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN - 2,
|
||||||
2,
|
2,
|
||||||
2
|
2);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// back to black
|
// back to black
|
||||||
@@ -122,27 +144,30 @@ void multi_converter_mode_display_draw(Canvas* const canvas, const MultiConverte
|
|||||||
if(i < 8) {
|
if(i < 8) {
|
||||||
_x += g_w + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN * 2 + 2;
|
_x += g_w + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN * 2 + 2;
|
||||||
} else if(i == 8) {
|
} else if(i == 8) {
|
||||||
_y += (MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN * 2) + 3;
|
_y += (MULTI_CONVERTER_DISPLAY_KEY_CHAR_HEIGHT +
|
||||||
|
MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN * 2) +
|
||||||
|
3;
|
||||||
_x = 8; // some padding at the beginning on second line
|
_x = 8; // some padding at the beginning on second line
|
||||||
} else {
|
} else {
|
||||||
_x += g_w + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN * 2 + 1;
|
_x += g_w + MULTI_CONVERTER_DISPLAY_KEY_FRAME_MARGIN * 2 + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void multi_converter_mode_display_navigation(InputKey key, MultiConverterState* const multi_converter_state) {
|
void multi_converter_mode_display_navigation(
|
||||||
|
InputKey key,
|
||||||
|
MultiConverterState* const multi_converter_state) {
|
||||||
// first move to keyboard position, then check if the ORIGIN allows that specific key, if not jump to the "closest one"
|
// first move to keyboard position, then check if the ORIGIN allows that specific key, if not jump to the "closest one"
|
||||||
switch(key) {
|
switch(key) {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case InputKeyUp:
|
case InputKeyUp:
|
||||||
case InputKeyDown:
|
case InputKeyDown:
|
||||||
if ((multi_converter_state->display).key >= 9) (multi_converter_state->display).key -= 9;
|
if((multi_converter_state->display).key >= 9)
|
||||||
else (multi_converter_state->display).key += 9;
|
(multi_converter_state->display).key -= 9;
|
||||||
|
else
|
||||||
|
(multi_converter_state->display).key += 9;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case InputKeyLeft:
|
case InputKeyLeft:
|
||||||
@@ -150,28 +175,34 @@ void multi_converter_mode_display_navigation(InputKey key, MultiConverterState*
|
|||||||
|
|
||||||
(multi_converter_state->display).key += (key == InputKeyLeft ? -1 : 1);
|
(multi_converter_state->display).key += (key == InputKeyLeft ? -1 : 1);
|
||||||
|
|
||||||
if ((multi_converter_state->display).key > MULTI_CONVERTER_DISPLAY_KEYS-1) (multi_converter_state->display).key = 0;
|
if((multi_converter_state->display).key > MULTI_CONVERTER_DISPLAY_KEYS - 1)
|
||||||
else if ((multi_converter_state->display).key < 0) (multi_converter_state->display).key = MULTI_CONVERTER_DISPLAY_KEYS-1;
|
(multi_converter_state->display).key = 0;
|
||||||
|
else if((multi_converter_state->display).key < 0)
|
||||||
|
(multi_converter_state->display).key = MULTI_CONVERTER_DISPLAY_KEYS - 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if destination key is disabled by max_number_keys, move to the closest one
|
// if destination key is disabled by max_number_keys, move to the closest one
|
||||||
// (this could be improved with more accurate keys movements, probably...)
|
// (this could be improved with more accurate keys movements, probably...)
|
||||||
if (multi_converter_get_unit(multi_converter_state->unit_type_orig).max_number_keys >= 16) return; // weird, since this means "do not show any number on the keyboard, but just in case..."
|
if(multi_converter_get_unit(multi_converter_state->unit_type_orig).max_number_keys >= 16)
|
||||||
|
return; // weird, since this means "do not show any number on the keyboard, but just in case..."
|
||||||
|
|
||||||
int8_t i = -1;
|
int8_t i = -1;
|
||||||
if(key == InputKeyRight || key == InputKeyDown) i = 1;
|
if(key == InputKeyRight || key == InputKeyDown) i = 1;
|
||||||
|
|
||||||
while ((multi_converter_state->display).key < 16 && (multi_converter_state->display).key > multi_converter_get_unit(multi_converter_state->unit_type_orig).max_number_keys-1) {
|
while((multi_converter_state->display).key < 16 &&
|
||||||
|
(multi_converter_state->display).key >
|
||||||
|
multi_converter_get_unit(multi_converter_state->unit_type_orig).max_number_keys -
|
||||||
|
1) {
|
||||||
(multi_converter_state->display).key += i;
|
(multi_converter_state->display).key += i;
|
||||||
if ((multi_converter_state->display).key > MULTI_CONVERTER_DISPLAY_KEYS-1) (multi_converter_state->display).key = 0;
|
if((multi_converter_state->display).key > MULTI_CONVERTER_DISPLAY_KEYS - 1)
|
||||||
else if ((multi_converter_state->display).key < 0) (multi_converter_state->display).key = MULTI_CONVERTER_DISPLAY_KEYS-1;
|
(multi_converter_state->display).key = 0;
|
||||||
|
else if((multi_converter_state->display).key < 0)
|
||||||
|
(multi_converter_state->display).key = MULTI_CONVERTER_DISPLAY_KEYS - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void multi_converter_mode_display_reset(MultiConverterState* const multi_converter_state) {
|
void multi_converter_mode_display_reset(MultiConverterState* const multi_converter_state) {
|
||||||
|
|
||||||
// clean the buffers
|
// clean the buffers
|
||||||
for(int i = 0; i < MULTI_CONVERTER_NUMBER_DIGITS; i++) {
|
for(int i = 0; i < MULTI_CONVERTER_NUMBER_DIGITS; i++) {
|
||||||
multi_converter_state->buffer_orig[i] = MULTI_CONVERTER_DISPLAY_CHAR_BLANK;
|
multi_converter_state->buffer_orig[i] = MULTI_CONVERTER_DISPLAY_CHAR_BLANK;
|
||||||
@@ -185,9 +216,9 @@ void multi_converter_mode_display_reset(MultiConverterState* const multi_convert
|
|||||||
multi_converter_state->display.negative = 0;
|
multi_converter_state->display.negative = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void multi_converter_mode_display_toggle_negative(MultiConverterState* const multi_converter_state) {
|
void multi_converter_mode_display_toggle_negative(
|
||||||
|
MultiConverterState* const multi_converter_state) {
|
||||||
if(multi_converter_get_unit(multi_converter_state->unit_type_orig).allow_negative) {
|
if(multi_converter_get_unit(multi_converter_state->unit_type_orig).allow_negative) {
|
||||||
|
|
||||||
if(!(multi_converter_state->display).negative) {
|
if(!(multi_converter_state->display).negative) {
|
||||||
// shift origin buffer one to right + add the "-" sign (last digit will be lost)
|
// shift origin buffer one to right + add the "-" sign (last digit will be lost)
|
||||||
for(int i = MULTI_CONVERTER_NUMBER_DIGITS - 1; i > 0; i--) {
|
for(int i = MULTI_CONVERTER_NUMBER_DIGITS - 1; i > 0; i--) {
|
||||||
@@ -197,15 +228,18 @@ void multi_converter_mode_display_toggle_negative(MultiConverterState* const mul
|
|||||||
multi_converter_state->buffer_orig[0] = MULTI_CONVERTER_DISPLAY_CHAR_NEGATIVE;
|
multi_converter_state->buffer_orig[0] = MULTI_CONVERTER_DISPLAY_CHAR_NEGATIVE;
|
||||||
|
|
||||||
// only increment cursor if we're not out of bound
|
// only increment cursor if we're not out of bound
|
||||||
if ((multi_converter_state->display).cursor < MULTI_CONVERTER_NUMBER_DIGITS) (multi_converter_state->display).cursor++;
|
if((multi_converter_state->display).cursor < MULTI_CONVERTER_NUMBER_DIGITS)
|
||||||
|
(multi_converter_state->display).cursor++;
|
||||||
} else {
|
} else {
|
||||||
// shift origin buffer one to left, append ' ' on the end
|
// shift origin buffer one to left, append ' ' on the end
|
||||||
for(int i = 0; i < MULTI_CONVERTER_NUMBER_DIGITS - 1; i++) {
|
for(int i = 0; i < MULTI_CONVERTER_NUMBER_DIGITS - 1; i++) {
|
||||||
if (multi_converter_state->buffer_orig[i] == MULTI_CONVERTER_DISPLAY_CHAR_BLANK) break;
|
if(multi_converter_state->buffer_orig[i] == MULTI_CONVERTER_DISPLAY_CHAR_BLANK)
|
||||||
|
break;
|
||||||
|
|
||||||
multi_converter_state->buffer_orig[i] = multi_converter_state->buffer_orig[i + 1];
|
multi_converter_state->buffer_orig[i] = multi_converter_state->buffer_orig[i + 1];
|
||||||
}
|
}
|
||||||
multi_converter_state->buffer_orig[MULTI_CONVERTER_NUMBER_DIGITS-1] = MULTI_CONVERTER_DISPLAY_CHAR_BLANK;
|
multi_converter_state->buffer_orig[MULTI_CONVERTER_NUMBER_DIGITS - 1] =
|
||||||
|
MULTI_CONVERTER_DISPLAY_CHAR_BLANK;
|
||||||
|
|
||||||
(multi_converter_state->display).cursor--;
|
(multi_converter_state->display).cursor--;
|
||||||
}
|
}
|
||||||
@@ -216,40 +250,44 @@ void multi_converter_mode_display_toggle_negative(MultiConverterState* const mul
|
|||||||
}
|
}
|
||||||
|
|
||||||
void multi_converter_mode_display_add_comma(MultiConverterState* const multi_converter_state) {
|
void multi_converter_mode_display_add_comma(MultiConverterState* const multi_converter_state) {
|
||||||
if (
|
if(!multi_converter_get_unit(multi_converter_state->unit_type_orig).allow_comma ||
|
||||||
!multi_converter_get_unit(multi_converter_state->unit_type_orig).allow_comma ||
|
(multi_converter_state->display).comma || !(multi_converter_state->display).cursor ||
|
||||||
(multi_converter_state->display).comma ||
|
((multi_converter_state->display).cursor == (MULTI_CONVERTER_NUMBER_DIGITS - 1)))
|
||||||
!(multi_converter_state->display).cursor ||
|
return; // maybe not allowerd; or one comma already in place; also cannot add commas as first or last chars
|
||||||
((multi_converter_state->display).cursor == (MULTI_CONVERTER_NUMBER_DIGITS - 1))
|
|
||||||
) return; // maybe not allowerd; or one comma already in place; also cannot add commas as first or last chars
|
|
||||||
|
|
||||||
// set flag to one
|
// set flag to one
|
||||||
(multi_converter_state->display).comma = 1;
|
(multi_converter_state->display).comma = 1;
|
||||||
|
|
||||||
multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] = MULTI_CONVERTER_DISPLAY_CHAR_COMMA;
|
multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] =
|
||||||
|
MULTI_CONVERTER_DISPLAY_CHAR_COMMA;
|
||||||
(multi_converter_state->display).cursor++;
|
(multi_converter_state->display).cursor++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void multi_converter_mode_display_add_number(MultiConverterState* const multi_converter_state) {
|
void multi_converter_mode_display_add_number(MultiConverterState* const multi_converter_state) {
|
||||||
if ((multi_converter_state->display).key > multi_converter_get_unit(multi_converter_state->unit_type_orig).max_number_keys-1) return;
|
if((multi_converter_state->display).key >
|
||||||
|
multi_converter_get_unit(multi_converter_state->unit_type_orig).max_number_keys - 1)
|
||||||
|
return;
|
||||||
|
|
||||||
if((multi_converter_state->display).key < 10) {
|
if((multi_converter_state->display).key < 10) {
|
||||||
multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] = (multi_converter_state->display).key + '0';
|
multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] =
|
||||||
|
(multi_converter_state->display).key + '0';
|
||||||
} else {
|
} else {
|
||||||
multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] = ((multi_converter_state->display).key - 10) + 'A';
|
multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] =
|
||||||
|
((multi_converter_state->display).key - 10) + 'A';
|
||||||
}
|
}
|
||||||
|
|
||||||
(multi_converter_state->display).cursor++;
|
(multi_converter_state->display).cursor++;
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiConverterModeTrigger multi_converter_mode_display_ok(uint8_t long_press, MultiConverterState* const multi_converter_state) {
|
MultiConverterModeTrigger multi_converter_mode_display_ok(
|
||||||
|
uint8_t long_press,
|
||||||
|
MultiConverterState* const multi_converter_state) {
|
||||||
if((multi_converter_state->display).key < MULTI_CONVERTER_DISPLAY_KEY_DEL) {
|
if((multi_converter_state->display).key < MULTI_CONVERTER_DISPLAY_KEY_DEL) {
|
||||||
if ((multi_converter_state->display).cursor >= MULTI_CONVERTER_NUMBER_DIGITS) return None; // limit reached, ignore
|
if((multi_converter_state->display).cursor >= MULTI_CONVERTER_NUMBER_DIGITS)
|
||||||
|
return None; // limit reached, ignore
|
||||||
|
|
||||||
// long press on 0 toggle NEGATIVE if allowed, on 1 adds COMMA if allowed
|
// long press on 0 toggle NEGATIVE if allowed, on 1 adds COMMA if allowed
|
||||||
if(long_press) {
|
if(long_press) {
|
||||||
|
|
||||||
if((multi_converter_state->display).key == MULTI_CONVERTER_DISPLAY_KEY_NEGATIVE) {
|
if((multi_converter_state->display).key == MULTI_CONVERTER_DISPLAY_KEY_NEGATIVE) {
|
||||||
// toggle negative
|
// toggle negative
|
||||||
multi_converter_mode_display_toggle_negative(multi_converter_state);
|
multi_converter_mode_display_toggle_negative(multi_converter_state);
|
||||||
@@ -268,10 +306,15 @@ MultiConverterModeTrigger multi_converter_mode_display_ok(uint8_t long_press, Mu
|
|||||||
} else if((multi_converter_state->display).key == MULTI_CONVERTER_DISPLAY_KEY_DEL) {
|
} else if((multi_converter_state->display).key == MULTI_CONVERTER_DISPLAY_KEY_DEL) {
|
||||||
if((multi_converter_state->display).cursor > 0) (multi_converter_state->display).cursor--;
|
if((multi_converter_state->display).cursor > 0) (multi_converter_state->display).cursor--;
|
||||||
|
|
||||||
if (multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] == MULTI_CONVERTER_DISPLAY_CHAR_COMMA) (multi_converter_state->display).comma = 0;
|
if(multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] ==
|
||||||
if (multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] == MULTI_CONVERTER_DISPLAY_CHAR_NEGATIVE) (multi_converter_state->display).negative = 0;
|
MULTI_CONVERTER_DISPLAY_CHAR_COMMA)
|
||||||
|
(multi_converter_state->display).comma = 0;
|
||||||
|
if(multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] ==
|
||||||
|
MULTI_CONVERTER_DISPLAY_CHAR_NEGATIVE)
|
||||||
|
(multi_converter_state->display).negative = 0;
|
||||||
|
|
||||||
multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] = MULTI_CONVERTER_DISPLAY_CHAR_BLANK;
|
multi_converter_state->buffer_orig[(multi_converter_state->display).cursor] =
|
||||||
|
MULTI_CONVERTER_DISPLAY_CHAR_BLANK;
|
||||||
|
|
||||||
multi_converter_mode_display_convert(multi_converter_state);
|
multi_converter_mode_display_convert(multi_converter_state);
|
||||||
|
|
||||||
@@ -280,5 +323,4 @@ MultiConverterModeTrigger multi_converter_mode_display_ok(uint8_t long_press, Mu
|
|||||||
}
|
}
|
||||||
|
|
||||||
return None;
|
return None;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -16,12 +16,16 @@ void multi_converter_mode_display_convert(MultiConverterState* const multi_conve
|
|||||||
//
|
//
|
||||||
// draw the main DISPLAY view with the current multi_converter_state values
|
// draw the main DISPLAY view with the current multi_converter_state values
|
||||||
//
|
//
|
||||||
void multi_converter_mode_display_draw(Canvas* const canvas, const MultiConverterState* multi_converter_state);
|
void multi_converter_mode_display_draw(
|
||||||
|
Canvas* const canvas,
|
||||||
|
const MultiConverterState* multi_converter_state);
|
||||||
|
|
||||||
//
|
//
|
||||||
// keyboard navigation on DISPLAY mode (NAVIGATION only, no BACK nor OK - InputKey guaranteed to be left/right/up/down)
|
// keyboard navigation on DISPLAY mode (NAVIGATION only, no BACK nor OK - InputKey guaranteed to be left/right/up/down)
|
||||||
//
|
//
|
||||||
void multi_converter_mode_display_navigation(InputKey key, MultiConverterState* const multi_converter_state);
|
void multi_converter_mode_display_navigation(
|
||||||
|
InputKey key,
|
||||||
|
MultiConverterState* const multi_converter_state);
|
||||||
|
|
||||||
//
|
//
|
||||||
// reset the DISPLAY mode with the current units, cleaning the buffers and different flags;
|
// reset the DISPLAY mode with the current units, cleaning the buffers and different flags;
|
||||||
@@ -52,4 +56,6 @@ void multi_converter_mode_display_add_number(MultiConverterState* const multi_co
|
|||||||
// handle the OK action when selecting a specific key on the keyboard (add a number, a symbol, change mode...)
|
// handle the OK action when selecting a specific key on the keyboard (add a number, a symbol, change mode...)
|
||||||
// returns a ModeTrigger enum value: may or may not let to a mode change on the main loop (WON'T change the mode here)
|
// returns a ModeTrigger enum value: may or may not let to a mode change on the main loop (WON'T change the mode here)
|
||||||
//
|
//
|
||||||
MultiConverterModeTrigger multi_converter_mode_display_ok(uint8_t long_press, MultiConverterState* const multi_converter_state);
|
MultiConverterModeTrigger multi_converter_mode_display_ok(
|
||||||
|
uint8_t long_press,
|
||||||
|
MultiConverterState* const multi_converter_state);
|
||||||
@@ -7,14 +7,21 @@
|
|||||||
#define MULTI_CONVERTER_INFO_STRING_OK "OK: Change"
|
#define MULTI_CONVERTER_INFO_STRING_OK "OK: Change"
|
||||||
#define MULTI_CONVERTER_INFO_STRING_BACK "BACK: Cancel"
|
#define MULTI_CONVERTER_INFO_STRING_BACK "BACK: Cancel"
|
||||||
|
|
||||||
void multi_converter_mode_select_draw_destination_offset(uint8_t x, uint8_t y, int8_t d, Canvas* const canvas, const MultiConverterState* multi_converter_state) {
|
void multi_converter_mode_select_draw_destination_offset(
|
||||||
|
uint8_t x,
|
||||||
|
uint8_t y,
|
||||||
|
int8_t d,
|
||||||
|
Canvas* const canvas,
|
||||||
|
const MultiConverterState* multi_converter_state) {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
while (i < MULTI_CONVERTER_AVAILABLE_UNITS) { // in case there's no match, to avoid an endless loop (in theory shouldn't happen, but...)
|
while(
|
||||||
int ut = multi_converter_get_unit_type_offset((multi_converter_state->select).selected_unit_type_dest, i * d);
|
i <
|
||||||
if (
|
MULTI_CONVERTER_AVAILABLE_UNITS) { // in case there's no match, to avoid an endless loop (in theory shouldn't happen, but...)
|
||||||
multi_converter_available_units[(multi_converter_state->select).selected_unit_type_orig].allowed_function(ut) &&
|
int ut = multi_converter_get_unit_type_offset(
|
||||||
(multi_converter_state->select).selected_unit_type_orig != ut
|
(multi_converter_state->select).selected_unit_type_dest, i * d);
|
||||||
) {
|
if(multi_converter_available_units[(multi_converter_state->select).selected_unit_type_orig]
|
||||||
|
.allowed_function(ut) &&
|
||||||
|
(multi_converter_state->select).selected_unit_type_orig != ut) {
|
||||||
canvas_draw_str(canvas, x, y, multi_converter_available_units[ut].name);
|
canvas_draw_str(canvas, x, y, multi_converter_available_units[ut].name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -22,15 +29,25 @@ void multi_converter_mode_select_draw_destination_offset(uint8_t x, uint8_t y, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void multi_converter_mode_select_draw_selected_unit(uint8_t x, uint8_t y, MultiConverterUnitType unit_type, Canvas* const canvas) {
|
void multi_converter_mode_select_draw_selected_unit(
|
||||||
canvas_draw_box(canvas, x - 2 , y - 10, canvas_string_width(canvas, multi_converter_available_units[unit_type].name) + 4, 13);
|
uint8_t x,
|
||||||
|
uint8_t y,
|
||||||
|
MultiConverterUnitType unit_type,
|
||||||
|
Canvas* const canvas) {
|
||||||
|
canvas_draw_box(
|
||||||
|
canvas,
|
||||||
|
x - 2,
|
||||||
|
y - 10,
|
||||||
|
canvas_string_width(canvas, multi_converter_available_units[unit_type].name) + 4,
|
||||||
|
13);
|
||||||
canvas_set_color(canvas, ColorWhite);
|
canvas_set_color(canvas, ColorWhite);
|
||||||
canvas_draw_str(canvas, x, y, multi_converter_available_units[unit_type].name);
|
canvas_draw_str(canvas, x, y, multi_converter_available_units[unit_type].name);
|
||||||
canvas_set_color(canvas, ColorBlack);
|
canvas_set_color(canvas, ColorBlack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void multi_converter_mode_select_draw(Canvas* const canvas, const MultiConverterState* multi_converter_state) {
|
void multi_converter_mode_select_draw(
|
||||||
|
Canvas* const canvas,
|
||||||
|
const MultiConverterState* multi_converter_state) {
|
||||||
int y = 10;
|
int y = 10;
|
||||||
int x = 10;
|
int x = 10;
|
||||||
|
|
||||||
@@ -45,19 +62,34 @@ void multi_converter_mode_select_draw(Canvas* const canvas, const MultiConverter
|
|||||||
// offset -1
|
// offset -1
|
||||||
y += 12;
|
y += 12;
|
||||||
|
|
||||||
canvas_draw_str(canvas, x, y, multi_converter_available_units[ multi_converter_get_unit_type_offset((multi_converter_state->select).selected_unit_type_orig, -1) ].name);
|
canvas_draw_str(
|
||||||
|
canvas,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
multi_converter_available_units[multi_converter_get_unit_type_offset(
|
||||||
|
(multi_converter_state->select).selected_unit_type_orig,
|
||||||
|
-1)]
|
||||||
|
.name);
|
||||||
|
|
||||||
// current selected element
|
// current selected element
|
||||||
y += 12;
|
y += 12;
|
||||||
|
|
||||||
multi_converter_mode_select_draw_selected_unit(x, y, (multi_converter_state->select).selected_unit_type_orig, canvas);
|
multi_converter_mode_select_draw_selected_unit(
|
||||||
|
x, y, (multi_converter_state->select).selected_unit_type_orig, canvas);
|
||||||
|
|
||||||
if((multi_converter_state->select).select_orig) canvas_draw_str(canvas, x - 6, y, ">");
|
if((multi_converter_state->select).select_orig) canvas_draw_str(canvas, x - 6, y, ">");
|
||||||
|
|
||||||
// offset +1
|
// offset +1
|
||||||
y += 12;
|
y += 12;
|
||||||
|
|
||||||
canvas_draw_str(canvas, x, y, multi_converter_available_units[ multi_converter_get_unit_type_offset((multi_converter_state->select).selected_unit_type_orig, 1) ].name);
|
canvas_draw_str(
|
||||||
|
canvas,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
multi_converter_available_units[multi_converter_get_unit_type_offset(
|
||||||
|
(multi_converter_state->select).selected_unit_type_orig,
|
||||||
|
1)]
|
||||||
|
.name);
|
||||||
|
|
||||||
// TO
|
// TO
|
||||||
y = 10;
|
y = 10;
|
||||||
@@ -76,7 +108,8 @@ void multi_converter_mode_select_draw(Canvas* const canvas, const MultiConverter
|
|||||||
// current selected element
|
// current selected element
|
||||||
y += 12;
|
y += 12;
|
||||||
|
|
||||||
multi_converter_mode_select_draw_selected_unit(x, y, (multi_converter_state->select).selected_unit_type_dest, canvas);
|
multi_converter_mode_select_draw_selected_unit(
|
||||||
|
x, y, (multi_converter_state->select).selected_unit_type_dest, canvas);
|
||||||
|
|
||||||
if(!(multi_converter_state->select).select_orig) canvas_draw_str(canvas, x - 6, y, ">");
|
if(!(multi_converter_state->select).select_orig) canvas_draw_str(canvas, x - 6, y, ">");
|
||||||
|
|
||||||
@@ -88,39 +121,54 @@ void multi_converter_mode_select_draw(Canvas* const canvas, const MultiConverter
|
|||||||
// OK / CANCEL
|
// OK / CANCEL
|
||||||
|
|
||||||
canvas_set_color(canvas, ColorBlack);
|
canvas_set_color(canvas, ColorBlack);
|
||||||
canvas_draw_box(canvas, 0, 64 - 12, canvas_string_width(canvas, MULTI_CONVERTER_INFO_STRING_OK) + 4, 12);
|
canvas_draw_box(
|
||||||
canvas_draw_box(canvas, 128 - 4 - canvas_string_width(canvas, MULTI_CONVERTER_INFO_STRING_BACK), 64 - 12, canvas_string_width(canvas, "BACK: Cancel") + 4, 12);
|
canvas, 0, 64 - 12, canvas_string_width(canvas, MULTI_CONVERTER_INFO_STRING_OK) + 4, 12);
|
||||||
|
canvas_draw_box(
|
||||||
|
canvas,
|
||||||
|
128 - 4 - canvas_string_width(canvas, MULTI_CONVERTER_INFO_STRING_BACK),
|
||||||
|
64 - 12,
|
||||||
|
canvas_string_width(canvas, "BACK: Cancel") + 4,
|
||||||
|
12);
|
||||||
|
|
||||||
canvas_set_color(canvas, ColorWhite);
|
canvas_set_color(canvas, ColorWhite);
|
||||||
canvas_draw_str(canvas, 2, 64 - 3, MULTI_CONVERTER_INFO_STRING_OK);
|
canvas_draw_str(canvas, 2, 64 - 3, MULTI_CONVERTER_INFO_STRING_OK);
|
||||||
canvas_draw_str(canvas, 128 - 2 - canvas_string_width(canvas, MULTI_CONVERTER_INFO_STRING_BACK), 64 - 3, MULTI_CONVERTER_INFO_STRING_BACK);
|
canvas_draw_str(
|
||||||
|
canvas,
|
||||||
|
128 - 2 - canvas_string_width(canvas, MULTI_CONVERTER_INFO_STRING_BACK),
|
||||||
|
64 - 3,
|
||||||
|
MULTI_CONVERTER_INFO_STRING_BACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void multi_converter_mode_select_reset(MultiConverterState* const multi_converter_state) {
|
void multi_converter_mode_select_reset(MultiConverterState* const multi_converter_state) {
|
||||||
|
|
||||||
// initial pre-selected values are equal to the current selected values
|
// initial pre-selected values are equal to the current selected values
|
||||||
(multi_converter_state->select).selected_unit_type_orig = multi_converter_state->unit_type_orig;
|
(multi_converter_state->select).selected_unit_type_orig =
|
||||||
(multi_converter_state->select).selected_unit_type_dest = multi_converter_state->unit_type_dest;
|
multi_converter_state->unit_type_orig;
|
||||||
|
(multi_converter_state->select).selected_unit_type_dest =
|
||||||
|
multi_converter_state->unit_type_dest;
|
||||||
|
|
||||||
(multi_converter_state->select).select_orig = 1;
|
(multi_converter_state->select).select_orig = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiConverterModeTrigger multi_converter_mode_select_exit(uint8_t save_changes, MultiConverterState* const multi_converter_state) {
|
MultiConverterModeTrigger multi_converter_mode_select_exit(
|
||||||
|
uint8_t save_changes,
|
||||||
|
MultiConverterState* const multi_converter_state) {
|
||||||
if(save_changes) {
|
if(save_changes) {
|
||||||
|
multi_converter_state->unit_type_dest =
|
||||||
|
(multi_converter_state->select).selected_unit_type_dest;
|
||||||
|
|
||||||
multi_converter_state->unit_type_dest = (multi_converter_state->select).selected_unit_type_dest;
|
if(multi_converter_state->unit_type_orig ==
|
||||||
|
(multi_converter_state->select).selected_unit_type_orig) {
|
||||||
if (multi_converter_state->unit_type_orig == (multi_converter_state->select).selected_unit_type_orig) {
|
|
||||||
// if the ORIGIN unit didn't changed, just trigger the convert
|
// if the ORIGIN unit didn't changed, just trigger the convert
|
||||||
|
|
||||||
return Convert;
|
return Convert;
|
||||||
} else {
|
} else {
|
||||||
multi_converter_state->unit_type_orig = (multi_converter_state->select).selected_unit_type_orig;
|
multi_converter_state->unit_type_orig =
|
||||||
multi_converter_state->unit_type_dest = (multi_converter_state->select).selected_unit_type_dest;
|
(multi_converter_state->select).selected_unit_type_orig;
|
||||||
|
multi_converter_state->unit_type_dest =
|
||||||
|
(multi_converter_state->select).selected_unit_type_dest;
|
||||||
|
|
||||||
return Reset;
|
return Reset;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return None;
|
return None;
|
||||||
@@ -130,14 +178,18 @@ void multi_converter_mode_select_switch(MultiConverterState* const multi_convert
|
|||||||
(multi_converter_state->select).select_orig ^= 1;
|
(multi_converter_state->select).select_orig ^= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void multi_converter_mode_select_change_unit(int8_t direction, MultiConverterState* const multi_converter_state) {
|
void multi_converter_mode_select_change_unit(
|
||||||
|
int8_t direction,
|
||||||
|
MultiConverterState* const multi_converter_state) {
|
||||||
MultiConverterUnitType d;
|
MultiConverterUnitType d;
|
||||||
if((multi_converter_state->select).select_orig) {
|
if((multi_converter_state->select).select_orig) {
|
||||||
(multi_converter_state->select).selected_unit_type_orig = multi_converter_get_unit_type_offset((multi_converter_state->select).selected_unit_type_orig, direction);
|
(multi_converter_state->select).selected_unit_type_orig =
|
||||||
|
multi_converter_get_unit_type_offset(
|
||||||
|
(multi_converter_state->select).selected_unit_type_orig, direction);
|
||||||
d = (multi_converter_state->select).selected_unit_type_dest;
|
d = (multi_converter_state->select).selected_unit_type_dest;
|
||||||
} else {
|
} else {
|
||||||
d = ((multi_converter_state->select).selected_unit_type_dest + direction) % MULTI_CONVERTER_AVAILABLE_UNITS;
|
d = ((multi_converter_state->select).selected_unit_type_dest + direction) %
|
||||||
|
MULTI_CONVERTER_AVAILABLE_UNITS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check each unit with the ORIGIN allowed_function() to make sure we're selecting a valid DESTINATION
|
// check each unit with the ORIGIN allowed_function() to make sure we're selecting a valid DESTINATION
|
||||||
@@ -145,10 +197,9 @@ void multi_converter_mode_select_change_unit(int8_t direction, MultiConverterSta
|
|||||||
// also notice that ORIGIN must be DIFFERENT than DESTINATION
|
// also notice that ORIGIN must be DIFFERENT than DESTINATION
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(i < MULTI_CONVERTER_AVAILABLE_UNITS) {
|
while(i < MULTI_CONVERTER_AVAILABLE_UNITS) {
|
||||||
if (
|
if(multi_converter_available_units[(multi_converter_state->select).selected_unit_type_orig]
|
||||||
multi_converter_available_units[(multi_converter_state->select).selected_unit_type_orig].allowed_function(d) &&
|
.allowed_function(d) &&
|
||||||
(multi_converter_state->select).selected_unit_type_orig != d
|
(multi_converter_state->select).selected_unit_type_orig != d) {
|
||||||
) {
|
|
||||||
(multi_converter_state->select).selected_unit_type_dest = d;
|
(multi_converter_state->select).selected_unit_type_dest = d;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -156,5 +207,4 @@ void multi_converter_mode_select_change_unit(int8_t direction, MultiConverterSta
|
|||||||
d = multi_converter_get_unit_type_offset(d, direction);
|
d = multi_converter_get_unit_type_offset(d, direction);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,25 @@
|
|||||||
//
|
//
|
||||||
// aux draw function for units offsets and draw stuff
|
// aux draw function for units offsets and draw stuff
|
||||||
//
|
//
|
||||||
void multi_converter_mode_select_draw_destination_offset(uint8_t x, uint8_t y, int8_t d, Canvas* const canvas, const MultiConverterState* multi_converter_state);
|
void multi_converter_mode_select_draw_destination_offset(
|
||||||
|
uint8_t x,
|
||||||
|
uint8_t y,
|
||||||
|
int8_t d,
|
||||||
|
Canvas* const canvas,
|
||||||
|
const MultiConverterState* multi_converter_state);
|
||||||
|
|
||||||
void multi_converter_mode_select_draw_selected_unit(uint8_t x, uint8_t y, MultiConverterUnitType unit_type, Canvas* const canvas);
|
void multi_converter_mode_select_draw_selected_unit(
|
||||||
|
uint8_t x,
|
||||||
|
uint8_t y,
|
||||||
|
MultiConverterUnitType unit_type,
|
||||||
|
Canvas* const canvas);
|
||||||
|
|
||||||
//
|
//
|
||||||
// draw the main SELECT view with the current multi_converter_state values
|
// draw the main SELECT view with the current multi_converter_state values
|
||||||
//
|
//
|
||||||
void multi_converter_mode_select_draw(Canvas* const canvas, const MultiConverterState* multi_converter_state);
|
void multi_converter_mode_select_draw(
|
||||||
|
Canvas* const canvas,
|
||||||
|
const MultiConverterState* multi_converter_state);
|
||||||
|
|
||||||
//
|
//
|
||||||
// reset the SELECT mode view, showing as "pre-selected" the current working units
|
// reset the SELECT mode view, showing as "pre-selected" the current working units
|
||||||
@@ -37,7 +48,9 @@ void multi_converter_mode_select_reset(MultiConverterState* const multi_converte
|
|||||||
//
|
//
|
||||||
// notice the MODE CHANGE itself is not done here but in the main loop (outside the call) via the ModeTrigger enum element
|
// notice the MODE CHANGE itself is not done here but in the main loop (outside the call) via the ModeTrigger enum element
|
||||||
//
|
//
|
||||||
MultiConverterModeTrigger multi_converter_mode_select_exit(uint8_t save_changes, MultiConverterState* const multi_converter_state);
|
MultiConverterModeTrigger multi_converter_mode_select_exit(
|
||||||
|
uint8_t save_changes,
|
||||||
|
MultiConverterState* const multi_converter_state);
|
||||||
|
|
||||||
//
|
//
|
||||||
// switch between selecting the ORIGIN or the DESTINATION unit on DISPLAY mode (since there're only
|
// switch between selecting the ORIGIN or the DESTINATION unit on DISPLAY mode (since there're only
|
||||||
@@ -55,4 +68,6 @@ void multi_converter_mode_select_switch(MultiConverterState* const multi_convert
|
|||||||
//
|
//
|
||||||
// (notice the draw step also perform which units are valid to display, so no worries about that here)
|
// (notice the draw step also perform which units are valid to display, so no worries about that here)
|
||||||
//
|
//
|
||||||
void multi_converter_mode_select_change_unit(int8_t direction, MultiConverterState* const multi_converter_state);
|
void multi_converter_mode_select_change_unit(
|
||||||
|
int8_t direction,
|
||||||
|
MultiConverterState* const multi_converter_state);
|
||||||
|
|||||||
@@ -3,13 +3,14 @@
|
|||||||
#define MULTI_CONVERTER_CHAR_OVERFLOW '#'
|
#define MULTI_CONVERTER_CHAR_OVERFLOW '#'
|
||||||
#define MULTI_CONVERTER_MAX_SUPORTED_INT 999999999
|
#define MULTI_CONVERTER_MAX_SUPORTED_INT 999999999
|
||||||
|
|
||||||
#define multi_converter_unit_set_overflow(b) for (int _i = 0; _i < MULTI_CONVERTER_NUMBER_DIGITS; _i++) b[_i] = MULTI_CONVERTER_CHAR_OVERFLOW;
|
#define multi_converter_unit_set_overflow(b) \
|
||||||
|
for(int _i = 0; _i < MULTI_CONVERTER_NUMBER_DIGITS; _i++) \
|
||||||
|
b[_i] = MULTI_CONVERTER_CHAR_OVERFLOW;
|
||||||
|
|
||||||
//
|
//
|
||||||
// DEC / HEX / BIN conversion
|
// DEC / HEX / BIN conversion
|
||||||
//
|
//
|
||||||
void multi_converter_unit_dec_hex_bin_convert(MultiConverterState* const multi_converter_state) {
|
void multi_converter_unit_dec_hex_bin_convert(MultiConverterState* const multi_converter_state) {
|
||||||
|
|
||||||
char dest[MULTI_CONVERTER_NUMBER_DIGITS];
|
char dest[MULTI_CONVERTER_NUMBER_DIGITS];
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -55,11 +56,12 @@ void multi_converter_unit_dec_hex_bin_convert(MultiConverterState* const multi_c
|
|||||||
} else {
|
} else {
|
||||||
// copy DEST (reversed) to destination and append empty chars at the end
|
// copy DEST (reversed) to destination and append empty chars at the end
|
||||||
for(int j = 0; j < MULTI_CONVERTER_NUMBER_DIGITS; j++) {
|
for(int j = 0; j < MULTI_CONVERTER_NUMBER_DIGITS; j++) {
|
||||||
if (i >= 1) multi_converter_state->buffer_dest[j] = dest[--i];
|
if(i >= 1)
|
||||||
else multi_converter_state->buffer_dest[j] = ' ';
|
multi_converter_state->buffer_dest[j] = dest[--i];
|
||||||
|
else
|
||||||
|
multi_converter_state->buffer_dest[j] = ' ';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t multi_converter_unit_dec_hex_bin_allowed(MultiConverterUnitType unit_type) {
|
uint8_t multi_converter_unit_dec_hex_bin_allowed(MultiConverterUnitType unit_type) {
|
||||||
@@ -70,7 +72,6 @@ uint8_t multi_converter_unit_dec_hex_bin_allowed(MultiConverterUnitType unit_typ
|
|||||||
// CEL / FAR / KEL
|
// CEL / FAR / KEL
|
||||||
//
|
//
|
||||||
void multi_converter_unit_temperature_convert(MultiConverterState* const multi_converter_state) {
|
void multi_converter_unit_temperature_convert(MultiConverterState* const multi_converter_state) {
|
||||||
|
|
||||||
double a = strtof(multi_converter_state->buffer_orig, NULL);
|
double a = strtof(multi_converter_state->buffer_orig, NULL);
|
||||||
uint8_t overflow = 0;
|
uint8_t overflow = 0;
|
||||||
|
|
||||||
@@ -109,16 +110,17 @@ void multi_converter_unit_temperature_convert(MultiConverterState* const multi_c
|
|||||||
if(overflow) {
|
if(overflow) {
|
||||||
multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
||||||
} else {
|
} else {
|
||||||
|
int ret = snprintf(
|
||||||
int ret = snprintf(multi_converter_state->buffer_dest, MULTI_CONVERTER_NUMBER_DIGITS + 1, "%.3lf", a);
|
multi_converter_state->buffer_dest, MULTI_CONVERTER_NUMBER_DIGITS + 1, "%.3lf", a);
|
||||||
|
|
||||||
if(ret < 0) multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
if(ret < 0) multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t multi_converter_unit_temperature_allowed(MultiConverterUnitType unit_type) {
|
uint8_t multi_converter_unit_temperature_allowed(MultiConverterUnitType unit_type) {
|
||||||
return (unit_type == UnitTypeCelsius || unit_type == UnitTypeFahernheit || unit_type == UnitTypeKelvin);
|
return (
|
||||||
|
unit_type == UnitTypeCelsius || unit_type == UnitTypeFahernheit ||
|
||||||
|
unit_type == UnitTypeKelvin);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -133,56 +135,85 @@ void multi_converter_unit_distance_convert(MultiConverterState* const multi_conv
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
case UnitTypeKilometers:
|
case UnitTypeKilometers:
|
||||||
if (multi_converter_state->unit_type_dest == UnitTypeMeters) a *= ((double) 1000);
|
if(multi_converter_state->unit_type_dest == UnitTypeMeters)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeCentimeters) a *= ((double) 100000);
|
a *= ((double)1000);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeMiles) a *= ((double) 0.6213711);
|
else if(multi_converter_state->unit_type_dest == UnitTypeCentimeters)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeFeet) a *= ((double) 3280.839895013);
|
a *= ((double)100000);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeInches) a *= ((double) 39370.078740157);
|
else if(multi_converter_state->unit_type_dest == UnitTypeMiles)
|
||||||
|
a *= ((double)0.6213711);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeFeet)
|
||||||
|
a *= ((double)3280.839895013);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeInches)
|
||||||
|
a *= ((double)39370.078740157);
|
||||||
break;
|
break;
|
||||||
case UnitTypeMeters:
|
case UnitTypeMeters:
|
||||||
if (multi_converter_state->unit_type_dest == UnitTypeKilometers) a /= ((double) 1000);
|
if(multi_converter_state->unit_type_dest == UnitTypeKilometers)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeCentimeters) a *= ((double) 100);
|
a /= ((double)1000);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeMiles) a *= ((double) 0.0006213711);
|
else if(multi_converter_state->unit_type_dest == UnitTypeCentimeters)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeFeet) a *= ((double) 3.280839895013);
|
a *= ((double)100);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeInches) a *= ((double) 39.370078740157);
|
else if(multi_converter_state->unit_type_dest == UnitTypeMiles)
|
||||||
|
a *= ((double)0.0006213711);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeFeet)
|
||||||
|
a *= ((double)3.280839895013);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeInches)
|
||||||
|
a *= ((double)39.370078740157);
|
||||||
break;
|
break;
|
||||||
case UnitTypeCentimeters:
|
case UnitTypeCentimeters:
|
||||||
if (multi_converter_state->unit_type_dest == UnitTypeKilometers) a /= ((double) 100000);
|
if(multi_converter_state->unit_type_dest == UnitTypeKilometers)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeMeters) a /= ((double) 100);
|
a /= ((double)100000);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeMiles) a *= ((double) 0.000006213711);
|
else if(multi_converter_state->unit_type_dest == UnitTypeMeters)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeFeet) a *= ((double) 0.03280839895013);
|
a /= ((double)100);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeInches) a *= ((double) 0.39370078740157);
|
else if(multi_converter_state->unit_type_dest == UnitTypeMiles)
|
||||||
|
a *= ((double)0.000006213711);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeFeet)
|
||||||
|
a *= ((double)0.03280839895013);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeInches)
|
||||||
|
a *= ((double)0.39370078740157);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UnitTypeMiles:
|
case UnitTypeMiles:
|
||||||
if (multi_converter_state->unit_type_dest == UnitTypeKilometers) a *= ((double) 1.609344);
|
if(multi_converter_state->unit_type_dest == UnitTypeKilometers)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeMeters) a *= ((double) 1609.344);
|
a *= ((double)1.609344);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeCentimeters) a *= ((double) 160934.4);
|
else if(multi_converter_state->unit_type_dest == UnitTypeMeters)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeFeet) a *= ((double) 5280);
|
a *= ((double)1609.344);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeInches) a *= ((double) 63360);
|
else if(multi_converter_state->unit_type_dest == UnitTypeCentimeters)
|
||||||
|
a *= ((double)160934.4);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeFeet)
|
||||||
|
a *= ((double)5280);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeInches)
|
||||||
|
a *= ((double)63360);
|
||||||
break;
|
break;
|
||||||
case UnitTypeFeet:
|
case UnitTypeFeet:
|
||||||
if (multi_converter_state->unit_type_dest == UnitTypeKilometers) a *= ((double) 0.0003048);
|
if(multi_converter_state->unit_type_dest == UnitTypeKilometers)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeMeters) a *= ((double) 0.3048);
|
a *= ((double)0.0003048);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeCentimeters) a *= ((double) 30.48);
|
else if(multi_converter_state->unit_type_dest == UnitTypeMeters)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeMiles) a *= ((double) 0.000189393939394);
|
a *= ((double)0.3048);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeInches) a *= ((double) 12);
|
else if(multi_converter_state->unit_type_dest == UnitTypeCentimeters)
|
||||||
|
a *= ((double)30.48);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeMiles)
|
||||||
|
a *= ((double)0.000189393939394);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeInches)
|
||||||
|
a *= ((double)12);
|
||||||
break;
|
break;
|
||||||
case UnitTypeInches:
|
case UnitTypeInches:
|
||||||
if (multi_converter_state->unit_type_dest == UnitTypeKilometers) a *= ((double) 0.0000254);
|
if(multi_converter_state->unit_type_dest == UnitTypeKilometers)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeMeters) a *= ((double) 0.0254);
|
a *= ((double)0.0000254);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeCentimeters) a *= ((double) 2.54);
|
else if(multi_converter_state->unit_type_dest == UnitTypeMeters)
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeMiles) a *= ((double) 0.0000157828282828);
|
a *= ((double)0.0254);
|
||||||
else if (multi_converter_state->unit_type_dest == UnitTypeFeet) a *= ((double) 0.0833333333333);
|
else if(multi_converter_state->unit_type_dest == UnitTypeCentimeters)
|
||||||
|
a *= ((double)2.54);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeMiles)
|
||||||
|
a *= ((double)0.0000157828282828);
|
||||||
|
else if(multi_converter_state->unit_type_dest == UnitTypeFeet)
|
||||||
|
a *= ((double)0.0833333333333);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(overflow) {
|
if(overflow) {
|
||||||
multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
||||||
} else {
|
} else {
|
||||||
|
int ret = snprintf(
|
||||||
int ret = snprintf(multi_converter_state->buffer_dest, MULTI_CONVERTER_NUMBER_DIGITS + 1, "%lf", a);
|
multi_converter_state->buffer_dest, MULTI_CONVERTER_NUMBER_DIGITS + 1, "%lf", a);
|
||||||
|
|
||||||
if(ret < 0) multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
if(ret < 0) multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
||||||
}
|
}
|
||||||
@@ -190,9 +221,9 @@ void multi_converter_unit_distance_convert(MultiConverterState* const multi_conv
|
|||||||
|
|
||||||
uint8_t multi_converter_unit_distance_allowed(MultiConverterUnitType unit_type) {
|
uint8_t multi_converter_unit_distance_allowed(MultiConverterUnitType unit_type) {
|
||||||
return (
|
return (
|
||||||
unit_type == UnitTypeKilometers || unit_type == UnitTypeMeters || unit_type == UnitTypeCentimeters ||
|
unit_type == UnitTypeKilometers || unit_type == UnitTypeMeters ||
|
||||||
unit_type == UnitTypeMiles || unit_type == UnitTypeFeet || unit_type == UnitTypeInches
|
unit_type == UnitTypeCentimeters || unit_type == UnitTypeMiles ||
|
||||||
);
|
unit_type == UnitTypeFeet || unit_type == UnitTypeInches);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -218,8 +249,8 @@ void multi_converter_unit_angle_convert(MultiConverterState* const multi_convert
|
|||||||
if(overflow) {
|
if(overflow) {
|
||||||
multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
||||||
} else {
|
} else {
|
||||||
|
int ret = snprintf(
|
||||||
int ret = snprintf(multi_converter_state->buffer_dest, MULTI_CONVERTER_NUMBER_DIGITS + 1, "%lf", a);
|
multi_converter_state->buffer_dest, MULTI_CONVERTER_NUMBER_DIGITS + 1, "%lf", a);
|
||||||
|
|
||||||
if(ret < 0) multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
if(ret < 0) multi_converter_unit_set_overflow(multi_converter_state->buffer_dest);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,9 @@
|
|||||||
#define MULTI_CONVERTER_AVAILABLE_UNITS 14
|
#define MULTI_CONVERTER_AVAILABLE_UNITS 14
|
||||||
|
|
||||||
#define multi_converter_get_unit(unit_type) multi_converter_available_units[unit_type]
|
#define multi_converter_get_unit(unit_type) multi_converter_available_units[unit_type]
|
||||||
#define multi_converter_get_unit_type_offset(unit_type, offset) (((unit_type + offset) % MULTI_CONVERTER_AVAILABLE_UNITS + MULTI_CONVERTER_AVAILABLE_UNITS) % MULTI_CONVERTER_AVAILABLE_UNITS)
|
#define multi_converter_get_unit_type_offset(unit_type, offset) \
|
||||||
|
(((unit_type + offset) % MULTI_CONVERTER_AVAILABLE_UNITS + MULTI_CONVERTER_AVAILABLE_UNITS) % \
|
||||||
|
MULTI_CONVERTER_AVAILABLE_UNITS)
|
||||||
// the modulo operation will fail with extremely large values on the units array
|
// the modulo operation will fail with extremely large values on the units array
|
||||||
|
|
||||||
// DEC / HEX / BIN
|
// DEC / HEX / BIN
|
||||||
@@ -31,23 +33,121 @@ uint8_t multi_converter_unit_angle_allowed(MultiConverterUnitType unit_type);
|
|||||||
// each unit is made of comma? + negative? + keyboard_length + mini_name + name + convert function + allowed function
|
// each unit is made of comma? + negative? + keyboard_length + mini_name + name + convert function + allowed function
|
||||||
// (setting functions as NULL will cause convert / select options to be ignored)
|
// (setting functions as NULL will cause convert / select options to be ignored)
|
||||||
//
|
//
|
||||||
static const MultiConverterUnit multi_converter_unit_dec = { 0, 0, 10, "DEC\0", "Decimal\0", multi_converter_unit_dec_hex_bin_convert, multi_converter_unit_dec_hex_bin_allowed };
|
static const MultiConverterUnit multi_converter_unit_dec = {
|
||||||
static const MultiConverterUnit multi_converter_unit_hex = { 0, 0, 16, "HEX\0", "Hexadecimal\0", multi_converter_unit_dec_hex_bin_convert, multi_converter_unit_dec_hex_bin_allowed };
|
0,
|
||||||
static const MultiConverterUnit multi_converter_unit_bin = { 0, 0, 2, "BIN\0", "Binary\0", multi_converter_unit_dec_hex_bin_convert, multi_converter_unit_dec_hex_bin_allowed };
|
0,
|
||||||
|
10,
|
||||||
|
"DEC\0",
|
||||||
|
"Decimal\0",
|
||||||
|
multi_converter_unit_dec_hex_bin_convert,
|
||||||
|
multi_converter_unit_dec_hex_bin_allowed};
|
||||||
|
static const MultiConverterUnit multi_converter_unit_hex = {
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
16,
|
||||||
|
"HEX\0",
|
||||||
|
"Hexadecimal\0",
|
||||||
|
multi_converter_unit_dec_hex_bin_convert,
|
||||||
|
multi_converter_unit_dec_hex_bin_allowed};
|
||||||
|
static const MultiConverterUnit multi_converter_unit_bin = {
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
"BIN\0",
|
||||||
|
"Binary\0",
|
||||||
|
multi_converter_unit_dec_hex_bin_convert,
|
||||||
|
multi_converter_unit_dec_hex_bin_allowed};
|
||||||
|
|
||||||
static const MultiConverterUnit multi_converter_unit_cel = { 1, 1, 10, "CEL\0", "Celsius\0", multi_converter_unit_temperature_convert, multi_converter_unit_temperature_allowed };
|
static const MultiConverterUnit multi_converter_unit_cel = {
|
||||||
static const MultiConverterUnit multi_converter_unit_far = { 1, 1, 10, "FAR\0", "Fahernheit\0", multi_converter_unit_temperature_convert, multi_converter_unit_temperature_allowed };
|
1,
|
||||||
static const MultiConverterUnit multi_converter_unit_kel = { 1, 1, 10, "KEL\0", "Kelvin\0", multi_converter_unit_temperature_convert, multi_converter_unit_temperature_allowed };
|
1,
|
||||||
|
10,
|
||||||
|
"CEL\0",
|
||||||
|
"Celsius\0",
|
||||||
|
multi_converter_unit_temperature_convert,
|
||||||
|
multi_converter_unit_temperature_allowed};
|
||||||
|
static const MultiConverterUnit multi_converter_unit_far = {
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
10,
|
||||||
|
"FAR\0",
|
||||||
|
"Fahernheit\0",
|
||||||
|
multi_converter_unit_temperature_convert,
|
||||||
|
multi_converter_unit_temperature_allowed};
|
||||||
|
static const MultiConverterUnit multi_converter_unit_kel = {
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
10,
|
||||||
|
"KEL\0",
|
||||||
|
"Kelvin\0",
|
||||||
|
multi_converter_unit_temperature_convert,
|
||||||
|
multi_converter_unit_temperature_allowed};
|
||||||
|
|
||||||
static const MultiConverterUnit multi_converter_unit_km = { 1, 0, 10, "KM\0", "Kilometers\0", multi_converter_unit_distance_convert, multi_converter_unit_distance_allowed };
|
static const MultiConverterUnit multi_converter_unit_km = {
|
||||||
static const MultiConverterUnit multi_converter_unit_m = { 1, 0, 10, "M\0", "Meters\0", multi_converter_unit_distance_convert, multi_converter_unit_distance_allowed };
|
1,
|
||||||
static const MultiConverterUnit multi_converter_unit_cm = { 1, 0, 10, "CM\0", "Centimeters\0", multi_converter_unit_distance_convert, multi_converter_unit_distance_allowed };
|
0,
|
||||||
static const MultiConverterUnit multi_converter_unit_mi = { 1, 0, 10, "MI\0", "Miles\0", multi_converter_unit_distance_convert, multi_converter_unit_distance_allowed };
|
10,
|
||||||
static const MultiConverterUnit multi_converter_unit_ft = { 1, 0, 10, "FT\0", "Feet\0", multi_converter_unit_distance_convert, multi_converter_unit_distance_allowed };
|
"KM\0",
|
||||||
static const MultiConverterUnit multi_converter_unit_in = { 1, 0, 10, " \"\0", "Inches\0", multi_converter_unit_distance_convert, multi_converter_unit_distance_allowed };
|
"Kilometers\0",
|
||||||
|
multi_converter_unit_distance_convert,
|
||||||
|
multi_converter_unit_distance_allowed};
|
||||||
|
static const MultiConverterUnit multi_converter_unit_m = {
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
10,
|
||||||
|
"M\0",
|
||||||
|
"Meters\0",
|
||||||
|
multi_converter_unit_distance_convert,
|
||||||
|
multi_converter_unit_distance_allowed};
|
||||||
|
static const MultiConverterUnit multi_converter_unit_cm = {
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
10,
|
||||||
|
"CM\0",
|
||||||
|
"Centimeters\0",
|
||||||
|
multi_converter_unit_distance_convert,
|
||||||
|
multi_converter_unit_distance_allowed};
|
||||||
|
static const MultiConverterUnit multi_converter_unit_mi = {
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
10,
|
||||||
|
"MI\0",
|
||||||
|
"Miles\0",
|
||||||
|
multi_converter_unit_distance_convert,
|
||||||
|
multi_converter_unit_distance_allowed};
|
||||||
|
static const MultiConverterUnit multi_converter_unit_ft = {
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
10,
|
||||||
|
"FT\0",
|
||||||
|
"Feet\0",
|
||||||
|
multi_converter_unit_distance_convert,
|
||||||
|
multi_converter_unit_distance_allowed};
|
||||||
|
static const MultiConverterUnit multi_converter_unit_in = {
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
10,
|
||||||
|
" \"\0",
|
||||||
|
"Inches\0",
|
||||||
|
multi_converter_unit_distance_convert,
|
||||||
|
multi_converter_unit_distance_allowed};
|
||||||
|
|
||||||
static const MultiConverterUnit multi_converter_unit_deg = { 1, 0, 10, "DEG\0", "Degree\0", multi_converter_unit_angle_convert, multi_converter_unit_angle_allowed };
|
static const MultiConverterUnit multi_converter_unit_deg = {
|
||||||
static const MultiConverterUnit multi_converter_unit_rad = { 1, 0, 10, "RAD\0", "Radian\0", multi_converter_unit_angle_convert, multi_converter_unit_angle_allowed };
|
1,
|
||||||
|
0,
|
||||||
|
10,
|
||||||
|
"DEG\0",
|
||||||
|
"Degree\0",
|
||||||
|
multi_converter_unit_angle_convert,
|
||||||
|
multi_converter_unit_angle_allowed};
|
||||||
|
static const MultiConverterUnit multi_converter_unit_rad = {
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
10,
|
||||||
|
"RAD\0",
|
||||||
|
"Radian\0",
|
||||||
|
multi_converter_unit_angle_convert,
|
||||||
|
multi_converter_unit_angle_allowed};
|
||||||
|
|
||||||
// index order set by the MultiConverterUnitType enum element (multi_converter_definitions.h)
|
// index order set by the MultiConverterUnitType enum element (multi_converter_definitions.h)
|
||||||
static const MultiConverterUnit multi_converter_available_units[MULTI_CONVERTER_AVAILABLE_UNITS] = {
|
static const MultiConverterUnit multi_converter_available_units[MULTI_CONVERTER_AVAILABLE_UNITS] = {
|
||||||
|
|||||||
0
lib/nfc/nfc_worker_i.h
Executable file → Normal file
0
lib/nfc/nfc_worker_i.h
Executable file → Normal file
Reference in New Issue
Block a user