LibDriver ADS1115
Loading...
Searching...
No Matches
driver_ads1115_shot.c
Go to the documentation of this file.
1
37
38#include "driver_ads1115_shot.h"
39
40static ads1115_handle_t gs_handle;
41
52{
53 uint8_t res;
54
55 /* link interface function */
63
64 /* set addr pin */
65 res = ads1115_set_addr_pin(&gs_handle, addr);
66 if (res != 0)
67 {
68 ads1115_interface_debug_print("ads1115: set addr failed.\n");
69
70 return 1;
71 }
72
73 /* ads1115 init */
74 res = ads1115_init(&gs_handle);
75 if (res != 0)
76 {
77 ads1115_interface_debug_print("ads1115: init failed.\n");
78
79 return 1;
80 }
81
82 /* set channel */
83 res = ads1115_set_channel(&gs_handle, channel);
84 if (res != 0)
85 {
86 ads1115_interface_debug_print("ads1115: set channel failed.\n");
87 (void)ads1115_deinit(&gs_handle);
88
89 return 1;
90 }
91
92 /* set default range */
94 if (res != 0)
95 {
96 ads1115_interface_debug_print("ads1115: set range failed.\n");
97 (void)ads1115_deinit(&gs_handle);
98
99 return 1;
100 }
101
102 /* set default rate */
104 if (res != 0)
105 {
106 ads1115_interface_debug_print("ads1115: set rate failed.\n");
107 (void)ads1115_deinit(&gs_handle);
108
109 return 1;
110 }
111
112 /* disable compare */
113 res = ads1115_set_compare(&gs_handle, ADS1115_BOOL_FALSE);
114 if (res != 0)
115 {
116 ads1115_interface_debug_print("ads1115: set compare failed.\n");
117 (void)ads1115_deinit(&gs_handle);
118
119 return 1;
120 }
121
122 return 0;
123}
124
133uint8_t ads1115_shot_read(float *s)
134{
135 int16_t raw;
136
137 /* read data */
138 if (ads1115_single_read(&gs_handle, (int16_t *)&raw, s) != 0)
139 {
140 return 1;
141 }
142 else
143 {
144 return 0;
145 }
146}
147
156{
157 uint8_t res;
158
159 /* deinit ads1115 */
160 res = ads1115_deinit(&gs_handle);
161 if (res != 0)
162 {
163 return 1;
164 }
165
166 return 0;
167}
driver ads1115 shot header file
uint8_t ads1115_set_addr_pin(ads1115_handle_t *handle, ads1115_address_t addr_pin)
set the iic address pin
ads1115_channel_t
ads1115 channel enumeration definition
uint8_t ads1115_init(ads1115_handle_t *handle)
initialize the chip
uint8_t ads1115_set_rate(ads1115_handle_t *handle, ads1115_rate_t rate)
set the sample rate
ads1115_address_t
ads1115 address enumeration definition
uint8_t ads1115_deinit(ads1115_handle_t *handle)
close the chip
uint8_t ads1115_set_range(ads1115_handle_t *handle, ads1115_range_t range)
set the adc range
uint8_t ads1115_single_read(ads1115_handle_t *handle, int16_t *raw, float *v)
read data from the chip once
struct ads1115_handle_s ads1115_handle_t
ads1115 handle structure definition
uint8_t ads1115_set_channel(ads1115_handle_t *handle, ads1115_channel_t channel)
set the adc channel
@ ADS1115_BOOL_FALSE
uint8_t ads1115_shot_deinit(void)
shot example deinit
uint8_t ads1115_shot_init(ads1115_address_t addr, ads1115_channel_t channel)
shot example init
#define ADS1115_SHOT_DEFAULT_RATE
#define ADS1115_SHOT_DEFAULT_RANGE
ads1115 shot example default definition
uint8_t ads1115_shot_read(float *s)
shot example read
uint8_t ads1115_interface_iic_init(void)
interface iic bus init
void ads1115_interface_delay_ms(uint32_t ms)
interface delay ms
void ads1115_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ads1115_interface_iic_deinit(void)
interface iic bus deinit
uint8_t ads1115_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t ads1115_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t ads1115_set_compare(ads1115_handle_t *handle, ads1115_bool_t enable)
enable or disable the interrupt compare