Add ADS1115 test
This commit is contained in:
34
tests/ads1x1x.c
Normal file
34
tests/ads1x1x.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include "mgos.h"
|
||||
#include "mgos_ads1x1x.h"
|
||||
#include "tests_autogen.h"
|
||||
|
||||
uint32_t test_ads1x1x_period_ms = 100;
|
||||
bool test_ads1x1x_enabled = true;
|
||||
|
||||
static struct mgos_ads1x1x *s_adc = NULL;
|
||||
|
||||
bool test_ads1x1x_create(void) {
|
||||
// LOG(LL_INFO, ("Setting up"));
|
||||
s_adc = mgos_ads1x1x_create(mgos_i2c_get_global(), 0x48, ADC_ADS1115);
|
||||
if (!s_adc) return false;
|
||||
|
||||
mgos_ads1x1x_set_fsr(s_adc, MGOS_ADS1X1X_FSR_4096);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_ads1x1x_run(void) {
|
||||
int16_t result[4];
|
||||
for(int i=0; i<4; i++) {
|
||||
if (!mgos_ads1x1x_read(s_adc, i, &result[i])) {
|
||||
LOG(LL_ERROR, ("Could not read device"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
LOG(LL_INFO, ("chan={%6d, %6d, %6d, %6d}", result[0], result[1], result[2], result[3]));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_ads1x1x_destroy(void) {
|
||||
mgos_ads1x1x_destroy(&s_adc);
|
||||
return true;
|
||||
}
|
Reference in New Issue
Block a user