Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 70:594fe5c1ad5c
- Parent:
- 69:609c69e91b4e
- Child:
- 71:9a303d90c9b8
--- a/main.cpp Wed Jun 27 09:20:28 2018 +0000 +++ b/main.cpp Wed Jun 27 09:22:45 2018 +0000 @@ -9,9 +9,6 @@ using namespace std; -//FileSystem for log creation -LocalFileSystem local("local"); - /******PINS AND DECLARATIONS*******/ @@ -458,136 +455,6 @@ int speedcheck = 0; -//****** SYSTEM LOGGER FUNCTIONS ******// - -/** -* -* -* -**/ -string train_dir_toString(Train* train){ - - string dir_string; - - if(train->goes_cw()){ - - dir_string = "cw"; - }else{ - - dir_string = "ccw"; - } - return dir_string; -} - -/** -* -* -* -**/ -string train_pos_toString(Train* train){ - - int i = train->get_position_number(); - std::string tr_pos; - std::stringstream ss; - - ss << i; - tr_pos = ss.str(); - - return tr_pos; -} - - -/** -* -* -* -**/ -void logger_add(string s){ - - FILE *fp = fopen("/local/sys_log.txt", "a"); - fprintf(fp, "%s \n", s); - fclose(fp); - -} - - -/** -* -* -* -**/ -void init_logger(){ - - FILE *fp = fopen("/local/sys_log.txt", "w"); - - fprintf(fp, "Log for the main train program: \n"); - fprintf(fp, "------------------------------- \n \n"); - - fclose(fp); - -} - -/** -* -* -* -**/ -void train_pos0_log(){ - - FILE *fp = fopen("/local/sys_log.txt", "a"); - - fprintf(fp, "DR_train START: D%s sensor, %s direction. \n", train_pos_toString(&DR_train), train_dir_toString(&DR_train)); - fprintf(fp, "LR_train START: D%s sensor, %s direction. \n \n", train_pos_toString(&LR_train), train_dir_toString(&LR_train)); - - fprintf(fp, "..............Program Start................ \n"); - - fclose(fp); - -} - - -/** -* -* -* -**/ -void print_next_sensors(Train* train){ - - FILE *fp = fopen("/local/sys_log.txt", "a"); - - for(int i=0; i<train->get_next_sensors().size(); i++){ - - fprintf(fp, "%d" ,train->get_next_sensors()[i]); - } - - fprintf(fp, "\n"); - fclose(fp); - -} - - -/** -* -* -* -**/ -void trains_posn_log(int sensor){ - - FILE *fp = fopen("/local/sys_log.txt", "a"); - - fprintf(fp, "SIGNAL FROM SENSOR D%d \n", sensor); - fprintf(fp, "DR_train: D%s sensor, %s direction. // Next positions: ", train_pos_toString(&DR_train), train_dir_toString(&DR_train)); - print_next_sensors(&DR_train); - - fprintf(fp, "LR_train: D%s sensor, %s direction. // Next positions: ", train_pos_toString(&LR_train), train_dir_toString(&LR_train)); - print_next_sensors(&LR_train); - fprintf(fp, "\n"); - - fclose(fp); -} - - - //**************** FUNCTIONS FOR DENVER TRAIN ****************// @@ -1143,8 +1010,7 @@ * **/ void update_train_pos(int sensor){ - led2 = 1; - logger_add("UPDATE IT"); + bool found_DR = false; bool found_LR = false; @@ -1161,16 +1027,12 @@ }else{ LR_dir = "ccw"; } - - - //wait(0.7); + if(sensor == DR_train.get_position_number() || sensor == LR_train.get_position_number()){ led2 = 0; }else{ - - //trains_posn_log(sensor); - + lcd.cls(); lcd.printf("S:D%d DR%d(",sensor,DR_train.get_position_number()); @@ -1579,9 +1441,6 @@ lcd.printf("Ready to start"); wait(1); - init_logger(); - train_pos0_log(); - logger_add("There we go lads this is the start of the program"); enable = 1;