Huseyin Berkay Berabi / GA-Final

Dependencies:   mbed-dev

Fork of GA-Berkay_Alex by Alejandro Ungria Hirte

Committer:
bberabi
Date:
Wed Feb 28 17:06:22 2018 +0000
Revision:
4:120ff05a7c27
Parent:
3:8bee1711d186
GA Final code with comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aungriah 0:a3b83d366423 1 #include "PC.h"
aungriah 0:a3b83d366423 2 #include "mbed.h"
aungriah 0:a3b83d366423 3
aungriah 0:a3b83d366423 4 PC::PC(PinName tx, PinName rx, int baudrate) : Serial(tx, rx)
aungriah 0:a3b83d366423 5 {
aungriah 0:a3b83d366423 6 baud(baudrate);
aungriah 0:a3b83d366423 7 cls();
aungriah 0:a3b83d366423 8
aungriah 0:a3b83d366423 9 command[0] = '\0';
aungriah 0:a3b83d366423 10 command_char_count = 0;
aungriah 0:a3b83d366423 11 }
aungriah 0:a3b83d366423 12
aungriah 0:a3b83d366423 13
aungriah 0:a3b83d366423 14 void PC::cls()
aungriah 0:a3b83d366423 15 {
aungriah 0:a3b83d366423 16 printf("\x1B[2J");
aungriah 0:a3b83d366423 17 }
aungriah 0:a3b83d366423 18
aungriah 0:a3b83d366423 19
aungriah 0:a3b83d366423 20 void PC::locate(int Spalte, int Zeile)
aungriah 0:a3b83d366423 21 {
aungriah 0:a3b83d366423 22 printf("\x1B[%d;%dH", Zeile + 1, Spalte + 1);
aungriah 0:a3b83d366423 23 }
aungriah 0:a3b83d366423 24
bberabi 4:120ff05a7c27 25 //This fufnction enable reading strings from matlab.
aungriah 0:a3b83d366423 26 void PC::readcommand(void (*executer)(char*))
aungriah 0:a3b83d366423 27 {
aungriah 0:a3b83d366423 28
bberabi 4:120ff05a7c27 29
bberabi 4:120ff05a7c27 30 char input = getc(); //get character from the serial bus
aungriah 3:8bee1711d186 31
bberabi 4:120ff05a7c27 32 if(input == '\r') { // \r is our end of command character when this shows up, command will be executed !
bberabi 4:120ff05a7c27 33
aungriah 3:8bee1711d186 34 this->command[command_char_count] = '\0';
aungriah 0:a3b83d366423 35 executer(&command[0]);
aungriah 3:8bee1711d186 36 this->command_char_count = 0; // reset command
aungriah 3:8bee1711d186 37 this->command[command_char_count] = '\0';
aungriah 3:8bee1711d186 38 // break;
bberabi 4:120ff05a7c27 39 } else if (command_char_count < COMMAND_MAX_LENGHT) { //wait for other characters
bberabi 1:346279def7ac 40 // printf("Debug Point 4");
aungriah 3:8bee1711d186 41 this->command[command_char_count] = input;
aungriah 3:8bee1711d186 42 this->command_char_count++;
aungriah 3:8bee1711d186 43
aungriah 0:a3b83d366423 44 }
aungriah 3:8bee1711d186 45 //}
bberabi 1:346279def7ac 46
aungriah 0:a3b83d366423 47
aungriah 0:a3b83d366423 48
bberabi 1:346279def7ac 49
bberabi 1:346279def7ac 50
aungriah 3:8bee1711d186 51 /* while (1)
aungriah 0:a3b83d366423 52 {
bberabi 1:346279def7ac 53
aungriah 0:a3b83d366423 54 if (readable())
aungriah 0:a3b83d366423 55 {
aungriah 0:a3b83d366423 56 scanf( "%s" , command );
aungriah 0:a3b83d366423 57 break;
aungriah 0:a3b83d366423 58 }
aungriah 0:a3b83d366423 59 }
aungriah 0:a3b83d366423 60
aungriah 0:a3b83d366423 61
aungriah 0:a3b83d366423 62
aungriah 0:a3b83d366423 63 executer(&command[0]);
bberabi 1:346279def7ac 64 command_char_count = 0; // reset command
bberabi 1:346279def7ac 65
aungriah 3:8bee1711d186 66 */
bberabi 1:346279def7ac 67
aungriah 0:a3b83d366423 68
aungriah 0:a3b83d366423 69
aungriah 0:a3b83d366423 70 }