Merge pull request #887 from Dmitry422/dev

LCD Color Inversion
This commit is contained in:
MMX
2025-04-10 03:07:04 +03:00
committed by GitHub
9 changed files with 91 additions and 14 deletions

View File

@@ -94,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_inversion;
}
void canvas_set_inverted_lcd(Canvas* canvas, bool inverted) {
furi_assert(canvas);
canvas->lcd_inversion = inverted;
}
void canvas_frame_set(
Canvas* canvas,
int32_t offset_x,
@@ -141,11 +151,24 @@ const CanvasFontParameters* canvas_get_font_params(const Canvas* canvas, Font fo
void canvas_clear(Canvas* canvas) {
furi_check(canvas);
u8g2_ClearBuffer(&canvas->fb);
if(canvas->lcd_inversion) {
u8g2_FillBuffer(&canvas->fb);
} else {
u8g2_ClearBuffer(&canvas->fb);
}
}
void canvas_set_color(Canvas* canvas, Color color) {
furi_check(canvas);
if(canvas->lcd_inversion) {
if(color == ColorBlack) {
color = ColorWhite;
} else if(color == ColorWhite) {
color = ColorBlack;
}
}
u8g2_SetDrawColor(&canvas->fb, color);
}
@@ -155,7 +178,14 @@ void canvas_set_font_direction(Canvas* canvas, CanvasDirection dir) {
}
void canvas_invert_color(Canvas* canvas) {
canvas->fb.draw_color = !canvas->fb.draw_color;
if((canvas->fb.draw_color == ColorXOR) && canvas->lcd_inversion) {
// ColorXOR = 0x02, inversion change it to White = 0x00
// but if we have lcd_inversion ON then we need Black =0x01 instead White 0x00
// so we force changing color to black
canvas->fb.draw_color = ColorBlack;
} else {
canvas->fb.draw_color = !canvas->fb.draw_color;
}
}
void canvas_set_font(Canvas* canvas, Font font) {

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_inversion;
};
/** Allocate memory and initialize canvas

View File

@@ -56,10 +56,6 @@ void night_shift_timer_callback(void* context) {
NotificationApp* app = context;
DateTime current_date_time;
// IN DEVELOPMENT
// // save current night_shift;
// float old_night_shift = app->current_night_shift;
// take system time and convert to minutes
furi_hal_rtc_get_datetime(&current_date_time);
uint32_t time = current_date_time.hour * 60 + current_date_time.minute;
@@ -73,12 +69,6 @@ void night_shift_timer_callback(void* context) {
app->current_night_shift = app->settings.night_shift;
app->rgb_srv->current_night_shift = app->settings.night_shift;
}
// IN DEVELOPMENT
// // if night shift was changed then update stock and rgb backlight to new value
// if(old_night_shift != app->current_night_shift) {
// notification_message(app, &sequence_display_backlight_on);
// }
}
// --- NIGHT SHIFT END ---
@@ -630,6 +620,12 @@ static NotificationApp* notification_app_alloc(void) {
furi_timer_alloc(night_shift_timer_callback, FuriTimerTypePeriodic, app);
// --- NIGHT SHIFT END ---
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;
}
@@ -660,6 +656,13 @@ static void notification_apply_settings(NotificationApp* app) {
night_shift_timer_start(app);
}
// --- NIGHT SHIFT END ---
//setup canvas variable "inversion" 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_inversion);
gui_direct_draw_release(tmp_gui);
furi_record_close(RECORD_GUI);
}
static void notification_init_settings(NotificationApp* app) {

View File

@@ -34,7 +34,7 @@ typedef struct {
Light light;
} NotificationLedLayer;
#define NOTIFICATION_SETTINGS_VERSION 0x03
#define NOTIFICATION_SETTINGS_VERSION 0x04
#define NOTIFICATION_SETTINGS_PATH INT_PATH(NOTIFICATION_SETTINGS_FILE_NAME)
typedef struct {
@@ -48,6 +48,7 @@ typedef struct {
float night_shift;
uint32_t night_shift_start;
uint32_t night_shift_end;
bool lcd_inversion;
} NotificationSettings;
struct NotificationApp {