versione al 6/5/18

Dependencies:   BSP_DISCO_F469NI LCD_DISCO_F469NI Shifter2 TS_DISCO_F469NI max31865 mbed

Revision:
0:c051cea27cbf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun May 06 14:32:42 2018 +0000
@@ -0,0 +1,226 @@
+#include "mbed.h"
+#include "TS_DISCO_F469NI.h"
+#include "LCD_DISCO_F469NI.h"
+#include "MAX31865.h"
+
+#include "AClean.c"
+#include "APower.c"
+#include "ARoast.c"
+#include "APulsanti.c"
+#include "Porta_aperto.c"
+#include "Porta_chiuso.c"
+#include "Giracaffe_acceso.c"
+#include "Giracaffe_spento.c"
+#include "Lampadina_acceso.c"
+#include "Lampadina_spento.c"
+#include "VTangenziale_acceso.c"
+#include "VTangenziale_spento.c"
+#include "VRadiale_acceso.c"
+#include "VRadiale_spento.c"
+#include "Resistenza1_acceso.c"
+#include "Resistenza1_spento.c"
+#include "Resistenza2_acceso.c"
+#include "Resistenza2_spento.c"
+#include "Ventola_acceso.c"
+#include "Ventola_spento.c"
+
+#include "functions.h"
+#include "colors.c"
+#include "Output.h"
+
+extern void clean(int, float, float);
+extern void roast(int, int);
+extern void stop();
+
+extern void temperature_update();
+
+bool stato_porta=0;             //da cancellare, solo per prova porta
+int tempo =1200;
+int temperatura = 250;
+
+int main()
+{
+    setup_griglia();            //setup, parte grafica
+    getData();                  //acquisisce lo stato degli switch
+    temperature_update();       //acquisisce le temperature
+    
+    while(1) {
+//acquisisco la pressione sullo schermo per attivare i vari oggetti
+        ts.GetState(&TS_State);
+        X = TS_State.touchX[0];                             //acquisisco la X
+        Y = TS_State.touchY[0];                             //acquisisco la Y
+
+//------------------------------------------------------------------------------
+///solo per prova
+        if ((TS_State.touchDetected) && (X>=230 && X<300 && Y>=20 && Y<90))    {
+            Lampadina.stato=!Lampadina.stato;
+            object_update();
+        }
+        if ((TS_State.touchDetected) && (X>=300 && X<370 && Y>=20 && Y<90))    {
+            Resistenza1.stato=!Resistenza1.stato;
+            object_update();
+        }
+        if ((TS_State.touchDetected) && (X>=370 && X<440 && Y>=20 && Y<90))    {
+            Resistenza2.stato=!Resistenza2.stato;
+            object_update();
+        }
+        if ((TS_State.touchDetected) && (X>=440 && X<510 && Y>=20 && Y<90))    {
+            Giracaffe.stato=!Giracaffe.stato;
+            object_update();
+        }
+        if ((TS_State.touchDetected) && (X>=230 && X<300 && Y>=90 && Y<160))   {
+            stato_porta=!stato_porta;
+            (stato_porta==1) ? chiudo_porta() : apro_porta();
+        }
+        if ((TS_State.touchDetected) && (X>=300 && X<370 && Y>=90 && Y<160))   {
+            VTangenziale.stato=!VTangenziale.stato;
+            object_update();
+        }
+        if ((TS_State.touchDetected) && (X>=370 && X<440 && Y>=90 && Y<160))   {
+            VRadiale.stato=!VRadiale.stato;
+            object_update();
+        }
+        if ((TS_State.touchDetected) && (X>=440 && X<510 && Y>=90 && Y<160))   {
+            Ventola.stato=!Ventola.stato;
+            object_update();
+        }
+        if ((TS_State.touchDetected) && (X>=620 && X<690 && Y>=20 && Y<90))    {
+            Apro_scarico();
+        }
+        if ((TS_State.touchDetected) && (X>=620 && X<690 && Y>=100 && Y<170))  {
+            Chiudo_scarico();
+        }
+//------------------------------------------------------------------------------        
+        
+        ////////////////////////////////////////////////////////////////////////
+    //if ROAST pressed
+        if ((TS_State.touchDetected) && (X>=20 && X<140 && Y>=290 && Y<410))   {       
+            roast(temperatura,tempo);
+        }
+    //if CLEAN pressed
+        if ((TS_State.touchDetected) && (X>=20 && X<140 && Y>=165 && Y<285))   {       
+            clean(12, 430.0, 460.0);
+        }
+    //if STOP pressed
+        if ((TS_State.touchDetected) && (X>=20 && X<140 && Y>=20 && Y<140))    {       
+            stop();
+        }
+    //if TEMPERATURA UPPER pressed
+        if ((TS_State.touchDetected) && (X>=200 && X<260 && Y>=270 && Y<330))  {
+            temperatura = temperatura+5;
+            if (temperatura >300) temperatura =300;
+        }
+    //if TEMPERATURA LOWER pressed
+        if ((TS_State.touchDetected) && (X>=200 && X<260 && Y>=350 && Y<410))  {
+            temperatura = temperatura-5;
+            if (temperatura <150) temperatura =150;
+        }
+    //if TEMPO UPPER pressed
+        if ((TS_State.touchDetected) && (X>=325 && X<385 && Y>=270 && Y<330))  {
+            tempo = tempo+15;
+            if (tempo >3000) tempo =3000;
+        }
+    //if TEMPO LOWER pressed
+        if ((TS_State.touchDetected) && (X>=325 && X<385 && Y>=350 && Y<410))  {
+            tempo = tempo-15;
+            if (tempo <120) tempo =120;
+        }
+//------------------------------------------------------------------------------        
+//scrivo minuti e secondi
+        int minuti = tempo/60;
+        int secondi = tempo%60;
+        sprintf((char*)text, "%2d", minuti);
+        lcd.DisplayStringAt(295,LINE(8), (uint8_t *)&text, LEFT_MODE);
+        sprintf((char*)text, "%2d", secondi);
+        lcd.DisplayStringAt(350,LINE(8), (uint8_t *)&text, LEFT_MODE);
+//scrivo temperatura
+        sprintf((char*)text, "%3d", temperatura);
+        lcd.DisplayStringAt(295,LINE(10), (uint8_t *)&text, LEFT_MODE);     
+//------------------------------------------------------------------------------          
+        object_update();
+        getData();
+        temperature_update();
+
+        wait(0.1);
+    }//close while(1)
+}//close main
+
+//CLEAN
+void clean(int clean_time, float setpointLOW, float setpointHIGH)
+{
+    //non procedo fino a quando la porta non è chiusa, lo scarico deve essere chiuso e anche il tappo del caffè
+    //per precauzione forzo le resistenze a essere spente
+    do {
+        Resistenza1_spento();
+        Resistenza2_spento();
+    } while (!chiudo_porta());
+
+    lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"CLEAN ATTIVO             ", LEFT_MODE);
+    Timer timer;
+    timer.start();
+    int previous_time, actual_time;
+    previous_time = timer.read();
+    Lampadina_acceso();
+    VRadiale_acceso();
+    while(1) {
+        actual_time = timer.read();
+        uint8_t text[30];
+        //acquisisco la pressione sullo schermo per vedere se devo stoppare il ciclo mentre faccio il clean
+        ts.GetState(&TS_State);
+        int X = TS_State.touchX[0];
+        int Y = TS_State.touchY[0];
+        if ((TS_State.touchDetected) && (X>=20 && X<140 && Y>=235 && Y<335)) {                //STOP
+            stop();
+            break;
+        }
+        //countdown dal clean_time a zero
+        if (actual_time-previous_time >=1) {
+            lcd.SetTextColor(black);
+            sprintf((char*)text, "%5d", clean_time);
+            lcd.DisplayStringAt(210,LINE(18), (uint8_t *)&text, LEFT_MODE);
+            previous_time = actual_time;
+            clean_time--;
+        }
+        //se il tempo di clean è finito avvio la procedura di stop
+        if (clean_time<0) {
+            stop();
+            break;
+        }
+    }
+}
+
+//STOP procedura di stop
+void stop()
+{
+    lcd.DisplayStringAt(10, LINE(18), (uint8_t *)"STOP                     ", LEFT_MODE);
+    lcd.DisplayStringAt(260,LINE(18), (uint8_t *)"      ", LEFT_MODE);
+    //spengo le resistenze
+    Resistenza1_spento();
+    Resistenza2_spento();
+
+//tengo fino a quando la temperatura non è sotto i 150 gradi
+    //tengo acceso per 5 secondi le ventole, lampade e giracaffe
+    VRadiale_acceso();
+    VTangenziale_acceso();
+    Ventola_acceso();
+    Lampadina_acceso();
+    Giracaffe_acceso();
+    wait (5.0);
+
+    //spengo tutto
+    VRadiale_spento();
+    VTangenziale_spento();
+    Ventola_spento();
+    Lampadina_spento();
+    Giracaffe_spento();
+    //scarico caffe
+
+    //apertura porta
+    apro_porta();
+}
+
+//ROAST
+void roast (int roast_temp, int roast_time)
+{
+
+}