mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 05:36:37 +00:00
Add backlight_invert
This commit is contained in:
parent
fe7db71e8b
commit
13c1c02d66
@ -77,6 +77,8 @@ class BaseDevice {
|
||||
{}
|
||||
virtual void set_backlight_pin(uint8_t pin)
|
||||
{}
|
||||
virtual void set_backlight_invert(bool override)
|
||||
{}
|
||||
virtual void set_backlight_level(uint8_t level)
|
||||
{}
|
||||
virtual uint8_t get_backlight_level()
|
||||
@ -85,6 +87,10 @@ class BaseDevice {
|
||||
}
|
||||
virtual void set_backlight_power(bool power)
|
||||
{}
|
||||
virtual bool get_backlight_invert()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool get_backlight_power()
|
||||
{
|
||||
return true;
|
||||
|
@ -197,6 +197,17 @@ void Esp32Device::set_backlight_pin(uint8_t pin)
|
||||
}
|
||||
}
|
||||
|
||||
void Esp32Device::set_backlight_invert(bool invert)
|
||||
{
|
||||
_backlight_invert = invert;
|
||||
update_backlight();
|
||||
}
|
||||
|
||||
bool Esp32Device::get_backlight_invert()
|
||||
{
|
||||
return _backlight_invert;
|
||||
}
|
||||
|
||||
void Esp32Device::set_backlight_level(uint8_t level)
|
||||
{
|
||||
_backlight_level = level;
|
||||
@ -229,7 +240,7 @@ void Esp32Device::update_backlight()
|
||||
#else
|
||||
uint32_t duty = _backlight_power ? map(_backlight_level, 0, 255, 0, 1023) : 0;
|
||||
if(_backlight_invert) duty = 1023 - duty;
|
||||
ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value
|
||||
ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -283,31 +294,32 @@ uint16_t Esp32Device::get_cpu_frequency()
|
||||
|
||||
bool Esp32Device::is_system_pin(uint8_t pin)
|
||||
{
|
||||
//Also see esp32.cpp / hasp_gpio.cpp
|
||||
#if defined(ESP32S2) //Arduino NUM_DIGITAL_PINS = 48 (but espressif says it only has 46)
|
||||
//From https://hggh.github.io/esp32/2021/01/06/ESP32-S2-pinout.html, it looks like IO26 is for PSRAM
|
||||
//More info https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/_images/esp32-s2_saola1-pinout.jpg
|
||||
//Datasheet https://www.espressif.com/sites/default/files/documentation/esp32-s2-wroom_esp32-s2-wroom-i_datasheet_en.pdf
|
||||
// Also see esp32.cpp / hasp_gpio.cpp
|
||||
#if defined(ESP32S2) // Arduino NUM_DIGITAL_PINS = 48 (but espressif says it only has 46)
|
||||
// From https://hggh.github.io/esp32/2021/01/06/ESP32-S2-pinout.html, it looks like IO26 is for PSRAM
|
||||
// More info https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/_images/esp32-s2_saola1-pinout.jpg
|
||||
// Datasheet
|
||||
// https://www.espressif.com/sites/default/files/documentation/esp32-s2-wroom_esp32-s2-wroom-i_datasheet_en.pdf
|
||||
|
||||
//From the ESP32S2-Wroom pdf, the flash appears to be on the upper set of IO.
|
||||
//SPICS0 = IO10 or IO34 ?
|
||||
//SPICLK = IO12 or IO36
|
||||
//SPIHD = IO9 or IO33
|
||||
//SPID = IO11 or IO35
|
||||
//SPIQ = IO13 or IO37
|
||||
//SPIWP = IO14 or IO38
|
||||
if((pin >= 33) && (pin <= 38)) return true; // SPI flash
|
||||
// From the ESP32S2-Wroom pdf, the flash appears to be on the upper set of IO.
|
||||
// SPICS0 = IO10 or IO34 ?
|
||||
// SPICLK = IO12 or IO36
|
||||
// SPIHD = IO9 or IO33
|
||||
// SPID = IO11 or IO35
|
||||
// SPIQ = IO13 or IO37
|
||||
// SPIWP = IO14 or IO38
|
||||
if((pin >= 33) && (pin <= 38)) return true; // SPI flash
|
||||
|
||||
if(psramFound()) {
|
||||
if((pin == 26) ) return true; // PSRAM. IO26 = SPICS1, the rest are shared with the flash
|
||||
}
|
||||
#else
|
||||
if((pin >= 6) && (pin <= 11)) return true; // integrated SPI flash
|
||||
if((pin == 37) || (pin == 38)) return true; // unavailable
|
||||
if(psramFound()) {
|
||||
if((pin == 16) || (pin == 17)) return true; // PSRAM
|
||||
}
|
||||
#endif
|
||||
if(psramFound()) {
|
||||
if((pin == 26)) return true; // PSRAM. IO26 = SPICS1, the rest are shared with the flash
|
||||
}
|
||||
#else
|
||||
if((pin >= 6) && (pin <= 11)) return true; // integrated SPI flash
|
||||
if((pin == 37) || (pin == 38)) return true; // unavailable
|
||||
if(psramFound()) {
|
||||
if((pin == 16) || (pin == 17)) return true; // PSRAM
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -360,7 +372,7 @@ long Esp32Device::get_uptime()
|
||||
// #warning Building for Lanbon L8
|
||||
#include "dev/esp32/lanbonl8.h"
|
||||
#elif defined(M5STACK)
|
||||
// #warning Building for M5Stack core2
|
||||
// #warning Building for M5Stack core2
|
||||
#include "dev/esp32/m5stackcore2.h"
|
||||
#else
|
||||
dev::Esp32Device haspDevice;
|
||||
|
@ -40,9 +40,11 @@ class Esp32Device : public BaseDevice {
|
||||
const char* get_hardware_id();
|
||||
|
||||
void set_backlight_pin(uint8_t pin) override;
|
||||
void set_backlight_invert(bool invert) override;
|
||||
void set_backlight_level(uint8_t val) override;
|
||||
uint8_t get_backlight_level() override;
|
||||
void set_backlight_power(bool power) override;
|
||||
bool get_backlight_invert() override;
|
||||
bool get_backlight_power() override;
|
||||
|
||||
size_t get_free_max_block() override;
|
||||
|
@ -82,6 +82,17 @@ void Esp8266Device::set_backlight_pin(uint8_t pin)
|
||||
}
|
||||
}
|
||||
|
||||
void Esp8266Device::set_backlight_invert(bool invert)
|
||||
{
|
||||
_backlight_invert = invert;
|
||||
update_backlight();
|
||||
}
|
||||
|
||||
bool Esp8266Device::get_backlight_invert()
|
||||
{
|
||||
return _backlight_invert;
|
||||
}
|
||||
|
||||
void Esp8266Device::set_backlight_level(uint8_t level)
|
||||
{
|
||||
_backlight_level = level;
|
||||
|
@ -26,9 +26,11 @@ class Esp8266Device : public BaseDevice {
|
||||
const char* get_hardware_id();
|
||||
|
||||
void set_backlight_pin(uint8_t pin) override;
|
||||
void set_backlight_invert(bool invert) override;
|
||||
void set_backlight_level(uint8_t val) override;
|
||||
uint8_t get_backlight_level() override;
|
||||
void set_backlight_power(bool power) override;
|
||||
bool get_backlight_invert() override;
|
||||
bool get_backlight_power() override;
|
||||
|
||||
size_t get_free_max_block() override;
|
||||
|
@ -105,6 +105,17 @@ void PosixDevice::set_backlight_pin(uint8_t pin)
|
||||
// PosixDevice::backlight_pin = pin;
|
||||
}
|
||||
|
||||
void PosixDevice::set_backlight_invert(bool invert)
|
||||
{
|
||||
_backlight_invert = invert;
|
||||
update_backlight();
|
||||
}
|
||||
|
||||
bool PosixDevice::get_backlight_invert()
|
||||
{
|
||||
return _backlight_invert;
|
||||
}
|
||||
|
||||
void PosixDevice::set_backlight_level(uint8_t level)
|
||||
{
|
||||
uint8_t new_level = level;
|
||||
|
@ -41,9 +41,11 @@ class PosixDevice : public BaseDevice {
|
||||
const char* get_hardware_id();
|
||||
|
||||
void set_backlight_pin(uint8_t pin);
|
||||
void set_backlight_invert(bool invert) override;
|
||||
void set_backlight_level(uint8_t val);
|
||||
uint8_t get_backlight_level();
|
||||
void set_backlight_power(bool power);
|
||||
bool get_backlight_invert() override;
|
||||
bool get_backlight_power();
|
||||
|
||||
size_t get_free_max_block();
|
||||
|
@ -77,6 +77,17 @@ const char* Stm32f4Device::get_chip_model()
|
||||
#endif
|
||||
}
|
||||
|
||||
void Stm32f4Device::set_backlight_invert(bool invert)
|
||||
{
|
||||
_backlight_invert = invert;
|
||||
update_backlight();
|
||||
}
|
||||
|
||||
bool Stm32f4Device::get_backlight_invert()
|
||||
{
|
||||
return _backlight_invert;
|
||||
}
|
||||
|
||||
void Stm32f4Device::set_backlight_level(uint8_t level)
|
||||
{
|
||||
_backlight_level = level;
|
||||
|
@ -33,9 +33,11 @@ class Stm32f4Device : public BaseDevice {
|
||||
const char* get_hardware_id();
|
||||
|
||||
void set_backlight_pin(uint8_t pin) override;
|
||||
void set_backlight_invert(bool invert) override;
|
||||
void set_backlight_level(uint8_t val) override;
|
||||
uint8_t get_backlight_level() override;
|
||||
void set_backlight_power(bool power) override;
|
||||
bool get_backlight_invert() override;
|
||||
bool get_backlight_power() override;
|
||||
|
||||
size_t get_free_max_block() override;
|
||||
|
@ -12,9 +12,9 @@
|
||||
|
||||
#define BACKLIGHT_CHANNEL 0
|
||||
|
||||
int _gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
int _gettimeofday(struct timeval* tv, struct timezone* tz)
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace dev {
|
||||
@ -82,6 +82,17 @@ const char* Stm32f7Device::get_chip_model()
|
||||
#endif
|
||||
}
|
||||
|
||||
void Stm32f7Device::set_backlight_invert(bool invert)
|
||||
{
|
||||
_backlight_invert = invert;
|
||||
update_backlight();
|
||||
}
|
||||
|
||||
bool Stm32f7Device::get_backlight_invert()
|
||||
{
|
||||
return _backlight_invert;
|
||||
}
|
||||
|
||||
void Stm32f7Device::set_backlight_level(uint8_t level)
|
||||
{
|
||||
_backlight_level = level;
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
#if defined(STM32F7xx)
|
||||
extern "C" {
|
||||
int _gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
int _gettimeofday(struct timeval* tv, struct timezone* tz);
|
||||
}
|
||||
|
||||
namespace dev {
|
||||
@ -36,9 +36,11 @@ class Stm32f7Device : public BaseDevice {
|
||||
const char* get_hardware_id();
|
||||
|
||||
void set_backlight_pin(uint8_t pin) override;
|
||||
void set_backlight_invert(bool invert) override;
|
||||
void set_backlight_level(uint8_t val) override;
|
||||
uint8_t get_backlight_level() override;
|
||||
void set_backlight_power(bool power) override;
|
||||
bool get_backlight_invert() override;
|
||||
bool get_backlight_power() override;
|
||||
|
||||
size_t get_free_max_block() override;
|
||||
|
@ -71,6 +71,17 @@ void Win32Device::set_backlight_pin(uint8_t pin)
|
||||
// Win32Device::_backlight_pin = pin;
|
||||
}
|
||||
|
||||
void Win32Device::set_backlight_invert(bool invert)
|
||||
{
|
||||
_backlight_invert = invert;
|
||||
update_backlight();
|
||||
}
|
||||
|
||||
bool Win32Device::get_backlight_invert()
|
||||
{
|
||||
return _backlight_invert;
|
||||
}
|
||||
|
||||
void Win32Device::set_backlight_level(uint8_t level)
|
||||
{
|
||||
uint8_t new_level = level;
|
||||
|
@ -62,9 +62,11 @@ class Win32Device : public BaseDevice {
|
||||
const char* get_hardware_id();
|
||||
|
||||
void set_backlight_pin(uint8_t pin);
|
||||
void set_backlight_invert(bool invert) override;
|
||||
void set_backlight_level(uint8_t val);
|
||||
uint8_t get_backlight_level();
|
||||
void set_backlight_power(bool power);
|
||||
bool get_backlight_invert() override;
|
||||
bool get_backlight_power();
|
||||
|
||||
size_t get_free_max_block();
|
||||
|
Loading…
x
Reference in New Issue
Block a user