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 | { |
wangyouqiang | a28de28 | 2024-04-18 11:30:08 +0800 | [diff] [blame] | 81 | if(numbers == NULL || size < 6) |
wangyouqiang | 0536d92 | 2024-01-23 11:40:25 +0800 | [diff] [blame] | 82 | { |
| 83 | LOGE("[qser_thermal]: numbers is NULL!"); |
wangyouqiang | a28de28 | 2024-04-18 11:30:08 +0800 | [diff] [blame] | 84 | return QSER_RESULT_FAIL; |
wangyouqiang | 0536d92 | 2024-01-23 11:40:25 +0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | int ret = 0; |
| 88 | int thermal = -1; |
| 89 | int thermal_num = 0; |
r.xiao | 2102d76 | 2024-06-07 03:10:38 -0700 | [diff] [blame] | 90 | mbtk_thermal_info_t temp; |
| 91 | memset(&temp, 0, sizeof(mbtk_thermal_info_t)); |
wangyouqiang | 0536d92 | 2024-01-23 11:40:25 +0800 | [diff] [blame] | 92 | |
| 93 | ret = qser_thermal_client_init(); |
| 94 | if(ret != QSER_RESULT_SUCCESS) |
| 95 | { |
| 96 | LOGE("[qser_thermal]qser_led_client_init fail."); |
| 97 | return QSER_RESULT_FAIL; |
| 98 | } |
| 99 | |
r.xiao | 2102d76 | 2024-06-07 03:10:38 -0700 | [diff] [blame] | 100 | ret = mbtk_temp_get(qser_info_handle, 0, &temp); |
| 101 | thermal = temp.ther; |
wangyouqiang | 0536d92 | 2024-01-23 11:40:25 +0800 | [diff] [blame] | 102 | if(ret != QSER_RESULT_SUCCESS) |
| 103 | { |
| 104 | LOGE("[qser_thermal]mbtk_temp_get fail."); |
| 105 | qser_thermal_client_deinit(); |
| 106 | return QSER_RESULT_FAIL; |
| 107 | } |
| 108 | |
| 109 | qser_thermal_client_deinit(); |
wangyouqiang | e05df26 | 2024-04-12 18:21:32 +0800 | [diff] [blame] | 110 | numbers[thermal_num++] = thermal; |
| 111 | for(; thermal_num < size; thermal_num++) |
| 112 | { |
| 113 | numbers[thermal_num] = 0; |
| 114 | } |
wangyouqiang | 0536d92 | 2024-01-23 11:40:25 +0800 | [diff] [blame] | 115 | |
wangyouqiang | a28de28 | 2024-04-18 11:30:08 +0800 | [diff] [blame] | 116 | return 6; |
wangyouqiang | 0536d92 | 2024-01-23 11:40:25 +0800 | [diff] [blame] | 117 | } |
| 118 | /****************************API***************************************/ |
| 119 | |
| 120 | #endif |