Compare commits

...

1 Commits

2 changed files with 38 additions and 16 deletions

View File

@ -19,6 +19,8 @@ PREFIX ?= /usr
BIN_INSTALL_DIR ?= $(PREFIX)/bin/$(TARGET_FILE)
INCLUDES := inc
INCLUDES += $(PREFIX)/include/
INCLUDES += $(EXTRA_INC)
LIBS = gpio_sys i2c_bb ads1115
@ -32,7 +34,9 @@ C_FLAGS += -fpic
C_FLAGS += -O0 -g -Wall -Wextra -Werror
CPP_FLAGS += $(addprefix -I, $(INCLUDES))
CHECK_FLAGS = --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr $(C_SRCS)
CHECK_FLAGS = $(addprefix -I,$(filter-out $(PREFIX)/include/,$(INCLUDES)))
CHECK_FLAGS += --enable=all --template=gcc --error-exitcode=1 --suppress=missingIncludeSystem --inline-suppr --force
C_SRCS = $(wildcard $(SRC_DIR)/*.c)
C_OBJS = $(patsubst $(SRC_DIR)%,$(OBJ_DIR)%,$(patsubst %.c,%.o,$(C_SRCS)))
@ -96,7 +100,7 @@ exec_unit_test: $(UNIT_TEST_TARGET)
.PHONY: check
check: $(C_SRCS)
$(CHECK) $(CPP_FLAGS) $(CHECK_FLAGS) $(C_SRCS)
$(CHECK) $(CHECK_FLAGS) $(C_SRCS)
$(UNIT_TEST_TARGET): $(UNIT_TEST_OBJS) $(THIS_MAKEFILE)
@mkdir -p $(BIN_DIR)/$(UNIT_TEST_SRC_DIR)

View File

@ -5,18 +5,19 @@
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <libgpio_sys/gpio_sys.h>
#include <libgpio_sys/gpio.h>
#include <libads1115/ads1115.h>
static struct gpio_sys gpio_sda = {
.pin = 4,
.direction = OUT,
.direction = 1,
};
static struct gpio_sys gpio_scl = {
.pin = 24,
.direction = OUT,
.direction = 1,
};
static struct i2c_bb i2c_dev = {
@ -29,32 +30,49 @@ static struct ads1115_dev ads = {
.i2c_slave_address = 0x48,
};
static bool run_condition = true;
static void signal_handler(int sig)
{
printf("Signal catched: %d\n Shutting down...\n", sig);
run_condition = false;
}
int main(void)
{
int res;
struct ads1115_conversation_result result;
struct sigaction sig_int_handler;
sig_int_handler.sa_handler = signal_handler;
sigemptyset(&sig_int_handler.sa_mask);
sig_int_handler.sa_flags = 0;
sigaction(SIGINT, &sig_int_handler, NULL);
res = ads1115_open(&ads);
if(res != 0) {
return res;
}
res = ads1115_start_conversation(&ads);
if(res != 0) {
ads1115_close(&ads);
return res;
}
while(run_condition) {
res = ads1115_start_conversation(&ads);
if(res != 0) {
ads1115_close(&ads);
return res;
}
res = ads1115_read_conversation_result(&ads, &result);
if(res != 0) {
ads1115_close(&ads);
return res;
res = ads1115_read_conversation_result(&ads, &result);
if(res != 0) {
ads1115_close(&ads);
return res;
}
printf("Conversation: %4.3fV (0x%04x).\n", result.voltage, result.raw);
usleep(50000);
}
ads1115_close(&ads);
printf("Conversation: %4.3fV (0x%04x).\n", result.voltage, result.raw);
return res;
}