Tijl Goens
/
EpaperdisplayII
tempcommit 13/05
Diff: main.cpp
- Revision:
- 1:63664175e603
- Parent:
- 0:73f2160fef5a
- Child:
- 2:048e163245b7
--- a/main.cpp Mon May 13 09:06:23 2019 +0000 +++ b/main.cpp Mon May 13 13:59:19 2019 +0000 @@ -1,7 +1,14 @@ #include "mbed.h" #include "epdpaint.h" #include <epd4in2b.h> +#include "Esp8266.h" +#include <string> +#include <vector> +#include "Shed.h" + //#include "image.h" +Serial pc(USBTX, USBRX); +Esp8266* wifi; unsigned char img[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -315,65 +322,87 @@ int x = 2; paint.DrawVerticalLine(x+38, y, 370, 0); for (int uur = 8; uur <= 19; uur++) { - - - char str_uur[10]; memset(&str_uur, 0, sizeof(str_uur)); // zero out the buffer sprintf(str_uur, "%d", uur); - if (uur < 10){ - paint.DrawStringAt(x+14, y, str_uur,&Font20, 0); - - } - else{ - paint.DrawStringAt(x, y, str_uur,&Font20, 0); - } - + paint.DrawStringAt(x, y, str_uur,&Font20, 0); paint.DrawHorizontalLine(x+38, y+8, 270, 0); y += 30; } } +void drawLesblok(Shed blok,Paint paint) +{ + int startUur = blok.getStart()->getHour(); + int startMinuten = blok.getStart()->getMinute(); + int eindUur = blok.getEinde()->getHour(); + int eindMinuten = blok.getEinde()->getMinute(); + string prof = blok.getProf(); + string klas = blok.getKlasgroep(); + string vak = blok.getVak(); + string comments = blok.getComments(); + + //RECTANGLE OP E-PAPER + int links = 50; //X 70-250 + int rechts = 290; + int boven = 38 + ((startUur-8)*30); //Y 38-368 = 8u - 19u + boven += 2; //Lijntje tussen 2 aansluitende lessen + boven += (startMinuten * 30 / 60); + int onder = (30*(eindUur - startUur)) + boven; + onder -= 2; //Lijntje tussen 2 aansluitende lessen + paint.DrawFilledRectangle(links,boven,rechts,onder,0); + /*printf("van %d %d tot %d %d \r\n",startUur,startMinuten,eindUur,eindMinuten); + printf("X %d tot %d Y %d tot %d \r\n",links,boven,rechts,onder);*/ + + //TEXT OP RECTANGLE + string strLijn1 = vak; + string strLijn2 = prof; + string strLijn3 = klas + " " + comments; + paint.DrawStringAt(links+1, boven+1, strLijn1.c_str(),&Font12, 1); + if(onder - boven >= 30) { + paint.DrawStringAt(links+1, boven+15, strLijn2.c_str(),&Font12, 1); + } + if(onder - boven >= 45) { + paint.DrawStringAt(links+1, boven+30, strLijn3.c_str(),&Font12, 1); + } +} int main() { + //E-PAPER Epd epd; epd.Init(); epd.ClearFrame(); - - while (true) { - printf("blub\r\n"); - //img mag niet const zijn!!! - Paint paint(img,400,300); - paint.DrawImage(0,100, int x1, int y1,unsigned char* image, int colored) - drawLayout(paint); - - - //paint.Clear(0); - - wait(1); - break; - - - } - - printf("after init\r\n"); + Paint paint(img,400,300); + drawLayout(paint); + //WIFI + pc.baud(9600); + wifi = new Esp8266(D1, D0, 9600, A3, D10); + while(1) { + wifi->setModuleMode(1); + wifi->connectToAP("test", "password"); + string jsonString = wifi->getRequest("TCP", "translini.be", 80, "/eink/?mbed=1&month=5&day=15"); + vector<string> dataStrings = wifi->processJsonString(jsonString); + //drawLayout(Paint p); - //epd.Reset(); - - //epd.DisplayFrame(); - //epd.DisplayFrame(NULL,gImage_mx5_test); - epd.DisplayFrame(img,NULL); - epd.Sleep(); - - - - - - - /* - printf("blub/r/n"); - Paint paint(img,16,10); - paint.DrawFilledRectangle(5, 5, 10, 10, 0); - */ + vector<Shed> sheds; + for(int i = 0; i < (int)dataStrings.size(); i++) { + sheds.push_back(Shed(dataStrings[i])); + } + for(int i = 0; i < ((int)sheds.size()); i++) { + /* + printf("Lokaal: %s\r\n", sheds[i].getLokaal().c_str()); + printf("Startuur: %s\r\n", (sheds[i].getStart()->getDatetime()).c_str()); + printf("Einduur: %s\r\n", (sheds[i].getEinde()->getDatetime()).c_str()); + printf("Prof: %s\r\n", sheds[i].getProf().c_str()); + printf("Klasgroep: %s\r\n", sheds[i].getKlasgroep().c_str()); + printf("Vak: %s\r\n", sheds[i].getVak().c_str()); + printf("Comments: %s\r\n\r\n", sheds[i].getComments().c_str());*/ + drawLesblok(sheds[i],paint); + } + epd.DisplayFrame(NULL,img); + epd.Sleep(); + pc.printf("\r\n\r\n"); + wait(60); + } }