fuck this

Dependencies:   BMP280

Committer:
Swaggie
Date:
Tue Jan 09 11:53:11 2018 +0000
Revision:
20:25939e03b803
Child:
21:6e733076f49c
Inputted Logging in main function and in LCD function.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Swaggie 20:25939e03b803 1 #include "Logging.h"
Swaggie 20:25939e03b803 2 #include <string>
Swaggie 20:25939e03b803 3
Swaggie 20:25939e03b803 4 using namespace std;
Swaggie 20:25939e03b803 5 Mail<uint32_t,32> ActivityLog;
Swaggie 20:25939e03b803 6 bool logging = false;
Swaggie 20:25939e03b803 7
Swaggie 20:25939e03b803 8 void LogEvent(uint32_t eventCode)
Swaggie 20:25939e03b803 9 {
Swaggie 20:25939e03b803 10 if (logging) { //Only do if logging is enabled
Swaggie 20:25939e03b803 11 uint32_t* Status = ActivityLog.alloc(); //Allocate space in mailbox
Swaggie 20:25939e03b803 12 *Status = eventCode; //Move data into memory
Swaggie 20:25939e03b803 13 ActivityLog.put(Status);//data is in queue
Swaggie 20:25939e03b803 14 }
Swaggie 20:25939e03b803 15 }
Swaggie 20:25939e03b803 16
Swaggie 20:25939e03b803 17 string CheckLoggingQueue(void)
Swaggie 20:25939e03b803 18 {
Swaggie 20:25939e03b803 19 string returnString = "";
Swaggie 20:25939e03b803 20 if (logging) { //Only do if logging is enabled
Swaggie 20:25939e03b803 21 osEvent evt = ActivityLog.get(); //Get the object from mailbox. This blocks until there is data
Swaggie 20:25939e03b803 22 if (evt.status == osEventMail) {
Swaggie 20:25939e03b803 23 //Does it have content? If not, there is no mail.
Swaggie 20:25939e03b803 24 uint32_t* mail = (uint32_t*)evt.value.p; //extract the value passed
Swaggie 20:25939e03b803 25 //Convert int value to string
Swaggie 20:25939e03b803 26 char intStr[4]; //Has to be done in two steps because of known to_string bug stackoverflow.com/questions/12975341
Swaggie 20:25939e03b803 27 sprintf(intStr, "%d", *mail);
Swaggie 20:25939e03b803 28 string mailAsString = string(intStr);
Swaggie 20:25939e03b803 29 ActivityLog.free(mail); //Now we can release the space in the mailbox
Swaggie 20:25939e03b803 30 returnString = "Data Logged:\n\r" + mailAsString;
Swaggie 20:25939e03b803 31 return returnString;
Swaggie 20:25939e03b803 32 } else {
Swaggie 20:25939e03b803 33 //There wasn't any data
Swaggie 20:25939e03b803 34 string returnString = "ERROR: There wasn't any data";
Swaggie 20:25939e03b803 35 }
Swaggie 20:25939e03b803 36 }
Swaggie 20:25939e03b803 37 return returnString;
Swaggie 20:25939e03b803 38 }