mirror of
https://github.com/Utyff/Zintercom.git
synced 2026-01-12 17:27:42 +03:00
some work on ring and btn events
This commit is contained in:
@@ -61,26 +61,26 @@
|
|||||||
#define HAL_LED_BLINK_DELAY() st( { volatile uint32 i; for (i=0; i<0x5800; i++) { }; } )
|
#define HAL_LED_BLINK_DELAY() st( { volatile uint32 i; for (i=0; i<0x5800; i++) { }; } )
|
||||||
|
|
||||||
#if defined(HAL_BOARD_TARGET)
|
#if defined(HAL_BOARD_TARGET)
|
||||||
//blue
|
//led
|
||||||
#define LED1_BV BV(4)
|
#define LED1_BV BV(4)
|
||||||
#define LED1_SBIT P1_4
|
#define LED1_SBIT P0_4
|
||||||
#define LED1_DDR P1DIR
|
#define LED1_DDR P0DIR
|
||||||
#define LED1_POLARITY ACTIVE_LOW
|
#define LED1_POLARITY ACTIVE_HIGH
|
||||||
//green
|
//catch
|
||||||
#define LED2_BV BV(1)
|
#define LED2_BV BV(1)
|
||||||
#define LED2_SBIT P1_1
|
#define LED2_SBIT P0_1
|
||||||
#define LED2_DDR P1DIR
|
#define LED2_DDR P0DIR
|
||||||
#define LED2_POLARITY ACTIVE_LOW
|
#define LED2_POLARITY ACTIVE_HIGH
|
||||||
//red
|
//answer
|
||||||
#define LED3_BV BV(0)
|
#define LED3_BV BV(2)
|
||||||
#define LED3_SBIT P1_0
|
#define LED3_SBIT P0_2
|
||||||
#define LED3_DDR P1DIR
|
#define LED3_DDR P0DIR
|
||||||
#define LED3_POLARITY ACTIVE_LOW
|
#define LED3_POLARITY ACTIVE_HIGH
|
||||||
//ex
|
//open
|
||||||
#define LED4_BV BV(4)
|
#define LED4_BV BV(3)
|
||||||
#define LED4_SBIT P1_5
|
#define LED4_SBIT P0_3
|
||||||
#define LED4_DDR P1DIR
|
#define LED4_DDR P0DIR
|
||||||
#define LED4_POLARITY ACTIVE_LOW
|
#define LED4_POLARITY ACTIVE_HIGH
|
||||||
|
|
||||||
|
|
||||||
#elif defined(HAL_BOARD_CHDTECH_DEV)
|
#elif defined(HAL_BOARD_CHDTECH_DEV)
|
||||||
|
|||||||
@@ -38,21 +38,28 @@
|
|||||||
#error "Board type must be defined"
|
#error "Board type must be defined"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ZIC_BATTERY_MODE
|
||||||
|
#define POWER_SAVING
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(HAL_BOARD_TARGET)
|
#if defined(HAL_BOARD_TARGET)
|
||||||
#define HAL_KEY_P0_INPUT_PINS BV(1)
|
#define HAL_KEY_P0_INPUT_PINS BV(1)
|
||||||
|
#define HAL_KEY_P0_INPUT_PINS_EDGE HAL_KEY_FALLING_EDGE
|
||||||
#define HAL_KEY_P2_INPUT_PINS BV(0)
|
#define HAL_KEY_P2_INPUT_PINS BV(0)
|
||||||
//#define CO2_UART_PORT 0x00
|
#define HAL_KEY_P2_INPUT_PINS_EDGE HAL_KEY_FALLING_EDGE
|
||||||
//#define HAL_UART_DMA 1
|
//#define HAL_UART_DMA 1
|
||||||
//#define HAL_UART_ISR 0
|
//#define HAL_UART_ISR 0
|
||||||
#define INT_HEAP_LEN 2256
|
#define INT_HEAP_LEN 2256
|
||||||
#elif defined(HAL_BOARD_CHDTECH_DEV)
|
#elif defined(HAL_BOARD_CHDTECH_DEV)
|
||||||
#define HAL_UART_DMA 1
|
#define HAL_UART_DMA 1
|
||||||
#define HAL_UART_ISR 2
|
#define HAL_UART_ISR 2
|
||||||
//#define CO2_UART_PORT 0x01
|
|
||||||
//#define HAL_KEY_P0_INPUT_PINS 0x21//pins 1 and 2. BV(1) bv(1) pin 2. bit (1 << n)
|
|
||||||
#define HAL_KEY_P0_INPUT_PINS BV(1)
|
#define HAL_KEY_P0_INPUT_PINS BV(1)
|
||||||
|
#define HAL_KEY_P0_INPUT_PINS_EDGE HAL_KEY_FALLING_EDGE
|
||||||
#define HAL_KEY_P2_INPUT_PINS BV(0)
|
#define HAL_KEY_P2_INPUT_PINS BV(0)
|
||||||
|
#define HAL_KEY_P2_INPUT_PINS_EDGE HAL_KEY_FALLING_EDGE
|
||||||
#define DO_DEBUG_UART
|
#define DO_DEBUG_UART
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FACTORY_RESET_HOLD_TIME_LONG 5000
|
#define FACTORY_RESET_HOLD_TIME_LONG 5000
|
||||||
|
|||||||
@@ -83,10 +83,11 @@ static void zclApp_Report(void);
|
|||||||
static void zclApp_OneReport(void);
|
static void zclApp_OneReport(void);
|
||||||
static void zclApp_ConfigInit(bool restart);
|
static void zclApp_ConfigInit(bool restart);
|
||||||
|
|
||||||
static void zclApp_BtnClick(void);
|
static void zclApp_BtnClick(bool hold);
|
||||||
static void zclApp_RingRun(void);
|
static void zclApp_RingRun(void);
|
||||||
static void zclApp_RingEnd(void);
|
static void zclApp_RingEnd(void);
|
||||||
|
|
||||||
|
//static uint32 pressTime = 0;
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* ZCL General Profile Callback table
|
* ZCL General Profile Callback table
|
||||||
@@ -126,15 +127,18 @@ void zclApp_Init(byte task_id) {
|
|||||||
#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);
|
||||||
if (keyCode == 1) {
|
if (keyCode == 1) {
|
||||||
zclFactoryResetter_HandleKeys(portAndAction, keyCode);
|
zclFactoryResetter_HandleKeys(portAndAction, keyCode);
|
||||||
}
|
}
|
||||||
zclCommissioning_HandleKeys(portAndAction, keyCode);
|
zclCommissioning_HandleKeys(portAndAction, keyCode);
|
||||||
if (portAndAction & HAL_KEY_PRESS) {
|
if (portAndAction & HAL_KEY_PRESS) {
|
||||||
|
zclApp_State.pressTime = osal_getClock();
|
||||||
if (keyCode == 1) {
|
if (keyCode == 1) {
|
||||||
LREPMaster("Key press\r\n");
|
LREPMaster("Key press\r\n");
|
||||||
osal_start_reload_timer(zclApp_TaskID, APP_BTN_CLICK_EVT, 250);
|
LREP("pressTime = %d\r\n", zclApp_State.pressTime);
|
||||||
|
//osal_start_reload_timer(zclApp_TaskID, APP_BTN_CLICK_EVT, 250);
|
||||||
}
|
}
|
||||||
else if (keyCode == 2) {
|
else if (keyCode == 2) {
|
||||||
LREPMaster("Ring start\r\n");
|
LREPMaster("Ring start\r\n");
|
||||||
@@ -145,7 +149,18 @@ static void zclApp_HandleKeys(byte portAndAction, byte keyCode) {
|
|||||||
#if defined( ZIC_BATTERY_MODE )
|
#if defined( ZIC_BATTERY_MODE )
|
||||||
zclBattery_Report();
|
zclBattery_Report();
|
||||||
#endif
|
#endif
|
||||||
if (keyCode == 2) {
|
if (keyCode == 1) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (keyCode == 2) {
|
||||||
zclApp_RingEnd();
|
zclApp_RingEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,14 +209,22 @@ uint16 zclApp_event_loop(uint8 task_id, uint16 events) {
|
|||||||
|
|
||||||
if (events & APP_BTN_CLICK_EVT) {
|
if (events & APP_BTN_CLICK_EVT) {
|
||||||
LREPMaster("APP_BTN_CLICK_EVT\r\n");
|
LREPMaster("APP_BTN_CLICK_EVT\r\n");
|
||||||
zclApp_BtnClick();
|
zclApp_BtnClick(false);
|
||||||
return (events ^ APP_BTN_CLICK_EVT);
|
return (events ^ APP_BTN_CLICK_EVT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events & APP_RING_RUN_EVT) {
|
if (events & APP_RING_RUN_EVT) {
|
||||||
LREPMaster("APP_RING_RUN_EVT\r\n");
|
LREPMaster("APP_RING_RUN_EVT\r\n");
|
||||||
zclApp_RingRun();
|
zclApp_RingRun();
|
||||||
return (events ^ APP_RING_RUN_EVT);
|
return (events ^ APP_RING_RUN_EVT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (events & APP_BTN_HOLD_EVT) {
|
||||||
|
LREPMaster("APP_BTN_HOLD_EVT\r\n");
|
||||||
|
zclApp_BtnClick(true);
|
||||||
|
return (events ^ APP_BTN_HOLD_EVT);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,32 +301,45 @@ static void zclApp_RingEnd(void) {
|
|||||||
zclApp_OneReport();
|
zclApp_OneReport();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void zclApp_BtnClick(void) {
|
static void zclApp_BtnClick(bool hold) {
|
||||||
|
|
||||||
static uint8 currentBtnClickPhase = 0;
|
static uint8 currentBtnClickPhase = 0;
|
||||||
LREP("currentBtnClickPhase %d\r\n", currentBtnClickPhase);
|
LREP("currentBtnClickPhase %d\r\n", currentBtnClickPhase);
|
||||||
switch (currentBtnClickPhase++) {
|
switch (currentBtnClickPhase++) {
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
//HalLedSet(LED_PIN, HAL_LED_MODE_ON);
|
if (hold) {
|
||||||
HAL_TURN_ON_LED1();
|
zclApp_Config.ModeSound = !zclApp_Config.ModeSound;
|
||||||
if (zclApp_Config.ModeOpen < Drop) {
|
HalLedSet(CATCH_PIN, !zclApp_Config.ModeSound);
|
||||||
zclApp_Config.ModeOpen++;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
zclApp_Config.ModeOpen = Never;
|
if (zclApp_Config.ModeOpen < Drop) {
|
||||||
|
zclApp_Config.ModeOpen++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
zclApp_Config.ModeOpen = Never;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
zclApp_OneReport();
|
zclApp_OneReport();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
//HalLedSet(LED_PIN, HAL_LED_MODE_OFF);
|
if (hold) {
|
||||||
HAL_TURN_OFF_LED1();
|
HalLedBlink(LED_PIN, zclApp_Config.ModeSound+1, 50, 750);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
HalLedBlink(LED_PIN, zclApp_Config.ModeOpen+1, 50, 250);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
osal_stop_timerEx(zclApp_TaskID, APP_BTN_CLICK_EVT);
|
if (hold) {
|
||||||
osal_clear_event(zclApp_TaskID, APP_BTN_CLICK_EVT);
|
osal_stop_timerEx(zclApp_TaskID, APP_BTN_HOLD_EVT);
|
||||||
|
osal_clear_event(zclApp_TaskID, APP_BTN_HOLD_EVT);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
osal_stop_timerEx(zclApp_TaskID, APP_BTN_CLICK_EVT);
|
||||||
|
osal_clear_event(zclApp_TaskID, APP_BTN_CLICK_EVT);
|
||||||
|
}
|
||||||
currentBtnClickPhase = 0;
|
currentBtnClickPhase = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -315,7 +351,7 @@ static void zclApp_Report(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void zclApp_OneReport(void) {
|
static void zclApp_OneReport(void) {
|
||||||
HalLedSet(LED_PIN, HAL_LED_MODE_BLINK);
|
//HalLedSet(LED_PIN, HAL_LED_MODE_BLINK);
|
||||||
bdb_RepChangedAttrValue(zclApp_FirstEP.EndPoint, ZCL_INTERCOM, ATTRID_MODEOPEN);
|
bdb_RepChangedAttrValue(zclApp_FirstEP.EndPoint, ZCL_INTERCOM, ATTRID_MODEOPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ 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
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* MACROS
|
* MACROS
|
||||||
*/
|
*/
|
||||||
@@ -109,6 +110,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
WorkState_t State;
|
WorkState_t State;
|
||||||
uint8 RingRunStep;
|
uint8 RingRunStep;
|
||||||
|
uint32 pressTime;
|
||||||
} device_state_t;
|
} device_state_t;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user