LCD Inversion finished by MMX

This commit is contained in:
Dmitry422
2025-04-09 23:37:30 +07:00
parent 4ec8f21e09
commit 224d4e060b
7 changed files with 37 additions and 17 deletions

View File

@@ -6,8 +6,6 @@
#include <stdint.h>
#include <u8g2_glue.h>
#include <notification/notification_app.h>
const CanvasFontParameters canvas_font_params[FontTotalNumber] = {
[FontPrimary] = {.leading_default = 12, .leading_min = 11, .height = 8, .descender = 2},
[FontSecondary] = {.leading_default = 11, .leading_min = 9, .height = 7, .descender = 2},
@@ -96,6 +94,16 @@ size_t canvas_get_buffer_size(const Canvas* canvas) {
return u8g2_GetBufferTileWidth(&canvas->fb) * u8g2_GetBufferTileHeight(&canvas->fb) * 8;
}
bool canvas_is_inverted_lcd(Canvas* canvas) {
furi_assert(canvas);
return canvas->lcd_inverse;
}
void canvas_set_inverted_lcd(Canvas* canvas, bool inverted) {
furi_assert(canvas);
canvas->lcd_inverse = inverted;
}
void canvas_frame_set(
Canvas* canvas,
int32_t offset_x,
@@ -143,8 +151,8 @@ const CanvasFontParameters* canvas_get_font_params(const Canvas* canvas, Font fo
void canvas_clear(Canvas* canvas) {
furi_check(canvas);
if(lcd_inverted) {
if(canvas->lcd_inverse) {
u8g2_FillBuffer(&canvas->fb);
} else {
u8g2_ClearBuffer(&canvas->fb);
@@ -154,7 +162,7 @@ void canvas_clear(Canvas* canvas) {
void canvas_set_color(Canvas* canvas, Color color) {
furi_check(canvas);
if(lcd_inverted) {
if(canvas->lcd_inverse) {
if(color == ColorBlack) {
color = ColorWhite;
} else if(color == ColorWhite) {
@@ -170,10 +178,10 @@ void canvas_set_font_direction(Canvas* canvas, CanvasDirection dir) {
}
void canvas_invert_color(Canvas* canvas) {
if((canvas->fb.draw_color == ColorXOR) && lcd_inverted) {
if((canvas->fb.draw_color == ColorXOR) && canvas->lcd_inverse) {
// ColorXOR = 0x02, inversion change it to White = 0x00
// but if we have lcd_inverse ON then we need Black =0x01 instead White 0x00
// so we force changing color to black
// so we force changing color to black
canvas->fb.draw_color = ColorBlack;
} else {
canvas->fb.draw_color = !canvas->fb.draw_color;

View File

@@ -447,6 +447,10 @@ void canvas_draw_icon_bitmap(
int16_t h,
const Icon* icon);
bool canvas_is_inverted_lcd(Canvas* canvas);
void canvas_set_inverted_lcd(Canvas* canvas, bool inverted);
#ifdef __cplusplus
}
#endif

View File

@@ -47,6 +47,7 @@ struct Canvas {
CompressIcon* compress_icon;
CanvasCallbackPairArray_t canvas_callback_pair;
FuriMutex* mutex;
bool lcd_inverse;
};
/** Allocate memory and initialize canvas

View File

@@ -620,7 +620,11 @@ static NotificationApp* notification_app_alloc(void) {
furi_timer_alloc(night_shift_timer_callback, FuriTimerTypePeriodic, app);
// --- NIGHT SHIFT END ---
lcd_inverted = false;
Gui* tmp_gui = furi_record_open(RECORD_GUI);
Canvas* tmp_canvas = gui_direct_draw_acquire(tmp_gui);
canvas_set_inverted_lcd(tmp_canvas, false);
gui_direct_draw_release(tmp_gui);
furi_record_close(RECORD_GUI);
return app;
}
@@ -653,8 +657,12 @@ static void notification_apply_settings(NotificationApp* app) {
}
// --- NIGHT SHIFT END ---
//setup global variable "inverted" by settings value;
lcd_inverted = app->settings.lcd_inverse;
//setup canvas variable "inverse" by settings value;
Gui* tmp_gui = furi_record_open(RECORD_GUI);
Canvas* tmp_canvas = gui_direct_draw_acquire(tmp_gui);
canvas_set_inverted_lcd(tmp_canvas, app->settings.lcd_inverse);
gui_direct_draw_release(tmp_gui);
furi_record_close(RECORD_GUI);
}
static void notification_init_settings(NotificationApp* app) {

View File

@@ -70,6 +70,3 @@ struct NotificationApp {
void notification_message_save_settings(NotificationApp* app);
void night_shift_timer_start(NotificationApp* app);
void night_shift_timer_stop(NotificationApp* app);
//global variable for using in canvac.c
extern bool lcd_inverted;