Server 'HUB' interface, with dummy pages for AC and Lighting control...touchscreen working.

Dependencies:   ID12RFID SPI_TFT_ILI9341 TFT_fonts mbed

Fork of TFT_Mikroelectronika_IL9341 by Oxford CWM Team

Files at this revision

API Documentation at this revision

Comitter:
bendavis96
Date:
Thu Jun 16 15:41:28 2016 +0000
Parent:
6:18c7288b5e00
Commit message:
Working HUB interface, with dummy pages for AC and Lighting control

Changed in this revision

ID12RFID.lib Show annotated file Show diff for this revision Revisions of this file
IDs.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 18c7288b5e00 -r ceeced183454 ID12RFID.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ID12RFID.lib	Thu Jun 16 15:41:28 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/ID12RFID/#f04afa911cf5
diff -r 18c7288b5e00 -r ceeced183454 IDs.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IDs.h	Thu Jun 16 15:41:28 2016 +0000
@@ -0,0 +1,79 @@
+void ben()
+{
+
+    rled = 0;
+    bled = 1;
+    gled = 1;
+
+    TFT.printf("B");
+    wait(0.05);
+    TFT.printf("e");
+    wait(0.05);
+    TFT.printf("n");
+    wait(0.05);
+    home();
+    break;
+}
+
+void joe()
+{
+    rled = 1;
+    bled = 0;
+    gled = 1;
+
+    TFT.printf("J");
+    wait(0.05);
+    TFT.printf("o");
+    wait(0.05);
+    TFT.printf("e");
+    wait(0.05);
+    home();
+    break;
+}
+
+void arthur()
+{
+    rled = 1;
+    bled = 0;
+    gled = 1;
+
+    TFT.printf("A");
+    wait(0.05);
+    TFT.printf("r");
+    wait(0.05);
+    TFT.printf("t");
+    wait(0.05);
+    TFT.printf("h");
+    wait(0.05);
+    TFT.printf("u");
+    wait(0.05);
+    TFT.printf("r");
+    wait(0.05);
+    home();
+    break
+}
+
+void intruder()
+{
+    rled = 0;
+    bled = 0;
+    gled = 0;
+    TFT.cls();                // clear the screen
+    TFT.set_font((unsigned char*) Arial24x23);
+    TFT.set_orientation(1);
+    TFT.locate(50,100);
+    TFT.printf("I");
+    TFT.printf("N");
+    TFT.printf("T");
+    TFT.printf("R");
+    TFT.printf("U");
+    TFT.printf("D");
+    TFT.printf("E");
+    TFT.printf("R");
+    break;
+}
+
+
+
+
+
diff -r 18c7288b5e00 -r ceeced183454 main.cpp
--- a/main.cpp	Tue Jun 14 11:01:24 2016 +0000
+++ b/main.cpp	Thu Jun 16 15:41:28 2016 +0000
@@ -1,8 +1,14 @@
-// example to test the TFT Display from Mikroelectronika
+
+//%%%%%% SERVER HUB %%%%%%%
+
 
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+//%%%%%%  Initialisations  %%%%%%%%
 #include "stdio.h"
 #include "mbed.h"
 #include "SPI_TFT_ILI9341.h"
+#include "ID12RFID.h"
 #include "string"
 #include "Arial12x12.h"
 #include "Arial24x23.h"
@@ -11,29 +17,40 @@
 
 
 Serial pc (USBTX,USBRX);
+ID12RFID rfid(PTE1);
+DigitalOut rled(LED1);
+DigitalOut gled(LED2);
+DigitalOut bled(LED3);
+
+int touching = 0;
 
 
 
 
 // the display has a backlight switch on board
-DigitalOut LCD_LED(PTA13);   // may not be needed on mikroelectronika board
-DigitalOut pwr(PTD7); // ditto
+DigitalOut LCD_LED(PTA13);   // LED Display
+DigitalOut pwr(PTD7); // Power
 
 // the TFT is connected to SPI pin 5-7
 //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc for lpc1768
 SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD5, PTD0, PTA13,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
 //NB better combination to use a coherent 2x4 block for lcd
 //   SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTA16, PTA17, PTC16,"TFT"); // mosi, miso, sclk, cs, reset, dc for frdmkl25z
-//   DigitalOut LCD_LED(PTC17);
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+//%%%%%%%%%%%  Subroutine to read the x location of the touch point  %%%%%%%%%%
+
 
 
-// Subroutine to read the x location of the touch point
 // need to set x+ to 3V and ground x- then read analogue voltage on ym
 //nb need to add a check for actual touch as opposed to random crap
+
 int readX()
 {
-    AnalogIn yp(PTB2);
-    AnalogIn ym(PTB3);
+    int delta=0,xv1=0,xv2=0,k=0;
+
+    AnalogIn yp(PTB3);
+    AnalogIn ym(PTB2);
     DigitalOut xp(PTB0);
     DigitalOut xm(PTB1);
 
@@ -42,14 +59,23 @@
     // dont need to do anyhting to set low side as it should be fine.
     // but do need to disconnect yp
     //yp.PinMode(PullNone)
-    int xval=(int)ym.read_u16();  // get value
-    return(xval);
+    for(k=0; k<10; k++) { // make 10 readings to average
+        xv1+=(int)ym.read_u16();  // get value
+        xv2+=(int)yp.read_u16(); // get other value
+    }
+    delta=abs(xv2-xv1)/10;
+    if(delta<300) touching=1;
+    else touching=0;
+// pc.printf("delta=%d \t %d\n\r",delta,touching);
+    xp=0;
+    xm=0;
+    return(xv2/10); //maybe better to return the average of both....
 }
 // subroutine to read y values - has different pin functions ..
 int readY()
 {
-    DigitalOut yp(PTB2);
-    DigitalOut ym(PTB3);
+    DigitalOut yp(PTB3);
+    DigitalOut ym(PTB2);
     AnalogIn xp(PTB0);
     AnalogIn xm(PTB1);
 
@@ -59,70 +85,362 @@
     // but do need to disconnect yp
     //yp.PinMode(PullNone)
     int yval=(int)xm.read_u16();  // get value
+
+    yp=0;
+    ym=0;
     return(yval);
 }
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+//%%%%%%  Home Display  %%%%%%%
+
+void start()
+{
+
+    pwr=1;
+    wait(0.2);
+
+    LCD_LED = 1;                // backlight on
+    rled = 1;
+    bled = 1;
+    gled = 1;
+
+    TFT.claim(stdout);          // send stdout to the TFT display
+    TFT.set_orientation(1);
+    TFT.background(Black);      // set background to black
+    TFT.foreground(Cyan);      // set chars to white
+    TFT.locate(80,110);
+    TFT.set_font((unsigned char*) Neu42x35);
+    TFT.cls();                  // clear the screen
+    TFT.printf("SmOuse");
+
+}
+
+void welcome()
+{
+    //Greeting
+    TFT.set_font((unsigned char*) Arial24x23);
+    TFT.set_orientation(1);
+    TFT.locate(50,100);
+    TFT.printf("W");
+    wait(0.05);
+    TFT.printf("e");
+    wait(0.05);
+    TFT.printf("l");
+    wait(0.05);
+    TFT.printf("c");
+    wait(0.05);
+    TFT.printf("o");
+    wait(0.05);
+    TFT.printf("m");
+    wait(0.05);
+    TFT.printf("e");
+    wait(0.05);
+    TFT.printf(",");
+    wait(0.05);
+    TFT.printf(" ");
+    wait(0.05);
+}
+
+
+void home()
+{
+    TFT.cls();
+    //show corners
+    TFT.circle(10,10,10,0xffff);
+    wait(0.1);
+    TFT.circle(308,10,10,0xffff);
+    wait(0.1);
+    TFT.circle(10,229,10,0xffff);
+    wait(0.1);
+    TFT.circle(308,229,10,0xffff);
+    wait(0.1);
+    //add menu buttons
+    TFT.rect(25,200,155,140,0xffff);
+    TFT.rect(165,200,295,140,0xffff);
+    //text for buttons
+    TFT.set_font((unsigned char*) Arial12x12);
+    TFT.locate(65,165);
+    TFT.printf("Lighting");
+    TFT.locate(195,165);
+    TFT.printf("AC Control");
+}
+
+void lights()
+{
+
+    TFT.cls();
+    TFT.locate(55,15);
+    TFT.set_font((unsigned char*) Arial24x23);
+    TFT.printf("Lighting System");
+    //show corners
+    TFT.circle(10,10,10,0xffff);
+    wait(0.1);
+    TFT.circle(308,10,10,0xffff);
+    wait(0.1);
+    TFT.circle(10,229,10,0xffff);
+    wait(0.1);
+    TFT.circle(308,229,10,0xffff);
+    wait(0.1);
+    //add menu buttons
+    TFT.rect(25,200,155,140,0xffff);
+    TFT.rect(165,200,295,140,0xffff);
+    //text for buttons
+    TFT.set_font((unsigned char*) Arial12x12);
+    TFT.locate(50,165);
+    TFT.printf("LIGHTS OFF");
+    TFT.locate(190,165);
+    TFT.printf("LIGHTS ON");
+}
+
+void temps()
+{
+
+    TFT.cls();
+    TFT.locate(90,15);
+    TFT.set_font((unsigned char*) Arial24x23);
+    TFT.printf("AC System");
+    //show corners
+    TFT.circle(10,10,10,0xffff);
+    wait(0.1);
+    TFT.circle(308,10,10,0xffff);
+    wait(0.1);
+    TFT.circle(10,229,10,0xffff);
+    wait(0.1);
+    TFT.circle(308,229,10,0xffff);
+    wait(0.1);
+    //add menu buttons
+    TFT.rect(25,200,155,140,0xffff);
+    TFT.rect(165,200,295,140,0xffff);
+    //text for buttons
+    TFT.set_font((unsigned char*) Arial12x12);
+    TFT.locate(60,165);
+    TFT.printf("FAN OFF");
+    TFT.locate(200,165);
+    TFT.printf("FAN ON");
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+//%%%%%  IDs  %%%%%%
+
+void ben()
+{
+
+    rled = 0;
+    bled = 1;
+    gled = 1;
+
+    TFT.printf("B");
+    wait(0.05);
+    TFT.printf("e");
+    wait(0.05);
+    TFT.printf("n");
+    wait(0.05);
+}
+
+void joe()
+{
+    rled = 1;
+    bled = 0;
+    gled = 1;
+
+    TFT.printf("J");
+    wait(0.05);
+    TFT.printf("o");
+    wait(0.05);
+    TFT.printf("e");
+    wait(0.05);
+
+}
+
+void arthur()
+{
+    rled = 1;
+    bled = 0;
+    gled = 1;
+
+    TFT.printf("A");
+    wait(0.05);
+    TFT.printf("r");
+    wait(0.05);
+    TFT.printf("t");
+    wait(0.05);
+    TFT.printf("h");
+    wait(0.05);
+    TFT.printf("u");
+    wait(0.05);
+    TFT.printf("r");
+    wait(0.05);
+
+}
+
+void intruder()
+{
+    rled = 0;
+    bled = 0;
+    gled = 0;
+    TFT.cls();                // clear the screen
+    TFT.set_font((unsigned char*) Neu42x35);
+    TFT.locate(45,105);
+    TFT.foreground(Red);
+    TFT.printf("INTRUDER!");
+    wait(0.4);
+    TFT.cls();
+    wait(0.2);
+    TFT.locate(45,105);
+    TFT.printf("INTRUDER!");
+    wait(0.4);
+    TFT.cls();
+    wait(0.2);
+    TFT.locate(45,105);
+    TFT.printf("INTRUDER!");
+    wait(0.4);
+    TFT.cls();
+    wait(0.2);
+    TFT.locate(45,105);
+    TFT.printf("INTRUDER!");
+    wait(0.4);
+    TFT.cls();
+    wait(0.2);
+    TFT.locate(45,105);
+    TFT.foreground(White);
+    TFT.cls();
+    rled = 1;
+    bled = 1;
+    gled = 1;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 
 
 
 int main()
 {
+    int display = 0;
+    int reading = 0;
+    int id = 0;
+//   int light = 0;
+//   int temp = 0;
+
     pc.baud(115200);
 
     int xpos=0,ypos=0,xp=0,yp=0;
-    pwr=1;
-    wait(0.2);
+
+    while (1) {
+
+        pc.printf("%d",id);
+
+        switch (display) {
+
+            case 0 : //start screen
+
+                start();
+
+                while (display == 0) {
 
-    int i;
-    LCD_LED = 1;            // backlight on
+                    reading = rfid.readable();
+                    if (reading) {
+                        display = 1;    //FOR TESTING LIGHTING, SHOULD BE 1
+                        id = rfid.read();
+                    }
+
+                }
+                break;
+
+            case 1 : //welcome screen
+
+        //        id = rfid.read();
+                home();
 
-    TFT.claim(stdout);        // send stdout to the TFT display
-    TFT.set_orientation(1);
-    TFT.background(Black);    // set background to black
-    TFT.foreground(White);    // set chars to white
-    TFT.cls();                // clear the screen
+                //Personalised
+                switch (id) {
+
+                    case 22311780 : //Ben
+                        welcome();
+                        ben();
+                        break;
+
+                    case 22320978 : //Joe
+                        welcome();
+                        joe();
+                        break;
 
-    //first show the 4 directions
-    TFT.set_orientation(0);
-    TFT.background(Black);
-    TFT.cls();
+                    case 22352757 : //Arthur
+                        welcome();
+                        arthur();
+                        break;
+
+                    default : //intruder case
+                        intruder();
+                        display = 0;
+                        break;
+                }
+                if (display == 0) { //intruder restarts system
+                    break;
+                }
+                while (display == 1) {
+                    //%%%%% TOUCH %%%%%%
+                    TFT.set_orientation(0);
+                    xpos= readX();
+                    ypos= readY();
 
-    TFT.set_font((unsigned char*) Arial12x12);
-    TFT.locate(0,0);
-    printf(" 0 Hello Mbed 0");
-    TFT.set_orientation(1);
-    TFT.locate(0,0);
-    printf(" 1 Hello Mbed 1");
-    TFT.set_orientation(2);
-    TFT.locate(0,0);
-    printf(" 2 Hello Mbed 2");
-    TFT.set_orientation(3);
-    TFT.locate(0,0);
-    printf(" 3 Hello Mbed 3");
-    TFT.set_orientation(3);
-    TFT.set_font((unsigned char*) Arial24x23);
-    TFT.locate(50,100);
-    TFT.printf("TFT orientation 3");
-    TFT.set_orientation(1);
-    for(i=0; i<10; i++) {
-        wait(1);        // wait one seconds
-        TFT.locate(50,160);
-        TFT.printf("count %d",i);
+                    xp=(240*(xpos-5800))/51200;
+                    yp=320-(320*(ypos-3000))/58300;
+
+                    if (yp<50 && touching==1) { //button for lighting
+
+                        display = 2;            //jump to lights
+                        TFT.set_orientation(1);
+                    }
+                    
+                    if (yp>270 && touching==1) { //button for ac system
+
+                        display = 3;            //jump to ac
+                        TFT.set_orientation(1);
+                    }
+                    
+                    
+                    //%%%%%% RFID Override %%%%%%%%
+                    reading = rfid.readable();
+                    if (reading) {
+                        id = rfid.read();
+                        TFT.set_orientation(1);
+                        break;
+                    }
+                }
+                break;
+
+
+
+            case 2 : //lighting screen
+
+
+                lights();
+                TFT.locate(50,100);
+                TFT.printf("I reached the light screen");
+
+                while (display == 2) {
+
+                    wait(2);
+                    display = 1;
+                }
+                break;
+            
+            case 3 : //temperature screen
+
+
+                temps();
+                TFT.locate(50,100);
+                TFT.printf("I reached the temp screen");
+
+                while (display == 3) {
+
+                    wait(2);
+                    display = 1;
+                }
+                break;
+
+
+        }
     }
-    TFT.set_orientation(1);
-    TFT.cls();
-    //   LCD_LED = 1;
-    TFT.circle(120,120,10,0xffff);
-    while(1==1) {
-
-        xpos=readX();
-        ypos=readY();
-        pc.printf("xpos=%d\t,\typo=%d",xpos,ypos);
-        xp=(240*xpos)/60000;
-        yp=(320*ypos)/60000;
-        pc.printf("\txp=%d\t,\typo=%d\n\r",xp,yp);
-        if(xp>5 && yp>5) TFT.circle(xp,yp,5,Yellow);
-        wait(0.1);
-
-    }
-
-}
+}
\ No newline at end of file
diff -r 18c7288b5e00 -r ceeced183454 mbed.bld
--- a/mbed.bld	Tue Jun 14 11:01:24 2016 +0000
+++ b/mbed.bld	Thu Jun 16 15:41:28 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file