Ion Systems / Mbed 2 deprecated Chipin_Main

Dependencies:   MCP23017 TCS3472_I2C WattBob_TextLCD mbed-rtos mbed

Committer:
IonSystems
Date:
Fri Dec 05 09:53:04 2014 +0000
Revision:
28:bdf2bf56f97b
Parent:
27:47a7bc902587
Commened main

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IonSystems 6:e64796f1f384 1 #include "mbed.h"
IonSystems 27:47a7bc902587 2 /* Allows easy enable and disable of log file.
IonSystems 27:47a7bc902587 3 * WARNING: Every time a file is changed on the MBED, it reconnects to the PC,
IonSystems 27:47a7bc902587 4 * resulting in hundrets of Autoplay notices appearing on your desktop window.
IonSystems 27:47a7bc902587 5 * Unplug the MBED from the PC for best results.
IonSystems 27:47a7bc902587 6 * Logging is extremely useful for debugging but should be disabled when not debugging.
IonSystems 27:47a7bc902587 7 */
IonSystems 27:47a7bc902587 8 bool logEnable = false;
IonSystems 6:e64796f1f384 9 LocalFileSystem local("local");
IonSystems 27:47a7bc902587 10
IonSystems 27:47a7bc902587 11 /* void writeFile(int r, int g, int b, int re)
IonSystems 27:47a7bc902587 12 * Write the values of each storage tube to the datafile.
IonSystems 27:47a7bc902587 13 * Ensures no negative values are written to the file.
IonSystems 27:47a7bc902587 14 */
IonSystems 23:f9e7e64784be 15 void writeFile(int r, int g, int b, int re)
IonSystems 23:f9e7e64784be 16 {
IonSystems 24:8868101d01d0 17 FILE* file = fopen("/local/df.txt","w"); // open file
IonSystems 23:f9e7e64784be 18 if(r >= 0) {
IonSystems 23:f9e7e64784be 19 fputc(r, file); // put char (data value) into file
IonSystems 23:f9e7e64784be 20 } else {
IonSystems 23:f9e7e64784be 21 fputc(0, file);
IonSystems 23:f9e7e64784be 22 }
IonSystems 23:f9e7e64784be 23 if(g >= 0) {
IonSystems 27:47a7bc902587 24 fputc(g, file);
IonSystems 23:f9e7e64784be 25 } else {
IonSystems 23:f9e7e64784be 26 fputc(0, file);
IonSystems 12:814a8fdbb6f7 27 }
IonSystems 23:f9e7e64784be 28 if(b >= 0) {
IonSystems 27:47a7bc902587 29 fputc(b, file);
IonSystems 23:f9e7e64784be 30 } else {
IonSystems 23:f9e7e64784be 31 fputc(0, file);
IonSystems 23:f9e7e64784be 32 }
IonSystems 23:f9e7e64784be 33 if(re >= 0) {
IonSystems 27:47a7bc902587 34 fputc(re, file);
IonSystems 23:f9e7e64784be 35 } else {
IonSystems 23:f9e7e64784be 36 fputc(0, file);
IonSystems 23:f9e7e64784be 37 }
IonSystems 23:f9e7e64784be 38 fclose(file); // close file
IonSystems 10:8c0696b99692 39 }
IonSystems 27:47a7bc902587 40 /* int readFile(int index)
IonSystems 27:47a7bc902587 41 * Read a character from the datafile and return as an integer.
IonSystems 27:47a7bc902587 42 */
IonSystems 23:f9e7e64784be 43 int readFile(int index)
IonSystems 23:f9e7e64784be 44 {
IonSystems 24:8868101d01d0 45 FILE* file = fopen ("/local/df.txt","r"); // open file for reading
IonSystems 20:6de191ac7ff3 46 int read_var = 0;
IonSystems 23:f9e7e64784be 47 for(int i = 0; i <= index; i++) {
IonSystems 10:8c0696b99692 48 read_var = fgetc(file); // read data value
IonSystems 6:e64796f1f384 49 }
IonSystems 10:8c0696b99692 50 fclose(file); // close file
IonSystems 23:f9e7e64784be 51 return read_var;
IonSystems 10:8c0696b99692 52 }
IonSystems 10:8c0696b99692 53
IonSystems 27:47a7bc902587 54 /* void log(char* text)
IonSystems 27:47a7bc902587 55 * Append a charcater array on a new line in the log file.
IonSystems 27:47a7bc902587 56 */
IonSystems 23:f9e7e64784be 57 void log(char* text)
IonSystems 23:f9e7e64784be 58 {
IonSystems 23:f9e7e64784be 59 if(logEnable) {
IonSystems 23:f9e7e64784be 60 FILE* file = fopen ("/local/log.txt", "a");
IonSystems 10:8c0696b99692 61 fputs(text, file);
IonSystems 10:8c0696b99692 62 fputs("\r\n", file);
IonSystems 10:8c0696b99692 63 fclose(file);
IonSystems 23:f9e7e64784be 64 }
IonSystems 10:8c0696b99692 65 }
IonSystems 27:47a7bc902587 66 /* void clearLog()
IonSystems 27:47a7bc902587 67 * Clear the log file.
IonSystems 27:47a7bc902587 68 */
IonSystems 23:f9e7e64784be 69 void clearLog()
IonSystems 23:f9e7e64784be 70 {
IonSystems 10:8c0696b99692 71 FILE* file = fopen ("/local/log.txt", "w");
IonSystems 23:f9e7e64784be 72 fclose(file);
IonSystems 10:8c0696b99692 73 }