1 diff -Naur old/asus_osd/asusosd.c new/asus_osd/asusosd.c
2 --- old/asus_osd/asusosd.c 2008-10-20 09:18:35.000000000 -0500
3 +++ new/asus_osd/asusosd.c 2008-10-22 21:26:38.000000000 -0500
10 #include <sys/socket.h>
15 #define VOLUME_CONTROL "/usr/bin/volume_control.sh"
16 -#define RADIO_CONTROL "/usr/bin/radio_control.sh"
18 +#define PWRMGMT_FILE "/var/state/fsb/osd"
20 static pthread_mutex_t q_lock;
21 static pthread_cond_t q_empty;
23 static int thread_alive;
25 +static int cfg_flags = 0;
28 +char btfilename[128] = {'\0'};
30 unsigned int img_data;
38 char* hotkey_get(int);
39 unsigned int hotkey_parse(char*);
47 int pipe_cmd(char pipe_cmd[]);
48 +static int read_config(char config[]);
51 main (int argc, char *argv[])
56 - struct sockaddr_un socket_addr;
66 pthread_cond_init(&q_empty, NULL);
67 pthread_create(&img_thread, NULL, image_thread, img_queue);
69 - socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
70 - if (socket_fd < 0) {
71 - printf("cannot create socket\n");
75 - memset(&socket_addr, 0, sizeof(socket_addr));
76 - socket_addr.sun_family = AF_UNIX;
77 - sprintf(socket_addr.sun_path, "%s", "/var/run/acpid.socket");
79 - if(connect(socket_fd, (struct sockaddr *)&socket_addr, sizeof(socket_addr)) < 0)
81 - printf("cannot connect socket\n");
86 - fcntl(socket_fd, F_SETFD, FD_CLOEXEC);
87 + socket_fd = connect_acpid();
88 setvbuf(stdout, NULL, _IOLBF, 0);
92 if((pfile=fopen("/proc/acpi/asus/brn","rb"))==NULL)
94 - printf("cannot open /proc/acpi/asus/brn\n");
95 + syslog(LOG_ERR, "cannot open /proc/acpi/asus/brn\n");
99 if(fscanf(pfile, "%d", &bri_value) != 1)
101 - printf("cannot read /proc/acpi/asus/brn\n");
102 + syslog(LOG_ERR, "cannot read /proc/acpi/asus/brn\n");
104 if(bri_value < 0 || 15 < bri_value)
107 - printf("read an invalid value [%d] from /proc/acpi/asus/brn\n", bri_value);
108 + syslog(LOG_ERR, "read an invalid value [%d] from /proc/acpi/asus/brn\n", bri_value);
113 - if((pfile=fopen("/proc/acpi/asus/wlan", "rb"))==NULL)
115 - printf("cannot read /proc/acpi/asus/wlan\n");
119 - if(fscanf(pfile, "%d", &wlan_value) != 1)
121 - printf("cannot read /proc/acpi/asus/wlan\n");
127 - if(wlan_value == 1)
128 - system("echo 1 > /proc/acpi/asus/wlan");
129 - else if(wlan_value == 0)
130 - system("echo 0 > /proc/acpi/asus/wlan");
132 - printf("read an invalid value [%d] from /proc/acpi/asus/wlan\n", wlan_value);
136 + /* Read the config file, see what is enabled */
137 + cfg_flags = read_config("/etc/acpi/eee.conf");
141 hotkey = hotkey_get(socket_fd);
144 + if (!strncmp("-1", hotkey, 2))
146 + syslog(LOG_ERR, "Broken pipe: Attempting to reconnect\n");
150 + for (j=1; j<6; j++)
153 + socket_fd = connect_acpid();
156 + syslog(LOG_ERR, "Attempt %d: failed\n", j);
161 + syslog(LOG_ERR, "Attempt %d: connected. Resuming.\n", j);
168 + syslog(LOG_ERR, "Unable to connect. Exiting.\n");
175 if(strncmp("hotkey ATKD ", hotkey, 12))
177 data = hotkey_parse(hotkey+12);
186 + struct sockaddr_un socket_addr;
188 + sfd = socket(AF_UNIX, SOCK_STREAM, 0);
190 + syslog(LOG_ERR, "cannot create socket\n");
194 + memset(&socket_addr, 0, sizeof(socket_addr));
195 + socket_addr.sun_family = AF_UNIX;
196 + sprintf(socket_addr.sun_path, "%s", "/var/run/acpid.socket");
198 + if(connect(sfd, (struct sockaddr *)&socket_addr, sizeof(socket_addr)) < 0)
200 + syslog(LOG_ERR, "cannot connect to socket: /var/run/acpid.socket\n");
205 + fcntl(sfd, F_SETFD, FD_CLOEXEC);
214 buf = realloc(buf, buflen);
216 - fprintf(stderr, "ERR: malloc(%d): %s\n",
217 + syslog(LOG_ERR, "ERR: malloc(%d): %s\n",
218 buflen, strerror(errno));
221 @@ -202,13 +235,13 @@
222 r = read(sfd, buf+i, 1);
223 if (r < 0 && errno != EINTR) {
224 /* we should do something with the data */
225 - fprintf(stderr, "ERR: read(): %s\n",
226 + syslog(LOG_ERR, "ERR: read(): %s\n",
230 /* signal this in an almost standard way */
235 /* scan for a newline */
236 if (buf[i] == '\n') {
238 hotkey = IMG_BRN_DN|(val<<8);
241 + else if (data[6] == '1' && data[7] == 'c')
245 + else if (data[6] == '1' && data[7] == 'd')
247 + if ((cfg_flags & 4) == 4)
258 case 13:printf("@@ audio mute %d\n", hotkey);
260 - if(!getvol(1)) //off
261 - hotkey = 16;//then on
262 + if(getvol(1)) //get volume status: 1=on 0=off
265 + printf("Volume on\n");
268 + printf("Volume off\n");
270 printf("@@ audio mute %d\n", hotkey);
272 case 14: //volume down
273 @@ -306,10 +357,24 @@
274 sprintf(filename, "%s%d%s", "/usr/share/asus_osd/VolumeDN",val,".png");
275 else if ((img_data&IMAGE_MASK) == IMG_VOL_UP)
276 sprintf(filename, "%s%d%s", "/usr/share/asus_osd/VolumeUP",val,".png");
277 - else if ((img_data&IMAGE_MASK) == IMG_AC_IN)
278 + else if ((img_data&IMAGE_MASK) == IMG_AC_IN && (cfg_flags & 2) != 2)
279 sprintf(filename, "%s", "/usr/share/asus_osd/ACMode.png");
280 - else if ((img_data&IMAGE_MASK) == IMG_AC_OUT)
281 + else if ((img_data&IMAGE_MASK) == IMG_AC_IN && (cfg_flags & 2) == 2)
282 + sprintf(filename, "%s", "/usr/share/asus_osd/ACMode_performance.png");
283 + else if ((img_data&IMAGE_MASK) == IMG_AC_OUT && (cfg_flags & 2) != 2)
284 sprintf(filename, "%s", "/usr/share/asus_osd/BatteryMode.png");
285 + else if ((img_data&IMAGE_MASK) == IMG_AC_OUT && (cfg_flags & 2) == 2)
286 + sprintf(filename, "%s", "/usr/share/asus_osd/BatteryMode_powersave.png");
287 + else if ((img_data&IMAGE_MASK) == IMG_FSB_PWRSAVE && (cfg_flags & 1) == 1)
288 + sprintf(filename, "%s", "/usr/share/asus_osd/PowerSaving.png");
289 + else if ((img_data&IMAGE_MASK) == IMG_FSB_HIGH && (cfg_flags & 1) == 1)
290 + sprintf(filename, "%s", "/usr/share/asus_osd/HighPerformance.png");
291 + else if ((img_data&IMAGE_MASK) == IMG_FSB_SUPER && (cfg_flags & 1) == 1)
292 + sprintf(filename, "%s", "/usr/share/asus_osd/SuperPerformance.png");
293 + else if ((img_data&IMAGE_MASK) == IMG_BLUETOOTH_ON && (cfg_flags & 4) == 4)
294 + sprintf(filename, "%s", "/usr/share/asus_osd/BluetoothOn.png");
295 + else if ((img_data&IMAGE_MASK) == IMG_BLUETOOTH_OFF && (cfg_flags & 4) == 4)
296 + sprintf(filename, "%s", "/usr/share/asus_osd/BluetoothOff.png");
302 create_image(filename);
304 - else printf("image_open error.\n");
305 + else syslog(LOG_ERR, "image_open error.\n");
314 sprintf(volcmd, "%s status", VOLUME_CONTROL);
315 if(!pipe_cmd(volcmd))
317 @@ -400,11 +466,141 @@
319 else if(strstr(volcmd, "[off]"))
321 - }else printf("@@ pipe cmd fail\n");
322 + }else syslog(LOG_ERR, "pipe cmd fail\n");
329 + FILE *statefile = NULL;
335 + /* sleep a millisecond between attempts to open the file,
336 + * for two seconds, then fail */
337 + for (i=0; i<2000; i++)
339 + statefile = fopen(PWRMGMT_FILE, "r");
340 + if (statefile == NULL)
348 + /* Read the file. If it doesn't contain
349 + * a valid state, close it, sleep, then try again */
350 + if (fgets(line, 80, statefile) != NULL)
352 + line[strlen(line)-1] = '\0';
353 + if (!strcmp(line, "PWRSAV"))
355 + fsb_value = IMG_FSB_PWRSAVE;
357 + else if (!strcmp(line, "HIPERF"))
359 + fsb_value = IMG_FSB_HIGH;
361 + else if (!strcmp(line, "SPPERF"))
363 + fsb_value = IMG_FSB_SUPER;
371 + if (fsb_value != 0)
373 + /* Got the value. Reset the OSD state file and break. */
374 + statefile = fopen(PWRMGMT_FILE, "w");
375 + if (statefile == NULL)
377 + syslog(LOG_ERR, "Unable to reset OSD state file '%s': %s. Returning.", PWRMGMT_FILE, strerror(errno));
392 + syslog(LOG_ERR, "Unable to open OSD state file '%s': %s. Returning.", PWRMGMT_FILE, strerror(errno));
395 + else if (fsb_value == 0)
397 + syslog(LOG_ERR, "Unable to determine FSB state in file '%s'. Returning.", PWRMGMT_FILE);
406 + FILE *btRead = NULL;
407 + int bt_toggle = 999;
408 + char buf[2] = {'\0'};
410 + if (strlen(btfilename) == 0)
412 + syslog(LOG_ERR, "NO BLUETOOTH_SWITCH file configured. Returning.\n");
417 + btRead = fopen(btfilename, "r");
418 + if (btRead != NULL)
420 + if (fread(buf, 1, 1, btRead) != 1)
422 + syslog(LOG_ERR, "Cannot read '%s'. Returning.\n", btfilename);
428 + bt_toggle = atoi(buf);
430 + if (bt_toggle == 0)
432 + return IMG_BLUETOOTH_OFF;
434 + else if (bt_toggle == 1)
436 + return IMG_BLUETOOTH_ON;
440 + syslog(LOG_ERR, "Invalid value returned from '%s': '%d'. Returning.\n", btfilename, bt_toggle);
450 + syslog(LOG_ERR, "Unable to read '%s': %s. Returning.", btfilename, strerror(errno));
457 int pipe_cmd(char cmd[])
459 int iData = 1,iCount = 0,iSize = sizeof(cmd);
461 return(EXIT_FAILURE);
464 +static int read_config(char config[])
470 + configfile = fopen(config, "r");
471 + if (configfile != NULL)
473 + while(fgets(line, 80, configfile) != NULL)
475 + if (line[0] == '#')
477 + //try to ignore comments
479 + else if (strstr(line, "ENABLE_PWRMGMT=Y") != NULL)
483 + else if (strstr(line, "ENABLE_PWRMGMT=y") != NULL)
487 + else if (strstr(line, "ENABLE_PWRMGMT_AUTO=Y") != NULL)
491 + else if (strstr(line, "ENABLE_PWRMGMT_AUTO=y") != NULL)
495 + else if (strstr(line, "ENABLE_BLUETOOTH=Y") != NULL)
499 + else if (strstr(line, "ENABLE_BLUETOOTH=y") != NULL)
503 + else if (strstr(line, "BLUETOOTH_SWITCH=") != NULL)
505 + sscanf(line, "BLUETOOTH_SWITCH=%*[\"\']%[^\"\']", btfilename);
512 + syslog(LOG_ERR, "Unable to open configuration file '%s': defaulting.", config);
515 + fclose(configfile);
519 diff -Naur old/asus_osd/asusosd_image.c new/asus_osd/asusosd_image.c
520 --- old/asus_osd/asusosd_image.c 2008-10-20 09:18:36.000000000 -0500
521 +++ new/asus_osd/asusosd_image.c 2008-10-21 18:05:40.000000000 -0500
527 #include <X11/Xlib.h>
528 #include <X11/Xutil.h>
531 static int xwindow_create(void);
532 static int ximage_create(void);
533 static int ximage_display(void);
534 +static void read_pos_from_config(char config[], int *x, int *y);
535 void destroy_osd(void);
536 //static void destroy_image(void);
537 static int x_msb(unsigned long u32val);
540 else if (!(pngfile = fopen(filename, "rb")))
542 - printf(": can't open PNG file [%s]\n", filename);
543 + syslog(LOG_ERR, ": can't open PNG file [%s]\n", filename);
549 if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) {
550 readpng_cleanup(TRUE);
551 - printf(": libpng error while checking for background color\n");
552 + syslog(LOG_ERR, ": libpng error while checking for background color\n");
560 - printf(": unable to decode PNG image\n");
561 + syslog(LOG_ERR, ": unable to decode PNG image\n");
566 XDestroyImage(ximage);
570 + XDestroyWindow(display, window);
571 + have_window = FALSE;
576 if (depth == 8 || need_colormap) {
577 colormap = XCreateColormap(display, root, visual, AllocNone);
579 - printf("XCreateColormap() failed\n");
580 + syslog(LOG_ERR, "XCreateColormap() failed\n");
583 have_colormap = TRUE;
587 if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) {
588 - printf("rpng internal logic error: negative X shift(s)!\n");
589 + syslog(LOG_ERR, "rpng internal logic error: negative X shift(s)!\n");
593 @@ -236,11 +239,14 @@
594 attr.border_pixel = 0;
595 x = 2;//(XDefaultScreenOfDisplay(display)->width - image_width)/2;
596 y = 2;//(XDefaultScreenOfDisplay(display)->height - image_height)/2;
598 + read_pos_from_config("/etc/acpi/eee.conf", &x, &y);
600 window = XCreateWindow(display, root, x, y, image_width, image_height, 0,
601 depth, InputOutput, visual, attrmask, &attr);
603 if (window == None) {
604 - printf("XCreateWindow() failed\n");
605 + syslog(LOG_ERR, "XCreateWindow() failed\n");
613 - printf(": unable to allocate image memory\n");
614 + syslog(LOG_ERR, ": unable to allocate image memory\n");
619 (char *)xdata, image_width, image_height, pad, 0);
622 - printf(": XCreateImage() failed\n");
623 + syslog(LOG_ERR, ": XCreateImage() failed\n");
632 +static void read_pos_from_config(char config[], int *x, int *y)
637 + configfile = fopen(config, "r");
638 + if (configfile != NULL)
640 + while(fgets(line, 80, configfile) != NULL)
642 + if (line[0] == '#')
644 + //try to ignore comments
646 + else if (strstr(line, "ASUSOSD_XPOS=center") != NULL)
648 + *x = (XDefaultScreenOfDisplay(display)->width - image_width)/2;
650 + else if (strstr(line, "ASUSOSD_XPOS=") != NULL)
652 + sscanf(line,"ASUSOSD_XPOS=%i" , x);
654 + else if (strstr(line, "ASUSOSD_YPOS=center") != NULL)
656 + *y = (XDefaultScreenOfDisplay(display)->height - image_height)/2;
658 + else if (strstr(line, "ASUSOSD_YPOS=") != NULL)
660 + sscanf(line,"ASUSOSD_YPOS=%i" , y);
666 + syslog(LOG_ERR, "Unable to open configuration file '%s': defaulting.", config);
669 + fclose(configfile);
674 diff -Naur old/asus_osd/asusosd_image.h new/asus_osd/asusosd_image.h
675 --- old/asus_osd/asusosd_image.h 2008-10-20 09:18:36.000000000 -0500
676 +++ new/asus_osd/asusosd_image.h 2008-10-21 17:48:13.000000000 -0500
678 #define IMG_AC_IN 50//0x0050
679 #define IMG_AC_OUT 51//0x0051
681 +#define IMG_FSB_PWRSAVE 60//0x0060
682 +#define IMG_FSB_HIGH 61//0x0061
683 +#define IMG_FSB_SUPER 62//0x0062
685 +#define IMG_BLUETOOTH_ON 70//0x0070
686 +#define IMG_BLUETOOTH_OFF 71//0x0071