BertlCard

Dependencies:   BertlLib mbed

Committer:
hollegha2
Date:
Thu Nov 19 08:12:24 2015 +0000
Revision:
1:69daffc2b325
Parent:
0:46edd470c018
Child:
2:90bc6c045ffd
V 3.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hollegha2 0:46edd470c018 1 #include "mbed.h"
hollegha2 0:46edd470c018 2 #include "Serial_HL.h"
hollegha2 0:46edd470c018 3 #include "Bertl14.h"
hollegha2 1:69daffc2b325 4 #include "BertlObjects.cpp"
hollegha2 1:69daffc2b325 5
hollegha2 1:69daffc2b325 6 // V 3.0
hollegha2 0:46edd470c018 7
hollegha2 0:46edd470c018 8 SerialBLK pc(USBTX, USBRX);
hollegha2 0:46edd470c018 9 // SerialBLK pc(p9, p10); // BlueTooth
hollegha2 0:46edd470c018 10 SvProtocol ua0(&pc);
hollegha2 0:46edd470c018 11
hollegha2 0:46edd470c018 12 // main=2^0 LS ENC 2^2
hollegha2 0:46edd470c018 13 BusOut boardPow(p30, P1_6, P1_7);
hollegha2 0:46edd470c018 14
hollegha2 0:46edd470c018 15 void CommandHandler();
hollegha2 1:69daffc2b325 16 void SwitchLeds();
hollegha2 0:46edd470c018 17
hollegha2 0:46edd470c018 18 int main(void)
hollegha2 0:46edd470c018 19 {
hollegha2 1:69daffc2b325 20 boardPow=1;
hollegha2 1:69daffc2b325 21 wait_ms(10);
hollegha2 0:46edd470c018 22 InitBertl();
hollegha2 0:46edd470c018 23 pex.useISR=0;
hollegha2 0:46edd470c018 24 leds=0;
hollegha2 0:46edd470c018 25 pex.ClearLeds();
hollegha2 0:46edd470c018 26 pc.format(8,SerialBLK::None,1);
hollegha2 0:46edd470c018 27 pc.baud(115200); // 115200
hollegha2 1:69daffc2b325 28 ua0.SvMessage("BertlKart_1");
hollegha2 0:46edd470c018 29
hollegha2 0:46edd470c018 30 Timer stw;
hollegha2 0:46edd470c018 31 stw.start();
hollegha2 0:46edd470c018 32 while(1) {
hollegha2 0:46edd470c018 33 CommandHandler();
hollegha2 1:69daffc2b325 34 if( (stw.read_ms()>10) ) {
hollegha2 1:69daffc2b325 35 SwitchLeds();
hollegha2 0:46edd470c018 36 stw.reset();
hollegha2 0:46edd470c018 37 if( ua0.acqON ) {
hollegha2 1:69daffc2b325 38 ua0.WriteSvI16(1, mL.encCnt);
hollegha2 1:69daffc2b325 39 ua0.WriteSvI16(2, mR.encCnt);
hollegha2 0:46edd470c018 40 }
hollegha2 0:46edd470c018 41 }
hollegha2 0:46edd470c018 42 }
hollegha2 0:46edd470c018 43 return 1;
hollegha2 0:46edd470c018 44 }
hollegha2 0:46edd470c018 45
hollegha2 1:69daffc2b325 46 int16_t ledsOn = 0;
hollegha2 1:69daffc2b325 47 void SwitchLeds()
hollegha2 1:69daffc2b325 48 {
hollegha2 1:69daffc2b325 49 pex.ReadButtons();
hollegha2 1:69daffc2b325 50 if( pex.IsAnyBackButton() ) {
hollegha2 1:69daffc2b325 51 if( ledsOn ) {
hollegha2 1:69daffc2b325 52 pex.ClearLeds();
hollegha2 1:69daffc2b325 53 ledsOn=0;
hollegha2 1:69daffc2b325 54 } else {
hollegha2 1:69daffc2b325 55 pex.SetLedPort(LED_BR2|LED_BL1);
hollegha2 1:69daffc2b325 56 ledsOn=1;
hollegha2 1:69daffc2b325 57 }
hollegha2 1:69daffc2b325 58 wait_ms(500);
hollegha2 1:69daffc2b325 59 }
hollegha2 1:69daffc2b325 60 }
hollegha2 1:69daffc2b325 61
hollegha2 0:46edd470c018 62 void CommandHandler()
hollegha2 0:46edd470c018 63 {
hollegha2 0:46edd470c018 64 uint8_t cmd;
hollegha2 0:46edd470c018 65 if( !pc.IsDataAvail() )
hollegha2 0:46edd470c018 66 return;
hollegha2 0:46edd470c018 67 cmd = ua0.GetCommand();
hollegha2 0:46edd470c018 68
hollegha2 0:46edd470c018 69 if( cmd==2 ) {
hollegha2 0:46edd470c018 70 if( ua0.ReadI16() )
hollegha2 1:69daffc2b325 71 pex.SetLedPort(LED_BR2|LED_BL1);
hollegha2 0:46edd470c018 72 else
hollegha2 0:46edd470c018 73 pex.ClearLeds();
hollegha2 0:46edd470c018 74 }
hollegha2 1:69daffc2b325 75 if( cmd==3 ) { // Rev. Brake
hollegha2 1:69daffc2b325 76 int16_t dir = pc.GetChar();
hollegha2 1:69daffc2b325 77 if( dir>0 ) { // 1 Brake for Forw.
hollegha2 1:69daffc2b325 78 mL.SetPow(-0.3);
hollegha2 1:69daffc2b325 79 mR.SetPow(-0.3);
hollegha2 1:69daffc2b325 80 } else { // 0 Brake for Backw.
hollegha2 1:69daffc2b325 81 mL.SetPow(0.3);
hollegha2 1:69daffc2b325 82 mR.SetPow(0.3);
hollegha2 1:69daffc2b325 83 }
hollegha2 1:69daffc2b325 84 wait_ms(50);
hollegha2 1:69daffc2b325 85 mL.SetPow(0);
hollegha2 1:69daffc2b325 86 mR.SetPow(0);
hollegha2 1:69daffc2b325 87 ua0.SvMessage("Rev Brake");
hollegha2 1:69daffc2b325 88 }
hollegha2 0:46edd470c018 89 if( cmd==4 ) {
hollegha2 1:69daffc2b325 90 mL.SetPow2(ua0.ReadF());
hollegha2 1:69daffc2b325 91 mR.SetPow2(ua0.ReadF());
hollegha2 0:46edd470c018 92 }
hollegha2 0:46edd470c018 93 if( cmd==5 ) {
hollegha2 1:69daffc2b325 94 mL.SetPow(ua0.ReadF());
hollegha2 1:69daffc2b325 95 mR.SetPow(ua0.ReadF());
hollegha2 0:46edd470c018 96 }
hollegha2 0:46edd470c018 97 }
hollegha2 0:46edd470c018 98
hollegha2 0:46edd470c018 99