El-POM1001
/
Fancy-Terminal
Cool Fancy Terminal
Fork of Terminal_HelloWorld by
Revision 4:14bd961881ff, committed 2015-10-15
- Comitter:
- madmonkeyman82
- Date:
- Thu Oct 15 18:51:22 2015 +0000
- Parent:
- 3:35b0711f1832
- Commit message:
- Denne er kul... m? testes... bruk Coolterm eller puTTY
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
variables.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 35b0711f1832 -r 14bd961881ff main.cpp --- 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
diff -r 35b0711f1832 -r 14bd961881ff variables.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/variables.h Thu Oct 15 18:51:22 2015 +0000 @@ -0,0 +1,27 @@ +#include "mbed.h" + +//defines +#define TYPES 5 +#define MENUWIDTH 66 +#define MENULINES 11 +#define MENUPOSX 5 +#define MENUPOSY 5 + +//Variables +char menu[] = +{ +"|----------------------------------------------------------------|" +"| ~Flaskepantkvitering~ |" +"|----------------------------------------------------------------|" +"|Antall flasker av type 1 : xx gir kr xxx.xx |" +"|Antall flasker av type 2 : xx gir kr xxx.xx |" +"|Antall flasker av type 3 : xx gir kr xxx.xx |" +"|Antall flasker av type 4 : xx gir kr xxx.xx |" +"|Antall flasker av type 5 : xx |" +"|----------------------------------------------------------------|" +"|TOTALT xxx flasker gir kr xxx.xx |" +"|----------------------------------------------------------------|" +}; + +static int aiFlaskeType[TYPES] = { 0,0,0,0,0 }; +static float aiFlaskeTypePrice[TYPES] = {1.00,1.00,2.00,2.00,0.00}; \ No newline at end of file