LibDriver TM1637
Loading...
Searching...
No Matches
driver_tm1637_read_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static tm1637_handle_t gs_handle;
41
50uint8_t tm1637_read_test(uint32_t times)
51{
52 uint8_t res;
53 uint32_t i;
54 tm1637_info_t info;
55
56 /* link interface function */
64
65 /* get information */
66 res = tm1637_info(&info);
67 if (res != 0)
68 {
69 tm1637_interface_debug_print("tm1637: get info failed.\n");
70
71 return 1;
72 }
73 else
74 {
75 /* print chip info */
76 tm1637_interface_debug_print("tm1637: chip is %s.\n", info.chip_name);
77 tm1637_interface_debug_print("tm1637: manufacturer is %s.\n", info.manufacturer_name);
78 tm1637_interface_debug_print("tm1637: interface is %s.\n", info.interface);
79 tm1637_interface_debug_print("tm1637: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
80 tm1637_interface_debug_print("tm1637: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
81 tm1637_interface_debug_print("tm1637: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
82 tm1637_interface_debug_print("tm1637: max current is %0.2fmA.\n", info.max_current_ma);
83 tm1637_interface_debug_print("tm1637: max temperature is %0.1fC.\n", info.temperature_max);
84 tm1637_interface_debug_print("tm1637: min temperature is %0.1fC.\n", info.temperature_min);
85 }
86
87 /* start read test */
88 tm1637_interface_debug_print("tm1637: start read test.\n");
89
90 /* tm1637 init */
91 res = tm1637_init(&gs_handle);
92 if (res != 0)
93 {
94 tm1637_interface_debug_print("tm1637: init failed.\n");
95
96 return 1;
97 }
98
99 for (i = 0; i < times; i++)
100 {
101 uint8_t seg;
102 uint8_t k;
103
104 /* delay 3000ms */
106
107 /* read segment */
108 res = tm1637_read_segment(&gs_handle, &seg, &k);
109 if (res != 0)
110 {
111 tm1637_interface_debug_print("tm1637: read segment failed.\n");
112 (void)tm1637_deinit(&gs_handle);
113
114 return 1;
115 }
116
117 /* output */
118 tm1637_interface_debug_print("tm1637: seg: 0x%02X.\n", seg);
119 tm1637_interface_debug_print("tm1637: k: 0x%02X.\n", k);
120 }
121
122 /* finish read test */
123 tm1637_interface_debug_print("tm1637: finish read test.\n");
124 (void)tm1637_deinit(&gs_handle);
125
126 return 0;
127}
driver tm1637 read test header file
uint8_t tm1637_read_segment(tm1637_handle_t *handle, uint8_t *seg, uint8_t *k)
read segment
uint8_t tm1637_info(tm1637_info_t *info)
get chip's information
uint8_t tm1637_deinit(tm1637_handle_t *handle)
close the chip
struct tm1637_info_s tm1637_info_t
tm1637 information structure definition
struct tm1637_handle_s tm1637_handle_t
tm1637 handle structure definition
uint8_t tm1637_init(tm1637_handle_t *handle)
initialize the chip
void tm1637_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t tm1637_interface_iic_init(void)
interface iic init
void tm1637_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t tm1637_interface_iic_read_cmd_custom(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic read command custom
uint8_t tm1637_interface_iic_write_cmd_custom(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic write command custom
uint8_t tm1637_interface_iic_deinit(void)
interface iic deinit
uint8_t tm1637_read_test(uint32_t times)
read test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]