Skip to content

Commit

Permalink
Merge pull request #8 from j0seph1387/patch-2
Browse files Browse the repository at this point in the history
Update and rename TasmotaSlave.cpp to TasmotaClient.cpp
  • Loading branch information
andrethomas authored Nov 22, 2020
2 parents a8334f1 + e6a34bb commit c25914b
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/TasmotaSlave.cpp → src/TasmotaClient.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
TasmotaSlave.cpp - Library for microcontrollers enslaved by Tasmota
TasmotaClient.cpp - Library for microcontrollers enclientd by Tasmota
Copyright (C) 2019 Andre Thomas
Expand All @@ -18,10 +18,10 @@
*/

#include <Arduino.h>
#include <TasmotaSlave.h>
#include <TasmotaClient.h>

/*************************************************\
* TasmotaSlave shared structures
* TasmotaClient shared structures
\*************************************************/

typedef union {
Expand All @@ -30,7 +30,7 @@ typedef union {
uint32_t func_json_append : 1; // Supports FUNC_JSON_APPEND callback
uint32_t func_every_second : 1; // Supports FUNC_EVERY_SECOND callback (No JSON)
uint32_t func_every_100_msecond : 1; // Supports FUNC_EVERY_100_MSECOND callback (No JSON)
uint32_t func_slave_send : 1; // Supports FUNC_COMMAND
uint32_t func_client_send : 1; // Supports FUNC_COMMAND
uint32_t spare4 : 1;
uint32_t spare5 : 1;
uint32_t spare6 : 1;
Expand Down Expand Up @@ -82,14 +82,14 @@ struct COMMAND {
uint8_t unused3;
} Command;

TasmotaSlave::TasmotaSlave(HardwareSerial *device)
TasmotaClient::TasmotaClient(HardwareSerial *device)
{
serial = device;
Settings.features_version = TASMOTA_SLAVE_LIB_VERSION;
Settings.features_version = TASMOTA_CLIENT_LIB_VERSION;
Settings.features.func_json_append = 0;
Settings.features.func_every_second = 0;
Settings.features.func_every_100_msecond = 0;
Settings.features.func_slave_send = 0;
Settings.features.func_client_send = 0;
Settings.features.spare4 = 0;
Settings.features.spare5 = 0;
Settings.features.spare6 = 0;
Expand Down Expand Up @@ -120,7 +120,7 @@ TasmotaSlave::TasmotaSlave(HardwareSerial *device)
Settings.features.spare31 = 0;
}

void TasmotaSlave::sendFeatures(void)
void TasmotaClient::sendFeatures(void)
{
char buffer[sizeof(Settings)];
memcpy(&buffer, &Settings, sizeof(Settings));
Expand All @@ -131,7 +131,7 @@ void TasmotaSlave::sendFeatures(void)
serial->write(char(PARAM_DATA_END));
}

void TasmotaSlave::sendJSON(char *json)
void TasmotaClient::sendJSON(char *json)
{
serial->write(char(PARAM_DATA_START));
for (uint8_t ca = 0; ca < strlen(json); ca++) {
Expand All @@ -140,31 +140,31 @@ void TasmotaSlave::sendJSON(char *json)
serial->write(char(PARAM_DATA_END));
}

void TasmotaSlave::attach_FUNC_JSON(callbackFunc func)
void TasmotaClient::attach_FUNC_JSON(callbackFunc func)
{
Settings.features.func_json_append = 1;
FUNC_JSON = func;
}

void TasmotaSlave::attach_FUNC_EVERY_SECOND(callbackFunc func)
void TasmotaClient::attach_FUNC_EVERY_SECOND(callbackFunc func)
{
Settings.features.func_every_second = 1;
FUNC_EVERY_SECOND = func;
}

void TasmotaSlave::attach_FUNC_EVERY_100_MSECOND(callbackFunc func)
void TasmotaClient::attach_FUNC_EVERY_100_MSECOND(callbackFunc func)
{
Settings.features.func_every_100_msecond = 1;
FUNC_EVERY_100_MSECOND = func;
}

void TasmotaSlave::attach_FUNC_COMMAND_SEND(callbackFunc1 func)
void TasmotaClient::attach_FUNC_COMMAND_SEND(callbackFunc1 func)
{
Settings.features.func_slave_send = 1;
Settings.features.func_client_send = 1;
FUNC_SEND = func;
}

uint8_t TasmotaSlave::waitforbytes(uint16_t num, uint16_t timeout)
uint8_t TasmotaClient::waitforbytes(uint16_t num, uint16_t timeout)
{
uint16_t timer = 0;
while (timer < timeout) {
Expand All @@ -177,7 +177,7 @@ uint8_t TasmotaSlave::waitforbytes(uint16_t num, uint16_t timeout)
return 0;
}

void TasmotaSlave::ProcessSend(uint8_t sz)
void TasmotaClient::ProcessSend(uint8_t sz)
{
if (waitforbytes(sz+2,50)) {
serial->read(); // read leading character
Expand All @@ -190,7 +190,7 @@ void TasmotaSlave::ProcessSend(uint8_t sz)
}
}

void TasmotaSlave::ProcessCommand(void)
void TasmotaClient::ProcessCommand(void)
{
if (waitforbytes(sizeof(Command)+1, 100)) {
char buffer[sizeof(Command)];
Expand All @@ -212,7 +212,7 @@ void TasmotaSlave::ProcessCommand(void)
case CMND_FUNC_EVERY_100_MSECOND:
FUNC_EVERY_100_MSECOND();
break;
case CMND_SLAVE_SEND:
case CMND_CLIENT_SEND:
ProcessSend(Command.parameter);
break;
default:
Expand All @@ -221,7 +221,7 @@ void TasmotaSlave::ProcessCommand(void)
}
}

void TasmotaSlave::SendCommand(uint8_t cmnd, uint8_t param)
void TasmotaClient::SendCommand(uint8_t cmnd, uint8_t param)
{
Command.command = cmnd;
Command.parameter = param;
Expand All @@ -236,7 +236,7 @@ void TasmotaSlave::SendCommand(uint8_t cmnd, uint8_t param)
serial->write(char(CMND_END));
}

void TasmotaSlave::SendTele(char *data)
void TasmotaClient::SendTele(char *data)
{
SendCommand(CMND_PUBLISH_TELE, strlen(data));
serial->write(char(PARAM_DATA_START));
Expand All @@ -246,7 +246,7 @@ void TasmotaSlave::SendTele(char *data)
serial->write(char(PARAM_DATA_END));
}

void TasmotaSlave::ExecuteCommand(char *cmnd)
void TasmotaClient::ExecuteCommand(char *cmnd)
{
SendCommand(CMND_EXECUTE_CMND, strlen(cmnd));
serial->write(char(PARAM_DATA_START));
Expand All @@ -256,7 +256,7 @@ void TasmotaSlave::ExecuteCommand(char *cmnd)
serial->write(char(PARAM_DATA_END));
}

void TasmotaSlave::loop(void)
void TasmotaClient::loop(void)
{
if (serial->available()) {
uint8_t cmnd = serial->read();
Expand Down

0 comments on commit c25914b

Please sign in to comment.