wangyouqiang | 0536d92 | 2024-01-23 11:40:25 +0800 | [diff] [blame^] | 1 | #if 1 |
| 2 | #include "mbtk_type.h" |
| 3 | #include "mbtk_log.h" |
| 4 | #include "lynq_qser_thermal.h" |
| 5 | #include "mbtk_info_api.h" |
| 6 | |
| 7 | /****************************DEFINE***************************************/ |
| 8 | #define QSER_RESULT_FAIL -1 |
| 9 | #define QSER_RESULT_SUCCESS 0 |
| 10 | /****************************DEFINE***************************************/ |
| 11 | |
| 12 | /****************************VARIABLE***************************************/ |
| 13 | extern mbtk_info_handle_t* qser_info_handle; |
| 14 | extern int qser_info_handle_num; |
| 15 | /****************************VARIABLE***************************************/ |
| 16 | |
| 17 | |
| 18 | /******************************FUNC*****************************************/ |
| 19 | static int qser_thermal_client_init(void) |
| 20 | { |
| 21 | if(qser_info_handle == NULL) |
| 22 | { |
| 23 | qser_info_handle = mbtk_info_handle_get(); |
| 24 | if(qser_info_handle) |
| 25 | { |
| 26 | qser_info_handle_num++; |
| 27 | } |
| 28 | else |
| 29 | { |
| 30 | LOGE("[qser_thermal] mbtk_info_handle_get() fail."); |
| 31 | return QSER_RESULT_FAIL; |
| 32 | } |
| 33 | } |
| 34 | else |
| 35 | { |
| 36 | qser_info_handle_num++; |
| 37 | } |
| 38 | |
| 39 | LOGE("[qser_thermal] mbtk_info_handle_get() success."); |
| 40 | return QSER_RESULT_SUCCESS; |
| 41 | } |
| 42 | |
| 43 | static int qser_thermal_client_deinit(void) |
| 44 | { |
| 45 | if(qser_info_handle) |
| 46 | { |
| 47 | LOGE("[qser_thermal] qser_info_handle_num = %d", qser_info_handle_num); |
| 48 | if(qser_info_handle_num == 1) |
| 49 | { // 最后一个引用,可释放。 |
| 50 | int ret = mbtk_info_handle_free(&qser_info_handle); |
| 51 | if(ret) |
| 52 | { |
| 53 | LOGE("[qser_thermal] mbtk_info_handle_free() fail."); |
| 54 | return QSER_RESULT_FAIL; |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | qser_info_handle_num = 0; |
| 59 | qser_info_handle = NULL; |
| 60 | } |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | qser_info_handle_num--; |
| 65 | } |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | LOGE("[qser_thermal] handle not inited."); |
| 70 | return QSER_RESULT_FAIL; |
| 71 | } |
| 72 | |
| 73 | return QSER_RESULT_SUCCESS; |
| 74 | } |
| 75 | |
| 76 | /******************************FUNC*****************************************/ |
| 77 | |
| 78 | /****************************API***************************************/ |
| 79 | int get_thermal_zone(int *numbers, int size) |
| 80 | { |
| 81 | if(numbers == NULL || size < 1) |
| 82 | { |
| 83 | LOGE("[qser_thermal]: numbers is NULL!"); |
| 84 | return -1; |
| 85 | } |
| 86 | |
| 87 | int ret = 0; |
| 88 | int thermal = -1; |
| 89 | int thermal_num = 0; |
| 90 | |
| 91 | ret = qser_thermal_client_init(); |
| 92 | if(ret != QSER_RESULT_SUCCESS) |
| 93 | { |
| 94 | LOGE("[qser_thermal]qser_led_client_init fail."); |
| 95 | return QSER_RESULT_FAIL; |
| 96 | } |
| 97 | |
| 98 | ret = mbtk_temp_get(qser_info_handle, 1, &thermal); |
| 99 | if(ret != QSER_RESULT_SUCCESS) |
| 100 | { |
| 101 | LOGE("[qser_thermal]mbtk_temp_get fail."); |
| 102 | qser_thermal_client_deinit(); |
| 103 | return QSER_RESULT_FAIL; |
| 104 | } |
| 105 | |
| 106 | qser_thermal_client_deinit(); |
| 107 | thermal_num = 1; |
| 108 | numbers[0] = thermal; |
| 109 | |
| 110 | return thermal_num; |
| 111 | } |
| 112 | /****************************API***************************************/ |
| 113 | |
| 114 | #endif |