mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-26 04:36:38 +00:00
Add virtual backlight dimming
This commit is contained in:
parent
e8850d99fe
commit
1ccbbf16ea
@ -51,7 +51,8 @@
|
|||||||
/**********************
|
/**********************
|
||||||
* TYPEDEFS
|
* TYPEDEFS
|
||||||
**********************/
|
**********************/
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
SDL_Window* window;
|
SDL_Window* window;
|
||||||
SDL_Renderer* renderer;
|
SDL_Renderer* renderer;
|
||||||
SDL_Texture* texture;
|
SDL_Texture* texture;
|
||||||
@ -115,7 +116,8 @@ void monitor_init(void)
|
|||||||
|
|
||||||
#ifndef MONITOR_EMSCRIPTEN
|
#ifndef MONITOR_EMSCRIPTEN
|
||||||
SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL);
|
SDL_CreateThread(monitor_sdl_refr_thread, "sdl_refr", NULL);
|
||||||
while(sdl_inited == false); /*Wait until 'sdl_refr' initializes the SDL*/
|
while(sdl_inited == false)
|
||||||
|
; /*Wait until 'sdl_refr' initializes the SDL*/
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +158,6 @@ void monitor_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t
|
|||||||
monitor.tft_fb[y * disp_drv->hor_res + x] = lv_color_to32(*color_p);
|
monitor.tft_fb[y * disp_drv->hor_res + x] = lv_color_to32(*color_p);
|
||||||
color_p++;
|
color_p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
uint32_t w = lv_area_get_width(area);
|
uint32_t w = lv_area_get_width(area);
|
||||||
@ -173,7 +174,6 @@ void monitor_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if MONITOR_DUAL
|
#if MONITOR_DUAL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -210,7 +210,6 @@ void monitor_flush2(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t
|
|||||||
monitor2.tft_fb[y * disp_drv->hor_res + x] = lv_color_to32(*color_p);
|
monitor2.tft_fb[y * disp_drv->hor_res + x] = lv_color_to32(*color_p);
|
||||||
color_p++;
|
color_p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
uint32_t w = lv_area_get_width(area);
|
uint32_t w = lv_area_get_width(area);
|
||||||
@ -265,13 +264,10 @@ int quit_filter(void * userdata, SDL_Event * event)
|
|||||||
if(event->window.event == SDL_WINDOWEVENT_CLOSE) {
|
if(event->window.event == SDL_WINDOWEVENT_CLOSE) {
|
||||||
sdl_quit_qry = true;
|
sdl_quit_qry = true;
|
||||||
}
|
}
|
||||||
}
|
} else if(event->type == SDL_QUIT) {
|
||||||
else if(event->type == SDL_QUIT) {
|
|
||||||
sdl_quit_qry = true;
|
sdl_quit_qry = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,6 +287,12 @@ static void monitor_sdl_clean_up(void)
|
|||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void monitor_backlight(uint8_t level)
|
||||||
|
{
|
||||||
|
SDL_SetTextureColorMod(monitor.texture, level, level, level);
|
||||||
|
window_update(&monitor);
|
||||||
|
}
|
||||||
|
|
||||||
static void monitor_sdl_init(void)
|
static void monitor_sdl_init(void)
|
||||||
{
|
{
|
||||||
/*Initialize the SDL*/
|
/*Initialize the SDL*/
|
||||||
@ -363,22 +365,21 @@ static void monitor_sdl_refr_core(void)
|
|||||||
|
|
||||||
/*Sleep some time*/
|
/*Sleep some time*/
|
||||||
SDL_Delay(SDL_REFR_PERIOD);
|
SDL_Delay(SDL_REFR_PERIOD);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_create(monitor_t* m)
|
static void window_create(monitor_t* m)
|
||||||
{
|
{
|
||||||
m->window = SDL_CreateWindow("TFT Simulator",
|
m->window = SDL_CreateWindow("TFT Simulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||||
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM,
|
||||||
MONITOR_HOR_RES * MONITOR_ZOOM, MONITOR_VER_RES * MONITOR_ZOOM, 0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/
|
0); /*last param. SDL_WINDOW_BORDERLESS to hide borders*/
|
||||||
|
|
||||||
#if MONITOR_VIRTUAL_MACHINE || defined(MONITOR_EMSCRIPTEN)
|
#if MONITOR_VIRTUAL_MACHINE || defined(MONITOR_EMSCRIPTEN)
|
||||||
m->renderer = SDL_CreateRenderer(m->window, -1, SDL_RENDERER_SOFTWARE);
|
m->renderer = SDL_CreateRenderer(m->window, -1, SDL_RENDERER_SOFTWARE);
|
||||||
#else
|
#else
|
||||||
m->renderer = SDL_CreateRenderer(m->window, -1, 0);
|
m->renderer = SDL_CreateRenderer(m->window, -1, 0);
|
||||||
#endif
|
#endif
|
||||||
m->texture = SDL_CreateTexture(m->renderer,
|
m->texture = SDL_CreateTexture(m->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES,
|
||||||
SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, MONITOR_HOR_RES, MONITOR_VER_RES);
|
MONITOR_VER_RES);
|
||||||
SDL_SetTextureBlendMode(m->texture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(m->texture, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
/*Initialize the frame buffer to gray (77 is an empirical value) */
|
/*Initialize the frame buffer to gray (77 is an empirical value) */
|
||||||
@ -389,7 +390,6 @@ static void window_create(monitor_t * m)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
m->sdl_refr_qry = true;
|
m->sdl_refr_qry = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_update(monitor_t* m)
|
static void window_update(monitor_t* m)
|
||||||
|
@ -43,6 +43,7 @@ extern "C" {
|
|||||||
void monitor_init(void);
|
void monitor_init(void);
|
||||||
void monitor_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p);
|
void monitor_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p);
|
||||||
void monitor_flush2(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p);
|
void monitor_flush2(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p);
|
||||||
|
void monitor_backlight(uint8_t level);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
@ -45,7 +45,7 @@ void Esp32Device::set_backlight_pin(uint8_t pin)
|
|||||||
Esp32Device::_backlight_pin = pin;
|
Esp32Device::_backlight_pin = pin;
|
||||||
|
|
||||||
/* Setup Backlight Control Pin */
|
/* Setup Backlight Control Pin */
|
||||||
if(pin != (uint8_t)-1) {
|
if(pin < GPIO_NUM_MAX) {
|
||||||
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin);
|
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin);
|
||||||
ledcSetup(BACKLIGHT_CHANNEL, 20000, 12);
|
ledcSetup(BACKLIGHT_CHANNEL, 20000, 12);
|
||||||
ledcAttachPin(pin, BACKLIGHT_CHANNEL);
|
ledcAttachPin(pin, BACKLIGHT_CHANNEL);
|
||||||
@ -81,11 +81,11 @@ bool Esp32Device::get_backlight_power()
|
|||||||
|
|
||||||
void Esp32Device::update_backlight()
|
void Esp32Device::update_backlight()
|
||||||
{
|
{
|
||||||
if(_backlight_pin == (uint8_t)-1) return;
|
if(pin < GPIO_NUM_MAX) {
|
||||||
|
|
||||||
uint32_t duty = _backlight_power ? map(_backlight_level, 0, 100, 0, 4095) : 0;
|
uint32_t duty = _backlight_power ? map(_backlight_level, 0, 100, 0, 4095) : 0;
|
||||||
ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value
|
ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t Esp32Device::get_free_max_block()
|
size_t Esp32Device::get_free_max_block()
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
#include "hasp_debug.h"
|
#include "hasp_debug.h"
|
||||||
|
#include "hasp/hasp_utilities.h"
|
||||||
|
|
||||||
|
#include "display/monitor.h"
|
||||||
|
|
||||||
namespace dev {
|
namespace dev {
|
||||||
|
|
||||||
@ -32,7 +35,7 @@ const char* Win32Device::get_display_driver()
|
|||||||
|
|
||||||
void Win32Device::set_backlight_pin(uint8_t pin)
|
void Win32Device::set_backlight_pin(uint8_t pin)
|
||||||
{
|
{
|
||||||
Win32Device::_backlight_pin = pin;
|
// Win32Device::_backlight_pin = pin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Device::set_backlight_level(uint8_t level)
|
void Win32Device::set_backlight_level(uint8_t level)
|
||||||
@ -60,7 +63,7 @@ bool Win32Device::get_backlight_power()
|
|||||||
|
|
||||||
void Win32Device::update_backlight()
|
void Win32Device::update_backlight()
|
||||||
{
|
{
|
||||||
if(_backlight_pin == -1) return;
|
monitor_backlight(_backlight_power ? map(_backlight_level, 0, 100, 0, 255) : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Win32Device::get_free_max_block()
|
size_t Win32Device::get_free_max_block()
|
||||||
|
@ -21,7 +21,7 @@ class Win32Device : public BaseDevice {
|
|||||||
Win32Device()
|
Win32Device()
|
||||||
{
|
{
|
||||||
_hostname = "winplate";
|
_hostname = "winplate";
|
||||||
_backlight_pin = -1;
|
// _backlight_pin = -1;
|
||||||
_backlight_power = 1;
|
_backlight_power = 1;
|
||||||
_backlight_level = 100;
|
_backlight_level = 100;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user