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 master_firmware_042716 by
Diff: main.cpp
- Revision:
- 1:90eadb418638
- Parent:
- 0:ea5937bf5485
- Child:
- 2:3a3260cd7215
--- a/main.cpp Thu Apr 28 02:20:35 2016 +0000
+++ b/main.cpp Thu Apr 28 04:06:32 2016 +0000
@@ -26,10 +26,6 @@
//string wifi_receive = ""; //data recieved from Feather
string wifi_sent = ""; //data sent to the Feather
-string mDimStr = "";
-string mTempStr = "";
-string sTempStr = "";
-string sDimStr = "";
string masterMode = "";
string slaveMode = "";
@@ -39,27 +35,40 @@
int mTemp = 0;
float dim_percent = 0.0;
+int itterate = 0;
+
bool receiveComplete = false;
bool decodeComplete = false;
-char wifi_message [18] = {};
+char wifi_message [16] = {'M','A','0','0','0','0','0','0','S','A','0','0','0','0','0','0'};
//Thread for receiving data
void wifi_receive(void const *args) {
while (1)
{
- int i = 0;
+
+ //pc.printf("in receive");
while (pc.readable()){ //DEBUGGING purposes
- wifi_message[i] = pc.getc(); //DEBUGGING purposes
- i = i+1;
- osDelay(45);
- }
+ //pc.printf("in read mode");
+ char temp = pc.getc();
+ wifi_message[itterate] = temp; //DEBUGGING purposes
+ itterate = itterate+1;
+ //pc.printf("I counter = : %d\n\r",itterate);
+ //pc.printf("I counter = : %d",i);
+ osDelay(1);
+ }
+ //pc.printf(wifi_message);
- if(i > 17) //Done receiving
+ if(itterate >= 15) //Done receiving
{
+ //pc.printf("I counter = : %d\n\r",itterate);
receiveComplete = true;
- i = 0; //reset iterator
+ itterate = 0; //reset iterator
pc.printf(wifi_message);
}
+ //else if (itterate < 17)
+ //{
+ // pc.printf("I counter = : %d\n\r",itterate);
+ //}
osDelay(45);
} // END superloop
@@ -68,33 +77,26 @@
void wifi_decode(void const *args) {
while (1) {
-
- if( receiveComplete )
+ if(receiveComplete )
{
receiveComplete = false;
- if(wifi_message[0] == 'G' && wifi_message[2] == 'M' && wifi_message[10] == 'S')
+ if(wifi_message[0] == 'M' && wifi_message[8] == 'S')
{
int data [12] = {};
- for (int i = 0; i < 7; i++)
+ for (int i = 0; i < 6; i++)
{
- data[i] = (int)wifi_message [i+4] -48;
- data[i+6] = (int)wifi_message[i+12] -48;
-
- }
- for(int i = 0; i<3; i++)
- {
- mDimStr += data[i];
- mTempStr += data[i+3];
- sDimStr += data[i+6];
- sTempStr += data[i+9];
+ data[i] = (int)wifi_message [i+2]-48;
+ data[i+6] = (int)wifi_message[i+10]-48;
}
mDimAmt = (data[0]*100)+(data[1]*10)+(data[2]); //Data 0:2 is the 3 digit percentiloe for Master
+ mTemp = (data[3]*100)+(data[4]*10)+(data[5]);
sDimAmt = (data[6]*100)+(data[7]*10)+(data[8]); //Data 6:8 is the 3 digit percentile for Slave
-
- pc.printf("Master dim amount: %03d", mDimAmt);
- pc.printf("Slave dim amount: %03d", sDimAmt);
+ sTemp = (data[9]*100)+(data[10]*10)+(data[11]);
+ pc.printf("%03d-%03d-%03d-%03d\n\r",mDimAmt,mTemp,sDimAmt,sTemp);
+ //pc.printf("Master dim amount: %03d\n\r", mDimAmt);
+ //pc.printf("Slave dim amount: %03d\n\r", sDimAmt);
//SET mutex for wifi action HERE
decodeComplete = true;
@@ -108,21 +110,22 @@
void wifi_action(void const *args) {
while (1) {
- if(decodeComplete)
- {
+ //if(decodeComplete)
+ //{
if(master_manual == false)
{
- pwm.write((float)(mDimAmt/100)); //send out dim value
-
+ //pc.printf("in auto mode diming");
+ float dimamount = (float)mDimAmt/100;
+ pwm.write(dimamount); //send out dim value
}
- }
- osDelay(45);
+ //}
+ osDelay(10);
} //END superloop
} //END wifi_action thread
void light_status_update(void const *args) {
while (1) {
- //pc.printf("GSMA000000SA000000");
+ //pc.printf("MA000000SA000000");
pot_value = pot.read();
if(pot_value > zero )
@@ -133,6 +136,7 @@
}
else if (pot_value < zero)
{
+ master_manual = false;
masterMode = "A";
}
if (decodeComplete == true)
@@ -163,11 +167,6 @@
{
osDelay(30);
}
-
-
-
-
-
}//END main
