LibDriver HLW8032
Loading...
Searching...
No Matches
driver_hlw8032.c
Go to the documentation of this file.
1
36
37#include "driver_hlw8032.h"
38
42#define CHIP_NAME "HLW TECHNOLOGY HLW8032"
43#define MANUFACTURER_NAME "HLW TECHNOLOGY"
44#define SUPPLY_VOLTAGE_MIN 4.5f
45#define SUPPLY_VOLTAGE_MAX 5.5f
46#define MAX_CURRENT 4.0f
47#define TEMPERATURE_MIN -40.0f
48#define TEMPERATURE_MAX 85.0f
49#define DRIVER_VERSION 1000
50
62{
63 if (handle == NULL) /* check handle */
64 {
65 return 2; /* return error */
66 }
67 if (handle->debug_print == NULL) /* check debug_print */
68 {
69 return 3; /* return error */
70 }
71 if (handle->uart_init == NULL) /* check uart_init */
72 {
73 handle->debug_print("hlw8032: uart_init is null.\n"); /* uart_init is null */
74
75 return 3; /* return error */
76 }
77 if (handle->uart_deinit == NULL) /* check uart_deinit */
78 {
79 handle->debug_print("hlw8032: uart_deinit is null.\n"); /* uart_deinit is null */
80
81 return 3; /* return error */
82 }
83 if (handle->uart_read == NULL) /* check uart_read */
84 {
85 handle->debug_print("hlw8032: uart_read is null.\n"); /* uart_read is null */
86
87 return 3; /* return error */
88 }
89 if (handle->uart_flush == NULL) /* check uart_flush */
90 {
91 handle->debug_print("hlw8032: uart_flush is null.\n"); /* uart_flush is null */
92
93 return 3; /* return error */
94 }
95 if (handle->delay_ms == NULL) /* check delay_ms */
96 {
97 handle->debug_print("hlw8032: delay_ms is null.\n"); /* delay_ms is null */
98
99 return 3; /* return error */
100 }
101
102 if (handle->uart_init() != 0) /* uart init */
103 {
104 handle->debug_print("hlw8032: uart init failed.\n"); /* uart init failed */
105
106 return 1; /* return error */
107 }
108 handle->mode = 0; /* init 0 */
109 handle->pf_counter = 0; /* init 0 */
110 handle->pf_last_counter = 0; /* init 0 */
111 handle->pf_last_ovf = 0; /* init 0 */
112 handle->is_first = 0; /* init 0 */
113 handle->voltage_coefficient = HLW8032_VOLTAGE_COEFFICIENT; /* set voltage coefficient */
114 handle->current_coefficient = HLW8032_CURRENT_COEFFICIENT; /* set current coefficient */
115 handle->voltage_kl = HLW8032_VOLTAGE_K1; /* set voltage kl */
116 handle->current_k2 = HLW8032_CURRENT_K2; /* set current k2 */
117 handle->power_k3 = HLW8032_POWER_K3; /* set power k3 */
118 handle->inited = 1; /* flag finish initialization */
119
120 return 0; /* success return 0 */
121}
122
134{
135 if (handle == NULL) /* check handle */
136 {
137 return 2; /* return error */
138 }
139 if (handle->inited != 1) /* check handle initialization */
140 {
141 return 3; /* return error */
142 }
143
144 if (handle->uart_deinit() != 0) /* uart deinit */
145 {
146 handle->debug_print("hlw8032: uart deinit failed.\n"); /* uart deinit failed */
147
148 return 1; /* return error */
149 }
150 handle->inited = 0; /* flag close */
151
152 return 0; /* success return 0 */
153}
154
169{
170 uint8_t res;
171 uint8_t i;
172 uint8_t j;
173 uint8_t offset;
174 uint8_t done;
175 uint16_t len;
176 uint16_t check_sum;
177 double cnt;
178 uint8_t buf[48];
179
180 if (handle == NULL) /* check handle */
181 {
182 return 2; /* return error */
183 }
184 if (handle->inited != 1) /* check handle initialization */
185 {
186 return 3; /* return error */
187 }
188
189 res = handle->uart_flush(); /* uart flush */
190 if (res != 0) /* check result */
191 {
192 handle->debug_print("hlw8032: uart flush failed.\n"); /* uart flush failed */
193
194 return 1; /* return error */
195 }
196 handle->delay_ms(250); /* delay 250ms */
197 len = handle->uart_read((uint8_t *)buf, 48); /* uart read */
198 if (len != 48) /* check result */
199 {
200 handle->debug_print("hlw8032: uart read failed.\n"); /* uart read failed */
201
202 return 1; /* return error */
203 }
204 offset = 0; /* init 0 */
205 done = 0; /* init 0 */
206 for (i = 0; i < 48; i++) /* loop all */
207 {
208 if ((i != 0) && (buf[i] == 0x5A) && ((i + 23) < 48)) /* check frame */
209 {
210 check_sum = 0; /* init 0 */
211 for (j = 0; j < 21; j++) /* sum all */
212 {
213 check_sum += buf[i - 1 + 2 + j]; /* add */
214 }
215 if (buf[i - 1 + 23] != (check_sum & 0xFF)) /* check frame trail */
216 {
217 continue; /* continue */
218 }
219 offset = i - 1; /* sava index */
220 done = 1; /* flag done */
221
222 break; /* break */
223 }
224 }
225 if (done != 1) /* check done */
226 {
227 handle->debug_print("hlw8032: frame is error.\n"); /* frame is error */
228
229 return 4; /* return error */
230 }
231 data->status = buf[offset + 0]; /* set status */
232 data->voltage_parameter_raw = ((uint32_t)buf[offset + 2] << 16) |
233 ((uint32_t)buf[offset + 3] << 8) |
234 ((uint32_t)buf[offset + 4] << 0); /* set voltage parameter raw */
235 data->voltage_raw = ((uint32_t)buf[offset + 5] << 16) |
236 ((uint32_t)buf[offset + 6] << 8) |
237 ((uint32_t)buf[offset + 7] << 0); /* set voltage raw */
238 data->current_parameter_raw = ((uint32_t)buf[offset + 8] << 16) |
239 ((uint32_t)buf[offset + 9] << 8) |
240 ((uint32_t)buf[offset + 10] << 0); /* set current parameter raw */
241 data->current_raw = ((uint32_t)buf[offset + 11] << 16) |
242 ((uint32_t)buf[offset + 12] << 8) |
243 ((uint32_t)buf[offset + 13] << 0); /* set current raw */
244 data->power_parameter_raw = ((uint32_t)buf[offset + 14] << 16) |
245 ((uint32_t)buf[offset + 15] << 8) |
246 ((uint32_t)buf[offset + 16] << 0); /* set power parameter raw */
247 data->power_raw = ((uint32_t)buf[offset + 17] << 16) |
248 ((uint32_t)buf[offset + 18] << 8) |
249 ((uint32_t)buf[offset + 19] << 0); /* set power raw */
250 data->update_status = buf[offset + 20]; /* set update status */
251 data->pf_counter = ((uint16_t)buf[offset + 21] << 8) |
252 ((uint16_t)buf[offset + 22] << 0); /* set pf counter */
253 if (data->status != 0x55) /* check status */
254 {
255 handle->debug_print("hlw8032: data is invalid.\n"); /* data is invalid */
256
257 return 5; /* return error */
258 }
259 if (handle->is_first != 0) /* check first */
260 {
261 uint8_t ovf;
262
263 ovf = (data->update_status >> 7) & 0x01; /* get ovf */
264 if (ovf != handle->pf_last_ovf) /* ovf */
265 {
266 handle->pf_counter += 65536; /* add 65536 */
267 handle->pf_counter += (int64_t)((int32_t)data->pf_counter -
268 (int32_t)handle->pf_last_counter); /* add to total counter */
269 }
270 else
271 {
272 handle->pf_counter += (int64_t)((int32_t)data->pf_counter -
273 (int32_t)handle->pf_last_counter); /* add to total counter */
274 }
275 handle->pf_last_ovf = ovf; /* save to last ovf */
276 handle->pf_last_counter = data->pf_counter; /* save to last counter */
277 }
278 else
279 {
280 handle->pf_last_counter = data->pf_counter; /* save to last counter */
281 handle->pf_last_ovf = (data->update_status >> 7) & 0x01; /* save to last ovf */
282 handle->is_first = 1; /* set fist */
283 }
284 if (handle->mode != 0) /* transformer */
285 {
286 if ((data->update_status & (1 << 6)) != 0) /* check voltage bit */
287 {
288 data->effective_voltage_v = (float)(data->voltage_parameter_raw) /
289 (float)(data->voltage_raw) *
290 (float)(handle->voltage_kl); /* set effective voltage */
291 }
292 else
293 {
294 data->effective_voltage_v = 0.0f; /* set 0.0 */
295 }
296 if ((data->update_status & (1 << 5)) != 0) /* check current bit */
297 {
298 data->effective_current_a = (float)(data->current_parameter_raw) /
299 (float)(data->current_raw) *
300 (float)(handle->current_k2); /* set effective current */
301 }
302 else
303 {
304 data->effective_current_a = 0.0f; /* set 0.0 */
305 }
306 if ((data->update_status & (1 << 4)) != 0) /* check power bit */
307 {
308 data->active_power_w = (float)(data->power_parameter_raw) /
309 (float)(data->power_raw) *
310 (float)(handle->power_k3); /* set active power */
311 }
312 else
313 {
314 data->active_power_w = 0.0f; /* set 0.0 */
315 }
316 if ((data->update_status & (7 << 4)) == (7 << 4)) /* check power bit */
317 {
318 data->apparent_power_w = (float)(data->effective_voltage_v) *
319 (float)(data->effective_current_a); /* set apparent power */
320 }
321 else
322 {
323 data->apparent_power_w = 0.0f; /* set 0.0 */
324 data->effective_current_a = 0.0f; /* force to 0.0 */
325 }
326 if ((data->update_status & (7 << 4)) == (7 << 4)) /* check power bit */
327 {
328 data->power_factor = data->active_power_w / data->apparent_power_w; /* set power factor */
329 if (data->power_factor > 1.0f) /* check range */
330 {
331 data->power_factor = 1.0f; /* force to 1.0 */
332 }
333 }
334 else
335 {
336 data->power_factor = 0.0f; /* set 0.0 */
337 }
338 cnt = (1.0 / (double)(data->power_parameter_raw)) *
339 (1.0 / ((double)(handle->power_k3))) *
340 1000000000.0 * 3600.0; /* get cnt */
341 data->quantity_electricity_kwh = (float)((double)(handle->pf_counter) /
342 (double)(cnt)); /* set quantity electricity */
343 }
344 else /* sample */
345 {
346 if ((data->update_status & (1 << 6)) != 0) /* check voltage bit */
347 {
348 data->effective_voltage_v = (float)(data->voltage_parameter_raw) /
349 (float)(data->voltage_raw) *
350 (float)(handle->voltage_coefficient); /* set effective voltage */
351 }
352 else
353 {
354 data->effective_voltage_v = 0.0f; /* set 0.0 */
355 }
356 if ((data->update_status & (1 << 5)) != 0) /* check current bit */
357 {
358 data->effective_current_a = (float)(data->current_parameter_raw) /
359 (float)(data->current_raw) *
360 (float)(handle->current_coefficient); /* set effective current */
361 }
362 else
363 {
364 data->effective_current_a = 0.0f; /* set 0.0 */
365 }
366 if ((data->update_status & (1 << 4)) != 0) /* check power bit */
367 {
368 data->active_power_w = (float)(data->power_parameter_raw) /
369 (float)(data->power_raw) *
370 (float)(handle->voltage_coefficient) *
371 (float)(handle->current_coefficient); /* set active power */
372 }
373 else
374 {
375 data->active_power_w = 0.0f; /* set 0.0 */
376 }
377 if ((data->update_status & (7 << 4)) == (7 << 4)) /* check power bit */
378 {
379 data->apparent_power_w = (float)(data->effective_voltage_v) *
380 (float)(data->effective_current_a); /* set apparent power */
381 }
382 else
383 {
384 data->apparent_power_w = 0.0f; /* set 0.0 */
385 data->effective_current_a = 0.0f; /* force to 0.0 */
386 }
387 if ((data->update_status & (7 << 4)) == (7 << 4)) /* check power bit */
388 {
389 data->power_factor = data->active_power_w / data->apparent_power_w; /* set power factor */
390 if (data->power_factor > 1.0f) /* check range */
391 {
392 data->power_factor = 1.0f; /* force to 1.0 */
393 }
394 }
395 else
396 {
397 data->power_factor = 0.0f; /* set 0.0 */
398 }
399 cnt = (1.0 / (double)(data->power_parameter_raw)) *
400 (1.0 / ((double)(handle->voltage_coefficient) *
401 (double)(handle->current_coefficient))) *
402 1000000000.0 * 3600.0; /* get cnt */
403 data->quantity_electricity_kwh = (float)((double)(handle->pf_counter) /
404 (double)(cnt)); /* set quantity electricity */
405 }
406
407 return 0; /* success return 0 */
408}
409
420uint8_t hlw8032_quantity_electricity_export(hlw8032_handle_t *handle, int64_t *quantity_electricity_counter)
421{
422 if (handle == NULL) /* check handle */
423 {
424 return 2; /* return error */
425 }
426 if (handle->inited != 1) /* check handle initialization */
427 {
428 return 3; /* return error */
429 }
430
431 *quantity_electricity_counter = handle->pf_counter; /* set quantity electricity counter */
432
433 return 0; /* success return 0 */
434}
435
448uint8_t hlw8032_quantity_electricity_import(hlw8032_handle_t *handle, int64_t quantity_electricity_counter)
449{
450 uint8_t res;
451 uint8_t i;
452 uint8_t j;
453 uint8_t offset;
454 uint8_t done;
455 uint8_t update_status;
456 uint16_t len;
457 uint16_t check_sum;
458 uint16_t pf_counter;
459 uint8_t buf[48];
460
461 if (handle == NULL) /* check handle */
462 {
463 return 2; /* return error */
464 }
465 if (handle->inited != 1) /* check handle initialization */
466 {
467 return 3; /* return error */
468 }
469
470 res = handle->uart_flush(); /* uart flush */
471 if (res != 0) /* check result */
472 {
473 handle->debug_print("hlw8032: uart flush failed.\n"); /* uart flush failed */
474
475 return 1; /* return error */
476 }
477 handle->delay_ms(250); /* delay 250ms */
478 len = handle->uart_read((uint8_t *)buf, 48); /* uart read */
479 if (len != 48) /* check result */
480 {
481 handle->debug_print("hlw8032: uart read failed.\n"); /* uart read failed */
482
483 return 1; /* return error */
484 }
485 offset = 0; /* init 0 */
486 done = 0; /* init 0 */
487 for (i = 0; i < 48; i++) /* loop all */
488 {
489 if ((i != 0) && (buf[i] == 0x5A) && ((i + 23) < 48)) /* check frame */
490 {
491 check_sum = 0; /* init 0 */
492 for (j = 0; j < 21; j++) /* sum all */
493 {
494 check_sum += buf[i - 1 + 2 + j]; /* add */
495 }
496 if (buf[i - 1 + 23] != (check_sum & 0xFF)) /* check frame trail */
497 {
498 continue; /* continue */
499 }
500 offset = i - 1; /* sava index */
501 done = 1; /* flag done */
502
503 break; /* break */
504 }
505 }
506 if (done != 1) /* check done */
507 {
508 handle->debug_print("hlw8032: frame is error.\n"); /* frame is error */
509
510 return 4; /* return error */
511 }
512
513 pf_counter = ((uint16_t)buf[offset + 21] << 8) |
514 ((uint16_t)buf[offset + 22] << 0); /* set pf counter */
515 update_status = buf[offset + 20]; /* set update status */
516 handle->pf_last_counter = pf_counter; /* save to last counter */
517 handle->pf_last_ovf = (update_status >> 7) & 0x01; /* save to last ovf */
518 handle->is_first = 1; /* set fist */
519 handle->pf_counter = quantity_electricity_counter; /* set quantity electricity counter */
520
521 return 0; /* success return 0 */
522}
523
536{
537 if (handle == NULL) /* check handle */
538 {
539 return 2; /* return error */
540 }
541 if (handle->inited != 1) /* check handle initialization */
542 {
543 return 3; /* return error */
544 }
545
546 handle->mode = (uint8_t)mode; /* set mode */
547
548 return 0; /* success return 0 */
549}
550
563{
564 if (handle == NULL) /* check handle */
565 {
566 return 2; /* return error */
567 }
568 if (handle->inited != 1) /* check handle initialization */
569 {
570 return 3; /* return error */
571 }
572
573 *mode = (hlw8032_mode_t)(handle->mode); /* set mode */
574
575 return 0; /* success return 0 */
576}
577
590{
591 if (handle == NULL) /* check handle */
592 {
593 return 2; /* return error */
594 }
595 if (handle->inited != 1) /* check handle initialization */
596 {
597 return 3; /* return error */
598 }
599
600 handle->voltage_coefficient = coeff; /* set voltage coefficient */
601
602 return 0; /* success return 0 */
603}
604
617{
618 if (handle == NULL) /* check handle */
619 {
620 return 2; /* return error */
621 }
622 if (handle->inited != 1) /* check handle initialization */
623 {
624 return 3; /* return error */
625 }
626
627 *coeff = handle->voltage_coefficient; /* set voltage coefficient */
628
629 return 0; /* success return 0 */
630}
631
644{
645 if (handle == NULL) /* check handle */
646 {
647 return 2; /* return error */
648 }
649 if (handle->inited != 1) /* check handle initialization */
650 {
651 return 3; /* return error */
652 }
653
654 handle->current_coefficient = coeff; /* set current coefficient */
655
656 return 0; /* success return 0 */
657}
658
671{
672 if (handle == NULL) /* check handle */
673 {
674 return 2; /* return error */
675 }
676 if (handle->inited != 1) /* check handle initialization */
677 {
678 return 3; /* return error */
679 }
680
681 *coeff = handle->current_coefficient; /* set current coefficient */
682
683 return 0; /* success return 0 */
684}
685
698{
699 if (handle == NULL) /* check handle */
700 {
701 return 2; /* return error */
702 }
703 if (handle->inited != 1) /* check handle initialization */
704 {
705 return 3; /* return error */
706 }
707
708 handle->voltage_kl = coeff; /* set coefficient */
709
710 return 0; /* success return 0 */
711}
712
725{
726 if (handle == NULL) /* check handle */
727 {
728 return 2; /* return error */
729 }
730 if (handle->inited != 1) /* check handle initialization */
731 {
732 return 3; /* return error */
733 }
734
735 *coeff = handle->voltage_kl; /* set coefficient */
736
737 return 0; /* success return 0 */
738}
739
752{
753 if (handle == NULL) /* check handle */
754 {
755 return 2; /* return error */
756 }
757 if (handle->inited != 1) /* check handle initialization */
758 {
759 return 3; /* return error */
760 }
761
762 handle->current_k2 = coeff; /* set coefficient */
763
764 return 0; /* success return 0 */
765}
766
779{
780 if (handle == NULL) /* check handle */
781 {
782 return 2; /* return error */
783 }
784 if (handle->inited != 1) /* check handle initialization */
785 {
786 return 3; /* return error */
787 }
788
789 *coeff = handle->current_k2; /* set coefficient */
790
791 return 0; /* success return 0 */
792}
793
806{
807 if (handle == NULL) /* check handle */
808 {
809 return 2; /* return error */
810 }
811 if (handle->inited != 1) /* check handle initialization */
812 {
813 return 3; /* return error */
814 }
815
816 handle->power_k3 = coeff; /* set coefficient */
817
818 return 0; /* success return 0 */
819}
820
833{
834 if (handle == NULL) /* check handle */
835 {
836 return 2; /* return error */
837 }
838 if (handle->inited != 1) /* check handle initialization */
839 {
840 return 3; /* return error */
841 }
842
843 *coeff = handle->power_k3; /* set coefficient */
844
845 return 0; /* success return 0 */
846}
847
861uint8_t hlw8032_get_buffer(hlw8032_handle_t *handle, char *buf, uint16_t len, uint32_t ms)
862{
863 uint8_t res;
864 uint16_t l;
865
866 if (handle == NULL) /* check handle */
867 {
868 return 2; /* return error */
869 }
870 if (handle->inited != 1) /* check handle initialization */
871 {
872 return 3; /* return error */
873 }
874
875 res = handle->uart_flush(); /* uart flush */
876 if (res != 0) /* check result */
877 {
878 handle->debug_print("hlw8032: uart flush failed.\n"); /* uart flush failed */
879
880 return 1; /* return error */
881 }
882 handle->delay_ms(ms); /* delay */
883 l = handle->uart_read((uint8_t *)buf, len); /* uart read */
884 if (l != len) /* check result */
885 {
886 handle->debug_print("hlw8032: uart read failed.\n"); /* uart read failed */
887
888 return 1; /* return error */
889 }
890
891 return 0; /* success return 0 */
892}
893
903{
904 if (info == NULL) /* check handle */
905 {
906 return 2; /* return error */
907 }
908
909 memset(info, 0, sizeof(hlw8032_info_t)); /* initialize hlw8032 info structure */
910 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
911 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
912 strncpy(info->interface, "UART", 8); /* copy interface name */
913 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
914 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
915 info->max_current_ma = MAX_CURRENT; /* set maximum current */
916 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
917 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
918 info->driver_version = DRIVER_VERSION; /* set driver version */
919
920 return 0; /* success return 0 */
921}
#define MAX_CURRENT
#define SUPPLY_VOLTAGE_MAX
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
driver hlw8032 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_get_mode(hlw8032_handle_t *handle, hlw8032_mode_t *mode)
get mode
uint8_t hlw8032_deinit(hlw8032_handle_t *handle)
close the chip
uint8_t hlw8032_get_sample_current_coefficient(hlw8032_handle_t *handle, float *coeff)
get sample current coefficient
uint8_t hlw8032_get_transformer_voltage_k1(hlw8032_handle_t *handle, float *coeff)
get transformer voltage k1
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
struct hlw8032_info_s hlw8032_info_t
hlw8032 information structure definition
uint8_t hlw8032_info(hlw8032_info_t *info)
get chip's information
uint8_t hlw8032_set_transformer_voltage_k1(hlw8032_handle_t *handle, float coeff)
set transformer voltage k1
uint8_t hlw8032_get_transformer_current_k2(hlw8032_handle_t *handle, float *coeff)
get transformer current k2
uint8_t hlw8032_get_sample_voltage_coefficient(hlw8032_handle_t *handle, float *coeff)
get sample voltage coefficient
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_get_transformer_power_k3(hlw8032_handle_t *handle, float *coeff)
get transformer power k3
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_CURRENT_COEFFICIENT
hlw8032 current coefficient definition
#define HLW8032_VOLTAGE_COEFFICIENT
hlw8032 voltage coefficient definition
#define HLW8032_CURRENT_K2
hlw8032 current k2 definition
#define HLW8032_VOLTAGE_K1
hlw8032 voltage k1 definition
#define HLW8032_POWER_K3
hlw8032 power k3 definition
uint8_t hlw8032_get_buffer(hlw8032_handle_t *handle, char *buf, uint16_t len, uint32_t ms)
get buffer
float quantity_electricity_kwh
uint32_t voltage_parameter_raw
uint32_t current_parameter_raw
uint32_t power_parameter_raw
uint8_t(* uart_flush)(void)
void(* delay_ms)(uint32_t ms)
uint8_t(* uart_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint16_t(* uart_read)(uint8_t *buf, uint16_t len)
uint8_t(* uart_init)(void)
uint32_t driver_version
char manufacturer_name[32]