LibDriver HLW8032
Loading...
Searching...
No Matches
driver_hlw8032_basic.c
Go to the documentation of this file.
1
36
38
39static hlw8032_handle_t gs_handle;
40
50{
51 uint8_t res;
52
53 /* link interface function */
61
62 /* hlw8032 init */
63 res = hlw8032_init(&gs_handle);
64 if (res != 0)
65 {
66 hlw8032_interface_debug_print("hlw8032: init failed.\n");
67
68 return 1;
69 }
70
71 /* set mode */
72 res = hlw8032_set_mode(&gs_handle, mode);
73 if (res != 0)
74 {
75 hlw8032_interface_debug_print("hlw8032: set mode failed.\n");
76 (void)hlw8032_deinit(&gs_handle);
77
78 return 1;
79 }
80
81 /* set default sample voltage coefficient */
83 if (res != 0)
84 {
85 hlw8032_interface_debug_print("hlw8032: set sample voltage coefficient failed.\n");
86 (void)hlw8032_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 /* set default sample current coefficient */
93 if (res != 0)
94 {
95 hlw8032_interface_debug_print("hlw8032: set sample current coefficient failed.\n");
96 (void)hlw8032_deinit(&gs_handle);
97
98 return 1;
99 }
100
101 /* set default transformer voltage k1 */
103 if (res != 0)
104 {
105 hlw8032_interface_debug_print("hlw8032: set transformer voltage k1 failed.\n");
106 (void)hlw8032_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* set default transformer current k2 */
113 if (res != 0)
114 {
115 hlw8032_interface_debug_print("hlw8032: set transformer current k2 failed.\n");
116 (void)hlw8032_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* set default transformer power k3 */
123 if (res != 0)
124 {
125 hlw8032_interface_debug_print("hlw8032: set transformer power k3 failed.\n");
126 (void)hlw8032_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 return 0;
132}
133
142uint8_t hlw8032_basic_quantity_electricity_export(int64_t *quantity_electricity_counter)
143{
144 uint8_t res;
145
146 /* export */
147 res = hlw8032_quantity_electricity_export(&gs_handle, quantity_electricity_counter);
148 if (res != 0)
149 {
150 return 1;
151 }
152
153 return 0;
154}
155
164uint8_t hlw8032_basic_quantity_electricity_import(int64_t quantity_electricity_counter)
165{
166 uint8_t res;
167
168 /* import */
169 res = hlw8032_quantity_electricity_import(&gs_handle, quantity_electricity_counter);
170 if (res != 0)
171 {
172 return 1;
173 }
174
175 return 0;
176}
177
187{
188 uint8_t res;
189
190 /* read */
191 res = hlw8032_read(&gs_handle, data);
192 if (res != 0)
193 {
194 return 1;
195 }
196
197 return 0;
198}
199
208{
209 /* deinit hlw8032 */
210 if (hlw8032_deinit(&gs_handle) != 0)
211 {
212 return 1;
213 }
214
215 return 0;
216}
driver hlw8032 basic header file
uint8_t hlw8032_set_transformer_current_k2(hlw8032_handle_t *handle, float coeff)
set transformer current k2
uint8_t hlw8032_read(hlw8032_handle_t *handle, hlw8032_data_t *data)
read the data
uint8_t hlw8032_deinit(hlw8032_handle_t *handle)
close the chip
uint8_t hlw8032_init(hlw8032_handle_t *handle)
initialize the chip
uint8_t hlw8032_set_mode(hlw8032_handle_t *handle, hlw8032_mode_t mode)
set mode
uint8_t hlw8032_set_transformer_voltage_k1(hlw8032_handle_t *handle, float coeff)
set transformer voltage k1
uint8_t hlw8032_quantity_electricity_export(hlw8032_handle_t *handle, int64_t *quantity_electricity_counter)
quantity electricity export
struct hlw8032_handle_s hlw8032_handle_t
hlw8032 handle structure definition
uint8_t hlw8032_quantity_electricity_import(hlw8032_handle_t *handle, int64_t quantity_electricity_counter)
quantity electricity import
uint8_t hlw8032_set_transformer_power_k3(hlw8032_handle_t *handle, float coeff)
set transformer power k3
uint8_t hlw8032_set_sample_voltage_coefficient(hlw8032_handle_t *handle, float coeff)
set sample voltage coefficient
hlw8032_mode_t
hlw8032 mode enumeration definition
uint8_t hlw8032_set_sample_current_coefficient(hlw8032_handle_t *handle, float coeff)
set sample current coefficient
struct hlw8032_data_s hlw8032_data_t
hlw8032 data structure definition
#define HLW8032_BASIC_DEFAULT_TRANSFORMER_POWER_K3
uint8_t hlw8032_basic_read(hlw8032_data_t *data)
basic example read
#define HLW8032_BASIC_DEFAULT_SAMPLE_VOLTAGE_COEFFICIENT
hlw8032 basic example default definition
uint8_t hlw8032_basic_quantity_electricity_import(int64_t quantity_electricity_counter)
basic example quantity electricity import
uint8_t hlw8032_basic_quantity_electricity_export(int64_t *quantity_electricity_counter)
basic example quantity electricity export
#define HLW8032_BASIC_DEFAULT_TRANSFORMER_CURRENT_K2
#define HLW8032_BASIC_DEFAULT_SAMPLE_CURRENT_COEFFICIENT
uint8_t hlw8032_basic_init(hlw8032_mode_t mode)
basic example init
#define HLW8032_BASIC_DEFAULT_TRANSFORMER_VOLTAGE_K1
uint8_t hlw8032_basic_deinit(void)
basic example deinit
void hlw8032_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t hlw8032_interface_uart_flush(void)
interface uart flush
void hlw8032_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t hlw8032_interface_uart_init(void)
interface uart init
uint8_t hlw8032_interface_uart_deinit(void)
interface uart deinit
uint16_t hlw8032_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read