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: BMP280
Revision 19:40c721f01ed2, committed 2018-01-09
- Comitter:
- Swaggie
- Date:
- Tue Jan 09 11:39:59 2018 +0000
- Parent:
- 13:41c394fa932c
- Child:
- 20:25939e03b803
- Commit message:
- Moved SD card HW to main file. Started detail commenting. SDCard commenting needs completing.
Changed in this revision
--- a/SDCard.cpp Tue Jan 09 10:25:17 2018 +0000
+++ b/SDCard.cpp Tue Jan 09 11:39:59 2018 +0000
@@ -5,13 +5,8 @@
#include "FATFileSystem.h"
#include "LCD.h"
-DigitalOut GreenLED(PB_11);
DigitalOut SDCardStatusLED(LED3);
-InterruptIn SD_WP(PE_10);
-InterruptIn UserButton(USER_BUTTON);
-SDBlockDevice sd(PB_5, D12, D13, D10);
-enum SDCardStates {INSERTED,REMOVED,DISMOUNTREQUEST};
bool SDCardPresent;
bool SDCardMounted;
unsigned short SDinternalIndex;
--- a/SDCard.h Tue Jan 09 10:25:17 2018 +0000
+++ b/SDCard.h Tue Jan 09 11:39:59 2018 +0000
@@ -1,17 +1,37 @@
#ifndef __SDCard__
#define __SDCard__
-
+/*
+*
+*/
+#include "mbed.h"
+#include "Sampling.h"
+#include "SDCard.h"
+#include "SDBlockDevice.h"
+#include "FATFileSystem.h"
+#include "LCD.h"
-enum SDCardStates;
-extern bool SDCardPresent;
-extern bool SDCardMounted;
-extern unsigned short SDinternalIndex;
-extern SDCardStates SDCurrentState;
+//Hardware devices
+extern InterruptIn SD_WP; //Pin that indicates if the card has been inserted (active low)
+extern InterruptIn UserButton;//Demount request
+extern SDBlockDevice sd; //SD Card device
+extern DigitalOut GreenLED; //Shows its safe to demount
+extern DigitalOut SDCardStatusLED;//Shows if the card is inserted
+
+enum SDCardStates{INSERTED,REMOVED,DISMOUNTREQUEST};
+
+//Variables
+extern bool SDCardPresent; //Is the SD card inserted?
+extern bool SDCardMounted; //Is the SD card initialised?
+extern unsigned short SDinternalIndex;//Used for clocking out the data from the sample index
+extern SDCardStates SDCurrentState; //State machine state
extern Thread SDCardThread;
+//Functions
void SDCardInit(void);
+//Starts the thread and sets up the interrupts
void SDCardRemovedISR(void);
+//
void SDCardInsertedISR(void);
void SDCardButtonISR(void);
void SDCardCode(void);
--- a/Sampling.h Tue Jan 09 10:25:17 2018 +0000 +++ b/Sampling.h Tue Jan 09 11:39:59 2018 +0000 @@ -1,6 +1,23 @@ #ifndef __Sampling__ #define __Sampling__ - +/* +* This module relates to the handling and sampling of enviromental data. +* Sampled data is held in 4 arrays. One for each different reading. Each +* of these is protected by a mutex lock, which is taken when data is being +* written to the registers. +* There are common indexes for the positions in the array. Stored is the position +* position of the oldest sample, the most recent sample, and where the next +* sample is to be written to. These operate in such a way that the array will fill +* and when fill will start to overwrite the oldest sample. +* Producer functions write samples to nextIndex position, allowing the most +* recent complete sample to continue to be read by consumers. +* +* A ticker runs at the sample rate interval. This signals two sampling threads. +* Two threads were used to prevent against delay from I2C interface. +* These threads take the samples then write them to the nextIndex, then signal done. +* On seeing that both threads are complete, the main thread then increments the +* indexes and passes the latest variables to the LCD. +*/ #include "mbed.h" #include "BMP280.h" #include "rtos.h"
--- a/WebUI.h Tue Jan 09 10:25:17 2018 +0000 +++ b/WebUI.h Tue Jan 09 11:39:59 2018 +0000 @@ -4,7 +4,7 @@ /* * This module handles the web interface. WebUISetup() is used to configure the * devices. -* WebUIUpdate() must then be attached to a thread. +* WebUIUpdate() is then attached to a thread. * This will wait on receiving a connection, before grabbing the latest samples * and making these part of the HTML response. */ @@ -20,10 +20,6 @@ extern TCPServer srv; //TCP/IP Server extern TCPSocket clt_sock; //Socket for communication extern SocketAddress clt_addr; //Address of incoming connection -extern float LDRVal; ///are these needed?!?!?!?!?! -extern float TempVal; -extern float Pressure; -extern time_t theTime; void WebUISetup(void); //Configures the TCP server
--- a/main.cpp Tue Jan 09 10:25:17 2018 +0000
+++ b/main.cpp Tue Jan 09 11:39:59 2018 +0000
@@ -6,51 +6,46 @@
#include "SDCard.h"
#include "SDBlockDevice.h"
-
-
//Hardware setup
-BMP280 sensor(D14, D15);
-AnalogIn LDRSensor(A0);
-DigitalOut SamplingLED(PB_10);
+BMP280 sensor(D14, D15); //enviromental sensor
+AnalogIn LDRSensor(A0); //LDR sensor
+DigitalOut SamplingLED(PB_10);//LED to indicate sampling
+//SD Card devices
+InterruptIn SD_WP(PE_10);
+InterruptIn UserButton(USER_BUTTON);
+SDBlockDevice sd(PB_5, D12, D13, D10);
+DigitalOut GreenLED(PB_11);
-Serial PC(USBTX, USBRX);
+Serial PC(USBTX, USBRX); //Serial interface
//SD Card Object
-
-//LCD Object
-ENVDISPLAY lcd(D9, D8, D7, D6, D4, D2,PE_12, PE_14);
-//File pointer for the SD card
-//FILE* fp;
+ENVDISPLAY lcd(D9, D8, D7, D6, D4, D2,PE_12, PE_14); //LCD pins and two timeset buttons
int main()
{
//Initialise devices
-////WebUISetup();
-
+ firstSample = true; //Set only at start of program
//Hardware Self Test
-
- //Initialise interrupts and times
- SerialStart();
- lcd.Start();
- SDCardInit();
- WebUISetup();
-
- ConfigThreadsAndIR();
- firstSample = true; //Set only at start of program
-
+ //Initialise interrupts and times
+ SerialStart(); //Start serial comms
+ lcd.Start(); //Start LCD functionality
+ SDCardInit(); //Start SDCard functionality
+ WebUISetup(); //Start Web Interface
+ ConfigThreadsAndIR(); //Start sampling
+
+
//Run
- while (true)
- {
- if (NewEnvSample && NewLDRSample)
- {
+ while (true) {
+ if (NewEnvSample && NewLDRSample) {
//New samples have been captured and are in the register
IncrementIndex();
- //LCD Update Function
- NewEnvSample = false;
+ NewEnvSample = false; //Reset sampling threads
NewLDRSample = false;
+
+ //push latest samples to LCD.
lcd.UpdateData(tempReadings[currentIndex],presReadings[currentIndex],LDRReadings[currentIndex],timeReadings[currentIndex]);
}
-
- }
+
+ }
}
\ No newline at end of file