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.
Fork of SolarNanoGridv3 by
Revision 12:d9b13f31206d, committed 2016-06-08
- Comitter:
- epgmdm
- Date:
- Wed Jun 08 22:48:09 2016 +0000
- Parent:
- 11:87ab310924f0
- Child:
- 13:de43f28c0365
- Commit message:
- Added getLogDir and getMaxCurrent as public methods to Battery
Changed in this revision
| Battery/Battery.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Battery/Battery.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Battery/Battery.cpp Wed Jun 08 22:12:52 2016 +0000
+++ b/Battery/Battery.cpp Wed Jun 08 22:48:09 2016 +0000
@@ -39,7 +39,7 @@
// ***** Variable initialisation *****
// Public variable initialisation
- maxChargeRate=0.0; // Charge rate in amps
+ maxChargeRate=1.0; // Charge rate in amps
// Protected variables initialisation
count=0;
@@ -69,6 +69,8 @@
flagSendFileSize=0;
flagSendFile=0;
flagSendFileDone=0;
+ flagGetMaxCharge=0;
+ sendingFile=0;
// Protected interrupts
button=NULL;
@@ -236,8 +238,23 @@
break;}
+
+ case ('M'):{
+ time_t now;
+ sscanf (&dataRx[2],"%f",&maxChargeRate );
+ if(maxChargeRate>2.0){
+ maxChargeRate=2.0;
+ }
+ if (maxChargeRate<0.0){
+ maxChargeRate=0.0;
+ }
+ DBG ("Max charge %f \n\r",maxChargeRate);
+
+ break;}
}
+
}
+
if (((status >>TX_DS)& 01) ==1) {
// maxRT=false;
nrf->flushTx();
@@ -268,6 +285,10 @@
nrf->flushRx();
nrf->retransmitData();
}
+ if ((!sendingFile)&&(checkedIn == 1)){
+ flagGetTime=1;
+ flagGetMaxCharge=1;
+ }
}
// ------------------------------------------------------------------------
@@ -321,57 +342,70 @@
* Slow routines for Battery
*/
void Battery::loop() {
- while (1) {
- *ledGreen = !checkedIn;
+
+ *ledGreen = !checkedIn;
- if (flagGetTime) {
- flagGetTime=0;
- getTime();
+ if (flagGetTime) {
+ flagGetTime=0;
+ requestTime();
+
+ }
+ if (flagGetMaxCharge) {
+ flagGetMaxCharge=0;
+ requestMaxCharge();
- }
- if (flagNextFile) {
- flagNextFile = 0;
- getTime();
- nextFileToTx();
- if (fileLength>0){
- INFO("Sending file %s.",txFileName)
- sendDirName();
- } else {
- INFO("No more files to send.")
- }
+ }
+ if (flagNextFile) {
+ flagNextFile = 0;
+ requestTime();
+ nextFileToTx();
+ if (fileLength>0){
+ INFO("Sending file %s.",txFileName)
+ sendDirName();
+ } else {
+ sendingFile=0;
+ INFO("No more files to send.")
}
- if (flagSendFileName) {
- flagSendFileName = 0;
- sendFileName();
+ }
+ if (flagSendFileName) {
+ flagSendFileName = 0;
+ sendFileName();
- }
- if (flagSendFileSize) {
- flagSendFileSize = 0;
- sendFileSize();
- }
- if (flagSendFile) {
- flagSendFile = 0;
- sendFile();
- }
- if (flagSendFileDone) {
- flagSendFileDone = 0;
- sendFileDone();
- INFO("File sent <%s>",txFileName);
- flag = &flagNextFile;
- delay->detach();
- delay->attach(this, &Battery::setFlag, 2.5);
- }
- __WFI();
+ }
+ if (flagSendFileSize) {
+ flagSendFileSize = 0;
+ sendFileSize();
+ }
+ if (flagSendFile) {
+ flagSendFile = 0;
+ sendFile();
}
+ if (flagSendFileDone) {
+ flagSendFileDone = 0;
+ sendFileDone();
+ INFO("File sent <%s>",txFileName);
+ flag = &flagNextFile;
+ delay->detach();
+ delay->attach(this, &Battery::setFlag, 2.5);
+ }
+
}
/**
* sends a request for time update.
*/
-void Battery::getTime() {
+void Battery::requestTime() {
DBG("getTime");
nrf->transmitData("T ",2);
}
+
+/**
+ * sends a request for time update.
+ */
+void Battery::requestMaxCharge() {
+ DBG("getTime");
+ nrf->transmitData("M ",2);
+}
/**
* Selects the next file to transmit
* Uses /sd/lastFileTx.txt to store the lst file transmitted
@@ -487,6 +521,7 @@
if (fileLength < 1) {
return;
}
+ sendingFile=1;
filePointer = 0;
sprintf(dataTx, "S %X", fileLength);
@@ -579,3 +614,20 @@
}
flag = NULL;
}
+
+
+/**
+ * Returns the max current that can be drawn from the system, in amps
+ */
+
+float Battery::getMaxCurrent(){
+ return maxChargeRate;
+}
+
+/**
+ * returns a string of the log directory
+ */
+char* Battery::getLogDirectory(){
+
+ return logDir;
+}
--- a/Battery/Battery.h Wed Jun 08 22:12:52 2016 +0000
+++ b/Battery/Battery.h Wed Jun 08 22:48:09 2016 +0000
@@ -61,6 +61,17 @@
*/
void checkIn();
+ /**
+ * Returns the max current that can be drawn from the system, in amps
+ */
+
+ float getMaxCurrent();
+
+ /**
+ * returns a string of the log directory
+ */
+ char *getLogDirectory();
+
protected:
// **********************
@@ -104,6 +115,8 @@
volatile char flagSendFileSize;
volatile char flagSendFile;
volatile char flagSendFileDone;
+ volatile char flagGetMaxCharge;
+ volatile char sendingFile;
// **********************
@@ -133,7 +146,7 @@
/**
* sends a request for time update.
*/
- void getTime();
+ void requestTime();
/**
* Sets the value pointed to by flag to 1.
*/
@@ -163,6 +176,11 @@
*/
void intNrf();
+ /**
+ * sends a request for time update.
+ */
+ void requestMaxCharge();
+
private:
// **********************
// * Private variables: *
@@ -170,5 +188,6 @@
volatile bool maxRT;
+
};
#endif
