void led_blink(int led_no, int on_duty_cycle, int off_duty_cycle) { int err, idx; idx = decide_led_array_index(led_no); if (idx == -WM_FAIL) return; if (os_timer_is_active(&led_data[idx].timer) == WM_SUCCESS) { err = os_timer_delete(&led_data[idx].timer); if (err != WM_SUCCESS) { return; } } led_data[idx].on_duty_cycle = on_duty_cycle; led_data[idx].off_duty_cycle = off_duty_cycle; board_led_on(led_no); led_data[idx].curr_state = LED_ON; err = os_timer_create(&led_data[idx].timer, "led-timer", os_msec_to_ticks(led_data[idx].on_duty_cycle), led_cb, (void *)idx, OS_TIMER_ONE_SHOT, OS_TIMER_AUTO_ACTIVATE); if (err != WM_SUCCESS) { return; } }
void miio_app_thread(void* arg) { static bool has_sync_time = false; g_mum = mum_create(); //*****************************button init*******************************/ os_timer_create(&g_reset_prov_timer, "reset-prov-timer", os_msec_to_ticks(4000), reset_prov, NULL, OS_TIMER_ONE_SHOT, OS_TIMER_NO_ACTIVATE); button_frame_work_init(); register_button_callback(0, button_1_press_handle); if (WM_SUCCESS != os_semaphore_create(&btn_pressed_sem, "btn_pressed_sem")) { LOG_ERROR("btn_pressed_sem creation failed\r\n"); } else if (WM_SUCCESS != os_semaphore_get(&btn_pressed_sem, OS_WAIT_FOREVER)) { LOG_ERROR("first get btn_pressed_sem failed.\r\n"); } //******************************button init end*******************************************/ local_timer_init();//add by [email protected] miio_led_on(); LOG_INFO("miio_app_thread while loop start.\r\n"); #ifdef MIIO_COMMANDS_DEBUG while(!ot_api_is_online())api_os_tick_sleep(100); uart_wifi_debug_init(); #endif while (1) { if (WM_SUCCESS == os_semaphore_get(&btn_pressed_sem, OS_NO_WAIT)) { mum_set_property(g_mum,"button_pressed","\"wifi_rst\""); } if(has_sync_time)//only after sync time, we start check timer check_schedule_and_set_timer(); else if(otn_is_online()) has_sync_time = true; os_thread_sleep(os_msec_to_ticks(PERIOD_CHECK_BUTTON)); } local_timer_deinit();//add by [email protected] //*****************************button deinit*******************************/ mum_destroy(&g_mum); os_timer_delete(&g_reset_prov_timer); os_semaphore_delete(&btn_pressed_sem); //******************************button deinit end*******************************************/ }
void led_off(int led_no) { int idx = decide_led_array_index(led_no); int err; if (idx == -WM_FAIL) return; if (os_timer_is_active(&led_data[idx].timer) == WM_SUCCESS) { err = os_timer_delete(&led_data[idx].timer); if (err != WM_SUCCESS) { wmprintf("Unable to delete LED timer\n\r"); return; } } led_data[idx].curr_state = LED_OFF; board_led_off(led_no); }