mirror of https://github.com/arendst/Tasmota.git
settings value changed to uint16 and now in seconds
This commit is contained in:
parent
9516f339d6
commit
873d0092e5
|
@ -36,6 +36,10 @@
|
||||||
#define WARMUP_PERIOD 30 // Turn on PMSX003 XX-seconds before read in passive mode
|
#define WARMUP_PERIOD 30 // Turn on PMSX003 XX-seconds before read in passive mode
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MIN_INTERVAL_PERIOD
|
||||||
|
#define MIN_INTERVAL_PERIOD 60 // minimum interval period in seconds required for passive mode
|
||||||
|
#endif
|
||||||
|
|
||||||
TasmotaSerial *PmsSerial;
|
TasmotaSerial *PmsSerial;
|
||||||
|
|
||||||
uint8_t pms_type = 1;
|
uint8_t pms_type = 1;
|
||||||
|
@ -157,40 +161,43 @@ bool PmsReadData(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Command Sensor15
|
* Command Sensor18 (currently using mcp230xx_int_timer variable - should change)
|
||||||
*
|
*
|
||||||
* 0 - Active Mode
|
* Warmup time for sensor is 30 seconds, therfore setting interval time to less than 60
|
||||||
* 1 .. 255 - Passive Mode (read sensor every x minutes)
|
* seconds doesn't really make sense.
|
||||||
|
*
|
||||||
|
* 0 - 59 - Active Mode (continuous sensor readings)
|
||||||
|
* 60 .. 65535 - Passive Mode (read sensor every x seconds)
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
bool PmsCommandSensor(void)
|
bool PmsCommandSensor(void)
|
||||||
{
|
{
|
||||||
if (XdrvMailbox.payload == 0)
|
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 65536))
|
||||||
{
|
{
|
||||||
// Set Active Mode
|
if (XdrvMailbox.payload < MIN_INTERVAL_PERIOD) {
|
||||||
Settings.novasds_startingoffset = 0;
|
// Set Active Mode if interval is less than 60 seconds
|
||||||
wake_mode = 1;
|
Settings.mcp230xx_int_timer = 0;
|
||||||
pms_ready = 1;
|
wake_mode = 1;
|
||||||
PmsSendCmd(CMD_MODE_ACTIVE);
|
pms_ready = 1;
|
||||||
PmsSendCmd(CMD_WAKEUP);
|
PmsSendCmd(CMD_MODE_ACTIVE);
|
||||||
}
|
PmsSendCmd(CMD_WAKEUP);
|
||||||
else if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 256))
|
} else {
|
||||||
{
|
// Set Passive Mode and schedule read once per interval time
|
||||||
// Set Passive Mode
|
Settings.mcp230xx_int_timer = XdrvMailbox.payload;
|
||||||
Settings.novasds_startingoffset = XdrvMailbox.payload;
|
PmsSendCmd(CMD_MODE_PASSIVE);
|
||||||
PmsSendCmd(CMD_MODE_PASSIVE);
|
PmsSendCmd(CMD_SLEEP);
|
||||||
PmsSendCmd(CMD_SLEEP);
|
wake_mode = 0;
|
||||||
wake_mode = 0;
|
pms_ready = 0;
|
||||||
pms_ready = 0;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pin[GPIO_PMS5003_TX] >= 99)
|
if (pin[GPIO_PMS5003_TX] >= 99)
|
||||||
{
|
{
|
||||||
// setting interval not supported if TX pin not connected
|
// setting interval not supported if TX pin not connected
|
||||||
Settings.novasds_startingoffset = 0;
|
Settings.mcp230xx_int_timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_18, Settings.novasds_startingoffset);
|
Response_P(S_JSON_SENSOR_INDEX_NVALUE, XSNS_18, Settings.mcp230xx_int_timer);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -199,17 +206,19 @@ bool PmsCommandSensor(void)
|
||||||
|
|
||||||
void PmsSecond(void) // Every second
|
void PmsSecond(void) // Every second
|
||||||
{
|
{
|
||||||
if (Settings.novasds_startingoffset > 0)
|
if (Settings.mcp230xx_int_timer >= MIN_INTERVAL_PERIOD)
|
||||||
{
|
{
|
||||||
// Passive Mode
|
// Passive Mode
|
||||||
pms_time++;
|
pms_time++;
|
||||||
if ((((uint16_t)Settings.novasds_startingoffset) * 60 - pms_time <= WARMUP_PERIOD) && !wake_mode)
|
if ((Settings.mcp230xx_int_timer - pms_time <= WARMUP_PERIOD) && !wake_mode)
|
||||||
{
|
{
|
||||||
|
// wakeup sensor WARMUP_PERIOD before read interval
|
||||||
wake_mode = 1;
|
wake_mode = 1;
|
||||||
PmsSendCmd(CMD_WAKEUP);
|
PmsSendCmd(CMD_WAKEUP);
|
||||||
}
|
}
|
||||||
if (pms_time >= ((uint16_t)Settings.novasds_startingoffset) * 60)
|
if (pms_time >= Settings.mcp230xx_int_timer)
|
||||||
{
|
{
|
||||||
|
// sensor is awake and warmed up, set up for reading
|
||||||
PmsSendCmd(CMD_READ_DATA);
|
PmsSendCmd(CMD_READ_DATA);
|
||||||
pms_ready = 1;
|
pms_ready = 1;
|
||||||
pms_time = 0;
|
pms_time = 0;
|
||||||
|
@ -221,7 +230,7 @@ void PmsSecond(void) // Every second
|
||||||
if (PmsReadData())
|
if (PmsReadData())
|
||||||
{
|
{
|
||||||
pms_valid = 10;
|
pms_valid = 10;
|
||||||
if (Settings.novasds_startingoffset > 0)
|
if (Settings.mcp230xx_int_timer >= MIN_INTERVAL_PERIOD)
|
||||||
{
|
{
|
||||||
PmsSendCmd(CMD_SLEEP);
|
PmsSendCmd(CMD_SLEEP);
|
||||||
wake_mode = 0;
|
wake_mode = 0;
|
||||||
|
@ -233,7 +242,7 @@ void PmsSecond(void) // Every second
|
||||||
if (pms_valid)
|
if (pms_valid)
|
||||||
{
|
{
|
||||||
pms_valid--;
|
pms_valid--;
|
||||||
if (Settings.novasds_startingoffset > 0)
|
if (Settings.mcp230xx_int_timer >= MIN_INTERVAL_PERIOD)
|
||||||
{
|
{
|
||||||
PmsSendCmd(CMD_READ_DATA);
|
PmsSendCmd(CMD_READ_DATA);
|
||||||
pms_ready = 1;
|
pms_ready = 1;
|
||||||
|
|
Loading…
Reference in New Issue