mirror of
https://github.com/Utyff/Zintercom.git
synced 2026-01-12 09:17:41 +03:00
v0.2
some code rework and cleanup R7 changed to 100 ohm converter exposes renamed
This commit is contained in:
@@ -117,9 +117,10 @@
|
|||||||
#define ACTIVE_HIGH !! /* double negation forces result to be '1' */
|
#define ACTIVE_HIGH !! /* double negation forces result to be '1' */
|
||||||
|
|
||||||
/* S1 */
|
/* S1 */
|
||||||
#define PUSH1_BV BV(1)
|
#define PUSH1_BV BV(0)
|
||||||
#define PUSH1_SBIT P0_1
|
#define PUSH1_SBIT P2_0
|
||||||
|
|
||||||
|
//???????????????????????????????
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -123,44 +123,29 @@ void zclApp_Init(byte task_id) {
|
|||||||
LREP("Build %s \r\n", zclApp_DateCodeNT);
|
LREP("Build %s \r\n", zclApp_DateCodeNT);
|
||||||
|
|
||||||
zclApp_ConfigInit(TIMER_START);
|
zclApp_ConfigInit(TIMER_START);
|
||||||
|
IO_IMODE_PORT_PIN(0,0,IO_TRI);
|
||||||
|
|
||||||
#if defined( ZIC_BATTERY_MODE )
|
#if defined( ZIC_BATTERY_MODE )
|
||||||
ZMacSetTransmitPower(TX_PWR_PLUS_4); // set 4dBm
|
ZMacSetTransmitPower(TX_PWR_PLUS_4); // set 4dBm
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void zclApp_HandleKeys(byte portAndAction, byte keyCode) {
|
static void zclApp_HandleKeys(byte portAndAction, byte keyCode) {
|
||||||
|
|
||||||
LREP("zclApp_HandleKeys portAndAction=0x%X keyCode=0x%X\r\n", portAndAction, keyCode);
|
//LREP("zclApp_HandleKeys portAndAction=0x%X keyCode=0x%X\r\n", portAndAction, keyCode);
|
||||||
zclCommissioning_HandleKeys(portAndAction, keyCode);
|
//zclCommissioning_HandleKeys(portAndAction, keyCode);
|
||||||
|
|
||||||
if (portAndAction & 0x01) { //P0 Ring //S1 P0_1
|
if (portAndAction & 0x01) { //P0 Ring //S1 P0_1
|
||||||
/*
|
|
||||||
afAddrType_t inderect_DstAddr = {.addrMode = (afAddrMode_t)AddrNotPresent, .endPoint = 0, .addr.shortAddr = 0};
|
|
||||||
if (portAndAction & HAL_KEY_PRESS) {
|
|
||||||
osal_pwrmgr_task_state(zclApp_TaskID, PWRMGR_HOLD);
|
|
||||||
LREPMaster("Ring start\r\n");
|
|
||||||
HalLedSet(LED_PIN, HAL_LED_MODE_BLINK);
|
|
||||||
zclGeneral_SendOnOff_CmdOn(zclApp_FirstEP.EndPoint, &inderect_DstAddr, FALSE, bdb_getZCLFrameCounter());
|
|
||||||
osal_start_reload_timer(zclApp_TaskID, APP_RING_RUN_EVT, 500);
|
|
||||||
}
|
|
||||||
if (portAndAction & HAL_KEY_RELEASE) {
|
|
||||||
zclApp_RingEnd();
|
|
||||||
zclGeneral_SendOnOff_CmdOff(zclApp_FirstEP.EndPoint, &inderect_DstAddr, FALSE, bdb_getZCLFrameCounter());
|
|
||||||
osal_pwrmgr_task_state(zclApp_TaskID, PWRMGR_CONSERVE);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
osal_stop_timerEx(zclApp_TaskID, APP_RING_STOP_EVT);
|
|
||||||
osal_clear_event(zclApp_TaskID, APP_RING_STOP_EVT);
|
|
||||||
if (portAndAction & HAL_KEY_PRESS) {
|
if (portAndAction & HAL_KEY_PRESS) {
|
||||||
|
|
||||||
//osal_pwrmgr_task_state(zclApp_TaskID, PWRMGR_HOLD);
|
//osal_pwrmgr_task_state(zclApp_TaskID, PWRMGR_HOLD);
|
||||||
//LREPMaster("Ring start\r\n");
|
|
||||||
//HalLedSet(LED_PIN, HAL_LED_MODE_BLINK);
|
|
||||||
//zclGeneral_SendOnOff_CmdOn(zclApp_FirstEP.EndPoint, &inderect_DstAddr, FALSE, bdb_getZCLFrameCounter());
|
|
||||||
//osal_start_reload_timer(zclApp_TaskID, APP_RING_RUN_EVT, 500);
|
|
||||||
//osal_start_reload_timer(zclApp_TaskID, APP_RING_RUN_EVT, 500); //start ring
|
|
||||||
|
|
||||||
|
|
||||||
//exit old stop timer
|
//exit old stop timer
|
||||||
|
osal_stop_timerEx(zclApp_TaskID, APP_RING_STOP_EVT);
|
||||||
|
osal_clear_event(zclApp_TaskID, APP_RING_STOP_EVT);
|
||||||
|
|
||||||
//start ring
|
//start ring
|
||||||
if (zclApp_State.RingRunStep == 0) {
|
if (zclApp_State.RingRunStep == 0) {
|
||||||
@@ -173,43 +158,22 @@ static void zclApp_HandleKeys(byte portAndAction, byte keyCode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//start new stop timer (ring ends timer)
|
//start new stop timer (ring ends timer)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//osal_start_reload_timer(zclApp_TaskID, APP_RING_RUN_EVT, 1000); //stop ring after 1s of inactive
|
|
||||||
}
|
|
||||||
osal_start_reload_timer(zclApp_TaskID, APP_RING_STOP_EVT, 3000);
|
osal_start_reload_timer(zclApp_TaskID, APP_RING_STOP_EVT, 3000);
|
||||||
//if (portAndAction & HAL_KEY_RELEASE) {
|
|
||||||
//zclApp_RingEnd();
|
|
||||||
//zclGeneral_SendOnOff_CmdOff(zclApp_FirstEP.EndPoint, &inderect_DstAddr, FALSE, bdb_getZCLFrameCounter());
|
|
||||||
//osal_pwrmgr_task_state(zclApp_TaskID, PWRMGR_CONSERVE);
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (portAndAction & 0x04) { //P2 Btn //S2 P2_0
|
if (portAndAction & 0x04) { //P2 Btn //S2 P2_0
|
||||||
zclFactoryResetter_HandleKeys(portAndAction, keyCode);
|
zclFactoryResetter_HandleKeys(portAndAction, keyCode);
|
||||||
if (portAndAction & HAL_KEY_PRESS) {
|
if (portAndAction & HAL_KEY_PRESS) {
|
||||||
zclApp_State.pressTime = osal_getClock();
|
|
||||||
LREPMaster("Key press\r\n");
|
|
||||||
LREP("pressTime = %d\r\n", zclApp_State.pressTime);
|
|
||||||
}
|
|
||||||
if (portAndAction & HAL_KEY_RELEASE) {
|
|
||||||
#if defined( ZIC_BATTERY_MODE )
|
#if defined( ZIC_BATTERY_MODE )
|
||||||
zclBattery_Report();
|
zclBattery_Report();
|
||||||
#endif
|
#endif
|
||||||
LREPMaster("Key release\r\n");
|
LREPMaster("Key pressed\r\n");
|
||||||
uint32 holdTime = osal_getClock() - zclApp_State.pressTime;
|
|
||||||
LREP("holdTime = %d \r\n", holdTime);
|
|
||||||
if (holdTime < 1) {
|
|
||||||
osal_start_reload_timer(zclApp_TaskID, APP_BTN_CLICK_EVT, 50);
|
osal_start_reload_timer(zclApp_TaskID, APP_BTN_CLICK_EVT, 50);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
osal_start_reload_timer(zclApp_TaskID, APP_BTN_HOLD_EVT, 50);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,6 +307,8 @@ static void zclApp_RingRun(void) {
|
|||||||
|
|
||||||
static void zclApp_TalkStart(void) {
|
static void zclApp_TalkStart(void) {
|
||||||
LREPMaster("Talk start\r\n");
|
LREPMaster("Talk start\r\n");
|
||||||
|
osal_stop_timerEx(zclApp_TaskID, APP_RING_STOP_EVT);
|
||||||
|
osal_clear_event(zclApp_TaskID, APP_RING_STOP_EVT);
|
||||||
zclApp_OneReport();
|
zclApp_OneReport();
|
||||||
HalLedSet(ANSWER_PIN, HAL_LED_MODE_ON);
|
HalLedSet(ANSWER_PIN, HAL_LED_MODE_ON);
|
||||||
if (zclApp_Config.ModeSound == true) {
|
if (zclApp_Config.ModeSound == true) {
|
||||||
@@ -377,6 +343,9 @@ static void zclApp_RingEnd(void) {
|
|||||||
zclApp_Config.ModeOpen = Never;
|
zclApp_Config.ModeOpen = Never;
|
||||||
}
|
}
|
||||||
zclApp_OneReport();
|
zclApp_OneReport();
|
||||||
|
#if defined( ZIC_BATTERY_MODE )
|
||||||
|
zclBattery_Report();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zclApp_BtnClick(bool hold) {
|
static void zclApp_BtnClick(bool hold) {
|
||||||
@@ -409,7 +378,7 @@ static void zclApp_BtnClick(bool hold) {
|
|||||||
HalLedBlink(LED_PIN, zclApp_Config.ModeOpen+1, 50, 250);
|
HalLedBlink(LED_PIN, zclApp_Config.ModeOpen+1, 50, 250);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
case 3:
|
||||||
if (hold) {
|
if (hold) {
|
||||||
osal_stop_timerEx(zclApp_TaskID, APP_BTN_HOLD_EVT);
|
osal_stop_timerEx(zclApp_TaskID, APP_BTN_HOLD_EVT);
|
||||||
osal_clear_event(zclApp_TaskID, APP_BTN_HOLD_EVT);
|
osal_clear_event(zclApp_TaskID, APP_BTN_HOLD_EVT);
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ extern "C" {
|
|||||||
#define APP_SAVE_ATTRS_EVT 0x0002
|
#define APP_SAVE_ATTRS_EVT 0x0002
|
||||||
#define APP_BTN_CLICK_EVT 0x0004
|
#define APP_BTN_CLICK_EVT 0x0004
|
||||||
#define APP_RING_RUN_EVT 0x0008
|
#define APP_RING_RUN_EVT 0x0008
|
||||||
#define APP_BTN_HOLD_EVT 0x0010
|
#define APP_BTN_HOLD_EVT 0x0016
|
||||||
#define APP_RING_STOP_EVT 0x0012
|
#define APP_RING_STOP_EVT 0x0032
|
||||||
#define APP_TALK_START_EVT 0x0014
|
#define APP_TALK_START_EVT 0x0064
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
|||||||
@@ -65,8 +65,8 @@ const uint8 zclApp_PowerSource = POWER_SOURCE_DC;
|
|||||||
#define DEFAULT_ModeSound TRUE
|
#define DEFAULT_ModeSound TRUE
|
||||||
|
|
||||||
#define DEFAULT_TimeRing 3 //seconds to ring, before answer
|
#define DEFAULT_TimeRing 3 //seconds to ring, before answer
|
||||||
#define DEFAULT_TimeTalk 1 //seconds to talk, before open
|
#define DEFAULT_TimeTalk 2 //seconds to talk, before open
|
||||||
#define DEFAULT_TimeOpen 2 //seconds to hold open
|
#define DEFAULT_TimeOpen 1 //seconds to hold open
|
||||||
|
|
||||||
|
|
||||||
application_config_t zclApp_Config = {
|
application_config_t zclApp_Config = {
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ const {
|
|||||||
exposes
|
exposes
|
||||||
} = require('zigbee-herdsman-converters');
|
} = require('zigbee-herdsman-converters');
|
||||||
|
|
||||||
const e = exposes.presets;
|
const ep = exposes.presets;
|
||||||
|
const ea = exposes.access;
|
||||||
|
|
||||||
const ZCL_DATATYPE_INT16 = 0x29;
|
const ZCL_DATATYPE_INT16 = 0x29;
|
||||||
const ZCL_DATATYPE_UINT8 = 0x20;
|
const ZCL_DATATYPE_UINT8 = 0x20;
|
||||||
@@ -61,46 +62,6 @@ const repInterval = {
|
|||||||
MINUTES_5: 300,
|
MINUTES_5: 300,
|
||||||
MINUTE: 60,
|
MINUTE: 60,
|
||||||
};
|
};
|
||||||
//const ACCESS_STATE = 0b001, ACCESS_WRITE = 0b010, ACCESS_READ = 0b100;
|
|
||||||
|
|
||||||
const hass = {
|
|
||||||
co2: {
|
|
||||||
type: 'sensor',
|
|
||||||
object_id: 'co2',
|
|
||||||
discovery_payload: {
|
|
||||||
unit_of_measurement: 'ppm',
|
|
||||||
icon: 'mdi:molecule-co2',
|
|
||||||
value_template: '{{ value_json.co2 }}',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
temperature: {
|
|
||||||
type: 'sensor',
|
|
||||||
object_id: 'temperature',
|
|
||||||
discovery_payload: {
|
|
||||||
unit_of_measurement: '°C',
|
|
||||||
device_class: 'temperature',
|
|
||||||
value_template: '{{ value_json.temperature }}',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
humidity: {
|
|
||||||
type: 'sensor',
|
|
||||||
object_id: 'humidity',
|
|
||||||
discovery_payload: {
|
|
||||||
unit_of_measurement: '%',
|
|
||||||
device_class: 'humidity',
|
|
||||||
value_template: '{{ value_json.humidity }}',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
presure: {
|
|
||||||
type: 'sensor',
|
|
||||||
object_id: 'pressure',
|
|
||||||
discovery_payload: {
|
|
||||||
unit_of_measurement: 'hPa',
|
|
||||||
device_class: 'pressure',
|
|
||||||
value_template: '{{ value_json.pressure }}',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -114,10 +75,10 @@ const fz = {
|
|||||||
result.state = ['Idle', 'Ring', 'Talk', 'Open', 'Drop'][msg.data[0x0050]];
|
result.state = ['Idle', 'Ring', 'Talk', 'Open', 'Drop'][msg.data[0x0050]];
|
||||||
}
|
}
|
||||||
if (msg.data.hasOwnProperty(0x0051)) {
|
if (msg.data.hasOwnProperty(0x0051)) {
|
||||||
result.mode_open = ['Never', 'Once', 'Always', 'Drop'][msg.data[0x0051]];
|
result.mode = ['Never', 'Once', 'Always', 'Drop'][msg.data[0x0051]];
|
||||||
}
|
}
|
||||||
if (msg.data.hasOwnProperty(0x0052)) {
|
if (msg.data.hasOwnProperty(0x0052)) {
|
||||||
result.mode_sound = ['OFF', 'ON'][msg.data[0x0052]];
|
result.sound = ['OFF', 'ON'][msg.data[0x0052]];
|
||||||
}
|
}
|
||||||
if (msg.data.hasOwnProperty(0x0053)) {
|
if (msg.data.hasOwnProperty(0x0053)) {
|
||||||
result.time_ring = msg.data[0x0053];
|
result.time_ring = msg.data[0x0053];
|
||||||
@@ -138,7 +99,7 @@ const fz = {
|
|||||||
|
|
||||||
const tz = {
|
const tz = {
|
||||||
diy_zintercom_config: {
|
diy_zintercom_config: {
|
||||||
key: ['state', 'mode_open', 'mode_sound', 'time_ring', 'time_talk', 'time_open', 'time_report'],
|
key: ['state', 'mode', 'sound', 'time_ring', 'time_talk', 'time_open', 'time_report'],
|
||||||
convertSet: async (entity, key, rawValue, meta) => {
|
convertSet: async (entity, key, rawValue, meta) => {
|
||||||
const lookup = {
|
const lookup = {
|
||||||
'OFF': 0x00,
|
'OFF': 0x00,
|
||||||
@@ -154,13 +115,13 @@ const tz = {
|
|||||||
|
|
||||||
let value = lookup.hasOwnProperty(rawValue) ? lookup[rawValue] : parseInt(rawValue, 10);
|
let value = lookup.hasOwnProperty(rawValue) ? lookup[rawValue] : parseInt(rawValue, 10);
|
||||||
|
|
||||||
if (key == 'mode_open') {
|
if (key == 'mode') {
|
||||||
value = modeOpenLookup.hasOwnProperty(rawValue) ? modeOpenLookup[rawValue] : parseInt(rawValue, 10);
|
value = modeOpenLookup.hasOwnProperty(rawValue) ? modeOpenLookup[rawValue] : parseInt(rawValue, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
const payloads = {
|
const payloads = {
|
||||||
mode_open: {0x0051: {value, type: 0x30}},
|
mode: {0x0051: {value, type: 0x30}},
|
||||||
mode_sound: {0x0052: {value, type: 0x10}},
|
sound: {0x0052: {value, type: 0x10}},
|
||||||
time_ring: {0x0053: {value, type: 0x20}},
|
time_ring: {0x0053: {value, type: 0x20}},
|
||||||
time_talk: {0x0054: {value, type: 0x20}},
|
time_talk: {0x0054: {value, type: 0x20}},
|
||||||
time_open: {0x0055: {value, type: 0x20}},
|
time_open: {0x0055: {value, type: 0x20}},
|
||||||
@@ -175,8 +136,8 @@ const tz = {
|
|||||||
convertGet: async (entity, key, meta) => {
|
convertGet: async (entity, key, meta) => {
|
||||||
const payloads = {
|
const payloads = {
|
||||||
state: ['closuresDoorLock', 0x0050],
|
state: ['closuresDoorLock', 0x0050],
|
||||||
mode_open: ['closuresDoorLock', 0x0051],
|
mode: ['closuresDoorLock', 0x0051],
|
||||||
mode_sound: ['closuresDoorLock', 0x0052],
|
sound: ['closuresDoorLock', 0x0052],
|
||||||
time_ring: ['closuresDoorLock', 0x0053],
|
time_ring: ['closuresDoorLock', 0x0053],
|
||||||
time_talk: ['closuresDoorLock', 0x0054],
|
time_talk: ['closuresDoorLock', 0x0054],
|
||||||
time_open: ['closuresDoorLock', 0x0055],
|
time_open: ['closuresDoorLock', 0x0055],
|
||||||
@@ -195,12 +156,6 @@ const device = {
|
|||||||
supports: '',
|
supports: '',
|
||||||
//homeassistant: [hass.temperature, hass.presure, hass.humidity, hass.co2],
|
//homeassistant: [hass.temperature, hass.presure, hass.humidity, hass.co2],
|
||||||
fromZigbee: [
|
fromZigbee: [
|
||||||
/*
|
|
||||||
fromZigbeeConverters.temperature,
|
|
||||||
fromZigbeeConverters.humidity,
|
|
||||||
fromZigbeeConverters.co2,
|
|
||||||
fromZigbeeConverters.pressure,
|
|
||||||
*/
|
|
||||||
fromZigbeeConverters.battery,
|
fromZigbeeConverters.battery,
|
||||||
fz.diy_zintercom_config,
|
fz.diy_zintercom_config,
|
||||||
],
|
],
|
||||||
@@ -274,22 +229,22 @@ const device = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
exposes: [
|
exposes: [
|
||||||
//exposes.numeric('co2', ACCESS_STATE).withUnit('ppm'),
|
exposes.enum('state', ea.STATE_GET, ['Idle', 'Ring', 'Talk', 'Open', 'Drop'])
|
||||||
e.battery(),
|
|
||||||
exposes.enum('state', exposes.access.STATE_GET, ['Idle', 'Ring', 'Talk', 'Open', 'Drop'])
|
|
||||||
.withDescription('Current state'),
|
.withDescription('Current state'),
|
||||||
exposes.enum('mode_open', exposes.access.ALL, ['Never', 'Once', 'Always', 'Drop'])
|
exposes.enum('mode', ea.ALL, ['Never', 'Once', 'Always', 'Drop'])
|
||||||
.withDescription('Auto open mode'),
|
.withDescription('Select open mode'),
|
||||||
exposes.binary('mode_sound', exposes.access.ALL, 'ON', 'OFF')
|
exposes.binary('sound', ea.ALL, 'ON', 'OFF').withProperty('sound')
|
||||||
.withDescription('Sound mode'),
|
.withDescription('Enable or disable sound'),
|
||||||
exposes.numeric('time_ring', exposes.access.ALL).withUnit('sec')
|
exposes.numeric('time_ring', ea.ALL).withUnit('sec')
|
||||||
.withDescription('Time to ring'),
|
.withDescription('Time to ring before answer'),
|
||||||
exposes.numeric('time_talk', exposes.access.ALL).withUnit('sec')
|
exposes.numeric('time_talk', ea.ALL).withUnit('sec')
|
||||||
.withDescription('Time to "speak" before open'),
|
.withDescription('Time to hold before open'),
|
||||||
exposes.numeric('time_open', exposes.access.ALL).withUnit('sec')
|
exposes.numeric('time_open', ea.ALL).withUnit('sec')
|
||||||
.withDescription('Time to "hold open button"'),
|
.withDescription('Time to open before end'),
|
||||||
exposes.numeric('time_report', exposes.access.ALL).withUnit('min')
|
exposes.numeric('time_report', ea.ALL).withUnit('min')
|
||||||
.withDescription('Reporting interval'),
|
.withDescription('Reporting interval'),
|
||||||
|
ep.battery(),
|
||||||
|
ep.linkquality(),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 340 KiB After Width: | Height: | Size: 330 KiB |
Reference in New Issue
Block a user