2022-01-05 16:10:18 +00:00
|
|
|
#include <furi_hal.h>
|
2021-10-17 20:34:36 +00:00
|
|
|
#include <furi.h>
|
|
|
|
|
2021-10-19 11:42:49 +00:00
|
|
|
// Need access to u8g2
|
|
|
|
#include <gui/gui_i.h>
|
|
|
|
#include <gui/canvas_i.h>
|
|
|
|
#include <u8g2_glue.h>
|
|
|
|
|
2021-10-17 20:34:36 +00:00
|
|
|
#include <gui/view_dispatcher.h>
|
|
|
|
#include <gui/modules/submenu.h>
|
2022-01-05 16:10:18 +00:00
|
|
|
#include <gui/modules/variable_item_list.h>
|
2021-10-17 20:34:36 +00:00
|
|
|
|
|
|
|
#include "view_display_test.h"
|
|
|
|
|
2021-11-12 13:04:35 +00:00
|
|
|
#define TAG "DisplayTest"
|
|
|
|
|
2021-10-17 20:34:36 +00:00
|
|
|
typedef struct {
|
|
|
|
Gui* gui;
|
|
|
|
ViewDispatcher* view_dispatcher;
|
|
|
|
ViewDisplayTest* view_display_test;
|
|
|
|
VariableItemList* variable_item_list;
|
|
|
|
Submenu* submenu;
|
2021-10-19 11:42:49 +00:00
|
|
|
|
|
|
|
bool config_bias;
|
|
|
|
uint8_t config_contrast;
|
|
|
|
uint8_t config_regulation_ratio;
|
2021-10-17 20:34:36 +00:00
|
|
|
} DisplayTest;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
DisplayTestViewSubmenu,
|
|
|
|
DisplayTestViewConfigure,
|
|
|
|
DisplayTestViewDisplayTest,
|
|
|
|
} DisplayTestView;
|
|
|
|
|
2021-10-19 11:42:49 +00:00
|
|
|
const bool config_bias_value[] = {
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
};
|
|
|
|
const char* const config_bias_text[] = {
|
|
|
|
"1/7",
|
|
|
|
"1/9",
|
|
|
|
};
|
|
|
|
|
|
|
|
const uint8_t config_regulation_ratio_value[] = {
|
|
|
|
0b000,
|
|
|
|
0b001,
|
|
|
|
0b010,
|
|
|
|
0b011,
|
|
|
|
0b100,
|
|
|
|
0b101,
|
|
|
|
0b110,
|
|
|
|
0b111,
|
|
|
|
};
|
|
|
|
const char* const config_regulation_ratio_text[] = {
|
|
|
|
"3.0",
|
|
|
|
"3.5",
|
|
|
|
"4.0",
|
|
|
|
"4.5",
|
|
|
|
"5.0",
|
|
|
|
"5.5",
|
|
|
|
"6.0",
|
|
|
|
"6.5",
|
|
|
|
};
|
|
|
|
|
2021-10-17 20:34:36 +00:00
|
|
|
static void display_test_submenu_callback(void* context, uint32_t index) {
|
|
|
|
DisplayTest* instance = (DisplayTest*)context;
|
|
|
|
view_dispatcher_switch_to_view(instance->view_dispatcher, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t display_test_previous_callback(void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(context);
|
2021-10-17 20:34:36 +00:00
|
|
|
return DisplayTestViewSubmenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t display_test_exit_callback(void* context) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(context);
|
2021-10-17 20:34:36 +00:00
|
|
|
return VIEW_NONE;
|
|
|
|
}
|
|
|
|
|
2021-10-19 11:42:49 +00:00
|
|
|
static void display_test_reload_config(DisplayTest* instance) {
|
|
|
|
FURI_LOG_I(
|
2021-11-12 13:04:35 +00:00
|
|
|
TAG,
|
2021-10-19 11:42:49 +00:00
|
|
|
"contrast: %d, regulation_ratio: %d, bias: %d",
|
|
|
|
instance->config_contrast,
|
|
|
|
instance->config_regulation_ratio,
|
|
|
|
instance->config_bias);
|
2021-10-21 12:24:34 +00:00
|
|
|
u8x8_d_st756x_init(
|
2021-10-19 11:42:49 +00:00
|
|
|
&instance->gui->canvas->fb.u8x8,
|
|
|
|
instance->config_contrast,
|
|
|
|
instance->config_regulation_ratio,
|
|
|
|
instance->config_bias);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void display_config_set_bias(VariableItem* item) {
|
|
|
|
DisplayTest* instance = variable_item_get_context(item);
|
|
|
|
uint8_t index = variable_item_get_current_value_index(item);
|
|
|
|
variable_item_set_current_value_text(item, config_bias_text[index]);
|
|
|
|
instance->config_bias = config_bias_value[index];
|
|
|
|
display_test_reload_config(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void display_config_set_regulation_ratio(VariableItem* item) {
|
|
|
|
DisplayTest* instance = variable_item_get_context(item);
|
|
|
|
uint8_t index = variable_item_get_current_value_index(item);
|
|
|
|
variable_item_set_current_value_text(item, config_regulation_ratio_text[index]);
|
|
|
|
instance->config_regulation_ratio = config_regulation_ratio_value[index];
|
|
|
|
display_test_reload_config(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void display_config_set_contrast(VariableItem* item) {
|
|
|
|
DisplayTest* instance = variable_item_get_context(item);
|
|
|
|
uint8_t index = variable_item_get_current_value_index(item);
|
2022-10-05 15:15:23 +00:00
|
|
|
FuriString* temp;
|
|
|
|
temp = furi_string_alloc();
|
|
|
|
furi_string_cat_printf(temp, "%d", index);
|
|
|
|
variable_item_set_current_value_text(item, furi_string_get_cstr(temp));
|
|
|
|
furi_string_free(temp);
|
2021-10-19 11:42:49 +00:00
|
|
|
instance->config_contrast = index;
|
|
|
|
display_test_reload_config(instance);
|
|
|
|
}
|
|
|
|
|
2024-03-19 14:43:52 +00:00
|
|
|
DisplayTest* display_test_alloc(void) {
|
2022-02-18 19:53:46 +00:00
|
|
|
DisplayTest* instance = malloc(sizeof(DisplayTest));
|
2021-10-17 20:34:36 +00:00
|
|
|
|
|
|
|
View* view = NULL;
|
|
|
|
|
2022-07-26 12:21:51 +00:00
|
|
|
instance->gui = furi_record_open(RECORD_GUI);
|
2021-10-17 20:34:36 +00:00
|
|
|
instance->view_dispatcher = view_dispatcher_alloc();
|
|
|
|
view_dispatcher_enable_queue(instance->view_dispatcher);
|
|
|
|
view_dispatcher_attach_to_gui(
|
|
|
|
instance->view_dispatcher, instance->gui, ViewDispatcherTypeFullscreen);
|
2021-10-19 11:42:49 +00:00
|
|
|
|
|
|
|
// Test
|
|
|
|
instance->view_display_test = view_display_test_alloc();
|
2021-10-17 20:34:36 +00:00
|
|
|
view = view_display_test_get_view(instance->view_display_test);
|
|
|
|
view_set_previous_callback(view, display_test_previous_callback);
|
|
|
|
view_dispatcher_add_view(instance->view_dispatcher, DisplayTestViewDisplayTest, view);
|
|
|
|
|
2021-10-19 11:42:49 +00:00
|
|
|
// Configure
|
|
|
|
instance->variable_item_list = variable_item_list_alloc();
|
|
|
|
view = variable_item_list_get_view(instance->variable_item_list);
|
|
|
|
view_set_previous_callback(view, display_test_previous_callback);
|
|
|
|
view_dispatcher_add_view(instance->view_dispatcher, DisplayTestViewConfigure, view);
|
|
|
|
|
2022-11-28 16:51:51 +00:00
|
|
|
// Configuration items
|
2021-10-19 11:42:49 +00:00
|
|
|
VariableItem* item;
|
|
|
|
instance->config_bias = false;
|
|
|
|
instance->config_contrast = 32;
|
|
|
|
instance->config_regulation_ratio = 0b101;
|
|
|
|
// Bias
|
|
|
|
item = variable_item_list_add(
|
|
|
|
instance->variable_item_list,
|
|
|
|
"Bias:",
|
|
|
|
COUNT_OF(config_bias_value),
|
|
|
|
display_config_set_bias,
|
|
|
|
instance);
|
|
|
|
variable_item_set_current_value_index(item, 1);
|
|
|
|
variable_item_set_current_value_text(item, config_bias_text[1]);
|
|
|
|
// Regulation Ratio
|
|
|
|
item = variable_item_list_add(
|
|
|
|
instance->variable_item_list,
|
|
|
|
"Reg Ratio:",
|
|
|
|
COUNT_OF(config_regulation_ratio_value),
|
|
|
|
display_config_set_regulation_ratio,
|
|
|
|
instance);
|
|
|
|
variable_item_set_current_value_index(item, 5);
|
|
|
|
variable_item_set_current_value_text(item, config_regulation_ratio_text[5]);
|
|
|
|
// Contrast
|
|
|
|
item = variable_item_list_add(
|
|
|
|
instance->variable_item_list, "Contrast:", 64, display_config_set_contrast, instance);
|
|
|
|
variable_item_set_current_value_index(item, 32);
|
|
|
|
variable_item_set_current_value_text(item, "32");
|
|
|
|
|
|
|
|
// Menu
|
2021-10-17 20:34:36 +00:00
|
|
|
instance->submenu = submenu_alloc();
|
|
|
|
view = submenu_get_view(instance->submenu);
|
|
|
|
view_set_previous_callback(view, display_test_exit_callback);
|
|
|
|
view_dispatcher_add_view(instance->view_dispatcher, DisplayTestViewSubmenu, view);
|
|
|
|
submenu_add_item(
|
|
|
|
instance->submenu,
|
|
|
|
"Test",
|
|
|
|
DisplayTestViewDisplayTest,
|
|
|
|
display_test_submenu_callback,
|
|
|
|
instance);
|
2021-10-19 11:42:49 +00:00
|
|
|
submenu_add_item(
|
|
|
|
instance->submenu,
|
|
|
|
"Configure",
|
|
|
|
DisplayTestViewConfigure,
|
|
|
|
display_test_submenu_callback,
|
|
|
|
instance);
|
2021-10-17 20:34:36 +00:00
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void display_test_free(DisplayTest* instance) {
|
|
|
|
view_dispatcher_remove_view(instance->view_dispatcher, DisplayTestViewSubmenu);
|
|
|
|
submenu_free(instance->submenu);
|
|
|
|
|
2021-10-19 11:42:49 +00:00
|
|
|
view_dispatcher_remove_view(instance->view_dispatcher, DisplayTestViewConfigure);
|
|
|
|
variable_item_list_free(instance->variable_item_list);
|
|
|
|
|
2021-10-17 20:34:36 +00:00
|
|
|
view_dispatcher_remove_view(instance->view_dispatcher, DisplayTestViewDisplayTest);
|
|
|
|
view_display_test_free(instance->view_display_test);
|
|
|
|
|
|
|
|
view_dispatcher_free(instance->view_dispatcher);
|
2022-07-26 12:21:51 +00:00
|
|
|
furi_record_close(RECORD_GUI);
|
2021-10-17 20:34:36 +00:00
|
|
|
|
|
|
|
free(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t display_test_run(DisplayTest* instance) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(instance);
|
2021-10-17 20:34:36 +00:00
|
|
|
view_dispatcher_switch_to_view(instance->view_dispatcher, DisplayTestViewSubmenu);
|
|
|
|
view_dispatcher_run(instance->view_dispatcher);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t display_test_app(void* p) {
|
2022-05-06 13:37:10 +00:00
|
|
|
UNUSED(p);
|
|
|
|
|
2021-10-17 20:34:36 +00:00
|
|
|
DisplayTest* instance = display_test_alloc();
|
|
|
|
|
|
|
|
int32_t ret = display_test_run(instance);
|
|
|
|
|
|
|
|
display_test_free(instance);
|
|
|
|
|
|
|
|
return ret;
|
2021-10-19 11:42:49 +00:00
|
|
|
}
|