00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00023 #include <liberipc/eripc.h>
00024 #include <liberipc/eripcbusyd.h>
00025 #include <liberipc/eripccontentlister.h>
00026
00027 #include <pthread.h>
00028 #include <string.h>
00029 #include <unistd.h>
00030 #include <fcntl.h>
00031 #include <sys/ioctl.h>
00032
00033 #define BUFSIZE 1024
00034
00035 #define BUTTON_IOCTL_BASE 'b'
00036 #define BUTTON_IOCTL_WRITE_ACTIVITY_LED _IOW( BUTTON_IOCTL_BASE,2,unsigned int)
00037
00038 static eCcBusyState busy = ccBusyState_Blink;
00039 static erClientChannel_t contentListerChannel;
00040
00041 static int execCommand(erIpcCmd_t * cmd)
00042 {
00043 switch ((int) cmd->cc)
00044 {
00045 case ccBusySetBusy:
00046 if (busy != ccBusyState_Shutdown)
00047 {
00048 busy = atoi(cmd->arg[0]);
00049 if (busy < 0 || busy >= ccBusyState_Undefined)
00050 {
00051 busy = ccBusyState_Off;
00052 }
00053
00054 clBusyIndicator(contentListerChannel, busy);
00055 }
00056 break;
00057
00058 case ccBusyUndefined:
00059 default:
00060
00061 break;
00062 }
00063 }
00064
00065 void serviceCallback(char *szBuffer, int *nBuf, void *data)
00066 {
00067 erIpcCmd_t command;
00068
00069 if (busyParseCommand(szBuffer, &command) >= 0)
00070 {
00071 execCommand(&command);
00072 }
00073 }
00074
00075 void* testIPC(void *arg)
00076 {
00077 char szBuffer[BUFSIZE];
00078 int nBuf = BUFSIZE;
00079 int nRet = 0;
00080
00081 nRet = erIpcStartServer(ER_BUSYD_CHANNEL, serviceCallback, szBuffer, &nBuf, NULL);
00082
00083 return (void*)nRet;
00084 }
00085
00086 void switch_led(int device, int led_status)
00087 {
00088 int ret = ioctl(device, BUTTON_IOCTL_WRITE_ACTIVITY_LED, &led_status);
00089 if (ret == -1)
00090 {
00091 printf("Error writing led %d\n", led_status);
00092 }
00093 }
00094
00095 int main(int argc, char *argv[])
00096 {
00097 pthread_t erTid;
00098 int button_device;
00099 int blink = 0;
00100 eCcBusyState wasbusy = ccBusyState_Undefined;
00101 int sleep = 100*1000;
00102 int ret = 0;
00103
00104 if (pthread_create(&erTid, NULL, testIPC, (void *) "1") != 0)
00105 {
00106 printf("%s %s: ", __FILE__, __FUNCTION__);
00107 perror("Could not create thread\n");
00108 }
00109
00110 ret = erIpcStartClient(ER_CONTENTLISTER_CHANNEL, &contentListerChannel);
00111 if (ret != 0)
00112 printf("erIpcStartClient returned %d", ret);
00113
00114 button_device = open("/dev/buttons", O_RDWR);
00115 if (button_device == -1)
00116 {
00117 printf("Error opening button device\n");
00118 exit(-1);
00119 }
00120
00121 while (1)
00122 {
00123 sleep = 100*1000;
00124
00125 switch (busy)
00126 {
00127 case ccBusyState_Blink:
00128 switch_led(button_device, blink);
00129 blink = !blink;
00130 sleep = 40*1000;
00131 break;
00132
00133 case ccBusyState_On:
00134 if (wasbusy != ccBusyState_On)
00135 {
00136 switch_led(button_device, 1);
00137 }
00138 break;
00139
00140 case ccBusyState_Shutdown:
00141 if (wasbusy != ccBusyState_Shutdown)
00142 {
00143 switch_led(button_device, 1);
00144 }
00145 break;
00146
00147 case ccBusyState_Off:
00148 default:
00149 if (wasbusy != ccBusyState_Off)
00150 {
00151 switch_led(button_device, 0);
00152 }
00153 }
00154
00155 wasbusy = busy;
00156 usleep(sleep);
00157 }
00158
00159 return 0;
00160 }