Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-cayman
99 changes: 9 additions & 90 deletions libraries/SuplaDevice/SuplaDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

#define SUPLADEVICE_CPP

#include "SuplaDevice.h"

#include <Arduino.h>

#include "SuplaDevice.h"
#include "SuplaImpulseCounter.h"
#include "io.h"
#include "supla-common/IEEE754tools.h"
Expand Down Expand Up @@ -82,7 +81,7 @@ void SuplaDeviceClass::status(int status, const char *msg) {
}
}

SuplaDeviceClass::SuplaDeviceClass() {
SuplaDeviceClass::SuplaDeviceClass() : port(-1) {
srpc = NULL;
registered = 0;
last_iterate_time = 0;
Expand Down Expand Up @@ -493,48 +492,6 @@ void SuplaDeviceClass::setRollerShutterButtons(int channel_number,
}
}

bool SuplaDeviceClass::addSensorNO(int sensorPin, bool pullUp) {
int c = addChannel(sensorPin, 0, false, false);
if (c == -1) return false;

Supla::Channel::reg_dev.channels[c].Type = SUPLA_CHANNELTYPE_SENSORNO;
if (pullUp) {
pinMode(sensorPin, INPUT_PULLUP);
} else {
pinMode(sensorPin, INPUT);
}

Supla::Channel::reg_dev.channels[c].value[0] =
Supla::Io::digitalRead(Supla::Channel::reg_dev.channels[c].Number,
sensorPin) == HIGH
? 1
: 0;
return true;
}

void SuplaDeviceClass::setDoubleValue(char value[SUPLA_CHANNELVALUE_SIZE],
double v) {
if (sizeof(double) == 8) {
memcpy(value, &v, 8);
} else if (sizeof(double) == 4) {
float2DoublePacked(v, (uint8_t *)value);
}
}

void SuplaDeviceClass::channelSetDoubleValue(int channelNum, double value) {
setDoubleValue(Supla::Channel::reg_dev.channels[channelNum].value, value);
}

void SuplaDeviceClass::channelSetTempAndHumidityValue(int channelNum,
double temp,
double humidity) {
long t = temp * 1000.00;
long h = humidity * 1000.00;

memcpy(Supla::Channel::reg_dev.channels[channelNum].value, &t, 4);
memcpy(&Supla::Channel::reg_dev.channels[channelNum].value[4], &h, 4);
}

void SuplaDeviceClass::setRGBWvalue(int channelNum,
char value[SUPLA_CHANNELVALUE_SIZE]) {
if (Params.cb.get_rgbw_value) {
Expand Down Expand Up @@ -585,10 +542,6 @@ bool SuplaDeviceClass::addDimmer(void) {
setRGBWvalue(c, Supla::Channel::reg_dev.channels[c].value);
}

bool SuplaDeviceClass::addSensorNO(int sensorPin) {
return addSensorNO(sensorPin, false);
}

bool SuplaDeviceClass::addImpulseCounter(int impulsePin,
int statusLedPin,
bool detectLowToHigh,
Expand Down Expand Up @@ -691,25 +644,6 @@ void SuplaDeviceClass::iterate_relay(SuplaChannelPin *pin,
}
}

void SuplaDeviceClass::iterate_sensor(SuplaChannelPin *pin,
TDS_SuplaDeviceChannel_C *channel,
unsigned long time_diff,
int channel_number) {
if (channel->Type == SUPLA_CHANNELTYPE_SENSORNO) {
uint8_t val = Supla::Io::digitalRead(channel->Number, pin->pin1);

if (val != pin->last_val) {
pin->last_val = val;
Supla::Channel::reg_dev.channels[channel->Number].value[0] = val;

if (pin->time_left <= 0) {
pin->time_left = 100;
channelValueChanged(channel->Number, val == HIGH ? 1 : 0);
}
}
}
};

void SuplaDeviceClass::rs_save_position(SuplaDeviceRollerShutter *rs) {
if (impl_rs_save_position) {
impl_rs_save_position(rs->channel_number, rs->position);
Expand Down Expand Up @@ -1038,7 +972,7 @@ void SuplaDeviceClass::iterate_rollershutter(

if (rs->last_position != rs->position) {
rs->last_position = rs->position;
channelValueChanged(rs->channel_number, (rs->position - 100) / 100, 0, 1);
channelValueChanged(rs->channel_number, (rs->position - 100) / 100);
}

if (rs->up_time > 600000 || rs->down_time > 600000) { // 10 min. - timeout
Expand Down Expand Up @@ -1124,7 +1058,6 @@ void SuplaDeviceClass::iterate(void) {
}

if (!Supla::Network::Connected()) {
int port = 2015; /* deprecated in ESP8266 */
status(STATUS_DISCONNECTED, "Not connected");

registered = 0;
Expand Down Expand Up @@ -1178,10 +1111,6 @@ void SuplaDeviceClass::iterate(void) {
&Supla::Channel::reg_dev.channels[a],
time_diff,
a);
iterate_sensor(&channel_pin[a],
&Supla::Channel::reg_dev.channels[a],
time_diff,
a);
iterate_impulse_counter(&channel_pin[a],
&Supla::Channel::reg_dev.channels[a],
time_diff,
Expand Down Expand Up @@ -1288,18 +1217,12 @@ void SuplaDeviceClass::onRegisterResult(
wait_for_iterate = millis() + 5000;
}

void SuplaDeviceClass::channelValueChanged(int channel_number,
char v,
double d,
char var) {
void SuplaDeviceClass::channelValueChanged(int channel_number, char v) {
if (srpc != NULL && registered == 1) {
char value[SUPLA_CHANNELVALUE_SIZE];
memset(value, 0, SUPLA_CHANNELVALUE_SIZE);

if (var == 1)
value[0] = v;
else if (var == 2)
setDoubleValue(value, d);
value[0] = v;
memcpy(Supla::Channel::reg_dev.channels[channel_number].value, value, 8);

supla_log(
Expand All @@ -1309,14 +1232,6 @@ void SuplaDeviceClass::channelValueChanged(int channel_number,
}
}

void SuplaDeviceClass::channelDoubleValueChanged(int channel_number, double v) {
channelValueChanged(channel_number, 0, v, 2);
}

void SuplaDeviceClass::channelValueChanged(int channel_number, char v) {
channelValueChanged(channel_number, v, 0, 1);
}

void SuplaDeviceClass::channelSetValue(int channel,
char value,
_supla_int_t DurationMS) {
Expand Down Expand Up @@ -1551,6 +1466,10 @@ bool SuplaDeviceClass::rollerShutterMotorIsOn(int channel_number) {
channel_pin[channel_number].pin2));
}

void SuplaDeviceClass::setServerPort(int value) {
port = value;
}

SuplaDeviceClass SuplaDevice;

SuplaDeviceCallbacks supla_arduino_get_callbacks(void) {
Expand Down
29 changes: 2 additions & 27 deletions libraries/SuplaDevice/SuplaDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
#define STATUS_LOCATION_IS_DISABLED 19
#define STATUS_DEVICE_LIMIT_EXCEEDED 20

typedef double (*_cb_arduino_get_double)(int channelNumber,
double current_value);
typedef void (*_cb_arduino_get_temperature_and_humidity)(int channelNumber,
double *temp,
double *humidity);
typedef void (*_cb_arduino_get_rgbw_value)(int channelNumber,
unsigned char *red,
unsigned char *green,
Expand Down Expand Up @@ -149,20 +144,14 @@ class SuplaDeviceClass {
bool isInitialized(bool msg);
void setString(char *dst, const char *src, int max_size);
int addChannel(int pin1, int pin2, bool hiIsLo, bool bistable);
void channelValueChanged(int channel_number, char v, double d, char var);
void channelSetValue(int channel, char value, _supla_int_t DurationMS);
void channelSetDoubleValue(int channelNum, double value);
void setDoubleValue(char value[SUPLA_CHANNELVALUE_SIZE], double v);
bool addDHT(int Type);
void channelSetTempAndHumidityValue(int channelNum,
double temp,
double humidity);
void setRGBWvalue(int channelNum, char value[SUPLA_CHANNELVALUE_SIZE]);
void channelSetRGBWvalue(int channel, char value[SUPLA_CHANNELVALUE_SIZE]);

SuplaDeviceParams Params;
SuplaChannelPin *channel_pin;
int channel_pin_count;
int port;

int rs_count;
SuplaDeviceRollerShutter *roller_shutter;
Expand Down Expand Up @@ -214,14 +203,6 @@ class SuplaDeviceClass {
TDS_SuplaDeviceChannel_C *channel,
unsigned long time_diff,
int channel_idx);
void iterate_sensor(SuplaChannelPin *pin,
TDS_SuplaDeviceChannel_C *channel,
unsigned long time_diff,
int channel_idx);
void iterate_thermometer(SuplaChannelPin *pin,
TDS_SuplaDeviceChannel_C *channel,
unsigned long time_diff,
int channel_idx);
void iterate_rollershutter(SuplaDeviceRollerShutter *rs,
SuplaChannelPin *pin,
TDS_SuplaDeviceChannel_C *channel);
Expand All @@ -230,10 +211,6 @@ class SuplaDeviceClass {
unsigned long time_diff,
int channel_number);

void begin_thermometer(SuplaChannelPin *pin,
TDS_SuplaDeviceChannel_C *channel,
int channel_number);

private:
bool suplaDigitalRead_isHI(int channelNumber, uint8_t pin);
void suplaDigitalWrite_setHI(int channelNumber, uint8_t pin, bool hi);
Expand All @@ -244,7 +221,6 @@ class SuplaDeviceClass {
~SuplaDeviceClass();

void channelValueChanged(int channel_number, char v);
void channelDoubleValueChanged(int channel_number, double v);

bool begin(char GUID[SUPLA_GUID_SIZE],
const char *Server,
Expand All @@ -267,8 +243,6 @@ class SuplaDeviceClass {
void setRollerShutterButtons(int channel_number,
int btnUpPin,
int btnDownPin);
bool addSensorNO(int sensorPin, bool pullUp);
bool addSensorNO(int sensorPin);
bool addRgbControllerAndDimmer(void);
bool addRgbController(void);
bool addDimmer(void);
Expand Down Expand Up @@ -308,6 +282,7 @@ class SuplaDeviceClass {

void setStatusFuncImpl(_impl_arduino_status impl_arduino_status);
void setTimerFuncImpl(_impl_arduino_timer impl_arduino_timer);
void setServerPort(int value);

void onVersionError(TSDC_SuplaVersionError *version_error);
void onRegisterResult(TSD_SuplaRegisterDeviceResult *register_device_result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,6 @@ void setup() {
SuplaDevice.addRollerShutterRelays(46, // 46 - Pin number where the 1st relay is connected
47, true); // 47 - Pin number where the 2nd relay is connected

// CHANNEL4 - Opening sensor (Normal Open)
SuplaDevice.addSensorNO(5); // 5 - Pin number where the sensor is connected
// Call SuplaDevice.addSensorNO(A0, true) with an extra "true" parameter
// to enable the internal pull-up resistor


// CHANNEL5 - Opening sensor (Normal Open)
SuplaDevice.addSensorNO(6); // 6 - Pin number where the sensor is connected


// CHANNEL6-9 - Thermometer DS18B20
// 4 DS18B20 thermometers at pin 23. DS address can be omitted when there is only one device at a pin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,6 @@ void setup() {
* Otherwise you will get "Channel conflict!" error.
*/

// CHANNEL0 - RELAY
SuplaDevice.addRelay(44, true); // 44 - Pin number where the relay is connected
// Call SuplaDevice.addRelay(44, true) with an extra "true" parameter
// to enable "port value inversion"
// where HIGH == LOW, and LOW == HIGH

// CHANNEL1 - RELAY
SuplaDevice.addRelay(45, true); // 45 - Pin number where the relay is connected

// CHANNEL3 - TWO RELAYS (Roller shutter operation)
SuplaDevice.addRollerShutterRelays(46, // 46 - Pin number where the 1st relay is connected
47, true); // 47 - Pin number where the 2nd relay is connected

// CHANNEL4 - Opening sensor (Normal Open)
SuplaDevice.addSensorNO(5); // 5 - Pin number where the sensor is connected
// Call SuplaDevice.addSensorNO(A0, true) with an extra "true" parameter
// to enable the internal pull-up resistor


// CHANNEL5 - Opening sensor (Normal Open)
SuplaDevice.addSensorNO(6); // 6 - Pin number where the sensor is connected


// CHANNEL6-9 - Thermometer DS18B20
// 4 DS18B20 thermometers at pin 23. DS address can be omitted when there is only one device at a pin
DeviceAddress ds1addr = {0x28, 0xFF, 0xC8, 0xAB, 0x6E, 0x18, 0x01, 0xFC};
DeviceAddress ds2addr = {0x28, 0xFF, 0x54, 0x73, 0x6E, 0x18, 0x01, 0x77};
Expand Down
25 changes: 20 additions & 5 deletions libraries/SuplaDevice/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "supla/network/network.h"

#include <Arduino.h>

#include "SuplaDevice.h"
#include "supla-common/log.h"
#include "supla-common/srpc.h"
#include "supla/element.h"
#include "supla/network/network.h"

namespace Supla {

Expand Down Expand Up @@ -57,10 +57,25 @@ void message_received(void *_srpc,
((SuplaDeviceClass *)_sdc)
->onRegisterResult(rd.data.sd_register_device_result);
break;
case SUPLA_SD_CALL_CHANNEL_SET_VALUE:
((SuplaDeviceClass *)_sdc)
->channelSetValueByServer(rd.data.sd_channel_new_value);
case SUPLA_SD_CALL_CHANNEL_SET_VALUE: {
auto element = Supla::Element::getElementByChannelNumber(
rd.data.sd_channel_new_value->ChannelNumber);
if (element) {
int actionResult =
element->handleNewValueFromServer(rd.data.sd_channel_new_value);
if (actionResult != -1) {
srpc_ds_async_set_channel_result(
_srpc,
rd.data.sd_channel_new_value->ChannelNumber,
rd.data.sd_channel_new_value->SenderID,
actionResult);
}
} else {
((SuplaDeviceClass *)_sdc)
->channelSetValueByServer(rd.data.sd_channel_new_value);
}
break;
}
case SUPLA_SDC_CALL_SET_ACTIVITY_TIMEOUT_RESULT:
((SuplaDeviceClass *)_sdc)
->channelSetActivityTimeoutResult(
Expand Down
Loading