|
@@ -3,7 +3,6 @@ |
|
|
#include <stdio.h> |
|
|
#include <stdio.h> |
|
|
#include <stdlib.h> |
|
|
#include <stdlib.h> |
|
|
#include <unistd.h> |
|
|
#include <unistd.h> |
|
|
#include <linux/i2c-dev.h> |
|
|
|
|
|
#include <sys/ioctl.h> |
|
|
#include <sys/ioctl.h> |
|
|
#include <sys/types.h> |
|
|
#include <sys/types.h> |
|
|
#include <sys/stat.h> |
|
|
#include <sys/stat.h> |
|
@@ -18,9 +17,9 @@ |
|
|
#include <linux/if_link.h> |
|
|
#include <linux/if_link.h> |
|
|
#include <signal.h> |
|
|
#include <signal.h> |
|
|
|
|
|
|
|
|
//#include "ssd1306.h" |
|
|
|
|
|
#include "spilcd_gfx.h" |
|
|
#include "spilcd_gfx.h" |
|
|
#include "spilcd_font.h" |
|
|
#include "spilcd_font.h" |
|
|
|
|
|
#include "base.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define NI_MAXHOST 1025 |
|
|
#define NI_MAXHOST 1025 |
|
@@ -29,8 +28,6 @@ |
|
|
volatile sig_atomic_t done = 0; |
|
|
volatile sig_atomic_t done = 0; |
|
|
struct sigaction action; |
|
|
struct sigaction action; |
|
|
|
|
|
|
|
|
//extern FONT_INFO *_font; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
* |
|
|
* @return |
|
|
* @return |
|
@@ -117,39 +114,80 @@ int main(int argc, char** argv) { |
|
|
perror("Error: cannot handle SIGTERM"); // Should not happen |
|
|
perror("Error: cannot handle SIGTERM"); // Should not happen |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
wiringPiSetup(); |
|
|
|
|
|
|
|
|
|
|
|
lcd_t* lcd = lcd_init(40000000, 1, 10, 7, 8); |
|
|
|
|
|
|
|
|
lcd_t* lcd = demo_init(); |
|
|
|
|
|
|
|
|
|
|
|
int rowy = 10; |
|
|
while (done == 0) { |
|
|
while (done == 0) { |
|
|
row = 2; |
|
|
|
|
|
//_font = (FONT_INFO*)&ubuntuMono_8ptFontInfo; |
|
|
|
|
|
/* Display time */ |
|
|
|
|
|
|
|
|
row = 0; |
|
|
|
|
|
|
|
|
|
|
|
// Date and Time |
|
|
mytime = time(NULL); |
|
|
mytime = time(NULL); |
|
|
tm = localtime (&mytime); |
|
|
tm = localtime (&mytime); |
|
|
//ssd1306ClearScreen(LAYER0 | LAYER1) ; |
|
|
|
|
|
lcd_fillScreen(lcd, 0, 0, 0); |
|
|
lcd_fillScreen(lcd, 0, 0, 0); |
|
|
strftime(time_buffer, 80," %H:%M:%S %x", tm); |
|
|
|
|
|
//ssd1306DrawString(0, row * 8, time_buffer, 1, WHITE, LAYER0); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * 8, time_buffer, 255, 255, 255); |
|
|
|
|
|
|
|
|
strftime(time_buffer, 80," %H:%M:%S", tm); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, time_buffer, 255, 255, 255); |
|
|
|
|
|
row++; |
|
|
|
|
|
strftime(time_buffer, 80," %x", tm); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, time_buffer, 200, 200, 200); |
|
|
|
|
|
row++; |
|
|
row++; |
|
|
row++; |
|
|
|
|
|
|
|
|
/* Display IP */ |
|
|
|
|
|
/* Get network information */ |
|
|
|
|
|
|
|
|
// CPU |
|
|
|
|
|
float c = GetCPULoad() ; |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, "CPU load:", 255, 255, 100); |
|
|
|
|
|
row++; |
|
|
|
|
|
snprintf(text_buffer, sizeof(text_buffer), " %0.2f", c); |
|
|
|
|
|
printf("CPU load avg: %s\n", text_buffer); |
|
|
|
|
|
if (c < 0.2) { |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 50, 255, 50); |
|
|
|
|
|
} else if (c < 0.5) { |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 255, 255, 50); |
|
|
|
|
|
} else { |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 255, 50, 50); |
|
|
|
|
|
} |
|
|
|
|
|
row++; |
|
|
|
|
|
|
|
|
|
|
|
/* Memory usage */ |
|
|
|
|
|
float m = GetMemUsage(); |
|
|
|
|
|
snprintf(text_buffer, sizeof(text_buffer), " %3.0f%%", m*100); |
|
|
|
|
|
printf("Mem used: %s\n", text_buffer); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, "Mem used:", 150, 150, 255); |
|
|
|
|
|
row++; |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 255, 255, 255); |
|
|
|
|
|
//ssd1306DrawRect(0, 0, 127, 13, INVERSE, LAYER0); |
|
|
|
|
|
//ssd1306FillRect(2, 2, (int)(123 * m), 9, INVERSE, LAYER0); |
|
|
|
|
|
row++; |
|
|
|
|
|
|
|
|
|
|
|
/* CPU temperature */ |
|
|
|
|
|
int t = GetCPUTemp() ; |
|
|
|
|
|
snprintf ( text_buffer, sizeof(text_buffer), "%3d C", t ); |
|
|
|
|
|
printf("CPU temp: %s\n", text_buffer); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, "CPU temp:", 255, 180, 170); |
|
|
|
|
|
row++; |
|
|
|
|
|
if (t < 20) { |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 150, 150, 255); |
|
|
|
|
|
} else if (t < 25) { |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 150, 255, 150); |
|
|
|
|
|
} else if (t < 30) { |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 255, 255, 100); |
|
|
|
|
|
} else if (t < 35) { |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 255, 120, 100); |
|
|
|
|
|
} else { |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 255, 80, 20); |
|
|
|
|
|
} |
|
|
|
|
|
row++; |
|
|
|
|
|
|
|
|
|
|
|
// Network devices and IPs |
|
|
if (getifaddrs(&ifaddr) == -1) |
|
|
if (getifaddrs(&ifaddr) == -1) |
|
|
{ |
|
|
{ |
|
|
perror("getifaddrs"); |
|
|
perror("getifaddrs"); |
|
|
exit(EXIT_FAILURE); |
|
|
exit(EXIT_FAILURE); |
|
|
} |
|
|
} |
|
|
/* Walk through linked list, maintaining head pointer so we |
|
|
|
|
|
can free list later */ |
|
|
|
|
|
for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) { |
|
|
for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) { |
|
|
if (ifa->ifa_addr == NULL) |
|
|
if (ifa->ifa_addr == NULL) |
|
|
continue; |
|
|
continue; |
|
|
|
|
|
|
|
|
family = ifa->ifa_addr->sa_family; |
|
|
family = ifa->ifa_addr->sa_family; |
|
|
/* Display interface name and family (including symbolic |
|
|
|
|
|
form of the latter for the common families) */ |
|
|
|
|
|
if ((strncmp ("eth", ifa->ifa_name, 3 ) == 0) && family == AF_INET) { |
|
|
if ((strncmp ("eth", ifa->ifa_name, 3 ) == 0) && family == AF_INET) { |
|
|
s = getnameinfo(ifa->ifa_addr, |
|
|
s = getnameinfo(ifa->ifa_addr, |
|
|
(ifa->ifa_addr->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : |
|
|
(ifa->ifa_addr->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : |
|
@@ -161,9 +199,11 @@ int main(int argc, char** argv) { |
|
|
exit(EXIT_FAILURE); |
|
|
exit(EXIT_FAILURE); |
|
|
} |
|
|
} |
|
|
printf("%-8s <%s>\n", ifa->ifa_name, host); |
|
|
printf("%-8s <%s>\n", ifa->ifa_name, host); |
|
|
snprintf ( text_buffer, sizeof(text_buffer), "%s: %s",ifa->ifa_name, host ); |
|
|
|
|
|
//ssd1306DrawString(0, row * 8, text_buffer, 1, WHITE, LAYER0); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * 8, text_buffer, 255, 255, 255); |
|
|
|
|
|
|
|
|
snprintf ( text_buffer, sizeof(text_buffer), "%s:", ifa->ifa_name); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 200, 200, 255); |
|
|
|
|
|
row++; |
|
|
|
|
|
snprintf ( text_buffer, sizeof(text_buffer), " %s", host ); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 200, 255, 200); |
|
|
row++; |
|
|
row++; |
|
|
} |
|
|
} |
|
|
if ((strncmp ("wlan", ifa->ifa_name, 4 ) == 0) && family == AF_INET) { |
|
|
if ((strncmp ("wlan", ifa->ifa_name, 4 ) == 0) && family == AF_INET) { |
|
@@ -177,53 +217,21 @@ int main(int argc, char** argv) { |
|
|
exit(EXIT_FAILURE); |
|
|
exit(EXIT_FAILURE); |
|
|
} |
|
|
} |
|
|
printf("%-8s <%s>\n", ifa->ifa_name, host); |
|
|
printf("%-8s <%s>\n", ifa->ifa_name, host); |
|
|
snprintf ( text_buffer, sizeof(text_buffer), "%s: %s",ifa->ifa_name, host ); |
|
|
|
|
|
//ssd1306DrawString(0, row * 8, text_buffer, 1, WHITE, LAYER0); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * 8, text_buffer, 255, 255, 255); |
|
|
|
|
|
|
|
|
snprintf ( text_buffer, sizeof(text_buffer), "%s:",ifa->ifa_name); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 255, 200, 200); |
|
|
|
|
|
row++; |
|
|
|
|
|
snprintf ( text_buffer, sizeof(text_buffer), " %s", host ); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * rowy, text_buffer, 200, 255, 200); |
|
|
row++; |
|
|
row++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
freeifaddrs(ifaddr); |
|
|
freeifaddrs(ifaddr); |
|
|
|
|
|
|
|
|
/* CPU usage |
|
|
|
|
|
* |
|
|
|
|
|
*/ |
|
|
|
|
|
float c = GetCPULoad() ; |
|
|
|
|
|
snprintf ( text_buffer, sizeof(text_buffer), "CPU loadavg: %0.2f", c ); |
|
|
|
|
|
printf("%s\n", text_buffer); |
|
|
|
|
|
//ssd1306DrawString(0, row * 8, text_buffer, 1, WHITE, LAYER0); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * 8, text_buffer, 255, 255, 255); |
|
|
|
|
|
row++; |
|
|
row++; |
|
|
|
|
|
|
|
|
/* Memory usage */ |
|
|
|
|
|
float m = GetMemUsage(); |
|
|
|
|
|
snprintf ( text_buffer, sizeof(text_buffer), "Mem used: %3.0f%%", m*100 ); |
|
|
|
|
|
printf("%s\n", text_buffer); |
|
|
|
|
|
//ssd1306DrawString(4, 2, text_buffer, 1, WHITE, LAYER0); |
|
|
|
|
|
lcd_drawText(lcd, 4, 2, text_buffer, 255, 255, 255); |
|
|
|
|
|
//ssd1306DrawRect(0, 0, 127, 13, INVERSE, LAYER0); |
|
|
|
|
|
//ssd1306FillRect(2, 2, (int)(123 * m), 9, INVERSE, LAYER0); |
|
|
|
|
|
|
|
|
|
|
|
/* CPU temperature */ |
|
|
|
|
|
int t = GetCPUTemp() ; |
|
|
|
|
|
snprintf ( text_buffer, sizeof(text_buffer), "CPU temp: %3d C", t ); |
|
|
|
|
|
printf("%s\n", text_buffer); |
|
|
|
|
|
//ssd1306DrawString(0, row * 8, text_buffer, 1, WHITE, LAYER0); |
|
|
|
|
|
lcd_drawText(lcd, 0, row * 8, text_buffer, 255, 255, 255); |
|
|
|
|
|
row++; |
|
|
|
|
|
|
|
|
|
|
|
/* Refresh screen */ |
|
|
|
|
|
//ssd1306Refresh(); |
|
|
|
|
|
//SSD1306MSDELAY(1000); |
|
|
|
|
|
lcd_redrawBuffer(lcd); |
|
|
lcd_redrawBuffer(lcd); |
|
|
sleep(1); |
|
|
sleep(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//_font = (FONT_INFO*)&ubuntuMono_24ptFontInfo; |
|
|
|
|
|
//ssd1306ClearScreen(LAYER0 | LAYER1) ; |
|
|
|
|
|
//ssd1306Refresh(); |
|
|
|
|
|
printf("All done!\r\n"); |
|
|
|
|
|
return (EXIT_SUCCESS); |
|
|
|
|
|
|
|
|
demo_deinit(lcd); |
|
|
} |
|
|
} |
|
|
|
|
|
|