LibDriver DS18B20
Loading...
Searching...
No Matches
driver_ds18b20_alarm.c
Go to the documentation of this file.
1
37
39
40static ds18b20_handle_t gs_handle;
41
49uint8_t ds18b20_alarm_init(void)
50{
51 uint8_t res;
52
53 /* link interface function */
64
65 /* ds18b20 init */
66 res = ds18b20_init(&gs_handle);
67 if (res != 0)
68 {
69 ds18b20_interface_debug_print("ds18b20: init failed.\n");
70
71 return 1;
72 }
73
74 /* set match rom mode */
76 if (res != 0)
77 {
78 ds18b20_interface_debug_print("ds18b20: set mode failed.\n");
79 (void)ds18b20_deinit(&gs_handle);
80
81 return 1;
82 }
83
84 return 0;
85}
86
97uint8_t ds18b20_alarm_set_threshold(uint8_t rom[8], float low, float high)
98{
99 uint8_t res;
100 int8_t threshold_high;
101 int8_t threshold_low;
102
103 /* set rom */
104 res = ds18b20_set_rom(&gs_handle, (uint8_t *)rom);
105 if (res != 0)
106 {
107 return 1;
108 }
109
110 /* convert high threshold */
111 res = ds18b20_alarm_convert_to_register(&gs_handle, high, (int8_t *)&threshold_high);
112 if (res != 0)
113 {
114 return 1;
115 }
116
117 /* convert low threshold */
118 res = ds18b20_alarm_convert_to_register(&gs_handle, low, (int8_t *)&threshold_low);
119 if (res != 0)
120 {
121 return 1;
122 }
123
124 /* set alarm threshold */
125 res = ds18b20_scratchpad_set_alarm_threshold(&gs_handle, threshold_high, threshold_low);
126 if (res != 0)
127 {
128 return 1;
129 }
130
131 return 0;
132}
133
144uint8_t ds18b20_alarm_get_threshold(uint8_t rom[8], float *low, float *high)
145{
146 uint8_t res;
147 int8_t threshold_high;
148 int8_t threshold_low;
149
150 /* set rom */
151 res = ds18b20_set_rom(&gs_handle, (uint8_t *)rom);
152 if (res != 0)
153 {
154 return 1;
155 }
156
157 /* get alarm threshold */
158 res = ds18b20_scrachpad_get_alarm_threshold(&gs_handle, (int8_t *)&threshold_high, (int8_t *)&threshold_low);
159 if (res != 0)
160 {
161 return 1;
162 }
163
164 /* convert low threshold */
165 res = ds18b20_alarm_convert_to_data(&gs_handle, threshold_low, low);
166 if (res != 0)
167 {
168 return 1;
169 }
170
171 /* convert high threshold */
172 res = ds18b20_alarm_convert_to_data(&gs_handle, threshold_high, high);
173 if (res != 0)
174 {
175 return 1;
176 }
177
178 return 0;
179}
180
190uint8_t ds18b20_alarm_search(uint8_t (*rom)[8], uint8_t *num)
191{
192 /* search alarm */
193 if (ds18b20_search_alarm(&gs_handle, rom, num) != 0)
194 {
195 return 1;
196 }
197 else
198 {
199 return 0;
200 }
201}
202
211{
212 /* ds18b20 close */
213 if (ds18b20_deinit(&gs_handle) != 0)
214 {
215 return 1;
216 }
217 else
218 {
219 return 0;
220 }
221}
driver ds18b20 alarm header file
uint8_t ds18b20_alarm_convert_to_data(ds18b20_handle_t *handle, int8_t reg, float *temp)
convert the register data to the alarm temperature
uint8_t ds18b20_search_alarm(ds18b20_handle_t *handle, uint8_t(*rom)[8], uint8_t *num)
search the ds18b20 alarm rom
uint8_t ds18b20_scrachpad_get_alarm_threshold(ds18b20_handle_t *handle, int8_t *threshold_high, int8_t *threshold_low)
get the alarm threshold in the scratchpad
uint8_t ds18b20_scratchpad_set_alarm_threshold(ds18b20_handle_t *handle, int8_t threshold_high, int8_t threshold_low)
set the alarm threshold in the scratchpad
uint8_t ds18b20_alarm_convert_to_register(ds18b20_handle_t *handle, float temp, int8_t *reg)
convert the alarm temperature to the register data
uint8_t ds18b20_init(ds18b20_handle_t *handle)
initialize the chip
uint8_t ds18b20_set_rom(ds18b20_handle_t *handle, uint8_t rom[8])
set the handle rom
struct ds18b20_handle_s ds18b20_handle_t
ds18b20 handle structure definition
uint8_t ds18b20_deinit(ds18b20_handle_t *handle)
close the chip
uint8_t ds18b20_set_mode(ds18b20_handle_t *handle, ds18b20_mode_t mode)
set the chip mode
@ DS18B20_MODE_MATCH_ROM
uint8_t ds18b20_alarm_search(uint8_t(*rom)[8], uint8_t *num)
alarm example find
uint8_t ds18b20_alarm_deinit(void)
alarm example deinit
uint8_t ds18b20_alarm_init(void)
alarm example init
uint8_t ds18b20_alarm_set_threshold(uint8_t rom[8], float low, float high)
alarm example set the threshold
uint8_t ds18b20_alarm_get_threshold(uint8_t rom[8], float *low, float *high)
alarm example get the threshold
uint8_t ds18b20_interface_deinit(void)
interface bus deinit
void ds18b20_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ds18b20_interface_write(uint8_t value)
interface bus write
uint8_t ds18b20_interface_init(void)
interface bus init
uint8_t ds18b20_interface_read(uint8_t *value)
interface bus read
void ds18b20_interface_debug_print(const char *const fmt,...)
interface print format data
void ds18b20_interface_disable_irq(void)
interface disable the interrupt
void ds18b20_interface_enable_irq(void)
interface enable the interrupt
void ds18b20_interface_delay_us(uint32_t us)
interface delay us