@@ -1223,6 +1223,9 @@ void SensorDigitalOutput::setInputIsElapsed(bool value) {
1223
1223
void SensorDigitalOutput::setWaitAfterSet (int value) {
1224
1224
_wait_after_set = value;
1225
1225
}
1226
+ void SensorDigitalOutput::setPulseWidth (int value) {
1227
+ _pulse_width = value;
1228
+ }
1226
1229
1227
1230
// main task
1228
1231
void SensorDigitalOutput::onLoop (Child* child) {
@@ -1231,7 +1234,7 @@ void SensorDigitalOutput::onLoop(Child* child) {
1231
1234
// update the timer
1232
1235
_safeguard_timer->update ();
1233
1236
// if the time is over, turn the output off
1234
- if (_safeguard_timer->isOver ()) setStatus (child, OFF);
1237
+ if (_safeguard_timer->isOver ()) setStatus (OFF);
1235
1238
}
1236
1239
}
1237
1240
@@ -1242,7 +1245,7 @@ void SensorDigitalOutput::onReceive(MyMessage* message) {
1242
1245
// by default handle a SET message but when legacy mode is set when a REQ message is expected instead
1243
1246
if ( (message->getCommand () == C_SET && ! _legacy_mode) || (message->getCommand () == C_REQ && _legacy_mode)) {
1244
1247
// switch the output
1245
- setStatus (child, message->getInt ());
1248
+ setStatus (message->getInt ());
1246
1249
}
1247
1250
if (message->getCommand () == C_REQ && ! _legacy_mode) {
1248
1251
// just return the current status
@@ -1251,7 +1254,7 @@ void SensorDigitalOutput::onReceive(MyMessage* message) {
1251
1254
}
1252
1255
1253
1256
// write the value to the output
1254
- void SensorDigitalOutput::setStatus (Child* child, int value) {
1257
+ void SensorDigitalOutput::setStatus (int value) {
1255
1258
// pre-process the input value
1256
1259
if (_input_is_elapsed) {
1257
1260
// the input provided is an elapsed time
@@ -1269,12 +1272,12 @@ void SensorDigitalOutput::setStatus(Child* child, int value) {
1269
1272
// if turning the output on and a safeguard timer is configured, start it
1270
1273
if (value == ON && _safeguard_timer->isConfigured () && ! _safeguard_timer->isRunning ()) _safeguard_timer->start ();
1271
1274
}
1272
- _setStatus (child, value);
1275
+ _setStatus (value);
1273
1276
// wait if needed for relay drawing a lot of current
1274
1277
if (_wait_after_set > 0 ) _node->sleepOrWait (_wait_after_set);
1275
1278
// store the new status so it will be sent to the controller
1276
1279
_status = value;
1277
- ((ChildInt*)child )->setValueInt (value);
1280
+ ((ChildInt*)children. get ( 1 ) )->setValueInt (value);
1278
1281
}
1279
1282
1280
1283
// setup the provided pin for output
@@ -1289,19 +1292,24 @@ void SensorDigitalOutput::_setupPin(Child* child, int pin) {
1289
1292
}
1290
1293
1291
1294
// switch to the requested status
1292
- void SensorDigitalOutput::_setStatus (Child* child, int value) {
1295
+ void SensorDigitalOutput::_setStatus (int value) {
1293
1296
int value_to_write = _getValueToWrite (value);
1294
1297
// set the value to the pin
1295
1298
digitalWrite (_pin, value_to_write);
1296
1299
#if FEATURE_DEBUG == ON
1297
1300
Serial.print (_name);
1298
1301
Serial.print (F (" I=" ));
1299
- Serial.print (child ->child_id );
1302
+ Serial.print (children. get ( 1 ) ->child_id );
1300
1303
Serial.print (F (" P=" ));
1301
1304
Serial.print (_pin);
1302
1305
Serial.print (F (" V=" ));
1303
1306
Serial.println (value_to_write);
1304
1307
#endif
1308
+ // if pulse width is set and status is on, turn it off after the configured interval
1309
+ if (_pulse_width > 0 && value == ON) {
1310
+ _node->sleepOrWait (_pulse_width);
1311
+ digitalWrite (_pin, !value_to_write);
1312
+ }
1305
1313
}
1306
1314
1307
1315
// reverse the value if needed based on the _on_value
@@ -1338,12 +1346,11 @@ SensorLatchingRelay::SensorLatchingRelay(NodeManager& node_manager, int pin, int
1338
1346
_pin_on = pin;
1339
1347
_pin_off = pin + 1 ;
1340
1348
children.get (1 )->description = _name;
1349
+ // set pulse duration
1350
+ _pulse_width = 50 ;
1341
1351
}
1342
1352
1343
1353
// setter/getter
1344
- void SensorLatchingRelay::setPulseWidth (int value) {
1345
- _pulse_width = value;
1346
- }
1347
1354
void SensorLatchingRelay::setPinOn (int value) {
1348
1355
_pin_on = value;
1349
1356
}
@@ -1358,7 +1365,7 @@ void SensorLatchingRelay::onSetup() {
1358
1365
}
1359
1366
1360
1367
// switch to the requested status
1361
- void SensorLatchingRelay::_setStatus (Child* child, int value) {
1368
+ void SensorLatchingRelay::_setStatus (int value) {
1362
1369
// select the right pin to send the pulse to
1363
1370
int pin = value == OFF ? _pin_off : _pin_on;
1364
1371
// set the value
@@ -1367,8 +1374,9 @@ void SensorLatchingRelay::_setStatus(Child* child, int value) {
1367
1374
_node->sleepOrWait (_pulse_width);
1368
1375
digitalWrite (pin, ! _on_value);
1369
1376
#if FEATURE_DEBUG == ON
1370
- Serial.print (F (" LAT I=" ));
1371
- Serial.print (child->child_id );
1377
+ Serial.print (_name);
1378
+ Serial.print (F (" I=" ));
1379
+ Serial.print (children.get (1 )->child_id );
1372
1380
Serial.print (F (" P=" ));
1373
1381
Serial.print (pin);
1374
1382
Serial.print (F (" S=" ));
@@ -4159,12 +4167,12 @@ void SensorConfiguration::onReceive(MyMessage* message) {
4159
4167
case 105 : custom_sensor->setSafeguard (request.getValueInt ()); break ;
4160
4168
case 106 : custom_sensor->setInputIsElapsed (request.getValueInt ()); break ;
4161
4169
case 107 : custom_sensor->setWaitAfterSet (request.getValueInt ()); break ;
4170
+ case 108 : custom_sensor->setPulseWidth (request.getValueInt ()); break ;
4162
4171
default : return ;
4163
4172
}
4164
4173
if (function > 200 && strcmp (sensor->getName ()," LATCHING" ) == 0 ) {
4165
4174
SensorLatchingRelay* custom_sensor_2 = (SensorLatchingRelay*)sensor;
4166
4175
switch (function) {
4167
- case 201 : custom_sensor_2->setPulseWidth (request.getValueInt ()); break ;
4168
4176
case 202 : custom_sensor_2->setPinOff (request.getValueInt ()); break ;
4169
4177
case 203 : custom_sensor_2->setPinOn (request.getValueInt ()); break ;
4170
4178
default : return ;
0 commit comments