Skip to content

Commit

Permalink
Adjust to protocol names
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrawehr committed Jul 5, 2021
1 parent aec5a1e commit 3a7c986
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
10 changes: 9 additions & 1 deletion examples/ConfigurableFirmata/ConfigurableFirmata.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,6 +77,11 @@ OneWireFirmata oneWire;
SerialFirmata serial;
#endif

#ifdef ENABLE_DHT
#include <DhtFirmata.h>
DhtFirmata dhtFirmata;
#endif

#include <FirmataExt.h>
FirmataExt firmataExt;

Expand Down
2 changes: 1 addition & 1 deletion src/ConfigurableFirmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions src/DhtFirmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,26 @@ 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"));
return false;
}
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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3a7c986

Please sign in to comment.