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

Committer:
madmonkeyman82
Date:
Fri Oct 16 16:22:25 2015 +0000
Revision:
6:e82da1b9e11a
Parent:
5:529715bcff18
testet med hastighet opp til 115200 bit/sek

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 0:93888862261d 1 #include "mbed.h"
madmonkeyman82 5:529715bcff18 2 #include "SerialTerminal.h"
madmonkeyman82 4:14bd961881ff 3 #include "variables.h"
simon 0:93888862261d 4
madmonkeyman82 6:e82da1b9e11a 5 SerialTerminal pc(USBTX, USBRX, 115200); // tx, rx
simon 0:93888862261d 6
madmonkeyman82 4:14bd961881ff 7
madmonkeyman82 4:14bd961881ff 8 //Prototypes
madmonkeyman82 4:14bd961881ff 9 void Beregn(void);
madmonkeyman82 4:14bd961881ff 10 void FlaskeRegistrering(int);
madmonkeyman82 4:14bd961881ff 11 void utskriftskjerm(void);
madmonkeyman82 4:14bd961881ff 12 void utskriftskjermV2(void);
madmonkeyman82 4:14bd961881ff 13 void UpdateTerminal(void);
madmonkeyman82 4:14bd961881ff 14
simon 0:93888862261d 15 int main() {
madmonkeyman82 4:14bd961881ff 16
madmonkeyman82 4:14bd961881ff 17 /*
madmonkeyman82 4:14bd961881ff 18 1. Type 1: 1/3 liter
madmonkeyman82 4:14bd961881ff 19 2. Type 2: 1/2 liter
madmonkeyman82 4:14bd961881ff 20 3. Type 3: 1 liter
madmonkeyman82 4:14bd961881ff 21 4. Type 4: 1 1/2 liter
madmonkeyman82 4:14bd961881ff 22 5. Type 5: Ukurante flasker
madmonkeyman82 4:14bd961881ff 23 */
madmonkeyman82 4:14bd961881ff 24
madmonkeyman82 4:14bd961881ff 25
madmonkeyman82 4:14bd961881ff 26 char cValg = -1;
madmonkeyman82 5:529715bcff18 27 pc.cls();
madmonkeyman82 5:529715bcff18 28 pc.locate(MENUPOSX, MENUPOSY);
madmonkeyman82 5:529715bcff18 29 pc.hideCursor();
madmonkeyman82 4:14bd961881ff 30 UpdateTerminal();
madmonkeyman82 4:14bd961881ff 31 //term.printf("Velkommen skriv inn flaske type etterfolg av enter tast\n");
madmonkeyman82 4:14bd961881ff 32 while (1)
madmonkeyman82 4:14bd961881ff 33 {
madmonkeyman82 4:14bd961881ff 34 //while (iValg != 0)
madmonkeyman82 4:14bd961881ff 35 //{
madmonkeyman82 4:14bd961881ff 36
madmonkeyman82 4:14bd961881ff 37 // scanf("%d", &iValg);
madmonkeyman82 4:14bd961881ff 38 cValg = getchar();
madmonkeyman82 4:14bd961881ff 39 if (cValg <= 57 || cValg >= 48)
madmonkeyman82 4:14bd961881ff 40 {
madmonkeyman82 4:14bd961881ff 41 if (cValg == 49) FlaskeRegistrering(0);
madmonkeyman82 4:14bd961881ff 42 else if (cValg == 50) FlaskeRegistrering(1);
madmonkeyman82 4:14bd961881ff 43 else if (cValg == 51) FlaskeRegistrering(2);
madmonkeyman82 4:14bd961881ff 44 else if (cValg == 52) FlaskeRegistrering(3);
madmonkeyman82 4:14bd961881ff 45 else if (cValg != 48) FlaskeRegistrering(4);
madmonkeyman82 4:14bd961881ff 46 }
madmonkeyman82 4:14bd961881ff 47 else
madmonkeyman82 4:14bd961881ff 48 {
madmonkeyman82 4:14bd961881ff 49 //printf("ugyldig inntasting\n");
madmonkeyman82 4:14bd961881ff 50 }
madmonkeyman82 4:14bd961881ff 51 //}
madmonkeyman82 4:14bd961881ff 52 wait(0.03);
madmonkeyman82 2:89b263d1a399 53 }
simon 0:93888862261d 54 }
madmonkeyman82 4:14bd961881ff 55
madmonkeyman82 4:14bd961881ff 56 void Beregn()
madmonkeyman82 4:14bd961881ff 57 {
madmonkeyman82 4:14bd961881ff 58 char *ptr_antall_type = &menu[66 * 3 + 28];
madmonkeyman82 4:14bd961881ff 59 char *ptr_kr_type = ptr_antall_type + 10;
madmonkeyman82 4:14bd961881ff 60 char *ptr_total;
madmonkeyman82 4:14bd961881ff 61 int iTotalFlasker = 0;
madmonkeyman82 4:14bd961881ff 62 float fTotalFlaskePris = 0.00;
madmonkeyman82 4:14bd961881ff 63 char buffer[15];
madmonkeyman82 4:14bd961881ff 64 int iKr_Offset = 66;
madmonkeyman82 4:14bd961881ff 65
madmonkeyman82 4:14bd961881ff 66 for (int i = 0; i < TYPES; i++, ptr_antall_type += iKr_Offset, ptr_kr_type += iKr_Offset)
madmonkeyman82 4:14bd961881ff 67 {
madmonkeyman82 4:14bd961881ff 68 iTotalFlasker += aiFlaskeType[i];
madmonkeyman82 4:14bd961881ff 69 fTotalFlaskePris += aiFlaskeType[i] * aiFlaskeTypePrice[i];
madmonkeyman82 4:14bd961881ff 70
madmonkeyman82 4:14bd961881ff 71 if (i <= 3)
madmonkeyman82 4:14bd961881ff 72 {
madmonkeyman82 4:14bd961881ff 73 //Flaske antall
madmonkeyman82 4:14bd961881ff 74 sprintf(buffer, "%2d", aiFlaskeType[i]);
madmonkeyman82 4:14bd961881ff 75 memcpy(ptr_antall_type, buffer, 2);
madmonkeyman82 4:14bd961881ff 76 //Flaske pris
madmonkeyman82 4:14bd961881ff 77 sprintf(buffer, "%6.2f", (aiFlaskeType[i] * aiFlaskeTypePrice[i]));
madmonkeyman82 4:14bd961881ff 78 memcpy(ptr_kr_type, buffer, 6);
madmonkeyman82 4:14bd961881ff 79
madmonkeyman82 4:14bd961881ff 80 }
madmonkeyman82 4:14bd961881ff 81 else
madmonkeyman82 4:14bd961881ff 82 {
madmonkeyman82 4:14bd961881ff 83 sprintf(buffer, "%2d", aiFlaskeType[i]);
madmonkeyman82 4:14bd961881ff 84 memcpy(ptr_antall_type, buffer, 2);
madmonkeyman82 4:14bd961881ff 85 }
madmonkeyman82 4:14bd961881ff 86 }
madmonkeyman82 4:14bd961881ff 87
madmonkeyman82 4:14bd961881ff 88 ptr_total = ptr_antall_type + (46);
madmonkeyman82 4:14bd961881ff 89
madmonkeyman82 4:14bd961881ff 90 //Flaske totoal antall
madmonkeyman82 4:14bd961881ff 91 sprintf(buffer, "%3d", iTotalFlasker);
madmonkeyman82 4:14bd961881ff 92 memcpy(ptr_total, buffer, 3);
madmonkeyman82 4:14bd961881ff 93 ptr_total += 19;
madmonkeyman82 4:14bd961881ff 94 sprintf(buffer, "%6.2f", fTotalFlaskePris);
madmonkeyman82 4:14bd961881ff 95 memcpy(ptr_total, buffer, 6);
madmonkeyman82 4:14bd961881ff 96 }
madmonkeyman82 4:14bd961881ff 97
madmonkeyman82 4:14bd961881ff 98 void FlaskeRegistrering(int FlaskeType)
madmonkeyman82 4:14bd961881ff 99 {
madmonkeyman82 4:14bd961881ff 100 aiFlaskeType[FlaskeType]++;
madmonkeyman82 4:14bd961881ff 101 UpdateTerminal();
madmonkeyman82 4:14bd961881ff 102 }
madmonkeyman82 4:14bd961881ff 103
madmonkeyman82 4:14bd961881ff 104 void UpdateTerminal()
madmonkeyman82 4:14bd961881ff 105 {
madmonkeyman82 4:14bd961881ff 106 Beregn();
madmonkeyman82 4:14bd961881ff 107 utskriftskjermV2();
madmonkeyman82 4:14bd961881ff 108 }
madmonkeyman82 4:14bd961881ff 109
madmonkeyman82 4:14bd961881ff 110 void utskriftskjermV2()
madmonkeyman82 4:14bd961881ff 111 {
madmonkeyman82 4:14bd961881ff 112 char *ptr_menu = menu;
madmonkeyman82 5:529715bcff18 113 pc.cls();
madmonkeyman82 5:529715bcff18 114 pc.locate(MENUPOSX, MENUPOSY);
madmonkeyman82 5:529715bcff18 115 pc.foreground(0xFF0000);
madmonkeyman82 4:14bd961881ff 116
madmonkeyman82 4:14bd961881ff 117 for (int i = 1; i <= MENULINES; i++)
madmonkeyman82 4:14bd961881ff 118 {
madmonkeyman82 4:14bd961881ff 119 for (int j = 1; j <= MENUWIDTH; j++, ptr_menu++)
madmonkeyman82 4:14bd961881ff 120 {
madmonkeyman82 5:529715bcff18 121 pc.printf("%c", *ptr_menu);
madmonkeyman82 4:14bd961881ff 122
madmonkeyman82 4:14bd961881ff 123 }
madmonkeyman82 5:529715bcff18 124 pc.locate(MENUPOSX, i + MENUPOSY);
madmonkeyman82 4:14bd961881ff 125 //term.printf("\n");
madmonkeyman82 4:14bd961881ff 126 }
madmonkeyman82 4:14bd961881ff 127 //term.printf("\n");
madmonkeyman82 4:14bd961881ff 128 }