glc002-firmware/app_ui.c

179 lines
3.7 KiB
C
Raw Normal View History

2022-04-01 16:59:22 +00:00
/********************************************************************************************************
* @file app_ui.c
*
* @brief This is the source file for app_ui
*
* @author Zigbee Group
* @date 2021
*
* @par Copyright (c) 2021, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************************************/
#if (__PROJECT_TL_DIMMABLE_LIGHT__)
/**********************************************************************
* INCLUDES
*/
#include "tl_common.h"
#include "zb_api.h"
#include "zcl_include.h"
#include "sampleLight.h"
#include "app_ui.h"
/**********************************************************************
* LOCAL CONSTANTS
*/
/**********************************************************************
* TYPEDEFS
*/
/**********************************************************************
* GLOBAL VARIABLES
*/
/**********************************************************************
* LOCAL FUNCTIONS
*/
2022-04-01 17:14:59 +00:00
void led_on(u32 pin)
{
2022-04-01 16:59:22 +00:00
drv_gpio_write(pin, LED_ON);
}
2022-04-01 17:14:59 +00:00
void led_off(u32 pin)
{
2022-04-01 16:59:22 +00:00
drv_gpio_write(pin, LED_OFF);
}
2022-04-01 17:14:59 +00:00
void led_init(void)
{
led_off(LED_STATUS_R);
led_off(LED_STATUS_G);
led_off(LED_STATUS_B);
2022-04-01 16:59:22 +00:00
}
2022-04-01 17:14:59 +00:00
void localPermitJoinState(void)
{
2022-04-01 16:59:22 +00:00
static bool assocPermit = 0;
2022-04-01 17:14:59 +00:00
if (assocPermit != zb_getMacAssocPermit())
{
2022-04-01 16:59:22 +00:00
assocPermit = zb_getMacAssocPermit();
2022-04-01 17:14:59 +00:00
if (assocPermit)
{
led_on(LED_STATUS_R);
2022-04-01 17:14:59 +00:00
}
else
{
led_off(LED_STATUS_R);
2022-04-01 16:59:22 +00:00
}
}
}
2022-04-01 17:14:59 +00:00
void buttonKeepPressed(u8 btNum)
{
if (btNum == VK_SW1)
{
2022-04-01 16:59:22 +00:00
gLightCtx.state = APP_FACTORY_NEW_DOING;
led_on(LED_STATUS_R);
led_on(LED_STATUS_G);
led_on(LED_STATUS_B);
2022-04-01 16:59:22 +00:00
zb_factoryReset();
2022-04-01 17:14:59 +00:00
}
else if (btNum == VK_SW2)
{
2022-04-01 16:59:22 +00:00
}
}
2022-04-01 17:14:59 +00:00
void buttonShortPressed(u8 btNum)
{
if (btNum == VK_SW1)
{
if (zb_isDeviceJoinedNwk())
{
2022-04-01 16:59:22 +00:00
gLightCtx.sta = !gLightCtx.sta;
2022-04-01 17:14:59 +00:00
if (gLightCtx.sta)
{
2022-04-01 16:59:22 +00:00
sampleLight_onoff(ZCL_ONOFF_STATUS_ON);
2022-04-01 17:14:59 +00:00
}
else
{
2022-04-01 16:59:22 +00:00
sampleLight_onoff(ZCL_ONOFF_STATUS_OFF);
}
}
2022-04-01 17:14:59 +00:00
}
else if (btNum == VK_SW2)
{
2022-04-01 16:59:22 +00:00
/* toggle local permit Joining */
static u8 duration = 0;
duration = duration ? 0 : 0xff;
zb_nlmePermitJoiningRequest(duration);
}
}
2022-04-01 17:14:59 +00:00
void keyScan_keyPressedCB(kb_data_t *kbEvt)
{
// u8 toNormal = 0;
2022-04-01 16:59:22 +00:00
u8 keyCode = kbEvt->keycode[0];
2022-04-01 17:14:59 +00:00
// static u8 lastKeyCode = 0xff;
2022-04-01 16:59:22 +00:00
buttonShortPressed(keyCode);
2022-04-01 17:14:59 +00:00
if (keyCode == VK_SW1)
{
2022-04-01 16:59:22 +00:00
gLightCtx.keyPressedTime = clock_time();
gLightCtx.state = APP_FACTORY_NEW_SET_CHECK;
}
}
2022-04-01 17:14:59 +00:00
void keyScan_keyReleasedCB(u8 keyCode)
{
2022-04-01 16:59:22 +00:00
gLightCtx.state = APP_STATE_NORMAL;
}
volatile u8 T_keyPressedNum = 0;
2022-04-01 17:14:59 +00:00
void app_key_handler(void)
{
2022-04-01 16:59:22 +00:00
static u8 valid_keyCode = 0xff;
2022-04-01 17:14:59 +00:00
if (gLightCtx.state == APP_FACTORY_NEW_SET_CHECK)
{
if (clock_time_exceed(gLightCtx.keyPressedTime, 5 * 1000 * 1000))
{
2022-04-01 16:59:22 +00:00
buttonKeepPressed(VK_SW1);
}
}
2022-04-01 17:14:59 +00:00
if (kb_scan_key(0, 1))
{
2022-04-01 16:59:22 +00:00
T_keyPressedNum++;
2022-04-01 17:14:59 +00:00
if (kb_event.cnt)
{
2022-04-01 16:59:22 +00:00
keyScan_keyPressedCB(&kb_event);
2022-04-01 17:14:59 +00:00
if (kb_event.cnt == 1)
{
2022-04-01 16:59:22 +00:00
valid_keyCode = kb_event.keycode[0];
}
2022-04-01 17:14:59 +00:00
}
else
{
2022-04-01 16:59:22 +00:00
keyScan_keyReleasedCB(valid_keyCode);
valid_keyCode = 0xff;
}
}
}
2022-04-01 17:14:59 +00:00
#endif /* __PROJECT_TL_DIMMABLE_LIGHT__ */