a

Dependencies:   EthernetInterface HTTPClient MFRC522 MbedJSONValue TextLCD mbed-rtos mbed

Fork of HEINEKEN_FRDM_K64F by Matija Slovic

Revision:
2:c8618b0777d3
Parent:
1:91f852e8c07f
Child:
3:0b3943b9655d
--- a/main.cpp	Wed Mar 02 19:30:09 2016 +0000
+++ b/main.cpp	Thu Mar 03 15:36:06 2016 +0000
@@ -7,19 +7,17 @@
 
 #define MF_RESET    PTD0
 
-DigitalOut          LedGreen(PTE26);
+DigitalOut          LedRed(LED2);
+DigitalOut          LedGreen(LED1);
 Serial              pc(USBTX, USBRX);
 TextLCD             lcd(PTC3, PTC2, PTA2, PTB23, PTA1, PTB9, TextLCD::LCD20x4); // rs, e, d4-d7
 MFRC522             RfChip(PTD2, PTD3, PTD1, PTE25, PTD0);           // mosi, miso, sclk, cs, reset
 DigitalOut          ventil(PTB18);
-InterruptIn         sensor(PTE24);
-
+InterruptIn         FLOW(PTE24);
 
-int rfID, Count, Calc;
-float CalcMl;
-float sum=0;
-int RFID[15];
-
+int Count; 
+//float Calc_mL, Calc_L;
+float VOL;
 
 void rpm()
 {
@@ -27,69 +25,70 @@
 }
 void ScreenSTART()
 {
-
     lcd.cls();
     lcd.printf("      HEINEKEN\n\n");
-
     lcd.printf(" Set your bracelet\n");
     lcd.printf(" against the reader");
 }
 void ScreenNATOCI(int left)
 {
     lcd.cls();
-    lcd.printf("Left %d beers.\n\n",left);
-    lcd.printf("Pour your beer!");
-    wait(2);
-    ScreenSTART();
-
+    lcd.printf("Pour your beer!\n\n");
+    lcd.printf("Left %d beers.",left);
 }
 void ScreenNEMA()
 {
     lcd.cls();
-    lcd.printf("Sorry no beear for you!");
-    wait(2);
+    lcd.printf("\n   Sorry no more\n   beer for you.");
+    wait(4);
     ScreenSTART();
 }
 void ScreenTNX()
 {
     lcd.cls();
-    lcd.printf("\nThank you for consumption!");
-    wait(2);
+    lcd.printf("\n     Thank you\n  for consumption!");
+    wait(4);
     ScreenSTART();
 }
-void WrongID()
+void ScreenWrongID()
 {
     lcd.cls();
-    lcd.printf("\n You do not have\n the correct bracelet!");
-    wait(2);
+    lcd.printf("\n  You do not have\n    the correct\n     bracelet!");
+    wait(4);
     ScreenSTART();
 }
 
 int main(void)
 {
-
-    //ventil = 0;
+    LedRed = 0;
+    LedGreen = 0;
+    ventil = 1;
+    Count = 0;
 
-    lcd.printf("Starting..\n");
-    pc.printf("Starting..\n");
+    lcd.printf("Starting...\n\n");
+    pc.printf("\nStarting..\n");
 
     EthernetInterface eth;
     eth.init("10.10.0.2","255.255.255.0","10.10.0.1"); //Use DHCP
     eth.connect();
-    pc.printf("IP Address is %s\n\r", eth.getIPAddress());
+    //pc.printf("IP Address is %s\n\r", eth.getIPAddress());
     TCPSocketConnection sock;
 
-
     RfChip.PCD_Init();
 
-    rfID = 0;
-    Count = 0;
+    lcd.printf("Ready");
+    //pc.printf("Ready");
+    LedRed = 1; wait(.4);
+    LedRed = 0; wait(.4);
+    LedRed = 1; wait(.4);
+    LedRed = 0; wait(.4);
+    LedRed = 1; wait(.4);
+    
     ScreenSTART();
 
-    lcd.printf("Ready\n");
-    pc.printf("Ready\n");
     while(1) {
-
+        VOL = 0;
+        LedRed = 1;
         LedGreen = 0;
         Count = 0;
 
@@ -97,14 +96,10 @@
             wait_ms(500);
             continue;
         }
-        // Select one of the cards
         if ( ! RfChip.PICC_ReadCardSerial()) {
             wait_ms(500);
             continue;
         }
-
-        LedGreen = 1;
-
         char cID[22];
         for (int i = 0; i < RfChip.uid.size; i++) {
             sprintf(cID+i*2, "%X02", RfChip.uid.uidByte[i]);
@@ -139,26 +134,49 @@
         MbedJSONValue responseJSON;
         parse(responseJSON, response.c_str());
 
-        bool tap = responseJSON["tap"].get<bool>();
+        int tap = responseJSON["tap"].get<int>();
         int left = responseJSON["left"].get<int>();
 
-        pc.printf("tociti ili ne?  %d",tap);
-        pc.printf("preostalo piva  %d",left);
+        pc.printf("tap?  %d \n\r",tap);
+        pc.printf("left beer  %d \n\r",left);
+        
+        //pc.printf("%s \n\r",responseFULL);
         
-        if(tap!=1){
+        if(tap < 0) {
+            ScreenWrongID();
+        }    
+        if(tap == 0) {
+            ventil = 1;
+            ScreenNEMA();
+        }
+        if(tap == 1) {
             ventil = 0;
-            ScreenNEMA();
+            ScreenNATOCI(left);
+
+            while(ventil==0) {
+                LedGreen = 1;
+                LedRed = 0;
+                FLOW.rise(&rpm);              
+                wait_ms(1000);                
+                FLOW.rise(NULL);              
+
+                //Calc = (Count * 60) / 7.5;                //flow rate in L/hour
+                //CalcMl = (Count * 8) / 3.6;               //flow rate in mL/hour        
+                //pc.printf ("Flow L/hour: %d\r\n",Calc);  
+                //pc.printf ("Flow mL/s: %.2f\r\n",CalcMl);  
+
+                VOL += Count;
+                //pc.printf("Sum = %.2f\n\r",sum);
+                
+                if(VOL>100) {
+                    ventil = 1;
+                    ScreenTNX();             
+                }
             }
-        if(tap==1){
-            ventil = 1;
-            ScreenNATOCI(left);
-            }
-
+        }
     }
-
-
 }
+     
 
 
 
-