Merge branch 'main' into hex-palette

This commit is contained in:
Blaz Kristan 2022-12-26 10:26:01 +01:00
commit b0d107f916
5 changed files with 47 additions and 58 deletions

View File

@ -138,7 +138,7 @@ class MPU6050Driver : public Usermod {
// (if it's going to break, usually the code will be 1)
DEBUG_PRINT(F("DMP Initialization failed (code "));
DEBUG_PRINT(devStatus);
DEBUG_PRINTLN(F(")"));
DEBUG_PRINTLN(")");
}
}

View File

@ -26,9 +26,8 @@ class ShtUsermod : public Usermod
const byte shtI2cAddress = 0x44; // i2c address of the sensor. 0x44 is the default for all SHT sensors. Change this, if needed
unsigned long shtLastTimeUpdated = 0; // Remembers when we read data the last time
bool shtDataRequested = false; // Reading data is done async. This remembers if we asked the sensor to read data
float shtCurrentTempC = 0; // Last read temperature in Celsius
float shtCurrentTempF = 0; // Last read temperature in Fahrenheit
float shtCurrentHumidity = 0; // Last read humidity in RH%
float shtCurrentTempC = 0.0f; // Last read temperature in Celsius
float shtCurrentHumidity = 0.0f; // Last read humidity in RH%
void initShtTempHumiditySensor();
@ -56,18 +55,22 @@ class ShtUsermod : public Usermod
bool readFromConfig(JsonObject &root);
void addToJsonInfo(JsonObject& root);
float getTemperatureC();
float getTemperatureF();
float getHumidity();
bool isEnabled() { return enabled; }
float getTemperature();
float getTemperatureC() { return shtCurrentTempC; }
float getTemperatureF() { return (shtCurrentTempC * 1.8f) + 32.0f; }
float getHumidity() { return shtCurrentHumidity; }
const char* getUnitString();
uint16_t getId() { return USERMOD_ID_SHT; }
};
// Strings to reduce flash memory usage (used more than twice)
const char ShtUsermod::_name[] PROGMEM = "SHT-Sensor";
const char ShtUsermod::_enabled[] PROGMEM = "Enabled";
const char ShtUsermod::_shtType[] PROGMEM = "SHT-Type";
const char ShtUsermod::_unitOfTemp[] PROGMEM = "Unit";
const char ShtUsermod::_name[] PROGMEM = "SHT-Sensor";
const char ShtUsermod::_enabled[] PROGMEM = "Enabled";
const char ShtUsermod::_shtType[] PROGMEM = "SHT-Type";
const char ShtUsermod::_unitOfTemp[] PROGMEM = "Unit";
const char ShtUsermod::_haMqttDiscovery[] PROGMEM = "Add-To-HA-MQTT-Discovery";
/**
@ -90,7 +93,6 @@ void ShtUsermod::initShtTempHumiditySensor()
shtTempHumidSensor->begin(shtI2cAddress, i2c_sda, i2c_scl);
if (shtTempHumidSensor->readStatus() == 0xFFFF) {
DEBUG_PRINTF("[%s] SHT init failed!\n", _name);
cleanupShtTempHumiditySensor();
cleanup();
return;
}
@ -107,12 +109,8 @@ void ShtUsermod::initShtTempHumiditySensor()
*/
void ShtUsermod::cleanupShtTempHumiditySensor()
{
if (isShtReady()) {
shtTempHumidSensor->reset();
}
if (isShtReady()) shtTempHumidSensor->reset();
delete shtTempHumidSensor;
shtInitDone = false;
}
@ -126,9 +124,7 @@ void ShtUsermod::cleanupShtTempHumiditySensor()
*/
void ShtUsermod::cleanup()
{
if (isShtReady()) {
cleanupShtTempHumiditySensor();
}
cleanupShtTempHumiditySensor();
if (pinAllocDone) {
PinManagerPinType pins[2] = { { i2c_sda, true }, { i2c_scl, true } };
@ -162,9 +158,9 @@ void ShtUsermod::publishTemperatureAndHumidityViaMqtt() {
char buf[128];
snprintf_P(buf, 127, PSTR("%s/temperature"), mqttDeviceTopic);
mqtt->publish(buf, 0, false, String((unitOfTemp ? getTemperatureF() : getTemperatureC())).c_str());
mqtt->publish(buf, 0, false, String(getTemperature()).c_str());
snprintf_P(buf, 127, PSTR("%s/humidity"), mqttDeviceTopic);
mqtt->publish(buf, 0, false, String(shtCurrentHumidity).c_str());
mqtt->publish(buf, 0, false, String(getHumidity()).c_str());
}
/**
@ -191,7 +187,7 @@ void ShtUsermod::publishHomeAssistantAutodiscovery() {
json[F("stat_cla")] = F("measurement");
snprintf_P(buf, 127, PSTR("%s-temperature"), escapedMac.c_str());
json[F("uniq_id")] = buf;
json[F("unit_of_meas")] = F("°C");
json[F("unit_of_meas")] = unitOfTemp ? F("°F") : F("°C");
appendDeviceToMqttDiscoveryMessage(json);
payload_size = serializeJson(json, json_str);
snprintf_P(buf, 127, PSTR("homeassistant/sensor/%s/%s-temperature/config"), escapedMac.c_str(), escapedMac.c_str());
@ -222,7 +218,7 @@ void ShtUsermod::publishHomeAssistantAutodiscovery() {
* @return void
*/
void ShtUsermod::appendDeviceToMqttDiscoveryMessage(JsonDocument& root) {
JsonObject device = root.createNestedObject("dev");
JsonObject device = root.createNestedObject(F("dev"));
device[F("ids")] = escapedMac.c_str();
device[F("name")] = serverDescription;
device[F("sw")] = versionString;
@ -290,13 +286,11 @@ void ShtUsermod::loop()
if (shtTempHumidSensor->dataReady()) {
if (shtTempHumidSensor->readData(false)) {
shtCurrentTempC = shtTempHumidSensor->getTemperature();
shtCurrentTempF = shtTempHumidSensor->getFahrenheit();
shtCurrentHumidity = shtTempHumidSensor->getHumidity();
publishTemperatureAndHumidityViaMqtt();
shtReadDataSuccess = true;
}
else {
} else {
shtReadDataSuccess = false;
}
@ -387,6 +381,7 @@ bool ShtUsermod::readFromConfig(JsonObject &root)
bool oldEnabled = enabled;
byte oldShtType = shtType;
byte oldUnitOfTemp = unitOfTemp;
bool oldHaMqttDiscovery = haMqttDiscovery;
getJsonValue(top[FPSTR(_enabled)], enabled);
@ -410,6 +405,11 @@ bool ShtUsermod::readFromConfig(JsonObject &root)
initShtTempHumiditySensor();
}
if (oldUnitOfTemp != unitOfTemp) {
publishTemperatureAndHumidityViaMqtt();
publishHomeAssistantAutodiscovery();
}
if (oldHaMqttDiscovery != haMqttDiscovery && haMqttDiscovery) {
publishHomeAssistantAutodiscovery();
}
@ -448,45 +448,34 @@ void ShtUsermod::addToJsonInfo(JsonObject& root)
if (shtLastTimeUpdated == 0) {
jsonTemp.add(F(" Not read yet"));
jsonHumidity.add(F(" Not read yet"));
}
else {
} else {
jsonTemp.add(F(" Error"));
jsonHumidity.add(F(" Error"));
}
return;
}
jsonHumidity.add(shtCurrentHumidity);
jsonHumidity.add(getHumidity());
jsonHumidity.add(F(" RH"));
unitOfTemp ? jsonTemp.add(getTemperatureF()) : jsonTemp.add(getTemperatureC());
unitOfTemp ? jsonTemp.add(F(" °F")) : jsonTemp.add(F(" °C"));
jsonTemp.add(getTemperature());
jsonTemp.add(unitOfTemp ? "°F" : "°C");
}
/**
* Getter for last read temperature in Celsius.
* Getter for last read temperature for configured unit.
*
* @return float
*/
float ShtUsermod::getTemperatureC() {
return shtCurrentTempC;
float ShtUsermod::getTemperature() {
return unitOfTemp ? getTemperatureF() : getTemperatureC();
}
/**
* Getter for last read temperature in Fahrenheit.
* Returns the current configured unit as human readable string.
*
* @return float
* @return const char*
*/
float ShtUsermod::getTemperatureF() {
return shtCurrentTempF;
}
/**
* Getter for last read humidity in RH%.
*
* @return float
*/
float ShtUsermod::getHumidity() {
return shtCurrentHumidity;
const char* ShtUsermod::getUnitString() {
return unitOfTemp ? "°F" : "°C";
}

View File

@ -2351,7 +2351,7 @@ static const char _data_FX_MODE_METEOR_SMOOTH[] PROGMEM = "Meteor Smooth@!,Trail
//Railway Crossing / Christmas Fairy lights
uint16_t mode_railway()
{
uint16_t dur = 40 + (255 - SEGMENT.speed) * 10;
uint16_t dur = (256 - SEGMENT.speed) * 40;
uint16_t rampdur = (dur * SEGMENT.intensity) >> 8;
if (SEGENV.step > dur)
{
@ -2368,16 +2368,16 @@ uint16_t mode_railway()
if (SEGENV.aux0) pos = 255 - pos;
for (int i = 0; i < SEGLEN; i += 2)
{
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(255 - pos, false, false, 255));
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(255 - pos, false, false, 255)); // do not use color 1 or 2, always use palette
if (i < SEGLEN -1)
{
SEGMENT.setPixelColor(i + 1, SEGMENT.color_from_palette(pos, false, false, 255));
SEGMENT.setPixelColor(i + 1, SEGMENT.color_from_palette(pos, false, false, 255)); // do not use color 1 or 2, always use palette
}
}
SEGENV.step += FRAMETIME;
return FRAMETIME;
}
static const char _data_FX_MODE_RAILWAY[] PROGMEM = "Railway@!,Smoothness;;!";
static const char _data_FX_MODE_RAILWAY[] PROGMEM = "Railway@!,Smoothness;1,2;!";
//Water ripple

View File

@ -96,11 +96,11 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
if (e131SkipOutOfSequence)
if (seq < e131LastSequenceNumber[previousUniverses] && seq > 20 && e131LastSequenceNumber[previousUniverses] < 250){
DEBUG_PRINT("skipping E1.31 frame (last seq=");
DEBUG_PRINT(F("skipping E1.31 frame (last seq="));
DEBUG_PRINT(e131LastSequenceNumber[previousUniverses]);
DEBUG_PRINT(", current seq=");
DEBUG_PRINT(F(", current seq="));
DEBUG_PRINT(seq);
DEBUG_PRINT(", universe=");
DEBUG_PRINT(F(", universe="));
DEBUG_PRINT(uni);
DEBUG_PRINTLN(")");
return;
@ -444,7 +444,7 @@ void sendArtnetPollReply(ArtPollReply *reply, IPAddress ipAddress, uint16_t port
reply->reply_sub_sw = (uint8_t)((portAddress >> 4) & 0x000F);
reply->reply_sw_out[0] = (uint8_t)(portAddress & 0x000F);
sprintf((char *)reply->reply_node_report, "#0001 [%04u] OK - WLED v" TOSTRING(WLED_VERSION), pollReplyCount);
snprintf_P((char *)reply->reply_node_report, sizeof(reply->reply_node_report)-1, PSTR("#0001 [%04u] OK - WLED v" TOSTRING(WLED_VERSION)), pollReplyCount);
if (pollReplyCount < 9999) {
pollReplyCount++;

View File

@ -569,7 +569,7 @@ bool WLED::initEthernet()
} else {
DEBUG_PRINT(F("initE: Failing due to invalid eth_clk_mode ("));
DEBUG_PRINT(es.eth_clk_mode);
DEBUG_PRINTLN(F(")"));
DEBUG_PRINTLN(")");
return false;
}