Diff of /oggs_app.c [25d26c] .. [c18e03]  Maximize  Restore

  Switch to side-by-side view

--- a/oggs_app.c
+++ b/oggs_app.c
@@ -37,6 +37,7 @@
 #include <libconfig.h>
 #include <shout/shout.h>
 #include <time.h>
+#include <errno.h>
 
 #include "rs232.h"
 #include "cp_config.h"
@@ -527,13 +528,32 @@
 }
 
 
+void handle_userleds(int pipefd)
+{
+	char leds, c;
+	int valid = 0;
+
+	while(read(pipefd,&c,1)) 
+	{
+		if( c >= '0' && c <= '7') {
+			leds = c - '0';
+			valid = 1;
+		}
+	}
+
+	if( valid )
+	{
+		SendByte(COM_PORT, CMD_STATUSLED_RIGHT | leds);
+	}
+}	
+
 
 int main(int argc, char *argv[])
 {
 	
 	int button;
 	MAIN_STM *state;
-	
+	int ret,pipefd;
 	
 
 	signal(SIGINT, handler); 
@@ -542,6 +562,25 @@
 	cp_config_init();
 	cp_group_init();
 	read_config();
+
+	ret = mkfifo(PIPEFILE, 0600);
+	
+	if(ret != 0 && errno != EEXIST)
+	{
+		fprintf(stderr,"Error creating pipe!\n");
+		return -1;
+	}
+		
+
+	pipefd=open(PIPEFILE,O_RDONLY);
+	if(pipefd == -1)
+	{
+		fprintf(stderr,"Error opening pipe!\n");
+		return -1;
+	}
+
+	int flags = fcntl(pipefd, F_GETFL, 0);
+	fcntl(pipefd, F_SETFL, flags | O_NONBLOCK);
 
 	if(OpenComport(COM_PORT,BAUD_RATE) != 0)
 	{
@@ -588,6 +627,7 @@
 	{
 		button = button_debounce();
 		main_stm(button, state);
+		handle_userleds(pipefd);
 		usleep(SLEEP_TIME);
 	}
 
@@ -595,6 +635,7 @@
 	config_destroy(&cfg);
 	shout_shutdown();
 	CloseComport(COM_PORT);
+	close(pipefd);
 
 	return 0;
 }