
Code for Browonout Generator box
Diff: main.cpp
- Revision:
- 5:a8297e5f4de1
- Parent:
- 4:44760dafcab7
- Child:
- 6:3f5d21480f11
--- a/main.cpp Fri Feb 14 12:20:31 2020 +0000 +++ b/main.cpp Fri Feb 14 12:34:20 2020 +0000 @@ -1,3 +1,6 @@ + +//By Barnaby Ayriss +//Owned by Buhler UK Ltd #include "mbed.h" #include <string> @@ -36,6 +39,9 @@ void power(char pwr = 0); void cycle_wait(long double tOn = configData[0], long double tOff = configData[2]); void cycle_loop(long double tOn = configData[0], long double tOff = configData[2]); +string read_serial_input(); +bool is_num_str(string str); +long double get_num_input(); void serial_mode(); @@ -83,9 +89,8 @@ bool isReading = false; bool isNumChar; string currentStr; - FILE* fp = fopen("/local/config.txt", "r"); - + while (!feof(fp)) { //loop till end of file c = fgetc(fp); @@ -109,6 +114,7 @@ pc.printf("Data: %Lf, %Lf, %Lf\r\n",configData[0],configData[1],configData[2]); } +//initialization function void init() { pc.printf("Initializing \r\n"); @@ -119,12 +125,14 @@ get_config_data(); } +//Sets the pin to control te machines power and its representative LED void power(char pwr) { do21 = pwr; led1 = pwr; } +//runs a power cycle using sleep commands void cycle_wait(long double tOn, long double tOff) { power(1); @@ -134,6 +142,7 @@ power(1); } +//runs an infinate powercycle loop void cycle_loop(long double tOn, long double tOff) { while(1) { @@ -141,6 +150,7 @@ } } +// ouputs a string from the serial input using a string read_serial_input() { bool flg_read = true; @@ -152,12 +162,11 @@ pc.putc(c); if(c == 8 or c == 127) { //If back space or delete remove last character str.pop_back(); - } else if (c == '\n') { - str.pop_back(); + } else if (c == '\n') { //If new line character + str.pop_back(); // removes return carriage character flg_read = false; break; - -// } else if(c < ' ') { //If none visible character, bar backspace or delete +// } else if(c < ' ') { //If none visible character, bar backspace or delete // flg_read = false; // break; } else { @@ -167,6 +176,7 @@ return str; } +//outputs if a string is comprised entirely of number characters bool is_num_str(string str) { bool isNumC = false; @@ -180,6 +190,7 @@ return output; } +//gets a string of only number characters from the serial input long double get_num_input() { long double output; @@ -203,35 +214,33 @@ } - +// Allows the user to operate the LPC1768 via serial communications void serial_mode() { pc.printf("Serial Mode \r\n"); - bool flg_read = true; - bool flg_read2 = true; char c; string str_c = ""; while(flg_read) { str_c = read_serial_input(); - if (str_c == "on"){ + if (str_c == "on"){ // turns machine on power(1); - pc.printf("on\r\n"); - } else if(str_c == "off"){ + pc.printf("power on\r\n"); + } else if(str_c == "off"){ // turns machine off power(0); - pc.printf("off\r\n"); - } else if(str_c == "cyclew") { + pc.printf("power off\r\n"); + } else if(str_c == "cyclew") { // runs a powercycle cycle_wait(); pc.printf("cycled \r\n"); - } else if(str_c == "loop") { + } else if(str_c == "loop") { // runs a continuous powercycle loop pc.printf("Looping restart unit to end loop\r\n"); cycle_loop(); - } else if(str_c == "newval") { + } else if(str_c == "newval") { // cahnges cycle time values pc.printf("enter your new on and off times(ms)\r\n"); pc.puts("Time on\r\n"); configData[0] = get_num_input(); - pc.puts("Time off\r\n"); + pc.puts("Time off\r\n"); configData[2] = get_num_input(); pc.printf("Data: %Lf, %Lf, %Lf\r\n",configData[0],configData[1],configData[2]); } else {