CC = gcc -Wall
+lib_inih := lib/inih
+libs := $(lib_inih)
all: hdmi-switcher
-hdmi-switcher: main.o
- $(CC) main.o -o hdmi-switcher -lwiringPi
+hdmi-switcher: main.o config.o
+ $(CC) $(lib_inih)/ini.o config.o main.o -o hdmi-switcher -lwiringPi
main.o: main.c
$(CC) -O -c main.c
+
+config.o: inih config.c config.h
+ $(CC) -O -c config.c
+
+inih:
+ $(MAKE) -C $(lib_inih)
+
+clean:
+ rm -f *.o *.bak *.out ex
+ for d in $(libs); do make --directory=$$d clean; done
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "config.h"
+
+static int handler(void* user, const char* section, const char* name, const char* value)
+{
+ configuration* pconfig = (configuration*)user;
+
+ #define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
+ if (MATCH("global", "credit_value")) {
+ pconfig->credit_value = atoi(value);
+ //}else if (MATCH("user", "name")) {
+ // pconfig->name = strdup(value);
+ //} else if (MATCH("user", "email")) {
+ // pconfig->email = strdup(value);
+ } else {
+ return 0; /* unknown section/name, error */
+ }
+ return 1;
+}
+
+int init_config(configuration *config)
+{
+ return ini_parse("config.ini", handler, config) >= 0;
+}
--- /dev/null
+#include "lib/inih/ini.h"
+
+typedef struct
+{
+ int credit_value;
+// const char* name;
+// const char* email;
+} configuration;
+
+int init_config(configuration *config);
--- /dev/null
+[global]
+credit_value=10 ; How many seconds inserting a credit adds to the timer
+
--- /dev/null
+Subproject commit d6945571ad745e12952e4b824f591864f190934e
#include <stdio.h>
#include <wiringPi.h>
#include <time.h>
+#include "config.h"
#define COIN_BUTTON 7
-#define CREDIT_EXTENSION 10
+configuration config;
int expires = -1;
int one_second_ago = 0;
{
if(digitalRead(COIN_BUTTON) == LOW)
{
- printf("Nice! I just added %d to your time.\n", CREDIT_EXTENSION);
+ printf("Nice! I just added %d to your time.\n", config.credit_value);
//Increment timer
if(expires == -1) //Initial credit, set the expiry to now plus time
{
- expires = now() + CREDIT_EXTENSION;
+ expires = now() + config.credit_value;
} else { //expiry already set, simply extend by time
- expires += CREDIT_EXTENSION;
+ expires += config.credit_value;
}
//wait for button to be released
int main (void)
{
+ init_config(&config);
init_gpio();
+
printf ("Short pin 7 and 9 to increment timer.\n") ;
while(1)