b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame] | 1 | #include "lynq_led.h" |
| 2 | #include "mbtk_type.h" |
| 3 | #include "mbtk_log.h" |
| 4 | #include "mbtk_info_api.h" |
| 5 | |
| 6 | /****************************DEFINE***************************************/ |
| 7 | #define QSER_RESULT_FAIL -1 |
| 8 | #define QSER_RESULT_SUCCESS 0 |
| 9 | /****************************DEFINE***************************************/ |
| 10 | |
| 11 | /****************************VARIABLE***************************************/ |
| 12 | extern mbtk_info_handle_t* qser_info_handle; |
| 13 | extern int qser_info_handle_num; |
| 14 | /****************************VARIABLE***************************************/ |
| 15 | |
| 16 | |
| 17 | /******************************FUNC*****************************************/ |
| 18 | static int qser_led_client_init(void) |
| 19 | { |
| 20 | if(qser_info_handle == NULL) |
| 21 | { |
| 22 | qser_info_handle = mbtk_info_handle_get(); |
| 23 | if(qser_info_handle) |
| 24 | { |
| 25 | qser_info_handle_num++; |
| 26 | } |
| 27 | else |
| 28 | { |
| 29 | LOGE("[qser_led] mbtk_info_handle_get() fail."); |
| 30 | return QSER_RESULT_FAIL; |
| 31 | } |
| 32 | } |
| 33 | else |
| 34 | { |
| 35 | qser_info_handle_num++; |
| 36 | } |
| 37 | |
| 38 | LOGE("[qser_led] mbtk_info_handle_get() success."); |
| 39 | return QSER_RESULT_SUCCESS; |
| 40 | } |
| 41 | |
| 42 | int qser_led_client_deinit(void) |
| 43 | { |
| 44 | if(qser_info_handle) |
| 45 | { |
| 46 | LOGE("[qser_led] qser_info_handle_num = %d", qser_info_handle_num); |
| 47 | if(qser_info_handle_num == 1) |
| 48 | { // 最后一个引用,可释放。 |
| 49 | int ret = mbtk_info_handle_free(&qser_info_handle); |
| 50 | if(ret) |
| 51 | { |
| 52 | LOGE("[qser_led] mbtk_info_handle_free() fail."); |
| 53 | return QSER_RESULT_FAIL; |
| 54 | } |
| 55 | else |
| 56 | { |
| 57 | qser_info_handle_num = 0; |
| 58 | qser_info_handle = NULL; |
| 59 | } |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | qser_info_handle_num--; |
| 64 | } |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | LOGE("[qser_led] handle not inited."); |
| 69 | return QSER_RESULT_FAIL; |
| 70 | } |
| 71 | |
| 72 | return QSER_RESULT_SUCCESS; |
| 73 | } |
| 74 | |
| 75 | /******************************FUNC*****************************************/ |
| 76 | |
| 77 | /****************************API***************************************/ |
| 78 | int lynq_set_netled_on(int led_mode) |
| 79 | { |
| 80 | //UNUSED(led_mode); |
| 81 | |
| 82 | if(led_mode != 0 && led_mode != 1) |
| 83 | { |
| 84 | LOGE("[qser_led]param is fail."); |
| 85 | return QSER_RESULT_FAIL; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | int ret = qser_led_client_init(); |
| 90 | if(ret != QSER_RESULT_SUCCESS) |
| 91 | { |
| 92 | LOGE("[qser_led]qser_led_client_init fail."); |
| 93 | return QSER_RESULT_FAIL; |
| 94 | } |
| 95 | |
| 96 | ret = mbtk_led_set(qser_info_handle, MBTK_LED_TYPE_NET, led_mode); |
| 97 | if(ret != 0) |
| 98 | { |
| 99 | LOGE("[qser_led]mbtk_led_gpio_init fail."); |
| 100 | qser_led_client_init(); |
| 101 | return QSER_RESULT_FAIL; |
| 102 | } |
| 103 | |
| 104 | ret = qser_led_client_init(); |
| 105 | |
| 106 | return QSER_RESULT_SUCCESS; |
| 107 | } |
| 108 | |
| 109 | int lynq_set_statusled_on(int led_mode) |
| 110 | { |
| 111 | //UNUSED(led_mode); |
| 112 | |
| 113 | if(led_mode != 0 && led_mode != 1) |
| 114 | { |
| 115 | LOGE("[qser_led]param is fail."); |
| 116 | return QSER_RESULT_FAIL; |
| 117 | } |
| 118 | |
| 119 | int ret = qser_led_client_init(); |
| 120 | if(ret != QSER_RESULT_SUCCESS) |
| 121 | { |
| 122 | LOGE("[qser_led]qser_led_client_init fail."); |
| 123 | return QSER_RESULT_FAIL; |
| 124 | } |
| 125 | |
| 126 | ret = mbtk_led_set(qser_info_handle, MBTK_LED_TYPE_STATUS, led_mode); |
| 127 | if(ret != 0) |
| 128 | { |
| 129 | LOGE("[qser_led]mbtk_led_gpio_init fail."); |
| 130 | qser_led_client_init(); |
| 131 | return QSER_RESULT_FAIL; |
| 132 | } |
| 133 | |
| 134 | ret = qser_led_client_init(); |
| 135 | |
| 136 | return QSER_RESULT_SUCCESS; |
| 137 | } |
| 138 | /****************************API***************************************/ |
| 139 | |
| 140 | |