Add the IKEA Ansluta remote-controllable lighting protocol

This commit is contained in:
Konstantin Tretyakov 2021-04-19 01:57:57 +02:00
parent 1648a0780a
commit ea571ac6ab
4 changed files with 122 additions and 1 deletions

View File

@ -0,0 +1,114 @@
/*
This project 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 3 of the License, or
(at your option) any later version.
Multiprotocol 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 Multiprotocol. If not, see <http://www.gnu.org/licenses/>.
*/
// This module makes it possible to bind to and control the IKEA "Ansluta" line
// of remote-controlled lights.
// To bind, first switch the receiver into binding mode, then the TX.
// Once bound, the TX can send one of three commands:
// lights off, lights dimmed 50% and lights on.
// Those are mapped to throttle ranges 0..0x55, 0x56..0xAA, 0xAB..0xFF.
#if defined(IKEA_ANSLUTA_CC2500_INO)
#include "iface_cc2500.h"
#define IKEA_ANSLUTA_BIND_COUNT 30 // ~ 2sec autobind/65ms per loop = 30 binding packets
// Address of the transmitter consist of two bytes, the first one we fix to 0x01,
// while the second is provided by the "Option" setting.
// Receiver learns the TX address during binding.
#define IKEA_ANSLUTA_ADDRESS_A 0x01
// Commands
#define IKEA_ANSLUTA_LIGHT_OFF 0x01
#define IKEA_ANSLUTA_LIGHT_DIM 0x02 // 50% dimmed light
#define IKEA_ANSLUTA_LIGHT_ON 0x03
#define IKEA_ANSLUTA_PAIR 0xFF
void IKEA_ANSLUTA_send_command(uint8_t command){
CC2500_Strobe(CC2500_SIDLE);
packet[4] = option;
packet[5] = command;
CC2500_WriteData(packet, 8);
}
uint16_t IKEA_ANSLUTA_callback(void)
{
if (IS_BIND_IN_PROGRESS && bind_counter == 0) bind_counter = IKEA_ANSLUTA_BIND_COUNT;
if (bind_counter) {
IKEA_ANSLUTA_send_command(IKEA_ANSLUTA_PAIR);
bind_counter--;
if (bind_counter == 0) {
BIND_DONE;
CC2500_SetPower();
}
}
else {
uint8_t throttle = convert_channel_8b(THROTTLE);
uint8_t cmd = throttle <= 0x55 ? IKEA_ANSLUTA_LIGHT_OFF :
throttle <= 0xAA ? IKEA_ANSLUTA_LIGHT_DIM :
IKEA_ANSLUTA_LIGHT_ON;
IKEA_ANSLUTA_send_command(cmd);
}
return 65535; // 65ms loop cycle is more than enough here (we could make it even longer if not for uint16_t)
}
void IKEA_ANSLUTA_init(void)
{
// All packets we send are the same
packet[0] = 0x06;
packet[1] = 0x55;
packet[2] = 0x01;
packet[3] = IKEA_ANSLUTA_ADDRESS_A;
packet[4] = option;
packet[5] = 0x00; // Command goes here
packet[6] = 0xAA;
packet[7] = 0xFF;
CC2500_Reset();
CC2500_WriteReg(CC2500_06_PKTLEN, 0xFF);
CC2500_WriteReg(CC2500_07_PKTCTRL1, 0x04);
CC2500_WriteReg(CC2500_08_PKTCTRL0, 0x05);
CC2500_WriteReg(CC2500_0A_CHANNR, 0x10);
CC2500_WriteReg(CC2500_0B_FSCTRL1, 0x09);
CC2500_WriteReg(CC2500_0C_FSCTRL0, 0x00);
CC2500_WriteReg(CC2500_0D_FREQ2, 0x5D);
CC2500_WriteReg(CC2500_0E_FREQ1, 0x93);
CC2500_WriteReg(CC2500_0F_FREQ0, 0xB1);
CC2500_WriteReg(CC2500_10_MDMCFG4, 0x2D);
CC2500_WriteReg(CC2500_11_MDMCFG3, 0x3B);
CC2500_WriteReg(CC2500_12_MDMCFG2, 0x73);
CC2500_WriteReg(CC2500_13_MDMCFG1, 0xA2);
CC2500_WriteReg(CC2500_14_MDMCFG0, 0xF8);
CC2500_WriteReg(CC2500_15_DEVIATN, 0x01);
CC2500_WriteReg(CC2500_16_MCSM2, 0x07);
CC2500_WriteReg(CC2500_17_MCSM1, 0x30);
CC2500_WriteReg(CC2500_18_MCSM0, 0x18);
CC2500_WriteReg(CC2500_19_FOCCFG, 0x1D);
CC2500_WriteReg(CC2500_1A_BSCFG, 0x1C);
CC2500_WriteReg(CC2500_1B_AGCCTRL2, 0xC7);
CC2500_WriteReg(CC2500_1C_AGCCTRL1, 0x00);
CC2500_WriteReg(CC2500_1D_AGCCTRL0, 0xB2);
CC2500_WriteReg(CC2500_21_FREND1, 0xB6);
CC2500_WriteReg(CC2500_22_FREND0, 0x10);
CC2500_WriteReg(CC2500_23_FSCAL3, 0xEA);
CC2500_WriteReg(CC2500_24_FSCAL2, 0x0A);
CC2500_WriteReg(CC2500_25_FSCAL1, 0x00);
CC2500_WriteReg(CC2500_26_FSCAL0, 0x11);
CC2500_WriteReg(CC2500_27_RCCTRL1, 0x41);
CC2500_WriteReg(CC2500_28_RCCTRL0, 0x00);
CC2500_SetTxRxMode(TX_EN);
CC2500_SetPower();
}
#endif

View File

@ -98,6 +98,7 @@ const char STR_E010R5[] ="E010r5";
const char STR_LOLI[] ="LOLI";
const char STR_E129[] ="E129";
const char STR_E016H[] ="E016H";
const char STR_IKEA_ANSLUTA[]="Ansluta";
const char STR_CONFIG[] ="Config";
const char STR_SUBTYPE_FLYSKY[] = "\x04""Std\0""V9x9""V6x6""V912""CX20";
@ -330,6 +331,9 @@ const mm_protocol_definition multi_protocols[] = {
#if defined(HUBSAN_A7105_INO)
{PROTO_HUBSAN, STR_HUBSAN, STR_SUBTYPE_HUBSAN, 3, OPTION_VIDFREQ, 0, 0, SW_A7105, HUBSAN_init, HUBSAN_callback },
#endif
#if defined(IKEA_ANSLUTA_CC2500_INO)
{PROTO_IKEA_ANSLUTA,STR_IKEA_ANSLUTA,NO_SUBTYPE, 0, OPTION_OPTION, 0, 0, SW_CC2500, IKEA_ANSLUTA_init,IKEA_ANSLUTA_callback },
#endif
#if defined(J6PRO_CYRF6936_INO)
{PROTO_J6PRO, STR_J6PRO, NO_SUBTYPE, 0, OPTION_NONE, 0, 1, SW_CYRF, J6PRO_init, J6PRO_callback },
#endif

View File

@ -113,7 +113,8 @@ enum PROTOCOLS
PROTO_E129 = 83, // =>CYRF6936
PROTO_JOYSWAY = 84, // =>A7105
PROTO_E016H = 85, // =>NRF24L01
PROTO_CONFIG = 86, // Module config
PROTO_IKEA_ANSLUTA = 86,// =>CC2500
PROTO_CONFIG = 87, // Module config
PROTO_NANORF = 126, // =>NRF24L01
PROTO_TEST = 127, // =>CC2500

View File

@ -203,6 +203,7 @@
#define FRSKY_RX_CC2500_INO
#define HITEC_CC2500_INO
#define HOTT_CC2500_INO
#define IKEA_ANSLUTA_CC2500_INO
#define SCANNER_CC2500_INO
#define FUTABA_CC2500_INO
#define SKYARTEC_CC2500_INO
@ -693,6 +694,7 @@ const PPM_Parameters PPM_prot[14*NBR_BANKS]= {
H107
H301
H501
PROTO_IKEA_ANSLUTA
PROTO_J6PRO
NONE
PROTO_JJRC345