fuck this

Dependencies:   BMP280

Logging.cpp

Committer:
Swaggie
Date:
2018-01-09
Revision:
20:25939e03b803
Child:
21:6e733076f49c

File content as of revision 20:25939e03b803:

#include "Logging.h"
#include <string>

using namespace std;
Mail<uint32_t,32> ActivityLog;
bool logging = false;

void LogEvent(uint32_t eventCode)
{
    if (logging) {  //Only do if logging is enabled
        uint32_t* Status = ActivityLog.alloc(); //Allocate space in mailbox
        *Status = eventCode;    //Move data into memory
        ActivityLog.put(Status);//data is in queue 
    }
}

string CheckLoggingQueue(void)
{
    string returnString = "";
    if (logging) {  //Only do if logging is enabled
        osEvent evt = ActivityLog.get();    //Get the object from mailbox. This blocks until there is data
        if (evt.status == osEventMail) {
            //Does it have content? If not, there is no mail.
            uint32_t* mail = (uint32_t*)evt.value.p;    //extract the value passed
            //Convert int value to string
            char intStr[4]; //Has to be done in two steps because of known to_string bug stackoverflow.com/questions/12975341
            sprintf(intStr, "%d", *mail);
            string mailAsString = string(intStr);
            ActivityLog.free(mail);     //Now we can release the space in the mailbox
            returnString = "Data Logged:\n\r" + mailAsString;
            return returnString;
        } else {
            //There wasn't any data
            string returnString = "ERROR: There wasn't any data";
        }
    }
    return returnString;
}