Skip to content

Commit

Permalink
Add ActionTrigger example (board: lightswitch_at)
Browse files Browse the repository at this point in the history
  • Loading branch information
klew committed Feb 27, 2022
1 parent cd3f050 commit b9b058e
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/build.sh
Expand Up @@ -142,6 +142,10 @@ case $1 in
"inCanRS_DHT22")
SPI_MODE="QIO"
FLASH_SIZE="4096"
;;
"lightswitch_at")
FOTA=1
FLASH_SIZE="2048"
;;

*)
Expand Down Expand Up @@ -170,6 +174,7 @@ case $1 in
echo " dimmer";
echo " rgbw_wroom";
echo " h801";
echo " lightswitch_at";
echo " lightswitch_x2";
echo " lightswitch_x2_54";
echo " lightswitch_x2_DHT11";
Expand Down
88 changes: 88 additions & 0 deletions src/include/board/lightswitch_at.c
@@ -0,0 +1,88 @@
/*
Copyright (C) AC SOFTWARE SP. Z O.O.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include "supla_esp.h"

void supla_esp_board_set_device_name(char *buffer, uint8 buffer_size) {

ets_snprintf(buffer, buffer_size, "SUPLA-LIGHTSWITCH-AT");
}

const uint8_t rsa_public_key_bytes[512] = {};

void supla_esp_board_gpio_init(void) {

supla_input_cfg[0].gpio_id = B_BTN1_PORT;
supla_input_cfg[0].flags = INPUT_FLAG_PULLUP | INPUT_FLAG_CFG_BTN;
supla_input_cfg[0].relay_gpio_id = B_RELAY1_PORT;
supla_input_cfg[0].channel = 1;

if (supla_esp_cfg.CfgButtonType == BTN_TYPE_MONOSTABLE) {
supla_input_cfg[0].type = INPUT_TYPE_BTN_MONOSTABLE;
supla_input_cfg[0].action_trigger_cap =
SUPLA_ACTION_CAP_HOLD |
SUPLA_ACTION_CAP_SHORT_PRESS_x1 |
SUPLA_ACTION_CAP_SHORT_PRESS_x2 |
SUPLA_ACTION_CAP_SHORT_PRESS_x3 |
SUPLA_ACTION_CAP_SHORT_PRESS_x4 |
SUPLA_ACTION_CAP_SHORT_PRESS_x5;
} else {
supla_input_cfg[0].type = INPUT_TYPE_BTN_BISTABLE;
supla_input_cfg[0].action_trigger_cap =
SUPLA_ACTION_CAP_TURN_ON |
SUPLA_ACTION_CAP_TURN_OFF |
SUPLA_ACTION_CAP_TOGGLE_x1 |
SUPLA_ACTION_CAP_TOGGLE_x2 |
SUPLA_ACTION_CAP_TOGGLE_x3 |
SUPLA_ACTION_CAP_TOGGLE_x4 |
SUPLA_ACTION_CAP_TOGGLE_x5;
}

supla_relay_cfg[0].gpio_id = B_RELAY1_PORT;
supla_relay_cfg[0].flags = RELAY_FLAG_RESTORE_FORCE;
supla_relay_cfg[0].channel = 0;

}

void supla_esp_board_set_channels(TDS_SuplaDeviceChannel_C *channels,
unsigned char *channel_count) {

*channel_count = 2;

channels[0].Number = 0;
channels[0].Type = SUPLA_CHANNELTYPE_RELAY;
channels[0].Flags = SUPLA_CHANNEL_FLAG_CHANNELSTATE;
channels[0].FuncList = SUPLA_BIT_FUNC_LIGHTSWITCH;
channels[0].Default = SUPLA_CHANNELFNC_LIGHTSWITCH;
channels[0].value[0] = supla_esp_gpio_relay_on(B_RELAY1_PORT);

channels[1].Number = 1;
channels[1].Type = SUPLA_CHANNELTYPE_ACTIONTRIGGER;
channels[1].FuncList = SUPLA_CHANNELFNC_ACTIONTRIGGER;
channels[1].Default = SUPLA_CHANNELFNC_ACTIONTRIGGER;
channels[1].ActionTriggerCaps = supla_input_cfg[0].action_trigger_cap;
channels[1].Flags = SUPLA_CHANNEL_FLAG_CHANNELSTATE;
channels[1].actionTriggerProperties.relatedChannelNumber = 1;
channels[1].actionTriggerProperties.disablesLocalOperation =
SUPLA_ACTION_CAP_TOGGLE_x1 | SUPLA_ACTION_CAP_SHORT_PRESS_x1;

}

void supla_esp_board_send_channel_values_with_delay(void *srpc) {
supla_esp_channel_value_changed(0, supla_esp_gpio_relay_on(B_RELAY1_PORT));
}
33 changes: 33 additions & 0 deletions src/include/board/lightswitch_at.h
@@ -0,0 +1,33 @@
/*
Copyright (C) AC SOFTWARE SP. Z O.O.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef LIGHTSWITCH_AT_H_
#define LIGHTSWITCH_AT_H_

#define ESP8266_SUPLA_PROTO_VERSION 16
#define B_RELAY1_PORT 13
#define B_BTN1_PORT 12
#define RETREIVE_CHANNEL_CONFIG 0b10

#define CFGBTN_TYPE_SELECTION
#define LED_RED_PORT 14

void supla_esp_board_send_channel_values_with_delay(void *srpc);

#endif // LIGHTSWITCH_AT_H_

4 changes: 4 additions & 0 deletions src/include/board/supla_esp_board.c
Expand Up @@ -73,6 +73,10 @@

#include "board/lightswitch.c"

#elif defined(__BOARD_lightswitch_at)

#include "board/lightswitch_at.c"

#elif defined(__BOARD_impulse_counter)

#include "board/impulse_counter.c"
Expand Down
4 changes: 4 additions & 0 deletions src/include/board/supla_esp_board.h
Expand Up @@ -70,6 +70,10 @@

#include "board/h801.h"

#elif defined(__BOARD_lightswitch_at)

#include "board/lightswitch_at.h"

#elif defined(__BOARD_lightswitch_x2) || \
defined(__BOARD_lightswitch_x2_DHT11) || \
defined(__BOARD_lightswitch_x2_DHT22) || \
Expand Down

0 comments on commit b9b058e

Please sign in to comment.