blob: f3e6e3d7aa68f5873bc80085eecab74860b64698 [file] [log] [blame]
b.liu1c74d692024-08-14 17:43:59 +08001#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***************************************/
13extern mbtk_info_handle_t* qser_info_handle;
14extern int qser_info_handle_num;
15/****************************VARIABLE***************************************/
16
17
18/******************************FUNC*****************************************/
19static 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
43static 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***************************************/
79int get_thermal_zone(int *numbers, int size)
80{
81 if(numbers == NULL || size < 6)
82 {
83 LOGE("[qser_thermal]: numbers is NULL!");
84 return QSER_RESULT_FAIL;
85 }
86
87 int ret = 0;
88 int thermal = -1;
89 int thermal_num = 0;
90 mbtk_thermal_info_t temp;
91 memset(&temp, 0, sizeof(mbtk_thermal_info_t));
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
100 ret = mbtk_temp_get(qser_info_handle, 0, &temp);
101 thermal = temp.ther;
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();
110 numbers[thermal_num++] = thermal;
111 for(; thermal_num < size; thermal_num++)
112 {
113 numbers[thermal_num] = 0;
114 }
115
116 return 6;
117}
118/****************************API***************************************/
119
120#endif