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:
- 0:ea5937bf5485
- Child:
- 1:90eadb418638
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Apr 28 02:20:35 2016 +0000
@@ -0,0 +1,175 @@
+#include "mbed.h"
+#include "cmsis_os.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <iostream>
+#include <string>
+#include <ctype.h>
+
+RawSerial XBEE(p37, p31); //Master to slave communication
+
+RawSerial pc(USBTX,USBRX); //UART monitor from pc
+RawSerial wifi(p9, p10); // master to wifi UART
+
+PwmOut pwm(p27);
+AnalogIn pot(p15);
+
+#define zero (float)0.01
+
+float pot_value = 0.0;
+
+bool master_manual = false;
+bool slave_manual = false;
+
+string received = "";
+string sent = "";
+//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 = "";
+
+int sDimAmt = 0;
+int mDimAmt = 0;
+int sTemp = 0;
+int mTemp = 0;
+float dim_percent = 0.0;
+
+bool receiveComplete = false;
+bool decodeComplete = false;
+char wifi_message [18] = {};
+
+//Thread for receiving data
+void wifi_receive(void const *args) {
+ while (1)
+ {
+ int i = 0;
+ while (pc.readable()){ //DEBUGGING purposes
+ wifi_message[i] = pc.getc(); //DEBUGGING purposes
+ i = i+1;
+ osDelay(45);
+ }
+
+ if(i > 17) //Done receiving
+ {
+ receiveComplete = true;
+ i = 0; //reset iterator
+ pc.printf(wifi_message);
+ }
+ osDelay(45);
+
+ } // END superloop
+}// END wifi_receive thread
+
+void wifi_decode(void const *args) {
+
+ while (1) {
+
+ if( receiveComplete )
+ {
+ receiveComplete = false;
+ if(wifi_message[0] == 'G' && wifi_message[2] == 'M' && wifi_message[10] == 'S')
+ {
+ int data [12] = {};
+ for (int i = 0; i < 7; 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];
+
+ }
+
+ mDimAmt = (data[0]*100)+(data[1]*10)+(data[2]); //Data 0:2 is the 3 digit percentiloe for Master
+ 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);
+
+ //SET mutex for wifi action HERE
+ decodeComplete = true;
+ }
+ }
+
+ osDelay(45);
+ } //END superloop
+} //END wifi_decode thread
+
+void wifi_action(void const *args) {
+
+ while (1) {
+ if(decodeComplete)
+ {
+ if(master_manual == false)
+ {
+ pwm.write((float)(mDimAmt/100)); //send out dim value
+
+ }
+ }
+ osDelay(45);
+ } //END superloop
+} //END wifi_action thread
+
+void light_status_update(void const *args) {
+ while (1) {
+ //pc.printf("GSMA000000SA000000");
+ pot_value = pot.read();
+
+ if(pot_value > zero )
+ {
+ master_manual = true;
+ pwm.write(pot_value);
+ masterMode = "M";
+ }
+ else if (pot_value < zero)
+ {
+ masterMode = "A";
+ }
+ if (decodeComplete == true)
+ {
+ pc.printf("GSM%s%03d%03d",masterMode,mDimAmt,mTemp);
+ decodeComplete = false;
+ }
+ osDelay(300);
+
+ } //END superloop
+} //END thread light_status_update
+
+osThreadDef(wifi_receive, osPriorityNormal, DEFAULT_STACK_SIZE);
+osThreadDef(wifi_decode, osPriorityNormal, DEFAULT_STACK_SIZE);
+osThreadDef(wifi_action, osPriorityNormal, DEFAULT_STACK_SIZE);
+osThreadDef(light_status_update, osPriorityNormal, DEFAULT_STACK_SIZE);
+
+int main ()
+{
+ osThreadCreate(osThread(wifi_receive),NULL);
+ osThreadCreate(osThread(wifi_decode),NULL);
+ osThreadCreate(osThread(wifi_action),NULL);
+ osThreadCreate(osThread(light_status_update),NULL);
+ pc.baud(115200);
+ wifi.baud(115200);
+ XBEE.baud(115200);
+ while(1)
+ {
+ osDelay(30);
+ }
+
+
+
+
+
+}//END main
+
+
+
+
\ No newline at end of file
