Init

Dependencies:   Break Motor Communication Steering mbed Controller

Committer:
skrickl
Date:
Thu Jul 13 13:45:55 2017 +0000
Revision:
1:2538cbbea1f8
bla

Who changed what in which revision?

UserRevisionLine numberNew contents of line
skrickl 1:2538cbbea1f8 1 #include "mbed.h"
skrickl 1:2538cbbea1f8 2
skrickl 1:2538cbbea1f8 3 #ifndef MOTOR_CONTROLLER_H
skrickl 1:2538cbbea1f8 4 #define MOTOR_CONTROLLER_H
skrickl 1:2538cbbea1f8 5
skrickl 1:2538cbbea1f8 6 #define BAUD_RATE 115200
skrickl 1:2538cbbea1f8 7 #define PIN_TX p9
skrickl 1:2538cbbea1f8 8 #define PIN_RX p10
skrickl 1:2538cbbea1f8 9 #define ENTER 0x0D
skrickl 1:2538cbbea1f8 10
skrickl 1:2538cbbea1f8 11 Serial mc(PIN_TX, PIN_RX); // tx, rx
skrickl 1:2538cbbea1f8 12
skrickl 1:2538cbbea1f8 13 void Rx_interruptMC();
skrickl 1:2538cbbea1f8 14 char temp_rx[80];
skrickl 1:2538cbbea1f8 15
skrickl 1:2538cbbea1f8 16 int initMotorController()
skrickl 1:2538cbbea1f8 17 {
skrickl 1:2538cbbea1f8 18 mc.baud(BAUD_RATE);
skrickl 1:2538cbbea1f8 19
skrickl 1:2538cbbea1f8 20 // Setup a serial interrupt function to receive data
skrickl 1:2538cbbea1f8 21 mc.attach(&Rx_interruptMC, Serial::RxIrq);
skrickl 1:2538cbbea1f8 22
skrickl 1:2538cbbea1f8 23 return 0;
skrickl 1:2538cbbea1f8 24 }
skrickl 1:2538cbbea1f8 25
skrickl 1:2538cbbea1f8 26 void Rx_interruptMC()
skrickl 1:2538cbbea1f8 27 {
skrickl 1:2538cbbea1f8 28 //led2 = 1;
skrickl 1:2538cbbea1f8 29 bool lineEnd = true;
skrickl 1:2538cbbea1f8 30 char raw_rx[80];
skrickl 1:2538cbbea1f8 31 int i = 0;
skrickl 1:2538cbbea1f8 32
skrickl 1:2538cbbea1f8 33 while (lineEnd)
skrickl 1:2538cbbea1f8 34 {
skrickl 1:2538cbbea1f8 35 raw_rx[i] = mc.getc();
skrickl 1:2538cbbea1f8 36 if ((int)raw_rx[i] == ENTER)
skrickl 1:2538cbbea1f8 37 {
skrickl 1:2538cbbea1f8 38 lineEnd = false;
skrickl 1:2538cbbea1f8 39 }
skrickl 1:2538cbbea1f8 40 i++;
skrickl 1:2538cbbea1f8 41 led3 = lineEnd;
skrickl 1:2538cbbea1f8 42 }
skrickl 1:2538cbbea1f8 43
skrickl 1:2538cbbea1f8 44 //Here now the Values of the MC in the current Value
skrickl 1:2538cbbea1f8 45 sprintf(temp_rx,raw_rx);
skrickl 1:2538cbbea1f8 46 //led2 = 0;
skrickl 1:2538cbbea1f8 47 }
skrickl 1:2538cbbea1f8 48 void writeLine(char *line)
skrickl 1:2538cbbea1f8 49 {
skrickl 1:2538cbbea1f8 50 mc.printf("%s\r\n",line);
skrickl 1:2538cbbea1f8 51 }
skrickl 1:2538cbbea1f8 52
skrickl 1:2538cbbea1f8 53 void writeWord(char *word)
skrickl 1:2538cbbea1f8 54 {
skrickl 1:2538cbbea1f8 55 mc.printf("%s",word);
skrickl 1:2538cbbea1f8 56 }
skrickl 1:2538cbbea1f8 57
skrickl 1:2538cbbea1f8 58 void startStatusWriting()
skrickl 1:2538cbbea1f8 59 {
skrickl 1:2538cbbea1f8 60 writeLine("status_start");
skrickl 1:2538cbbea1f8 61 }
skrickl 1:2538cbbea1f8 62
skrickl 1:2538cbbea1f8 63 void endStatusWriting()
skrickl 1:2538cbbea1f8 64 {
skrickl 1:2538cbbea1f8 65 writeLine("status_end");
skrickl 1:2538cbbea1f8 66 }
skrickl 1:2538cbbea1f8 67
skrickl 1:2538cbbea1f8 68
skrickl 1:2538cbbea1f8 69 #endif