From 66bd1cadce8eede21b5d65ab3fc445ae35446384 Mon Sep 17 00:00:00 2001 From: Pim van Pelt <pim@ipng.nl> Date: Wed, 16 Jan 2019 21:20:17 +0100 Subject: [PATCH] Add ADS1115 test --- tests/ads1x1x.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/ads1x1x.c diff --git a/tests/ads1x1x.c b/tests/ads1x1x.c new file mode 100644 index 0000000..d9d439c --- /dev/null +++ b/tests/ads1x1x.c @@ -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; +}