diff --git a/examples/ConfigurableFirmata/ConfigurableFirmata.ino b/examples/ConfigurableFirmata/ConfigurableFirmata.ino index 9b44ff6..97ce19d 100644 --- a/examples/ConfigurableFirmata/ConfigurableFirmata.ino +++ b/examples/ConfigurableFirmata/ConfigurableFirmata.ino @@ -19,12 +19,15 @@ const int NETWORK_PORT = 27016; // Note that the SERVO module currently is not supported on ESP32. So either disable this or patch the library #define ENABLE_SERVO #define ENABLE_ACCELSTEPPER -#define ENABLE_BASIC_SCHEDULER + +// This is rarely used +// #define ENABLE_BASIC_SCHEDULER #define ENABLE_SERIAL #define ENABLE_I2C #define ENABLE_SPI #define ENABLE_ANALOG #define ENABLE_DIGITAL +#define ENABLE_DHT #ifdef ENABLE_DIGITAL @@ -74,6 +77,11 @@ OneWireFirmata oneWire; SerialFirmata serial; #endif +#ifdef ENABLE_DHT +#include +DhtFirmata dhtFirmata; +#endif + #include FirmataExt firmataExt; diff --git a/src/ConfigurableFirmata.h b/src/ConfigurableFirmata.h index a744feb..b036f28 100644 --- a/src/ConfigurableFirmata.h +++ b/src/ConfigurableFirmata.h @@ -67,7 +67,7 @@ #define STRING_DATA 0x71 // a string message with 14-bits per char #define STEPPER_DATA 0x72 // control a stepper motor #define ONEWIRE_DATA 0x73 // send an OneWire read/write/reset/select/skip/search request -#define DHT_SENSOR_DATA 0x74 // Used by DhtFirmata +#define DHTSENSOR_DATA 0x74 // Used by DhtFirmata #define SHIFT_DATA 0x75 // a bitstream to/from a shift register #define I2C_REQUEST 0x76 // send an I2C read/write request #define I2C_REPLY 0x77 // a reply to an I2C read request diff --git a/src/DhtFirmata.h b/src/DhtFirmata.h index c05e214..6ce7da0 100644 --- a/src/DhtFirmata.h +++ b/src/DhtFirmata.h @@ -75,7 +75,7 @@ void DhtFirmata::handleCapability(byte pin) boolean DhtFirmata::handleSysex(byte command, byte argc, byte *argv) { switch (command) { - case DHT_SENSOR_DATA_REQUEST: + case DHTSENSOR_DATA: if (argc < 2) { Firmata.sendString(F("Error in DHT command: Not enough parameters")); @@ -83,12 +83,18 @@ boolean DhtFirmata::handleSysex(byte command, byte argc, byte *argv) } performDhtTransfer(argv[0], argc - 1, argv + 1); return true; + } return false; } void DhtFirmata::performDhtTransfer(byte command, byte argc, byte *argv) { + if (command == DHTSENSOR_DETACH) + { + disableDht(); + return; + } // command byte: DHT Type byte dhtType = command; // The proposed protocol specification https://github.com/firmata/protocol/pull/106/commits/9389c89d3d7998dc2bd703f8c796e6a7c03f2551 @@ -125,8 +131,8 @@ void DhtFirmata::performDhtTransfer(byte command, byte argc, byte *argv) short temperature = (short)(_dht->readTemperature() * 10); Firmata.startSysex(); - Firmata.write(DHT_SENSOR_DATA_REQUEST); - Firmata.write(DHT_SENSOR_DATA_RESPONSE); + Firmata.write(DHTSENSOR_DATA); + Firmata.write(DHTSENSOR_RESPONSE); Firmata.write(pin); Firmata.write(temperature & 0x7f); Firmata.write((temperature >> 7) & 0x7f);