diff --git a/Source/hal_board_cfg.h b/Source/hal_board_cfg.h index 68379d9..55d447f 100644 --- a/Source/hal_board_cfg.h +++ b/Source/hal_board_cfg.h @@ -117,9 +117,10 @@ #define ACTIVE_HIGH !! /* double negation forces result to be '1' */ /* S1 */ -#define PUSH1_BV BV(1) -#define PUSH1_SBIT P0_1 - +#define PUSH1_BV BV(0) +#define PUSH1_SBIT P2_0 + + //??????????????????????????????? diff --git a/Source/zcl_app.c b/Source/zcl_app.c index 9a25ae4..9fcc2dc 100644 --- a/Source/zcl_app.c +++ b/Source/zcl_app.c @@ -123,44 +123,29 @@ void zclApp_Init(byte task_id) { LREP("Build %s \r\n", zclApp_DateCodeNT); zclApp_ConfigInit(TIMER_START); + IO_IMODE_PORT_PIN(0,0,IO_TRI); + #if defined( ZIC_BATTERY_MODE ) ZMacSetTransmitPower(TX_PWR_PLUS_4); // set 4dBm #endif } + + static void zclApp_HandleKeys(byte portAndAction, byte keyCode) { - LREP("zclApp_HandleKeys portAndAction=0x%X keyCode=0x%X\r\n", portAndAction, keyCode); - zclCommissioning_HandleKeys(portAndAction, keyCode); + //LREP("zclApp_HandleKeys portAndAction=0x%X keyCode=0x%X\r\n", portAndAction, keyCode); + //zclCommissioning_HandleKeys(portAndAction, keyCode); 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) { + //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 - + osal_stop_timerEx(zclApp_TaskID, APP_RING_STOP_EVT); + osal_clear_event(zclApp_TaskID, APP_RING_STOP_EVT); //start ring if (zclApp_State.RingRunStep == 0) { @@ -173,43 +158,22 @@ static void zclApp_HandleKeys(byte portAndAction, byte keyCode) { } //start new stop timer (ring ends timer) - + osal_start_reload_timer(zclApp_TaskID, APP_RING_STOP_EVT, 3000); - - - //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); - //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 zclFactoryResetter_HandleKeys(portAndAction, keyCode); 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 ) zclBattery_Report(); #endif - LREPMaster("Key release\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); - } - else { - osal_start_reload_timer(zclApp_TaskID, APP_BTN_HOLD_EVT, 50); - } + LREPMaster("Key pressed\r\n"); + osal_start_reload_timer(zclApp_TaskID, APP_BTN_CLICK_EVT, 50); } + } } @@ -343,6 +307,8 @@ static void zclApp_RingRun(void) { static void zclApp_TalkStart(void) { 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(); HalLedSet(ANSWER_PIN, HAL_LED_MODE_ON); if (zclApp_Config.ModeSound == true) { @@ -376,7 +342,10 @@ static void zclApp_RingEnd(void) { if (zclApp_Config.ModeOpen == Once) { zclApp_Config.ModeOpen = Never; } - zclApp_OneReport(); + zclApp_OneReport(); + #if defined( ZIC_BATTERY_MODE ) + zclBattery_Report(); + #endif } 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); } break; - default: + case 3: if (hold) { osal_stop_timerEx(zclApp_TaskID, APP_BTN_HOLD_EVT); osal_clear_event(zclApp_TaskID, APP_BTN_HOLD_EVT); diff --git a/Source/zcl_app.h b/Source/zcl_app.h index a563a02..f4bc23f 100644 --- a/Source/zcl_app.h +++ b/Source/zcl_app.h @@ -21,9 +21,9 @@ extern "C" { #define APP_SAVE_ATTRS_EVT 0x0002 #define APP_BTN_CLICK_EVT 0x0004 #define APP_RING_RUN_EVT 0x0008 -#define APP_BTN_HOLD_EVT 0x0010 -#define APP_RING_STOP_EVT 0x0012 -#define APP_TALK_START_EVT 0x0014 +#define APP_BTN_HOLD_EVT 0x0016 +#define APP_RING_STOP_EVT 0x0032 +#define APP_TALK_START_EVT 0x0064 /********************************************************************* * MACROS diff --git a/Source/zcl_app_data.c b/Source/zcl_app_data.c index eeea7a2..bb1b9d7 100644 --- a/Source/zcl_app_data.c +++ b/Source/zcl_app_data.c @@ -65,8 +65,8 @@ const uint8 zclApp_PowerSource = POWER_SOURCE_DC; #define DEFAULT_ModeSound TRUE #define DEFAULT_TimeRing 3 //seconds to ring, before answer -#define DEFAULT_TimeTalk 1 //seconds to talk, before open -#define DEFAULT_TimeOpen 2 //seconds to hold open +#define DEFAULT_TimeTalk 2 //seconds to talk, before open +#define DEFAULT_TimeOpen 1 //seconds to hold open application_config_t zclApp_Config = { diff --git a/converters/DIY_Zintercom.js b/converters/DIY_Zintercom.js index 7d2a347..b71d8aa 100644 --- a/converters/DIY_Zintercom.js +++ b/converters/DIY_Zintercom.js @@ -4,7 +4,8 @@ const { exposes } = require('zigbee-herdsman-converters'); -const e = exposes.presets; +const ep = exposes.presets; +const ea = exposes.access; const ZCL_DATATYPE_INT16 = 0x29; const ZCL_DATATYPE_UINT8 = 0x20; @@ -61,46 +62,6 @@ const repInterval = { MINUTES_5: 300, 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]]; } 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)) { - result.mode_sound = ['OFF', 'ON'][msg.data[0x0052]]; + result.sound = ['OFF', 'ON'][msg.data[0x0052]]; } if (msg.data.hasOwnProperty(0x0053)) { result.time_ring = msg.data[0x0053]; @@ -138,7 +99,7 @@ const fz = { const tz = { 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) => { const lookup = { 'OFF': 0x00, @@ -154,13 +115,13 @@ const tz = { 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); } const payloads = { - mode_open: {0x0051: {value, type: 0x30}}, - mode_sound: {0x0052: {value, type: 0x10}}, + mode: {0x0051: {value, type: 0x30}}, + sound: {0x0052: {value, type: 0x10}}, time_ring: {0x0053: {value, type: 0x20}}, time_talk: {0x0054: {value, type: 0x20}}, time_open: {0x0055: {value, type: 0x20}}, @@ -175,8 +136,8 @@ const tz = { convertGet: async (entity, key, meta) => { const payloads = { state: ['closuresDoorLock', 0x0050], - mode_open: ['closuresDoorLock', 0x0051], - mode_sound: ['closuresDoorLock', 0x0052], + mode: ['closuresDoorLock', 0x0051], + sound: ['closuresDoorLock', 0x0052], time_ring: ['closuresDoorLock', 0x0053], time_talk: ['closuresDoorLock', 0x0054], time_open: ['closuresDoorLock', 0x0055], @@ -195,12 +156,6 @@ const device = { supports: '', //homeassistant: [hass.temperature, hass.presure, hass.humidity, hass.co2], fromZigbee: [ - /* - fromZigbeeConverters.temperature, - fromZigbeeConverters.humidity, - fromZigbeeConverters.co2, - fromZigbeeConverters.pressure, - */ fromZigbeeConverters.battery, fz.diy_zintercom_config, ], @@ -254,8 +209,8 @@ const device = { minimumReportInterval: 0, maximumReportInterval: 3600, reportableChange: 0, - }, - ]; + }, + ]; await firstEndpoint.configureReporting('closuresDoorLock', payload); /**/ /* @@ -274,22 +229,22 @@ const device = { }, exposes: [ - //exposes.numeric('co2', ACCESS_STATE).withUnit('ppm'), - e.battery(), - exposes.enum('state', exposes.access.STATE_GET, ['Idle', 'Ring', 'Talk', 'Open', 'Drop']) + exposes.enum('state', ea.STATE_GET, ['Idle', 'Ring', 'Talk', 'Open', 'Drop']) .withDescription('Current state'), - exposes.enum('mode_open', exposes.access.ALL, ['Never', 'Once', 'Always', 'Drop']) - .withDescription('Auto open mode'), - exposes.binary('mode_sound', exposes.access.ALL, 'ON', 'OFF') - .withDescription('Sound mode'), - exposes.numeric('time_ring', exposes.access.ALL).withUnit('sec') - .withDescription('Time to ring'), - exposes.numeric('time_talk', exposes.access.ALL).withUnit('sec') - .withDescription('Time to "speak" before open'), - exposes.numeric('time_open', exposes.access.ALL).withUnit('sec') - .withDescription('Time to "hold open button"'), - exposes.numeric('time_report', exposes.access.ALL).withUnit('min') + exposes.enum('mode', ea.ALL, ['Never', 'Once', 'Always', 'Drop']) + .withDescription('Select open mode'), + exposes.binary('sound', ea.ALL, 'ON', 'OFF').withProperty('sound') + .withDescription('Enable or disable sound'), + exposes.numeric('time_ring', ea.ALL).withUnit('sec') + .withDescription('Time to ring before answer'), + exposes.numeric('time_talk', ea.ALL).withUnit('sec') + .withDescription('Time to hold before open'), + exposes.numeric('time_open', ea.ALL).withUnit('sec') + .withDescription('Time to open before end'), + exposes.numeric('time_report', ea.ALL).withUnit('min') .withDescription('Reporting interval'), + ep.battery(), + ep.linkquality(), ], }; diff --git a/hardware/BOM_Zintercom.csv b/hardware/BOM_Zintercom.csv index 7bf99c6..c17b6a2 100644 Binary files a/hardware/BOM_Zintercom.csv and b/hardware/BOM_Zintercom.csv differ diff --git a/hardware/Schematic_Zintercom.png b/hardware/Schematic_Zintercom.png index 02000e2..cf35b90 100644 Binary files a/hardware/Schematic_Zintercom.png and b/hardware/Schematic_Zintercom.png differ