bruker nå ny serial klasse med større hastighet.. Forøvrig baser en del av koden på Flaskepant oppgaven fra lab.

Dependencies:   SerialTerminal mbed

Fork of Fancy-Terminal by El-POM1001

Revision:
4:14bd961881ff
Parent:
3:35b0711f1832
Child:
5:529715bcff18
--- a/main.cpp	Thu Oct 15 17:02:36 2015 +0000
+++ b/main.cpp	Thu Oct 15 18:51:22 2015 +0000
@@ -1,24 +1,127 @@
-// simple test for a ANSI/VT100 Terminal, sford
-
 #include "mbed.h"
 #include "Terminal.h"
+#include "variables.h"
 
 Terminal term(USBTX, USBRX); // tx, rx
 
+
+//Prototypes
+void Beregn(void);
+void FlaskeRegistrering(int);
+void utskriftskjerm(void);
+void utskriftskjermV2(void);
+void UpdateTerminal(void);
+
 int main() {
-    
-    
-    while(1)
-    {
+
+    /*  
+    1. Type 1: 1/3 liter
+    2. Type 2: 1/2 liter
+    3. Type 3: 1 liter
+    4. Type 4: 1 1/2 liter
+    5. Type 5: Ukurante flasker
+    */
+
+
+    char cValg = -1;
     term.cls();
-    term.locate(20,10);
-    term.printf("How are you?");
-    wait(2);
-    term.locate(20,11);
-    term.foreground(0xFF0000);
-    term.background(0x000007F);
-    term.printf("I'm Great!");
-    term.hideCursor();
-    wait(2);
+    term.locate(MENUPOSX, MENUPOSY);
+    UpdateTerminal();
+    //term.printf("Velkommen skriv inn flaske type etterfolg av enter tast\n");
+    while (1)
+    {
+    //while (iValg != 0)
+    //{
+
+       // scanf("%d", &iValg);
+        cValg = getchar();
+        if (cValg <= 57 || cValg >= 48)
+        {
+            if      (cValg == 49) FlaskeRegistrering(0);
+            else if (cValg == 50) FlaskeRegistrering(1);
+            else if (cValg == 51) FlaskeRegistrering(2);
+            else if (cValg == 52) FlaskeRegistrering(3);
+            else if (cValg != 48) FlaskeRegistrering(4);
+        }
+        else
+        {
+            //printf("ugyldig inntasting\n");
+        }
+     //}
+        wait(0.03);
     }
 }
+
+void Beregn()
+{
+    char *ptr_antall_type = &menu[66 * 3 + 28];
+    char *ptr_kr_type = ptr_antall_type + 10;
+    char *ptr_total;
+    int iTotalFlasker = 0;
+    float fTotalFlaskePris = 0.00;
+    char buffer[15];
+    int iKr_Offset = 66;
+
+    for (int i = 0; i < TYPES; i++, ptr_antall_type += iKr_Offset, ptr_kr_type += iKr_Offset)
+    {
+        iTotalFlasker += aiFlaskeType[i];
+        fTotalFlaskePris += aiFlaskeType[i] * aiFlaskeTypePrice[i];
+
+        if (i <= 3)
+        {
+            //Flaske antall
+            sprintf(buffer, "%2d", aiFlaskeType[i]);
+            memcpy(ptr_antall_type, buffer, 2);
+            //Flaske pris
+            sprintf(buffer, "%6.2f", (aiFlaskeType[i] * aiFlaskeTypePrice[i]));
+            memcpy(ptr_kr_type, buffer, 6);
+
+        }
+        else
+        {
+            sprintf(buffer, "%2d", aiFlaskeType[i]);
+            memcpy(ptr_antall_type, buffer, 2);
+        }
+    }
+
+    ptr_total = ptr_antall_type + (46);
+
+    //Flaske totoal antall
+    sprintf(buffer, "%3d", iTotalFlasker);
+    memcpy(ptr_total, buffer, 3);
+    ptr_total += 19;
+    sprintf(buffer, "%6.2f", fTotalFlaskePris);
+    memcpy(ptr_total, buffer, 6);
+}
+
+void FlaskeRegistrering(int FlaskeType)
+{
+    aiFlaskeType[FlaskeType]++;
+    UpdateTerminal();
+}
+
+void UpdateTerminal()
+{
+    Beregn();
+    utskriftskjermV2(); 
+}
+
+void utskriftskjermV2()
+{
+    char *ptr_menu = menu;
+    term.cls();
+    term.locate(MENUPOSX, MENUPOSY);
+    term.foreground(0xFF0000);
+
+    for (int i = 1; i <= MENULINES; i++)
+    {
+        for (int j = 1; j <= MENUWIDTH; j++, ptr_menu++)
+        {
+            term.printf("%c", *ptr_menu);
+
+        }
+        term.locate(MENUPOSX, i + MENUPOSY);
+        //term.printf("\n");
+    }
+    //term.printf("\n");
+}
\ No newline at end of file