/*************************************************************************** * Copyright (C) 12/2012 by Olaf Rempel * * razzor@kopf-tisch.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include #include #include #include #include #include #include "lcd.h" #include "lcdpage.h" /* * system: * - os version done * - kernel version done * - hostname done * - date/time done * - uptime done * - avgload done * - cpu usage * - memory/swap usage * - temperature done (pic.c) * - fan error done (pic.c) * * disk drives: * - temperature -> disk * - state (idle / running), time to idle -> disk * - current i/o (aggregated?) * * partitions: * - used / free / total * * ethernet interface: * - link (10/100/1000) * - current i/o * * ip interface: * - ip address/netmask * - default gateway * - dns * */ static int lcdpage_system(struct lcddev *dev, int event, void *privdata) { static int subpage; int retval = 0; char line1[64]; char line2[64]; memset(line1, 0x00, sizeof(line1)); memset(line2, 0x00, sizeof(line2)); switch (event) { case LCDPAGE_EVENT_BUTTON1: lcd_set_backlight(dev, 1); subpage++; break; case LCDPAGE_EVENT_ENTER: lcd_set_backlight(dev, 1); subpage = 0; break; case LCDPAGE_EVENT_BACKLIGHT: case LCDPAGE_EVENT_EXIT: return 0; default: break; } if (subpage == 0) { FILE *fp = fopen("/etc/issue.net", "r"); if (fp != NULL) { fread(line1, 1, sizeof(line1), fp); fclose(fp); char *trim = memchr(line1, 0x0A, sizeof(line1)); if (trim != NULL) *trim = '\0'; trim = memchr(line1, 0x0D, sizeof(line1)); if (trim != NULL) *trim = '\0'; } else { strcpy(line1, ""); } struct utsname utsbuf; uname(&utsbuf); snprintf(line2, sizeof(line2), "%s %s", utsbuf.sysname, utsbuf.release); lcd_setlines(dev, line1, line2); } else if (subpage == 1) { /* copy hostname */ if (gethostname(line2, sizeof(line2)) < 0) { strcpy(line2, ""); } int len = strlen(line2); line2[len++] = '.'; /* append domainname */ if (getdomainname(line2 + len, sizeof(line2) - len) < 0) { strcpy(line2 + len, "unknown"); } lcd_setlines(dev, "Hostname:", line2); } else if (subpage == 2) { struct tm tmp; time_t now; time(&now); localtime_r(&now, &tmp); strftime(line1, sizeof(line1), "Time: %H:%M:%S", &tmp); strftime(line2, sizeof(line2), "Date: %Y/%m/%d", &tmp); lcd_setlines(dev, line1, line2); retval = 1000; /* update every second */ } else if (subpage == 3) { struct sysinfo info; if (sysinfo(&info) < 0) { return 0; } int tmp, days, hours, minutes; days = info.uptime / 86400; tmp = info.uptime % 86400; hours = tmp / 3600; tmp = tmp % 3600; minutes = tmp / 60; tmp = tmp % 60; snprintf(line2, sizeof(line2), " %03dd %02d:%02d:%02d", days, hours, minutes, tmp); lcd_setlines(dev, "Uptime:", line2); retval = 1000; } else if (subpage == 4) { double loadavg[3]; if (getloadavg(loadavg, 3) < 0) { return 0; } snprintf(line2, sizeof(line2), " %1.2f %1.2f %1.2f", loadavg[0], loadavg[1], loadavg[2]); lcd_setlines(dev, "Load Average:", line2); retval = 1000; } else { return LCDPAGE_COMMAND_NEXT; } /* update every 1000ms */ return retval; } static int lcdpage_network(struct lcddev *dev, int event, void *privdata) { static int subpage; switch (event) { case LCDPAGE_EVENT_BUTTON1: lcd_set_backlight(dev, 1); subpage++; break; case LCDPAGE_EVENT_ENTER: lcd_set_backlight(dev, 1); subpage = 0; break; case LCDPAGE_EVENT_BACKLIGHT: case LCDPAGE_EVENT_EXIT: return 0; default: break; } switch (subpage) { case 0: lcd_setlines(dev, "Address(br0):", "10.10.250.135"); break; case 1: lcd_setlines(dev, "Netmask(br0):", "255.255.0.0"); break; case 2: lcd_setlines(dev, "Gateway(br0):", "10.10.250.250"); break; default: return LCDPAGE_COMMAND_NEXT; } return 0; } void lcdpage_free(void) { /* nothing to do, lcdpages are cleaned up in lcd_close() */ } int lcdpage_init(struct lcddev *dev) { lcd_addpage_cb(dev, 200, lcdpage_system, NULL); lcd_addpage_cb(dev, 100, lcdpage_network, NULL); return 0; }