Dallas sensor detection.
Minor clenaup & fixes.
This commit is contained in:
parent
0d8e763a5f
commit
1a279d14c4
@ -57,23 +57,24 @@ class UsermodTemperature : public Usermod {
|
||||
static const char _enabled[];
|
||||
static const char _readInterval[];
|
||||
|
||||
//Dallas sensor quick reading. Credit to - Author: Peter Scargill, August 17th, 2013
|
||||
//Dallas sensor quick (& dirty) reading. Credit to - Author: Peter Scargill, August 17th, 2013
|
||||
int16_t readDallas() {
|
||||
byte i;
|
||||
byte data[2];
|
||||
int16_t result;
|
||||
int16_t result; // raw data from sensor
|
||||
oneWire->reset();
|
||||
oneWire->write(0xCC);
|
||||
oneWire->write(0xBE);
|
||||
for (i=0; i < 2; i++) data[i] = oneWire->read();
|
||||
oneWire->write(0xCC); // skip ROM
|
||||
oneWire->write(0xBE); // read (temperature) from EEPROM
|
||||
for (i=0; i < 2; i++) data[i] = oneWire->read(); // first 2 bytes contain temperature
|
||||
for (i=2; i < 8; i++) oneWire->read(); // read unused bytes
|
||||
result = (data[1]<<8) | data[0];
|
||||
result >>= 4;
|
||||
if (data[1]&0x80) result |= 61440;
|
||||
if (data[0]&0x08) ++result;
|
||||
result >>= 4; // 9-bit precision accurate to 1°C (/16)
|
||||
if (data[1]&0x80) result |= 0xF000; // fix negative value
|
||||
//if (data[0]&0x08) ++result;
|
||||
oneWire->reset();
|
||||
oneWire->write(0xCC);
|
||||
oneWire->write(0x44,1);
|
||||
return result*10;
|
||||
oneWire->write(0xCC); // skip ROM
|
||||
oneWire->write(0x44,0); // request new temperature reading (without parasite power)
|
||||
return result;
|
||||
}
|
||||
|
||||
void requestTemperatures() {
|
||||
@ -84,7 +85,7 @@ class UsermodTemperature : public Usermod {
|
||||
}
|
||||
|
||||
void getTemperature() {
|
||||
temperature = readDallas()/10.0f;
|
||||
temperature = readDallas();
|
||||
if (!degC) temperature = temperature * 1.8f + 32;
|
||||
lastMeasurement = millis();
|
||||
waitingForConversion = false;
|
||||
@ -92,20 +93,9 @@ class UsermodTemperature : public Usermod {
|
||||
DEBUG_PRINTF("Read temperature %2.1f.\n", temperature);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
void setup() {
|
||||
//bool sensorFound = false;
|
||||
|
||||
// pin retrieved from cfg.json (readFromConfig()) prior to running setup()
|
||||
if (!pinManager.allocatePin(temperaturePin,false)) {
|
||||
temperaturePin = -1; // allocation failed
|
||||
DEBUG_PRINTLN(F("Temperature pin allocation failed."));
|
||||
} else {
|
||||
//DeviceAddress deviceAddress;
|
||||
oneWire = new OneWire(temperaturePin);
|
||||
oneWire->reset();
|
||||
/*
|
||||
bool findSensor() {
|
||||
DEBUG_PRINTLN(F("Searching for sensor..."));
|
||||
uint8_t deviceAddress[8] = {0,0,0,0,0,0,0,0};
|
||||
// find out if we have DS18xxx sensor attached
|
||||
oneWire->reset_search();
|
||||
while (oneWire->search(deviceAddress)) {
|
||||
@ -116,20 +106,32 @@ class UsermodTemperature : public Usermod {
|
||||
case 0x28: // DS1822
|
||||
case 0x3B: // DS1825
|
||||
case 0x42: // DS28EA00
|
||||
sensorFound = true; // sensor found;
|
||||
DEBUG_PRINTLN(F("Sensor found."));
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
disabled = disabled || (temperaturePin==-1);
|
||||
|
||||
if (!disabled) {
|
||||
DEBUG_PRINTLN(F("Dallas Temperature found"));
|
||||
public:
|
||||
|
||||
void setup() {
|
||||
int retries = 10;
|
||||
// pin retrieved from cfg.json (readFromConfig()) prior to running setup()
|
||||
if (!pinManager.allocatePin(temperaturePin,false)) {
|
||||
temperaturePin = -1; // allocation failed
|
||||
disabled = true;
|
||||
DEBUG_PRINTLN(F("Temperature pin allocation failed."));
|
||||
} else {
|
||||
DEBUG_PRINTLN(F("Dallas Temperature not found"));
|
||||
if (!disabled) {
|
||||
// config says we are enabled
|
||||
oneWire = new OneWire(temperaturePin);
|
||||
if (!oneWire->reset())
|
||||
disabled = true; // resetting 1-Wire bus yielded an error
|
||||
else
|
||||
while ((disabled=!findSensor()) && retries--) delay(25); // try to find sensor
|
||||
}
|
||||
}
|
||||
initDone = true;
|
||||
}
|
||||
@ -152,7 +154,7 @@ class UsermodTemperature : public Usermod {
|
||||
}
|
||||
|
||||
// we were waiting for a conversion to complete, have we waited log enough?
|
||||
if (now - lastTemperaturesRequest >= 800 /* 93.75ms per the datasheet but can be up to 750ms*/) {
|
||||
if (now - lastTemperaturesRequest >= 800 /* 93.75ms per the datasheet but can be up to 750ms */) {
|
||||
getTemperature();
|
||||
|
||||
if (WLED_MQTT_CONNECTED) {
|
||||
|
@ -86,6 +86,8 @@ void deserializeConfig() {
|
||||
noWifiSleep = !noWifiSleep;
|
||||
//int wifi_phy = doc[F("wifi")][F("phy")]; //force phy mode n?
|
||||
|
||||
DEBUG_PRINTLN(F(" Done network."));
|
||||
|
||||
JsonObject hw = doc[F("hw")];
|
||||
|
||||
// initialize LED pins and lengths prior to other HW
|
||||
@ -120,8 +122,6 @@ void deserializeConfig() {
|
||||
if (length==0 || length+lC > MAX_LEDS) continue; // zero length or we reached max. number of LEDs, just stop
|
||||
uint16_t start = elm[F("start")] | 0;
|
||||
if (start >= lC+length) continue; // something is very wrong :)
|
||||
//limit length of strip if it would exceed total configured LEDs
|
||||
//if (start + length > ledCount) length = ledCount - start;
|
||||
uint8_t colorOrder = elm[F("order")];
|
||||
uint8_t skipFirst = elm[F("skip")];
|
||||
uint8_t ledType = elm["type"] | TYPE_WS2812_RGB;
|
||||
@ -134,11 +134,12 @@ void deserializeConfig() {
|
||||
lC += length;
|
||||
BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst);
|
||||
mem += BusManager::memUsage(bc);
|
||||
if (mem <= MAX_LED_MEMORY) busses.add(bc);
|
||||
DEBUG_PRINT(F(" Adding bus no. "));
|
||||
DEBUG_PRINTLN(busses.getNumBusses());
|
||||
if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip()
|
||||
}
|
||||
if (lC > ledCount) ledCount = lC; // fix incorrect total length (honour analog setup)
|
||||
//strip.finalizeInit(); // will be done in WLED::beginStrip()
|
||||
if (hw_led["rev"]) busses.getBus(0)->reversed = true; //set 0.11 global reversed setting for first bus
|
||||
DEBUG_PRINTLN(F(" Done LEDs."));
|
||||
|
||||
JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0];
|
||||
CJSON(buttonType, hw_btn_ins_0["type"]);
|
||||
@ -178,6 +179,7 @@ void deserializeConfig() {
|
||||
if (relay.containsKey("rev")) {
|
||||
rlyMde = !relay["rev"];
|
||||
}
|
||||
DEBUG_PRINTLN(F(" Done HW."));
|
||||
|
||||
//int hw_status_pin = hw[F("status")]["pin"]; // -1
|
||||
|
||||
@ -388,6 +390,7 @@ void deserializeConfig() {
|
||||
}
|
||||
#endif
|
||||
|
||||
DEBUG_PRINTLN(F("Starting usermod config."));
|
||||
JsonObject usermods_settings = doc["um"];
|
||||
usermods.readFromConfig(usermods_settings);
|
||||
}
|
||||
|
@ -76,9 +76,9 @@ void loadPlaylist(JsonObject playlistObj) {
|
||||
for (int i = it; i < playlistLen; i++) entries[i].dur = entries[it -1].dur;
|
||||
|
||||
it = 0;
|
||||
JsonArray tr = playlistObj["transition"];
|
||||
JsonArray tr = playlistObj[F("transition")];
|
||||
if (tr.isNull()) {
|
||||
entries[0].tr = playlistObj["transition"] | (transitionDelay / 100);
|
||||
entries[0].tr = playlistObj[F("transition")] | (transitionDelay / 100);
|
||||
it = 1;
|
||||
} else {
|
||||
for (int transition : tr) {
|
||||
|
@ -258,7 +258,6 @@ void getSettingsJS(byte subPage, char* dest)
|
||||
{
|
||||
char nS[8];
|
||||
|
||||
// (TODO: usermod config shouldn't use state. instead we should load "um" object from cfg.json)
|
||||
// add reserved and usermod pins as d.um_p array
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE/2);
|
||||
JsonObject mods = doc.createNestedObject(F("um"));
|
||||
@ -279,7 +278,7 @@ void getSettingsJS(byte subPage, char* dest)
|
||||
}
|
||||
} else {
|
||||
if (i++) oappend(SET_F(","));
|
||||
oappendi((int)obj["pin"]);
|
||||
oappendi(obj["pin"].as<int>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -317,16 +316,13 @@ void getSettingsJS(byte subPage, char* dest)
|
||||
|
||||
// set limits
|
||||
oappend(SET_F("bLimits("));
|
||||
oappend(itoa(WLED_MAX_BUSSES,nS,10));
|
||||
oappend(",");
|
||||
oappend(itoa(MAX_LEDS_PER_BUS,nS,10));
|
||||
oappend(",");
|
||||
oappend(itoa(WLED_MAX_BUSSES,nS,10)); oappend(",");
|
||||
oappend(itoa(MAX_LEDS_PER_BUS,nS,10)); oappend(",");
|
||||
oappend(itoa(MAX_LED_MEMORY,nS,10));
|
||||
oappend(SET_F(");"));
|
||||
|
||||
sappend('v',SET_F("LC"),ledCount);
|
||||
|
||||
// bool skip = false;
|
||||
for (uint8_t s=0; s < busses.getNumBusses(); s++) {
|
||||
Bus* bus = busses.getBus(s);
|
||||
char lp[4] = "L0"; lp[2] = 48+s; lp[3] = 0; //ascii 0-9 //strip data pin
|
||||
@ -351,7 +347,6 @@ void getSettingsJS(byte subPage, char* dest)
|
||||
sappend('c',cv,bus->reversed);
|
||||
sappend('c',sl,bus->skipFirstLed());
|
||||
// sappend('c',ew,bus->isRgbw());
|
||||
// if (!skip) skip = bus->skipFirstLed()>0;
|
||||
}
|
||||
sappend('v',SET_F("MA"),strip.ablMilliampsMax);
|
||||
sappend('v',SET_F("LA"),strip.milliampsPerLed);
|
||||
@ -379,7 +374,6 @@ void getSettingsJS(byte subPage, char* dest)
|
||||
sappend('v',SET_F("TL"),nightlightDelayMinsDefault);
|
||||
sappend('v',SET_F("TW"),nightlightMode);
|
||||
sappend('i',SET_F("PB"),strip.paletteBlend);
|
||||
// sappend('c',SET_F("SL"),skip);
|
||||
sappend('v',SET_F("RL"),rlyPin);
|
||||
sappend('c',SET_F("RM"),rlyMde);
|
||||
sappend('v',SET_F("BT"),btnPin);
|
||||
|
Loading…
Reference in New Issue
Block a user