mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Add M5Stack Core2 backlight dimming
This commit is contained in:
parent
84f5685ca7
commit
8b28ecc8cf
@ -20,6 +20,7 @@ void M5StackCore2::init(void)
|
|||||||
|
|
||||||
Axp.SetCHGCurrent(AXP192::kCHG_100mA);
|
Axp.SetCHGCurrent(AXP192::kCHG_100mA);
|
||||||
Axp.SetLcdVoltage(2800);
|
Axp.SetLcdVoltage(2800);
|
||||||
|
_backlight_power = true;
|
||||||
|
|
||||||
Axp.SetBusPowerMode(0);
|
Axp.SetBusPowerMode(0);
|
||||||
Axp.SetCHGCurrent(AXP192::kCHG_190mA);
|
Axp.SetCHGCurrent(AXP192::kCHG_190mA);
|
||||||
@ -44,16 +45,49 @@ void M5StackCore2::init(void)
|
|||||||
Axp.SetLed(1);
|
Axp.SetLed(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void M5StackCore2::set_backlight_level(uint8_t level)
|
||||||
|
{
|
||||||
|
_backlight_level = level;
|
||||||
|
update_backlight();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t M5StackCore2::get_backlight_level()
|
||||||
|
{
|
||||||
|
return _backlight_level;
|
||||||
|
}
|
||||||
|
|
||||||
|
void M5StackCore2::set_backlight_power(bool power)
|
||||||
|
{
|
||||||
|
_backlight_power = power;
|
||||||
|
update_backlight();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool M5StackCore2::get_backlight_power()
|
||||||
|
{
|
||||||
|
return _backlight_power;
|
||||||
|
}
|
||||||
|
|
||||||
|
void M5StackCore2::update_backlight()
|
||||||
|
{
|
||||||
|
if(_backlight_power) {
|
||||||
|
uint16_t voltage = map(_backlight_level, 0, 255, 2500, 3300);
|
||||||
|
Axp.SetLcdVoltage(voltage);
|
||||||
|
} else {
|
||||||
|
Axp.SetDCVoltage(2, 2200);
|
||||||
|
}
|
||||||
|
// Axp.SetDCDC3(_backlight_power); // LCD backlight
|
||||||
|
}
|
||||||
|
|
||||||
void M5StackCore2::get_sensors(JsonDocument& doc)
|
void M5StackCore2::get_sensors(JsonDocument& doc)
|
||||||
{
|
{
|
||||||
Esp32Device::get_sensors(doc);
|
Esp32Device::get_sensors(doc);
|
||||||
|
|
||||||
JsonObject sensor = doc.createNestedObject(F("AXP192"));
|
JsonObject sensor = doc.createNestedObject(F("AXP192"));
|
||||||
sensor[F("BattVoltage")] = Axp.GetBatVoltage();
|
sensor[F("BattVoltage")] = Axp.GetBatVoltage();
|
||||||
sensor[F("BattPower")] = Axp.GetBatPower();
|
sensor[F("BattPower")] = Axp.GetBatPower();
|
||||||
// sensor[F("Batt%")] = Axp.getBattPercentage();
|
// sensor[F("Batt%")] = Axp.getBattPercentage();
|
||||||
sensor[F("BattChargeCurrent")] = Axp.GetBatChargeCurrent();
|
sensor[F("BattChargeCurrent")] = Axp.GetBatChargeCurrent();
|
||||||
sensor[F("Temperature")] = Axp.GetTempInAXP192();
|
sensor[F("Temperature")] = Axp.GetTempInAXP192();
|
||||||
sensor[F("Charging")] = Axp.isCharging();
|
sensor[F("Charging")] = Axp.isCharging();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,4 +96,3 @@ void M5StackCore2::get_sensors(JsonDocument& doc)
|
|||||||
dev::M5StackCore2 haspDevice;
|
dev::M5StackCore2 haspDevice;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -14,6 +14,16 @@ class M5StackCore2 : public Esp32Device {
|
|||||||
public:
|
public:
|
||||||
void init() override;
|
void init() override;
|
||||||
void get_sensors(JsonDocument& doc);
|
void get_sensors(JsonDocument& doc);
|
||||||
|
|
||||||
|
void set_backlight_level(uint8_t level);
|
||||||
|
uint8_t get_backlight_level();
|
||||||
|
void set_backlight_power(bool power);
|
||||||
|
bool get_backlight_power();
|
||||||
|
void update_backlight();
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t _backlight_level;
|
||||||
|
uint8_t _backlight_power;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dev
|
} // namespace dev
|
||||||
|
Loading…
x
Reference in New Issue
Block a user