Skip to content

Commit

Permalink
Merge pull request #33 from mposzywak/arif-#31
Browse files Browse the repository at this point in the history
Added shadeTTimer and shadePTimer cmds and writing of shade timer val…
  • Loading branch information
mposzywak authored Mar 28, 2021
2 parents f5eb1fb + f7060a0 commit d30d436
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 59 deletions.
42 changes: 42 additions & 0 deletions ARiF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ static ARiFClass::t ARiFClass::t_func1 = {0, 1000 * ARiF_BEACON_INT}; /* for ARi
static ARiFClass::t ARiFClass::t_func2 = {0, 1000}; /* for everysecond on the DHCP checking */
static byte ARiFClass::lastShadePosition = 0;
static byte ARiFClass::lastShadeTilt = 0;
static int ARiFClass::lastShadePositionTimer = 0;
static int ARiFClass::lastShadeTiltTimer = 0;
static byte ARiFClass::mode = 0;
static byte ARiFClass::lastLightType = 0;
static unsigned long ARiFClass::lastLightTimer = 0;
Expand Down Expand Up @@ -250,6 +252,34 @@ static byte ARiFClass::update() {
return U_NOTHING;
}
break;
case CMD_MODE_LIGHTS:
client.println(F(HTTP_200_OK));
client.println();
client.stop();
return CMD_MODE_LIGHTS;
break;
case CMD_MODE_SHADES:
client.println(F(HTTP_200_OK));
client.println();
client.stop();
return CMD_MODE_SHADES;
break;
case CMD_TIMER_POS:
lastDevID = getValue(buff, DEVID);
lastShadePositionTimer = getValue(buff, VALUE);
client.println(F(HTTP_200_OK));
client.println();
client.stop();
return CMD_TIMER_POS;
break;
case CMD_TIMER_TILT:
lastDevID = getValue(buff, DEVID);
lastShadeTiltTimer = getValue(buff, VALUE);
client.println(F(HTTP_200_OK));
client.println();
client.stop();
return CMD_TIMER_TILT;
break;
case CMD_UNKNOWN:
client.println(F(HTTP_500_Error));
client.stop();
Expand Down Expand Up @@ -317,6 +347,10 @@ static long ARiFClass::getValue(char *buff, int value) {
if (strstr(buff, "cmd=shadeSTOP")) return CMD_SHADESTOP;
if (strstr(buff, "cmd=ctrlON")) return CMD_CTRL_ON;
if (strstr(buff, "cmd=ctrlOFF")) return CMD_CTRL_OFF;
if (strstr(buff, "cmd=modeLights")) return CMD_MODE_LIGHTS;
if (strstr(buff, "cmd=modeShades")) return CMD_MODE_SHADES;
if (strstr(buff, "cmd=shadePTimer")) return CMD_TIMER_POS;
if (strstr(buff, "cmd=shadeTTimer")) return CMD_TIMER_TILT;
return CMD_UNKNOWN;
}
}
Expand Down Expand Up @@ -472,6 +506,14 @@ unsigned long ARiFClass::getLastLightTimer() {
return lastLightTimer;
}

int ARiFClass::getLastShadePositionTimer() {
return lastShadePositionTimer;
}

int ARiFClass::getLastShadeTiltTimer() {
return lastShadeTiltTimer;
}

void ARiFClass::deregister() {
isRegistered = false;
ardID = 0;
Expand Down
17 changes: 17 additions & 0 deletions ARiF.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define HTTP_200_OK "HTTP/1.1 200 OK\nContent-Type: text/html\nConnnection: close\n\n"
#define HTTP_500_Error "HTTP/1.1 500\nContent-Type: text/html\nConnnection: close\n\n"
#define HTTP_403_Error "HTTP/1.1 403\nContent-Type: text/html\nConnnection: close\n\n"
#define HTTP_404_Error "HTTP/1.1 404\nContent-Type: text/html\nConnnection: close\n\n"

/* Shades version 1 with the shade position and tilt */
#define VER_SHD_1 0
Expand All @@ -36,6 +37,10 @@
#define CMD_LIGHT_TIMER 10
#define CMD_CTRL_ON 11
#define CMD_CTRL_OFF 12
#define CMD_MODE_LIGHTS 13
#define CMD_MODE_SHADES 14
#define CMD_TIMER_POS 15
#define CMD_TIMER_TILT 16
#define CMD_UNKNOWN 200

/* values returned by update() other than the CMDs above */
Expand Down Expand Up @@ -141,6 +146,12 @@ class ARiFClass {
/* variable holding light timer received by the last lightTimer command */
static unsigned long lastLightTimer;

/* variable holding last shade position timer */
static int lastShadePositionTimer;

/* variable holding last shade tilt timer */
static int lastShadeTiltTimer;

/* holds information if this arduino is registered */
static bool isRegistered;

Expand Down Expand Up @@ -244,6 +255,12 @@ class ARiFClass {
/* get the timer of the last received lightTimer command */
unsigned long getLastLightTimer();

/* get the shade Position Timer received through shadePTimer command */
int getLastShadePositionTimer();

/* get the shade Tilt Timer received through shadeTTimer command */
int getLastShadeTiltTimer();

/* send the shade sync information */
static void sendShadeSynced(byte devID);

Expand Down
94 changes: 82 additions & 12 deletions Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@
CONTROLLINO_D20 };

/* The input pin devID array */
static byte Settings::digitINdevID[IN_PINS] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
//static byte Settings::digitINdevID[IN_PINS] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };

/* the output pin devID array */
static byte Settings::digitOUTdevID[OUT_PINS] = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70 };
//static byte Settings::digitOUTdevID[OUT_PINS] = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70 };

/* the shadeID array */
/* the shadeID array (numbers must be consecutive) */
static byte Settings::shadeIDs[SHADES] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

/* the lightID array */
/* the lightID array (numbers must be consecutive) */
static byte Settings::lightIDs[LIGHTS] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };

#elif defined(CONTROLLINO_MAXI)
Expand Down Expand Up @@ -108,15 +108,15 @@
CONTROLLINO_D11 };

/* The input pin devID array */
static byte Settings::digitINdevID[IN_PINS] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
//static byte Settings::digitINdevID[IN_PINS] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };

/* the output pin devID array */
static byte Settings::digitOUTdevID[OUT_PINS] = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61 };
//static byte Settings::digitOUTdevID[OUT_PINS] = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61 };

/* the shadeID array */
/* the shadeID array (numbers must be consecutive) */
static byte Settings::shadeIDs[SHADES] = { 1, 2, 3, 4, 5, 6 };

/* the lightID array */
/* the lightID array (numbers must be consecutive) */
static byte Settings::lightIDs[LIGHTS] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

#elif defined(ARDUINO_AVR_MEGA2560)
Expand Down Expand Up @@ -180,15 +180,15 @@
65 };

/* The input pin devID array */
static byte Settings::digitINdevID[IN_PINS] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
//static byte Settings::digitINdevID[IN_PINS] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };

/* the output pin devID array */
static byte Settings::digitOUTdevID[OUT_PINS] = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61 };
//static byte Settings::digitOUTdevID[OUT_PINS] = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61 };

/* the shadeID array */
/* the shadeID array (numbers must be consecutive) */
static byte Settings::shadeIDs[SHADES] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };

/* the lightID array */
/* the lightID array (numbers must be consecutive) */
static byte Settings::lightIDs[LIGHTS] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28 };

#else
Expand Down Expand Up @@ -346,6 +346,7 @@ static void Settings::EEPROMSetMode(byte mode) {
*/

static void Settings::EEPROMSetLightConfig(byte devID, byte type, unsigned long timer) {
if (devID > LIGHTS) return;
byte index = EEPROM_IDX_LIGHTS + (6 * (devID - 1)); /* start address for Light data structure */
EEPROM.write(index + 1, type);
EEPROMWritelong(index + 2, timer);
Expand All @@ -359,6 +360,7 @@ static byte Settings::EEPROMGetLightType(byte devID) {
}

static void Settings::EEPROMSetLightType(byte devID, byte type) {
if (devID > LIGHTS) return;
byte index = EEPROM_IDX_LIGHTS + (6 * (devID - 1)); /* start address for Light data structure */
EEPROM.write(index + 1, type);
}
Expand All @@ -371,11 +373,13 @@ static unsigned long Settings::EEPROMGetLightTimer(byte devID) {
}

static void Settings::EEPROMSetLightTimer(byte devID, unsigned long timer) {
if (devID > LIGHTS) return;
byte index = EEPROM_IDX_LIGHTS + (6 * (devID - 1)); /* start address for Light data structure */
EEPROMWritelong(index + 2, timer);
}

static void Settings::EEPROMSetLightStatus(byte devID, byte status) {
if (devID > LIGHTS) return;
byte index = EEPROM_IDX_LIGHTS + (6 * (devID - 1)); /* start address for Light data structure */
EEPROM.write(index, status);
}
Expand Down Expand Up @@ -404,6 +408,20 @@ static void Settings::EEPROMWritelong(int address, unsigned long value) {
EEPROM.write(address + 3, one);
}

static int Settings::EEPROMReadInt(int address) {
byte byte1 = EEPROM.read(address);
byte byte2 = EEPROM.read(address + 1);
return (byte1 << 8) + byte2;
}

static void Settings::EEPROMWriteInt(int address, int value) {
byte byte1 = value >> 8;
byte byte2 = value & 0xFF;
EEPROM.write(address, byte1);
EEPROM.write(address + 1, byte2);
}


static void Settings::EEPROMSetLightCentral(byte mode) {
EEPROM.write(EEPROM_IDX_CENT_CTRL, mode);
}
Expand All @@ -414,6 +432,58 @@ static byte Settings::EEPROMGetLightCentral() {
return mode;
}

/* The shadeIDs and lightIDs are used as index values for the entries in the EEPROM hence they must all start from 1 and be consecutive in order for the
EEPROM storage of individual configuration of devices to work properly */

/* The following scheme shows how the data is stored (for a shade type device):
* xx xxxx xx xx xx xxxx
* | | | | | |__________ The tile timer value (int)
* | | | | |__________ The position timer value (byte)
* | | | |__________ The shade device type: (byte)
* | | |_________ flags field (byte)
* | |_______ The Tilt position of shade device: (int)
* |____ The Position of the shade (current state): (byte)
*/

static void Settings::EEPROMSetShadeType(byte devID, byte type) {
if (devID > SHADES) return;
byte index = EEPROM_IDX_SHADES + (7 * (devID - 1));
EEPROM.write(index + 4, type);
}

static void Settings::EEPROMSetShadeTiltTimer(byte devID, int timer) {
if (devID > SHADES) return;
byte index = EEPROM_IDX_SHADES + (7 * (devID - 1));
EEPROMWriteInt(index + 6, timer);
}

static void Settings::EEPROMSetShadePosTimer(byte devID, byte timer) {
if (devID > SHADES) return;
byte index = EEPROM_IDX_SHADES + (7 * (devID - 1));
EEPROM.write(index + 5, timer);
}

static byte Settings::EEPROMGetShadeType(byte devID) {
byte index = EEPROM_IDX_SHADES + (7 * (devID - 1));
byte type;
type = EEPROM.read(index + 4);
return type;
}

static int Settings::EEPROMGetShadeTiltTimer(byte devID) {
byte index = EEPROM_IDX_SHADES + (7 * (devID - 1));
int timer;
timer = EEPROMReadInt(index + 6);
return timer;
}

static byte Settings::EEPROMGetShadePosTimer(byte devID) {
byte index = EEPROM_IDX_SHADES + (7 * (devID - 1));
byte timer;
timer = EEPROM.read(index + 5);
return timer;
}

static byte Settings::SDCardInit() {
#if defined(CONTROLLINO_MEGA)
/* no support on Controllino for SD Card */
Expand Down
31 changes: 30 additions & 1 deletion Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
#define EEPROM_IDX_RASPYIP 3 // length 6
#define EEPROM_IDX_MODE 9 // length 1
#define EEPROM_IDX_LIGHTS 10 // length 210 -> 30 (lights) x 6 (1 status + 1 type + 4 timer) + 30 (buffer for future use)
#define EEPROM_IDX_CENT_CTRL 220 // length
#define EEPROM_IDX_CENT_CTRL 220 // length
#define EEPROM_IDX_SHADES 221 // length 150 -> 15 (shades) x 8 (4 status + 1 type + 1 pos timer + 2 tilt timer) + 30 (buffer for future use)

/* flags */
#define EEPROM_FLG_SHADE_SYNC 1
#define EEPROM_FLG_SHADE_INMOTION 2

/* functional modes of the entire device */
#define MODE_LIGHTS 0
Expand Down Expand Up @@ -73,6 +78,12 @@ class Settings {
/* write a long vlaue into EEPROM at a given address */
static void EEPROMWritelong(int address, unsigned long value);

/* read an int value from EEPROM's given address */
static int Settings::EEPROMReadInt(int address);

/* write an int vlaue into EEPROM at a given address */
static void Settings::EEPROMWriteInt(int address, int value);

public:

/* The input pin devID array */
Expand Down Expand Up @@ -178,6 +189,24 @@ class Settings {
/* Read Central Control mode from the EEPROM */
static byte EEPROMGetLightCentral();

/* Write Shade type into memory */
static void EEPROMSetShadeType(byte devID, byte type);

/* Write Shade tilt timer into memory */
static void EEPROMSetShadeTiltTimer(byte devID, int timer);

/* Write Shade position timer into memory */
static void EEPROMSetShadePosTimer(byte devID, byte timer);

/* Read Shade type from memory */
static byte EEPROMGetShadeType(byte devID);

/* Read Shade tilt timer from memory */
static int EEPROMGetShadeTiltTimer(byte devID);

/* Read Shade position timer from memory */
static byte EEPROMGetShadePosTimer(byte devID);

/*
* SD Card related functions
*/
Expand Down
Loading

0 comments on commit d30d436

Please sign in to comment.