mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-13 14:32:36 +00:00
147 lines
4.9 KiB
C
147 lines
4.9 KiB
C
#include "flipfrid_scene_select_field.h"
|
|
|
|
void flipfrid_center_displayed_key(FlipFridState* context, uint8_t index) {
|
|
//const char* key_cstr = string_get_cstr(context->data_str);
|
|
uint8_t str_index = (index * 3);
|
|
int data_len = sizeof(context->data) / sizeof(context->data[0]);
|
|
|
|
char str[20];
|
|
int index_temp = 0;
|
|
|
|
for(uint8_t i = 0; i < data_len; i++) {
|
|
index_temp += snprintf(&str[index_temp], 20-index_temp, "%x", context->data[i]);
|
|
}
|
|
|
|
|
|
char display_menu[17] = {
|
|
'X', 'X', ' ', 'X', 'X', ' ', '<', 'X', 'X', '>', ' ', 'X', 'X', ' ', 'X', 'X', '\0'};
|
|
|
|
if(index > 1) {
|
|
display_menu[0] = str[str_index - 6];
|
|
display_menu[1] = str[str_index - 5];
|
|
} else {
|
|
display_menu[0] = ' ';
|
|
display_menu[1] = ' ';
|
|
}
|
|
|
|
if(index > 0) {
|
|
display_menu[3] = str[str_index - 3];
|
|
display_menu[4] = str[str_index - 2];
|
|
} else {
|
|
display_menu[3] = ' ';
|
|
display_menu[4] = ' ';
|
|
}
|
|
|
|
display_menu[7] = str[str_index];
|
|
display_menu[8] = str[str_index + 1];
|
|
|
|
if((str_index + 4) <= (uint8_t)strlen(str)) {
|
|
display_menu[11] = str[str_index + 3];
|
|
display_menu[12] = str[str_index + 4];
|
|
} else {
|
|
display_menu[11] = ' ';
|
|
display_menu[12] = ' ';
|
|
}
|
|
|
|
if((str_index + 8) <= (uint8_t)strlen(str)) {
|
|
display_menu[14] = str[str_index + 6];
|
|
display_menu[15] = str[str_index + 7];
|
|
} else {
|
|
display_menu[14] = ' ';
|
|
display_menu[15] = ' ';
|
|
}
|
|
|
|
string_reset(context->notification_msg);
|
|
string_set_str(context->notification_msg, display_menu);
|
|
}
|
|
|
|
void flipfrid_scene_select_field_on_enter(FlipFridState* context) {
|
|
string_clear(context->notification_msg);
|
|
}
|
|
|
|
void flipfrid_scene_select_field_on_exit(FlipFridState* context) {
|
|
UNUSED(context);
|
|
}
|
|
|
|
void flipfrid_scene_select_field_on_tick(FlipFridState* context) {
|
|
UNUSED(context);
|
|
}
|
|
|
|
void flipfrid_scene_select_field_on_event(FlipFridEvent event, FlipFridState* context) {
|
|
if(event.evt_type == EventTypeKey) {
|
|
if(event.input_type == InputTypeShort) {
|
|
const char* key_cstr = string_get_cstr(context->data_str);
|
|
int data_len = sizeof(context->data) / sizeof(context->data[0]);
|
|
|
|
// don't look, it's ugly but I'm a python dev so...
|
|
uint8_t nb_bytes = 0;
|
|
for(uint8_t i = 0; i < strlen(key_cstr); i++) {
|
|
if(' ' == key_cstr[i]) {
|
|
nb_bytes++;
|
|
}
|
|
}
|
|
|
|
switch(event.key) {
|
|
case InputKeyDown:
|
|
FURI_LOG_D(TAG, "Size down: %d", data_len);
|
|
for(uint8_t i = 0; i < data_len; i++) {
|
|
FURI_LOG_D(TAG, "in for down: %d", i);
|
|
if(context->key_index == i) {
|
|
FURI_LOG_D(TAG, "in for down if: %d", context->data[i]);
|
|
context->data[i] = (context->data[i] - 1);
|
|
}
|
|
}
|
|
break;
|
|
case InputKeyUp:
|
|
for(uint8_t i = 0; i < data_len; i++) {
|
|
FURI_LOG_D(TAG, "in for down: %d", i);
|
|
if(context->key_index == i) {
|
|
FURI_LOG_D(TAG, "in for down if: %d", context->data[i]);
|
|
context->data[i] = (context->data[i] + 1);
|
|
}
|
|
}
|
|
break;
|
|
case InputKeyLeft:
|
|
if(context->key_index > 0) {
|
|
context->key_index = context->key_index - 1;
|
|
}
|
|
break;
|
|
case InputKeyRight:
|
|
if(context->key_index < nb_bytes) {
|
|
context->key_index = context->key_index + 1;
|
|
}
|
|
break;
|
|
case InputKeyOk:
|
|
string_reset(context->notification_msg);
|
|
context->current_scene = SceneAttack;
|
|
break;
|
|
case InputKeyBack:
|
|
string_reset(context->notification_msg);
|
|
context->current_scene = SceneSelectFile;
|
|
break;
|
|
}
|
|
FURI_LOG_D(TAG, "Position: %d/%d", context->key_index, nb_bytes);
|
|
}
|
|
}
|
|
}
|
|
|
|
void flipfrid_scene_select_field_on_draw(Canvas* canvas, FlipFridState* context) {
|
|
canvas_clear(canvas);
|
|
canvas_set_color(canvas, ColorBlack);
|
|
|
|
// Frame
|
|
//canvas_draw_frame(canvas, 0, 0, 128, 64);
|
|
|
|
// Title
|
|
canvas_set_font(canvas, FontPrimary);
|
|
canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignTop, "Use < > to select byte.");
|
|
|
|
char msg_index[18];
|
|
snprintf(msg_index, sizeof(msg_index), "Field index : %d", context->key_index);
|
|
canvas_draw_str_aligned(canvas, 64, 26, AlignCenter, AlignTop, msg_index);
|
|
|
|
flipfrid_center_displayed_key(context, context->key_index);
|
|
canvas_set_font(canvas, FontSecondary);
|
|
canvas_draw_str_aligned(
|
|
canvas, 64, 40, AlignCenter, AlignTop, string_get_cstr(context->notification_msg));
|
|
}
|