Added compile-time project configuration
authorvolpol <volpol@packet-gain.de>
Sat, 1 Sep 2018 12:28:59 +0000 (14:28 +0200)
committervolpol <volpol@packet-gain.de>
Sat, 1 Sep 2018 12:28:59 +0000 (14:28 +0200)
.gitignore
Makefile
config.def.h [new file with mode: 0644]
hx711.c
hx711.h
led.c
led.h
main.c
mgmt.c
pump.c

index 397e904abf0942c25456b6164e5e92abd299aebc..0c017fcc0823d713a73302399958653301fd3ffb 100644 (file)
@@ -1,2 +1,4 @@
 *.o
+*.d
+config.h
 bbd
index a167ffb99484a5e87bdae948b42a6ef19bc9227b..cf6b40e10ac891857cc0e1b59286a5b0956f7aa2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,25 @@
 .PHONY: all clean
 
 CFLAGS=-Wall -std=gnu99
-#CFLAGS+=-DDEBUG
-CFLAGS += -DHAVE_HX711
+
+USRCFG=config.h
+
+OBJS=hx711.o c_gpio.o pump.o net.o main.o mgmt.o led.o event_gpio.o
+
+DEPS := $(OBJS:.o=.d)
 
 all: bbd
 
+-include $(DEPS)
+
 clean:
-       rm -f *.o bbd
+       rm -f $(OBJS) $(DEPS) bbd
+
+%.o: %.c
+       $(CC) $(CFLAGS) -MMD -MF $(patsubst %.o,%.d,$@) -c -o $@ $<
+
+bbd: $(OBJS)
+       $(CC) $(LDFLAGS) -o $@ -pthread $(OBJS)
 
-bbd: hx711.o c_gpio.o pump.o net.o main.o mgmt.o led.o event_gpio.o
-       $(CC) $(LDFLAGS) -o $@ -pthread $^
+$(USRCFG): config.def.h
+       cp $< $@
diff --git a/config.def.h b/config.def.h
new file mode 100644 (file)
index 0000000..8451f1c
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef CONFIG_H
+#define CONFIG_H 1
+
+#define DEBUG
+#define HAVE_HX711
+
+#define GPIO_HX711_SCK 5
+#define GPIO_HX711_DOUT 6
+
+#define GPIO_LED_R 22
+#define GPIO_LED_Y 23
+#define GPIO_LED_B 24
+
+#define GPIO_RESET 14
+#define RESET_BOUNCE_TIME 10
+
+#define NUM_PUMPS 12
+
+#define GPIO_PUMP1   9
+#define GPIO_PUMP2  21
+#define GPIO_PUMP3  12
+#define GPIO_PUMP4   7
+#define GPIO_PUMP5  26
+#define GPIO_PUMP6  13
+#define GPIO_PUMP7  19
+#define GPIO_PUMP8   8
+#define GPIO_PUMP9  20
+#define GPIO_PUMP10 11
+#define GPIO_PUMP11 16
+#define GPIO_PUMP12 25
+
+#define MGMT_WEIGHT_GAIN 5
+#define MGMT_WEIGHT_GAIN_TIME 10
+#define MGMT_WEIGHT_LOSS 200
+
+#endif /* CONFIG_H */
diff --git a/hx711.c b/hx711.c
index cea20c6c1b978368990f1752cbd93b0181aee311..4d9cea4b6ac4184840016c655e6e48d34e5c8cc2 100644 (file)
--- a/hx711.c
+++ b/hx711.c
@@ -1,8 +1,9 @@
 #include <stdbool.h>
 #include <stdint.h>
-#include "hx711.h"
-
 #include <unistd.h>
+
+#include "config.h"
+#include "hx711.h"
 #include "c_gpio.h"
 
 
diff --git a/hx711.h b/hx711.h
index 5e53c1de20db893bdef87d72513b0327d5e5ae18..e8b053a200406018e5c826bf890b365e24d3e5c6 100644 (file)
--- a/hx711.h
+++ b/hx711.h
@@ -1,7 +1,7 @@
 #ifndef HX711_h
 #define HX711_h
 
-    #define PD_SCK_PIN          5
+    #define PD_SCK_PIN          GPIO_HX711_SCK
 
     #define PD_SCK_SET_OUTPUT   setup_gpio (PD_SCK_PIN, OUTPUT, PUD_OFF)
     #define PD_SCK_SET_INPUT   setup_gpio (PD_SCK_PIN, INPUT, PUD_OFF)
@@ -9,7 +9,7 @@
     #define PD_SCK_SET_HIGH     output_gpio(PD_SCK_PIN, HIGH)
     #define PD_SCK_SET_LOW      output_gpio(PD_SCK_PIN, LOW)
 
-    #define DOUT_PIN            6
+    #define DOUT_PIN            GPIO_HX711_DOUT
     #define DOUT_READ           input_gpio(DOUT_PIN)
 
     #define DOUT_SET_INPUT      setup_gpio (DOUT_PIN, INPUT, PUD_OFF)
diff --git a/led.c b/led.c
index be8a1c7b306283c0895205cf98078630f57e4811..cdc7e11ab6d2d33101574fe093e7166919aa6a3a 100644 (file)
--- a/led.c
+++ b/led.c
 #include <unistd.h>
 #include "log.h"
 
-#include "led.h"
+#include "config.h"
 #include "c_gpio.h"
 
 
 int led_init(void){
-       setup_gpio(LED_R, OUTPUT, PUD_OFF);
-       setup_gpio(LED_Y, OUTPUT, PUD_OFF);
-       setup_gpio(LED_B, OUTPUT, PUD_OFF);
+       setup_gpio(GPIO_LED_R, OUTPUT, PUD_OFF);
+       setup_gpio(GPIO_LED_Y, OUTPUT, PUD_OFF);
+       setup_gpio(GPIO_LED_B, OUTPUT, PUD_OFF);
        return 0;
 }
 
 int led_deinit(void){
-       setup_gpio(LED_R, INPUT, PUD_OFF);
-       setup_gpio(LED_Y, INPUT, PUD_OFF);
-       setup_gpio(LED_B, INPUT, PUD_OFF);
+       setup_gpio(GPIO_LED_R, INPUT, PUD_OFF);
+       setup_gpio(GPIO_LED_Y, INPUT, PUD_OFF);
+       setup_gpio(GPIO_LED_B, INPUT, PUD_OFF);
        return 0;
 }
 
 void status_ready(void){
        WHOAMI;
-       output_gpio(LED_R, LOW);
-       output_gpio(LED_Y, LOW);
-       output_gpio(LED_B, HIGH);
+       output_gpio(GPIO_LED_R, LOW);
+       output_gpio(GPIO_LED_Y, LOW);
+       output_gpio(GPIO_LED_B, HIGH);
 }
 
 void status_busy(void){
        WHOAMI;
-       output_gpio(LED_R, LOW);
-       output_gpio(LED_Y, HIGH);
-       output_gpio(LED_B, LOW);
+       output_gpio(GPIO_LED_R, LOW);
+       output_gpio(GPIO_LED_Y, HIGH);
+       output_gpio(GPIO_LED_B, LOW);
 }
 void status_error(void){
        WHOAMI;
-       output_gpio(LED_R, HIGH);
-       output_gpio(LED_Y, LOW);
-       output_gpio(LED_B, LOW);
+       output_gpio(GPIO_LED_R, HIGH);
+       output_gpio(GPIO_LED_Y, LOW);
+       output_gpio(GPIO_LED_B, LOW);
 }
diff --git a/led.h b/led.h
index 60a9a71db11022e3bb3524175d8e0dc2ddf12aa9..b99767592105571ecca79ca9a6ad4b03c3547421 100644 (file)
--- a/led.h
+++ b/led.h
@@ -1,10 +1,6 @@
 #ifndef LED_H
 #define LED_H 1
 
-#define LED_R 22
-#define LED_Y 23
-#define LED_B 24
-
 int led_init(void);
 int led_deinit(void);
 void status_ready(void);
diff --git a/main.c b/main.c
index b0c62434a33c300a661f2eb1b832a21dacc4310b..c5c86e5a186463bbb202525f1a1fa2b7e98b6ccf 100644 (file)
--- a/main.c
+++ b/main.c
@@ -12,6 +12,7 @@
 
 #include <pthread.h>
 
+#include "config.h"
 #include "c_gpio.h"
 #include "event_gpio.h"
 #include "pump.h"
@@ -37,9 +38,6 @@ static void handle_signal(int sig){
     }
 }
 
-#define GPIO_RESET 14
-#define RESET_BOUNCE_TIME 10
-
 static void reset_cb(unsigned int gpio){
        if (GPIO_RESET != gpio) return;
        fprintf (stderr, "RESET EVENT on GPIO %u\n",gpio);
diff --git a/mgmt.c b/mgmt.c
index 9ea903caf07d41e567966f3fdcd3267c47dbdce5..97681976745da828be20d7decb1d387fca6ff40a 100644 (file)
--- a/mgmt.c
+++ b/mgmt.c
@@ -1,5 +1,6 @@
 #include <time.h>
 #include <stdio.h>
+#include "config.h"
 
 #ifdef HAVE_HX711
 #include <stdint.h>
@@ -37,7 +38,7 @@ void mgmt_init(void){
 int mgmt_start(int ml){
     HX711_power_up();
     HX711_tare(3);
-    stop_time = time(NULL) + 10;
+    stop_time = time(NULL) + MGMT_WEIGHT_GAIN_TIME;
     start_weight = curweight();
     stop_weight = start_weight + ml;
     return 0;
@@ -47,7 +48,7 @@ int mgmt_stop(void){
     int res = MGMT_CONTINUE;
     double cw = curweight();
     if (cw >= stop_weight) res = MGMT_NORMAL_STOP; else
-    if (time(NULL) >= stop_time && MAX(cw, start_weight) - MIN(cw, start_weight) < 5) res = MGMT_ABORT;
+    if (time(NULL) >= stop_time && MAX(cw, start_weight) - MIN(cw, start_weight) < MGMT_WEIGHT_GAIN) res = MGMT_ABORT;
     return res;
 }
 
diff --git a/pump.c b/pump.c
index 8aceb39a87bb181192f46f7fbaffc962ab2d67bd..96aa74ea50917a283f1a382006af9220ebaa7b33 100644 (file)
--- a/pump.c
+++ b/pump.c
 #include <unistd.h>
 #include "log.h"
 
+#include "config.h"
 #include "pump.h"
 #include "c_gpio.h"
 
-#define NUM_PUMPS 12
 static int P2G[NUM_PUMPS] = {
-    9, //21,
-    21, //20,
-    12, //16,
-    
-    7, //26,
-    26, //19,
-    13, //13,
-
-    19, //12,
-    8, //7,
-    20, //8,
-
-    11, //25,
-    16, //11,
-    25 //9
+       GPIO_PUMP1,
+       GPIO_PUMP2,
+       GPIO_PUMP3,
+       
+       GPIO_PUMP4,
+       GPIO_PUMP5,
+       GPIO_PUMP6,
+       
+       GPIO_PUMP7,
+       GPIO_PUMP8,
+       GPIO_PUMP9,
+       
+       GPIO_PUMP10,
+       GPIO_PUMP11,
+       GPIO_PUMP12
 };
 
 int pump_add(int num){