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.
Dependencies: Peripherals SD_Lib Time_Lib_v2 Year3_Version5 BMP280 LCDFunctions TextLCD BME280 Serial_Lib
Revision 8:dde5976445b4, committed 2018-11-23
- Comitter:
- erolleyparnell
- Date:
- Fri Nov 23 20:12:19 2018 +0000
- Parent:
- 7:981670f59caf
- Child:
- 9:d783366f2203
- Commit message:
- Rearrange source code;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Buffer/circular_buffer.cpp Fri Nov 23 20:12:19 2018 +0000
@@ -0,0 +1,46 @@
+
+#include "mbed.h"
+#include "data_types.hpp"
+#include "platform/CircularBuffer.h"
+#define BUF_SIZE 120
+
+class Buffer
+{
+ //Variables
+ public:
+
+ private:
+ CircularBuffer<SensorData, BUF_SIZE> buf;
+
+ protected:
+
+ //Functions
+ public:
+ Buffer()
+ {
+
+ //char data_stream[] = "DataToBeAddedToBuffer";
+ }
+ ~Buffer(){}
+ void write_buffer()
+ {
+ if (!buf.full())
+ {
+ //buf.push(data)
+ }
+ }
+ void read_buffer()
+ {
+
+ }
+ void store_buffer()
+ {
+
+ }
+ private:
+ protected:
+
+};
+
+
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Buffer/circular_buffer.hpp Fri Nov 23 20:12:19 2018 +0000 @@ -0,0 +1,3 @@ +extern CircularBuffer<char, BUF_SIZE> buf; +extern char data_stream[] = "DataToBeAddedToBuffer"; +extern void init_buffer(); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Buffer/data_types.cpp Fri Nov 23 20:12:19 2018 +0000
@@ -0,0 +1,8 @@
+#include "mbed.h"
+
+typedef struct
+{
+time_t time;
+ float y;
+ float z;
+} SensorData;
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Buffer/data_types.hpp Fri Nov 23 20:12:19 2018 +0000
@@ -0,0 +1,1 @@
+typedef struct {} SensorData;
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCDFunctions.lib Fri Nov 23 20:12:19 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/ELEC351/code/LCDFunctions/#063d075c40cb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Serial_Lib.lib Fri Nov 23 20:12:19 2018 +0000 @@ -0,0 +1,1 @@ +Serial_Lib#f1c1af0cbefc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Threads_Lib.lib Fri Nov 23 20:12:19 2018 +0000 @@ -0,0 +1,1 @@ +Threads_Lib#deacb908e4c5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Time_Lib.lib Fri Nov 23 20:12:19 2018 +0000 @@ -0,0 +1,1 @@ +Time_Lib#195f49822389
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Year3Threads_Version3.lib Fri Nov 23 20:12:19 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/ELEC351/code/Year3Threads_Version3/#981670f59caf
--- a/main.cpp Fri Nov 23 14:20:10 2018 +0000
+++ b/main.cpp Fri Nov 23 20:12:19 2018 +0000
@@ -3,20 +3,16 @@
#include "SDBlockDevice.h"
#include "FATFileSystem.h"
#include "sample_hardware.hpp"
+#include "thread_functions.hpp"
-#define Day 1
-#define Month 2
-#define Year 3
-#define Hour 4
-#define Minute 5
-#define Second 6
+
//Function declarations
void displayOnLcd();
void updateRealTimeClock(char *buffer);
void getLineFromSerial(char *keyBuffer, int bufferLength);
void displayMessageOnConsole();
-void SetingTimeWithButtons ();
+void SettingTimeWithButtons ();
void FunctionSensor();
void FunctionTime();
void FunctionSerial();
@@ -75,309 +71,3 @@
t3.start(FunctionSerial);
}
-
-
-void displayOnLcd() {
- date_mutex.lock();
-
- myled = !myled;
-
- currentTime = time(NULL);
- strftime(lcdBuffer, 32, "%d/%m/%Y %H:%M:%S", localtime(¤tTime));
-
- //lcd.cls();
-// lcd.locate(0,0);
- pc.printf("%s\n\r", lcdBuffer);
-
- myled = !myled;
- date_mutex.unlock();
-};
-
-void updateRealTimeClock(char *buffer) {
- date_mutex.lock();
-
- char *tp;
- char *timeArray[6];
- int arrayIndex;
- struct tm struct_time;
-
- // extract number from string
- arrayIndex = 0;
- tp = strtok( buffer, " /:-" );
- timeArray[arrayIndex++] = tp;
- printf("%d ", atoi(tp));
- while ( tp != NULL && arrayIndex < 6 ) {
- tp = strtok( NULL," /:-" );
- timeArray[arrayIndex++] = tp;
- if ( tp != NULL ) {
- printf("%d ", atoi(tp));
- }
-}
- printf("\r\n");
-
- // store number into time struct
- struct_time.tm_mday = atoi(timeArray[0]);
- struct_time.tm_mon = atoi(timeArray[1]) - 1;
- struct_time.tm_year = atoi(timeArray[2]) - 1900;
- struct_time.tm_hour = atoi(timeArray[3]);
- struct_time.tm_min = atoi(timeArray[4]);
- struct_time.tm_sec = atoi(timeArray[5]);
-
- currentTime = mktime(&struct_time);
- set_time(currentTime);
-
- date_mutex.unlock();
-}
-
-void getLineFromSerial(char *keyBuffer, int bufferLength)
-{
- date_mutex.lock();
-
- char c;
- int index = 0;
-
- for (;;) {
- // break if keyBuffer is full
- if (index >= bufferLength) {
- break;
- }
-
- // read input
- c = pc.getc();
- //printf(" %d ", c);
- pc.putc(c);
-
- // break if end
- if (c == '\r') {
- keyBuffer[index++] = c;
- printf("\n");
- break;
- }
-
- // store in keyBuffer
- keyBuffer[index++] = c;
-
- date_mutex.unlock();
- }
-}
-
-void displayMessageOnConsole() {
- date_mutex.lock();
-
- currentTime = time(NULL);
- //strftime(lcdBuffer, 32, "%Y/%m/%d %H:%M:%S", localtime(¤tTime));
- strftime(lcdBuffer, 32, "%d/%m/%Y %H:%M:%S", localtime(¤tTime));
-
- printf("Current Time:%s\r\n", lcdBuffer);
- printf("Enter new Time (dd/mm/YYYY HH:MM:SS)\r\n");
-
- date_mutex.unlock();
-}
-
-void SetingTimeWithButtons () {
-
- int day = 0;
- int month = 0;
- int year = 2017;
- int hour = 0;
- int min = 0;
- int sec = 0;
-
- setting = Day;
- t = 1;
-
- while(t == 1) {
- switch (setting) {
- case Day:
- if (SW1 == 1) {
- wait(0.2);
- day = day + 1;
- lcd.cls();
- lcd.locate(0,0);
- lcd.printf("Day = %d\n", day);
- }
- if (SW2 == 1) {
- setting = Month;
- wait(0.5);
- }
- break;
-
- case Month:
- if (SW1 == 1) {
- wait(0.2);
- month = month + 1;
- lcd.cls();
- lcd.locate(0,0);
- lcd.printf("Month = %d\n", month);
- }
- if (SW2 == 1) {
- setting = Year;
- wait(0.5);
- }
- break;
-
- case Year:
- if (SW1 == 1) {
- wait(0.2);
- year = year + 1;
- lcd.cls();
- lcd.locate(0,0);
- lcd.printf("Year = %d\n", year);
- }
- if (SW2 == 1) {
- setting = Hour;
- wait(0.5);
- }
- break;
-
- case Hour:
- if (SW1 == 1) {
- wait(0.2);
- hour = hour + 1;
- lcd.cls();
- lcd.locate(0,0);
- lcd.printf("Hour = %d\n", hour);
- }
- if (SW2 == 1) {
- setting = Minute;
- wait(0.5);
- }
- break;
-
- case Minute:
- if (SW1 == 1) {
- wait(0.2);
- min = min + 1;
- lcd.cls();
- lcd.locate(0,0);
- lcd.printf("Minute = %d\n", min);
- }
- if (SW2 == 1) {
- setting = Second;
- wait(0.5);
- }
- break;
-
- case Second:
- if (SW1 == 1) {
- wait(0.2);
- sec = sec + 1;
- lcd.cls();
- lcd.locate(0,0);
- lcd.printf("Second = %d\n", sec);
- }
- if (SW2 == 1) {
- wait(0.5);
- t = 0;
- }
- break;
- }
- }
-
- struct tm struct_time;
-
- //store number into time struct
- struct_time.tm_year = year - 1900;
- struct_time.tm_mon = month;
- struct_time.tm_mday = day;
- struct_time.tm_hour = hour;
- struct_time.tm_min = min;
- struct_time.tm_sec = sec;
-
- // Coverting to time
- time_t currentTime = mktime(&struct_time);
- set_time(currentTime);
-
- }
-
-
-void FunctionSensor()
-{
- while (true) {
- double temp = sensor.getTemperature();
- double pressure = sensor.getPressure();
- lcd.cls();
- lcd.printf("Temp Pressure\n");
- lcd.printf("%6.1f ",temp);
- lcd.printf("%.2f\n",pressure);
-
- //Write to SD
- //fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure);
-
- Thread::wait(15000); //Updates the state every 15 seconds
- }
-}
-
-void FunctionTime()
-{
- while (true) {
- char lineBuffer[32];
- char *pointer;
- pointer = lineBuffer;
- if (SW1 == 1) { //Set time on Putty
- // show initial message on console
- displayMessageOnConsole();
-
- // get input from console
- getLineFromSerial(pointer, sizeof(lineBuffer));
-
- myled = !myled;
- // update RTC based on input value
- updateRealTimeClock(pointer);
- }
- if (SW2 == 1) { // Set time with Buttons
- pc.printf("Ready");
- wait(0.5);
- SetingTimeWithButtons ();
- }
- while(true) {
- displayOnLcd();
- myled = !myled;
- Thread::wait(1000);
- }
- }
-
-}
-
-void FunctionSerial()
-{
- date_mutex.lock();
-
- lcd.cls();
- lcd.printf("Observe Putty\n\n");
-
-
- pc.printf("\n\rEnter command:\n\r");
- pc.printf("READ ALL \n\r");
- char str[9] = "READ ALL";
- // reads for 8 waiting for new line and ignoring spaces
- pc.scanf("%8[^\n]*c",str);
- //prints typed command
- pc.printf("Chosen Command = ");
- pc.printf("%s\n\r",str);
-
- //check if typed command is equal to string
- if (!strcmp(str, "READ ALL")) {
- //if (str == "READ ALL") {
- // pc.printf("yay\n\r");
-
- //get current values
- double temp = sensor.getTemperature();
- double pressure = sensor.getPressure();
- fLDR = LDD_ADC_In;
- volts = fLDR*3.3f;
- strftime(lcdBuffer, 32, "%d/%m/%Y %H:%M:%S,", localtime(¤tTime));
-
- pc.printf("Date and Time = %s\r\n", lcdBuffer);
- pc.printf("Temperature = %6.1f deg C,\n\r",temp);
- pc.printf("Pressure = %.2f mB,\n\r",pressure);
- pc.printf("Light = %6.4f volts,\n\r", volts);
-
- }
- else {
- pc.printf("INVALID COMMAND\n\r");
- }
-
- date_mutex.unlock();
-
-}
\ No newline at end of file