#include "includes.h" static uint8_t key_last = KEY_NONE; /* LED 期望颜色缓存:索引 = LedNum_TypeDef(0~7),COLOR_OTHER 表示灭 */ //static LedColor_TypeDef led_cache[8] = { // COLOR_OTHER, COLOR_OTHER, COLOR_OTHER, COLOR_OTHER, // COLOR_OTHER, COLOR_OTHER, COLOR_OTHER, COLOR_OTHER //}; void app_tm1629_init(void) { rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER); TM1629D_Key_LED_Init(); TM1629D_AllLedOff(); TM1629D_UpdateDisplay(0); rt_mutex_release(TM1629_Mutex); } uint8_t app_tm1629_Scan_Key(void) { uint8_t key = 0; //static uint8_t Last_Tm1926D_Key = 0; rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER); key = TM1629D_GetKey(); rt_mutex_release(TM1629_Mutex); if(key != key_last) { key_last = key; LOG_I("KEY", "tm1629 key=%u", (unsigned)key); TM1629_Handle(key); return key; } return KEY_NONE; } static void app_tm1629_led_set(LedNum_TypeDef led, LedColor_TypeDef color, uint8_t on) { if(on) { //if(led_cache[led] == color) return; //led_cache[led] = color; TM1629D_ControlLed(led, color, 1); } else { //if(led_cache[led] == color) return; //led_cache[led] = COLOR_OTHER; TM1629D_ControlLed(led, COLOR_OTHER, 1); } TM1629D_UpdateDisplay(0); } void app_tm1629_set_chord_led(uint8_t key_idx, LedColor_TypeDef color) { if(key_idx < 1 || key_idx > 21) return; LedNum_TypeDef led = (LedNum_TypeDef)((key_idx - 1) / 3); //L1-L7 rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER); app_tm1629_led_set(led,color,1); rt_mutex_release(TM1629_Mutex); } void app_tm1629_set_led(LedNum_TypeDef led, LedColor_TypeDef color) { rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER); TM1629D_AllLedOff(); app_tm1629_led_set(led,color,1); rt_mutex_release(TM1629_Mutex); } void app_tm1629_all_off(void) { rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER); TM1629D_AllLedOff(); TM1629D_UpdateDisplay(0); rt_mutex_release(TM1629_Mutex); // for (int i = 0; i < 8; i++) // led_cache[i] = COLOR_OTHER; } void app_tm1629_all_on(LedColor_TypeDef color) { rt_mutex_take(TM1629_Mutex, RT_WAITING_FOREVER); TM1629D_AllLedOff(); TM1629D_AllLedOn(color); TM1629D_UpdateDisplay(0); rt_mutex_release(TM1629_Mutex); // for (int i = 0; i < 8; i++) // led_cache[i] = color; }