diff --git a/src/Example_Code/Main.c b/src/Example_Code/Main.c index 3192c4b..af33036 100644 --- a/src/Example_Code/Main.c +++ b/src/Example_Code/Main.c @@ -40,7 +40,6 @@ void BreakDeal(int sig) int main(int argc, char* argv[]) { - int display_offset=7; int date=atoi(argv[1]); int lanip=atoi(argv[2]); int cputemp=atoi(argv[3]); @@ -186,29 +185,43 @@ int main(int argc, char* argv[]) //setCursor(0,0); - + setTextColor(WHITE); // info display - for(int i = 1; i < time; i++){ - if (date+lanip+cpufreq+cputemp+netspeed == 1){ - setTextSize(2); - setTextColor(WHITE); - if (date) testdate(date); - if (lanip) testlanip(lanip); - if (cpufreq) testcpufreq(cpufreq); - if (cputemp) testcputemp(cputemp); - if (netspeed) testnetspeed(netspeed); + int sum = date+lanip+cpufreq+cputemp+netspeed; + if (sum == 0) {clearDisplay(); return 0;} + for(int i = 1; i < time; i++){ + if (sum == 1){//only one item for display + if (date) testdate(CENTER, 8); + if (lanip) testlanip(CENTER, 8); + if (cpufreq) testcpufreq(CENTER, 8); + if (cputemp) testcputemp(CENTER, 8); + if (netspeed) testnetspeed(SPLIT,0); + Display(); + usleep(1000000); + clearDisplay(); + }else if (sum == 2){//two items for display + if(date) {testdate(CENTER, 16*(date-1));} + if(lanip) {testlanip(CENTER, 16*(date+lanip-1));} + if(cpufreq) {testcpufreq(CENTER, 16*(date+lanip+cpufreq-1));} + if(cputemp) {testcputemp(CENTER, 16*(date+lanip+cpufreq+cputemp-1));} + if(netspeed) {testnetspeed(MERGE, 16*(date+lanip+cpufreq+cputemp+netspeed-1));} Display(); usleep(1000000); clearDisplay(); } - else{ - setTextSize(1); - setTextColor(WHITE); - if(date) {setCursor(display_offset, 8*(date-1)); testdate(0);} - if(lanip) {setCursor(display_offset, 8*(date+lanip-1)); testlanip(0);} - if(cpufreq) {setCursor(display_offset, 8*(date+lanip+cpufreq-1)); testcpufreq(0);} - if(cputemp) {setCursor(display_offset, 8*(date+lanip+cpufreq+cputemp-1));testcputemp(0);} - if(netspeed) {setCursor(display_offset, 8*(date+lanip+cpufreq+cputemp+netspeed-1));testnetspeed(0);} + else{//more than two items for display + if(date) {testdate(FULL, 8*(date-1));} + if(lanip) {testlanip(FULL, 8*(date+lanip-1));} + if(cpufreq && cputemp) { + testcpu(8*(date+lanip)); + if(netspeed) {testnetspeed(FULL, 8*(date+lanip+1+netspeed-1));} + } + else{ + if(cpufreq) {testcpufreq(FULL, 8*(date+lanip+cpufreq-1));} + if(cputemp) {testcputemp(FULL, 8*(date+lanip+cpufreq+cputemp-1));} + if(netspeed) {testnetspeed(FULL, 8*(date+lanip+cpufreq+cputemp+netspeed-1));} + } + Display(); usleep(1000000); clearDisplay(); diff --git a/src/Example_Code/Main.o b/src/Example_Code/Main.o deleted file mode 100644 index 792a895..0000000 Binary files a/src/Example_Code/Main.o and /dev/null differ diff --git a/src/Example_Code/example_app.c b/src/Example_Code/example_app.c index d1a6879..13ca0c8 100644 --- a/src/Example_Code/example_app.c +++ b/src/Example_Code/example_app.c @@ -91,7 +91,7 @@ static const unsigned char logo16_glcd_bmp[] = FILE *fp; char content_buff[BUFMAX]; char buf[BUFMAX]; - +int display_offset =7; /* draw many lines */ void testdrawline() { @@ -407,122 +407,196 @@ void deeplyembedded_credits() } -void testdate(int standalone) +void testdate(int mode, int y) { time_t rawtime; time_t curtime; uint8_t timebuff[TIMESIZE]; curtime = time(NULL); time(&rawtime); - if(standalone) + switch (mode) { - /* - strftime(timebuff,80,"%Y-%m-%d",localtime(&rawtime)); - sprintf(buf,"%s",timebuff); - setCursor((127-strlen(buf)*11)/2-2,0); - print_strln(buf); - strftime(timebuff,80,"%H:%M:%S",localtime(&rawtime)); - sprintf(buf,"%s",timebuff); - setCursor((127-strlen(buf)*11)/2,16); - print_strln(buf);*/ - setTextSize(3); - strftime(timebuff,80,"%H:%M",localtime(&rawtime)); - sprintf(buf,"%s",timebuff); - setCursor((127-strlen(buf)*16)/2-4,4); - print_strln(buf); + case CENTER: + setTextSize(2); + strftime(timebuff,80,"%H:%M",localtime(&rawtime)); + sprintf(buf,"%s",timebuff); + setCursor((127-strlen(buf)*11)/2-4, y); + break; + case FULL: + setTextSize(1); + strftime(timebuff,80,"%Y-%m-%d %H:%M:%S",localtime(&rawtime)); + sprintf(buf,"%s",timebuff); + setCursor(display_offset, y); } - else { - strftime(timebuff,80,"%Y-%m-%d %H:%M:%S",localtime(&rawtime)); - sprintf(buf,"%s",timebuff); - print_strln(buf); - } - + print_strln(buf); } -void testlanip(int standalone) +void testlanip(int mode, int y) { + setTextSize(1); if((fp=popen(IPPATH,"r"))!=NULL) { fscanf(fp,"%s",content_buff); fclose(fp); //ipbuff[strlen(ipbuff)-1]=32; - if(standalone) {sprintf(buf,"%s",content_buff); setTextSize(1); setCursor((127-strlen(buf)*6)/2, 12);} - else sprintf(buf,"IP:%s",content_buff); + switch(mode) + { + case CENTER: + setTextSize(1); + sprintf(buf,"%s",content_buff); + setCursor((127-strlen(buf)*6)/2, y+4); + break; + + case FULL: + setTextSize(1); + sprintf(buf,"IP:%s",content_buff); + setCursor(display_offset, y); + } print_strln(buf); } } -void testcputemp(int standalone) +void testcputemp(int mode, int y) { if((fp=fopen(TEMPPATH,"r"))!=NULL) { fgets(content_buff,TEMPSIZE,fp); fclose(fp); - if(standalone) {sprintf(buf, "%.2f C",atoi(content_buff)/100.0); setCursor((127-strlen(buf)*11)/2, 8);} - else sprintf(buf,"CPU TEMP:%.2f C",atoi(content_buff)/100.0); - print_strln(buf); + switch (mode) + { + case CENTER: + setTextSize(2); + sprintf(buf, "%.2f",atoi(content_buff)/100.0); + setCursor((127-(strlen(buf)+2)*11)/2-4, y); + print_str(buf); + oled_write(247); + oled_write(67); + break; + case FULL: + setTextSize(1); + sprintf(buf,"CPU TEMP:%.2f",atoi(content_buff)/100.0); + setCursor(display_offset, y); + print_str(buf); + oled_write(247); + oled_write(67); + } + } } -void testcpufreq(int standalone) +void testcpufreq(int mode, int y) { if((fp=popen(FREQPATH,"r")) != NULL) { fgets(content_buff,FREQSIZE,fp); fclose(fp); - if(standalone) {sprintf(buf,"%d MHz",atoi(content_buff)/1000); setCursor((127-strlen(buf)*11)/2, 8);} - else sprintf(buf,"CPU FREQ:%d MHz",atoi(content_buff)/1000); + switch(mode) + { + case CENTER: + setTextSize(2); + sprintf(buf,"%dMHz",atoi(content_buff)/1000); + setCursor((127-strlen(buf)*11)/2-4, y); + break; + case FULL: + setTextSize(1); + sprintf(buf,"CPU FREQ:%dMHz",atoi(content_buff)/1000); + setCursor(display_offset, y); + } print_strln(buf); } } -void testnetspeed(int standalone) +void testnetspeed(int mode, int y) { int in,out; if((fp=popen(NETPATH,"r")) != NULL) { - + fscanf(fp,"%d %d", &in, &out); fclose(fp); in = in*8; out = out*8; - if(standalone){ + switch(mode) + { + case SPLIT: setTextSize(2); - setCursor(7,0); - oled_write(24); - if (in < 1000) sprintf(buf, "%db/s", in); - else if (in > 1000000) sprintf(buf, "%.2fm/s", in/1000000.0); - else sprintf(buf, "%.2fk/s", in/1000.0); - print_strln(buf); - setCursor(7,16); + if (in < 1000) sprintf(buf, "%03db", in); + else if (in > 1000000) sprintf(buf, "%03dM", in/1000000); + else sprintf(buf, "%03dK", in/1000); + setCursor((127-(strlen(buf)+1)*11)/2,0); + oled_write(24); + print_str(buf); + + if (out < 1000) sprintf(buf, "%03db", out); + else if (out > 1000000) sprintf(buf, "%03dM", out/1000000); + else sprintf(buf, "%03dK", out/1000); + setCursor((127-(strlen(buf)+1)*11)/2,16); oled_write(25); - if (out < 1000) sprintf(buf, "%db/s", out); - else if (out > 1000000) sprintf(buf, "%.2fm/s", out/1000000.0); - else sprintf(buf, "%.2fk/s", out/1000.0); - print_strln(buf); - } - else{ + print_str(buf); + break; + case MERGE: + setTextSize(1); + if (in < 1000) sprintf(buf, "%03db ", in); + else if (in > 1000000) sprintf(buf, "%03dM", in/1000000); + else sprintf(buf, "%03dK ", in/1000); + setCursor((127-(2*strlen(buf)-1)*6)/2-4, y+4); + oled_write(24); + print_str(buf); + if (out < 1000) sprintf(buf, "%03db", out); + else if (out > 1000000) sprintf(buf, "%03dM", out/1000000); + else sprintf(buf, "%03dK", out/1000); + oled_write(25); + print_str(buf); + break; + case FULL: setTextSize(1); + setCursor(display_offset, y); oled_write(24); - if (in < 1000) sprintf(buf, "%db/s ", in); - else if (in > 1000000) sprintf(buf, "%.2fm/s ", in/1000000.0); - else sprintf(buf, "%.2fk/s ", in/1000.0); - print_str(buf); - oled_write(25); - if (out < 1000) sprintf(buf, "%db/s", out); - else if (out > 1000000) sprintf(buf, "%.2fm/s", out/1000000.0); - else sprintf(buf, "%.2fk/s", out/1000.0); - print_str(buf); - } + if (in < 1000) sprintf(buf, "%03db ", in); + else if (in > 1000000) sprintf(buf, "%03dM", in/1000000); + else sprintf(buf, "%03dK ", in/1000); + print_str(buf); + oled_write(25); + if (out < 1000) sprintf(buf, "%03db", out); + else if (out > 1000000) sprintf(buf, "%03dM", out/1000000); + else sprintf(buf, "%03dK", out/1000); + print_str(buf); + } + } + +} +void testcpu(int y) +{ +//freq + setTextSize(1); + setCursor(display_offset, y); + if((fp=popen(FREQPATH,"r")) != NULL) + { + fgets(content_buff,FREQSIZE,fp); + fclose(fp); + sprintf(buf,"CPU:%dMHz ", atoi(content_buff)/1000); + print_str(buf); } + +//temp + if((fp=fopen(TEMPPATH,"r"))!=NULL) + { + fgets(content_buff,TEMPSIZE,fp); + fclose(fp); + sprintf(buf, "%.2f",atoi(content_buff)/100.0); + print_str(buf); + oled_write(247); + oled_write(67); + } } + void testprintinfo() { setTextSize(1); diff --git a/src/Example_Code/example_app.h b/src/Example_Code/example_app.h index 5adb415..eb04358 100644 --- a/src/Example_Code/example_app.h +++ b/src/Example_Code/example_app.h @@ -1,3 +1,8 @@ +#define CENTER 0 //single item display +#define SPLIT 1 //two items +#define MERGE 2 +#define FULL 3 + void testdrawline(); void testdrawrect(); void testfillrect(); @@ -15,10 +20,11 @@ void testdrawbitmap(const unsigned char *bitmap, unsigned char w, unsigned char void testdrawbitmap_eg(); void deeplyembedded_credits(); void testprintinfo(); -void testdate(int standalone); -void testlanip(int standalone); -void testcpufreq(int standalone); -void testcputemp(int standalone); -void testnetspeed(int standalone); +void testdate(int mode, int y); +void testlanip(int mode, int y); +void testcpufreq(int mode, int y); +void testcputemp(int mode, int y); +void testnetspeed(int mode, int y); +void testcpu(int y); diff --git a/src/Example_Code/example_app.o b/src/Example_Code/example_app.o deleted file mode 100644 index 1d469cd..0000000 Binary files a/src/Example_Code/example_app.o and /dev/null differ diff --git a/src/SSD1306_OLED_Library/SSD1306_OLED.o b/src/SSD1306_OLED_Library/SSD1306_OLED.o deleted file mode 100644 index dd33a09..0000000 Binary files a/src/SSD1306_OLED_Library/SSD1306_OLED.o and /dev/null differ