Skip to content

Commit

Permalink
Improve RGT emulator, add buttons handler
Browse files Browse the repository at this point in the history
Improving RGT emulator: user can set up to 5 sensors per HC with average calculation.
Add handling presence buttons and TWW push on pins D21 (INT 2)(TWW push), D20 (INT 3)(presence ROOM1), D19 (INT 4)(presence ROOM2), D18 (INT 5)(presence ROOM3)
  • Loading branch information
dukess committed Jan 18, 2021
1 parent 45f0911 commit c192995
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 18 deletions.
89 changes: 81 additions & 8 deletions BSB_lan.ino
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,14 @@ long custom_longs[20] = { 0 };
byte newMinuteValue = 99;
#endif

#ifdef BUTTONS
volatile byte PressedButtons = 0;
#define TWW_PUSH_BUTTON_PRESSED 1
#define ROOM1_PRESENCE_BUTTON_PRESSED 2
#define ROOM2_PRESENCE_BUTTON_PRESSED 4
#define ROOM3_PRESENCE_BUTTON_PRESSED 8
#endif

static const int anz_ex_gpio = sizeof(protected_GPIO) / sizeof(byte) * 8;
static const int numLogValues = sizeof(log_parameters) / sizeof(log_parameters[0]);
static const int numCustomFloats = sizeof(custom_floats) / sizeof(custom_floats[0]);
Expand Down Expand Up @@ -672,6 +680,21 @@ uint8_t current_switchday = 0;
static uint16_t baseConfigAddrInEEPROM = 0; //offset from start address
void mqtt_callback(char* topic, byte* payload, unsigned int length); //Luposoft: predefintion

#ifdef BUTTONS
void interruptHandlerTWWPush(){
PressedButtons |= TWW_PUSH_BUTTON_PRESSED;
}
void interruptHandlerPresenceROOM1(){
PressedButtons |= ROOM1_PRESENCE_BUTTON_PRESSED;
}
void interruptHandlerPresenceROOM2(){
PressedButtons |= ROOM2_PRESENCE_BUTTON_PRESSED;
}
void interruptHandlerPresenceROOM3(){
PressedButtons |= ROOM3_PRESENCE_BUTTON_PRESSED;
}
#endif

/** *****************************************************************
* Function: initConfigTable(uint8_t)
* Does: creating config parameters address table.
Expand Down Expand Up @@ -1839,6 +1862,15 @@ void EEPROM_dump() {
}
}

void switchPresenseState(uint16_t line){ //for programs 701, 1001, 1301
int state = 0;
query(line);
state = atoi(decodedTelegram.value) + 1;
if(state > 2) state = 1;
sprintf_P(decodedTelegram.value, PSTR("%d"), state);
set(line, decodedTelegram.value, true);
}

bool programIsreadOnly(uint8_t param_len){
if((DEFAULT_FLAG & FL_SW_CTL_RONLY) == FL_SW_CTL_RONLY){ //software-controlled
switch(programWriteMode) {
Expand Down Expand Up @@ -8572,9 +8604,20 @@ uint8_t pps_offset = 0;
if(newMinuteValue != tempTime){
newMinuteValue = tempTime;
for (uint8_t i = 0; i < 3; i++){
if(rgte_sensorid[i] != 0 && rgte_sensorid[i] != 0xFFFF){
query(rgte_sensorid[i]);
if(decodedTelegram.type == VT_TEMP && decodedTelegram.error == 0){
if(rgte_sensorid[i][0] != 0){
uint8_t z = 0;
float value = 0;
for(uint8_t j = 0; j < 5; j++){
if(rgte_sensorid[i][j] != 0){
query(rgte_sensorid[i][j]);
if(decodedTelegram.type == VT_TEMP && decodedTelegram.error == 0){
z++;
value += atof(decodedTelegram.value);
}
}
}
if(z != 0){
_printFIXPOINT(decodedTelegram.value, value / z, 2);
set(10000 + i, decodedTelegram.value, false); //send INF message like RGT1 - RGT3 devices
}
}
Expand All @@ -8583,6 +8626,26 @@ uint8_t pps_offset = 0;
}
#endif

#ifdef BUTTONS
if(PressedButtons){
switch(PressedButtons){
case TWW_PUSH_BUTTON_PRESSED: strcpy_P(decodedTelegram.value, PSTR("1")); set(1603, decodedTelegram.value, true); PressedButtons &= ~TWW_PUSH_BUTTON_PRESSED; break;
case ROOM1_PRESENCE_BUTTON_PRESSED:
switchPresenseState(701);
PressedButtons &= ~ROOM1_PRESENCE_BUTTON_PRESSED;
break;
case ROOM2_PRESENCE_BUTTON_PRESSED:
switchPresenseState(1001);
PressedButtons &= ~ROOM2_PRESENCE_BUTTON_PRESSED;
break;
case ROOM3_PRESENCE_BUTTON_PRESSED:
switchPresenseState(1301);
PressedButtons &= ~ROOM3_PRESENCE_BUTTON_PRESSED;
break;
}
}
#endif

#ifdef WATCH_SOCKETS
ShowSockStatus();
checkSockStatus();
Expand Down Expand Up @@ -8991,11 +9054,9 @@ void setup() {
registerConfigVariable(CF_VERBOSE, (byte *)&verbose);
registerConfigVariable(CF_MONITOR, (byte *)&monitor);
registerConfigVariable(CF_CHECKUPDATE, (byte *)&enable_version_check);
#ifdef RGT_EMULATOR
registerConfigVariable(CF_RGT1_SENSOR_ID, (byte *)&rgte_sensorid[0]);
registerConfigVariable(CF_RGT2_SENSOR_ID, (byte *)&rgte_sensorid[1]);
registerConfigVariable(CF_RGT3_SENSOR_ID, (byte *)&rgte_sensorid[2]);
#endif
registerConfigVariable(CF_RGT1_SENSOR_ID, (byte *)&rgte_sensorid[0][0]);
registerConfigVariable(CF_RGT2_SENSOR_ID, (byte *)&rgte_sensorid[1][0]);
registerConfigVariable(CF_RGT3_SENSOR_ID, (byte *)&rgte_sensorid[2][0]);

#endif

Expand Down Expand Up @@ -9423,6 +9484,18 @@ mdns.addServiceRecord(PSTR("BSB-LAN web service._http"), HTTPPort, MDNSServiceTC
#ifdef CUSTOM_COMMANDS
#include "BSB_lan_custom_setup.h"
#endif

#ifdef BUTTONS
pinMode(21, INPUT_PULLUP);
attachInterrupt(21, interruptHandlerTWWPush, FALLING); //TWW push button
pinMode(20, INPUT_PULLUP);
attachInterrupt(20, interruptHandlerPresenceROOM1, FALLING); //Presence ROOM 1 button
pinMode(19, INPUT_PULLUP);
attachInterrupt(19, interruptHandlerPresenceROOM2, FALLING); //Presence ROOM 2 button
pinMode(18, INPUT_PULLUP);
attachInterrupt(18, interruptHandlerPresenceROOM3, FALLING); //Presence ROOM 3 button
#endif

printlnToDebug(PSTR("Setup complete"));
debug_mode = save_debug_mode; //restore actual debug mode
}
6 changes: 3 additions & 3 deletions BSB_lan_EEPROMconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ PROGMEM_LATE const configuration_struct config[]={
{CF_PPS_WRITE, 1, CCAT_BUS, CPI_SWITCH, CDT_BYTE, CF_PPS_WRITE_TXT, sizeof(pps_write)},//need handler
#ifdef WEBCONFIG
{CF_ROOM_DEVICE, 2, CCAT_BUS, CPI_DROPDOWN, CDT_UINT16, CF_QAA_TYPE_TXT, sizeof(pps_values[PPS_QTP])},//immediately apply
{CF_RGT1_SENSOR_ID, 5, CCAT_RGT_EMUL, CPI_TEXT, CDT_UINT16, CF_RGT1_SENSOR_TXT, sizeof(log_parameters[0])},
{CF_RGT2_SENSOR_ID, 5, CCAT_RGT_EMUL, CPI_TEXT, CDT_UINT16, CF_RGT2_SENSOR_TXT, sizeof(log_parameters[0])},
{CF_RGT3_SENSOR_ID, 5, CCAT_RGT_EMUL, CPI_TEXT, CDT_UINT16, CF_RGT3_SENSOR_TXT, sizeof(log_parameters[0])},
{CF_RGT1_SENSOR_ID, 5, CCAT_RGT_EMUL, CPI_TEXT, CDT_PROGNRLIST, CF_RGT1_SENSOR_TXT, sizeof(rgte_sensorid)/3},//immediately apply
{CF_RGT2_SENSOR_ID, 5, CCAT_RGT_EMUL, CPI_TEXT, CDT_PROGNRLIST, CF_RGT2_SENSOR_TXT, sizeof(rgte_sensorid)/3},//immediately apply
{CF_RGT3_SENSOR_ID, 5, CCAT_RGT_EMUL, CPI_TEXT, CDT_PROGNRLIST, CF_RGT3_SENSOR_TXT, sizeof(rgte_sensorid)/3},//immediately apply
{CF_PASSKEY, 2, CCAT_IPV4, CPI_TEXT, CDT_STRING, CF_PASSKEY_TXT, sizeof(PASSKEY)},//immediately apply
{CF_BASICAUTH, 2, CCAT_IPV4, CPI_TEXT, CDT_STRING, CF_BASICAUTH_TXT, sizeof(USER_PASS_B64)},//immediately apply
{CF_DHCP, 2, CCAT_IPV4, CPI_SWITCH, CDT_BYTE, CF_DHCP_TXT, sizeof(useDHCP)}, //need reboot
Expand Down
5 changes: 4 additions & 1 deletion BSB_lan_config.h.default
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ bool enable_version_check = false;
#define JSONCONFIG

#define RGT_EMULATOR
int rgte_sensorid[3] = {0, 0, 0}; //Temperature sensor program ID for RTG1 - RTG3. If zero then RTG will not be emulated.
int rgte_sensorid[3][5] = {{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}; //Temperature sensor program IDs for RGT1 - RGT3. If zero then RGT will not be emulated. If more than one program set per RGT then average will be calculated and used.

//Enable presence buttons and TWW push on pins D21 (INT 2)(TWW push), D20 (INT 3)(presence ROOM1), D19 (INT 4)(presence ROOM2), D18 (INT 5)(presence ROOM3)
#define BUTTONS

// Variables for future use:
// Compile room unit replacement extension
Expand Down
6 changes: 3 additions & 3 deletions localization/LANG_DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@
#define CF_MQTT_TOPIC_TEXT "Topic prefix"
#define CF_MQTT_DEVICE_TEXT "Geräte ID"
#define CF_CHECKUPDATE_TEXT "Auf Updates überprüfen"
#define CF_RGT1_SENSOR_TEXT "Temp sensor program ID for RGT1"
#define CF_RGT2_SENSOR_TEXT "Temp sensor program ID for RGT2"
#define CF_RGT3_SENSOR_TEXT "Temp sensor program ID for RGT3"
#define CF_RGT1_SENSOR_TEXT "Temp sensors program IDs for RGT1"
#define CF_RGT2_SENSOR_TEXT "Temp sensors program IDs for RGT2"
#define CF_RGT3_SENSOR_TEXT "Temp sensors program IDs for RGT3"

#define CAT_GENERAL_TEXT "Generell"
#define CAT_IPV4_TEXT "Netzwerk"
Expand Down
6 changes: 3 additions & 3 deletions localization/LANG_RU.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@
#define CF_MQTT_DEVICE_TEXT "Идентификатор устройства"
#define CF_MQTT_TOPIC_TEXT "Префикс темы"
#define CF_CHECKUPDATE_TEXT "Проверять обновления"
#define CF_RGT1_SENSOR_TEXT "Номер программы датчика температуры для RGT1"
#define CF_RGT2_SENSOR_TEXT "Номер программы датчика температуры для RGT2"
#define CF_RGT3_SENSOR_TEXT "Номер программы датчика температуры для RGT3"
#define CF_RGT1_SENSOR_TEXT "Номера программ датчиков температуры для RGT1"
#define CF_RGT2_SENSOR_TEXT "Номера программ датчиков температуры для RGT2"
#define CF_RGT3_SENSOR_TEXT "Номера программ датчиков температуры для RGT3"


#define CAT_GENERAL_TEXT "Основные"
Expand Down

0 comments on commit c192995

Please sign in to comment.