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.
Diff: main.cpp
- Revision:
- 2:b258510a2573
- Parent:
- 1:32ac32201889
- Child:
- 3:34f37e33016d
--- a/main.cpp Mon Apr 25 01:32:33 2016 +0000
+++ b/main.cpp Mon Apr 25 02:29:13 2016 +0000
@@ -80,32 +80,58 @@
data[i] = (int)wifi_message[i+4]-48; // first 6 values are in char, subtracting 48 gives raw int
data[i+6] = (int)wifi_message[i+12]-48; // second 6 values are for slave values
}
+ for(int i = 0; i < 3; i++) // Convert integer array to string
+ {
+ mDimStr += data[i+4];
+ mTempStr += data[i+7];
+ sDimStr += data[i+12];
+ sTempStr += data[i+15];
+ }
+
+ if(data[0] > 1 || data[6] > 1) // Logic check for dim amount for both master and slave
+ wifi.printf("Somehow... you are dimming over 100%...");
+ else
+ {
+ mDimAmt = (data[0]*100)+(data[1]*10)+(data[2]); // Data 0:2 is the 3 digit percentile for master
+ sDimAmt = (data[6]*100)+(data[7]*10)+(data[8]); // data 6:8 is the 3 digit percentile for slave
+ }
if (toupper(wifi_message [1]) == 'S') //Print status
{
- for(int i = 0; i < 3; i++) // Convert integer array to string
- {
- mDimStr += data[i+4];
- mTempStr += data[i+7];
- sDimStr += data[i+12];
- sTempStr += data[i+15];
- }
- pc.printf("Master Dim: %s\n", mDimStr); // Print to terminal, NOTICE: weird warning
- pc.printf("Master Temp: %s\n", mTempStr);
- pc.printf("Slave Dim: %s\n", sDimStr);
- pc.printf("Slave Temp: %s\n", sTempStr);
+ wifi.printf("Master Dim: %s\n", mDimStr); // Print to terminal, NOTICE: weird warning
+ wifi.printf("Master Temp: %s\n", mTempStr);
+ wifi.printf("Slave Dim: %s\n", sDimStr);
+ wifi.printf("Slave Temp: %s\n", sTempStr);
}
else if (toupper(wifi_message [1]) == 'D') //Dim
{
- for(int i = 0; i < 3; i++) // Grab master and slave dim values
- {
- mDimAmt += data[i];
- //mTemp += data[i+3];
- sDimAmt += data[i+6];
- //sTemp += data[i+9];
- }
-
+ // ----------------------------- Prioritize Wireless/Manual Mode -----------------------------------
+
+ if ( mPot.read() > 0.0 || wifi_message[3] == '0') // If the pot is at any value or in physical mode
+ {
+ master_manual = true;
+ mPot_val = mPot.read(); //read in value from potentiometer
+ pwm.write(mPot_val); //output potentiometer value to pwm
+ }
+
+ else if (wifi_message[3] == '1' ) //Check: Wireless for master
+ {
+ pwm.write((float)(mDimAmt/100)); //Send out dim value from parsed data wirelessly
+
+ }
+
+ if ( sPot.read() > 0.0 || wifi_message[11] == '0')
+ {
+ slave_manual = true;
+ sPot_val = sPot.read();
+ pwm.write(sPot_val);
+ }
+ else if (wifi_message [11] == '1' ) //Check: Wireless for slave
+ {
+ pwm.write((float)(sDimAmt/100)); //Send out dim value from parsed data wirelessly
+
+ }
}
/* IGNORE THIS
@@ -127,38 +153,7 @@
}
- // ----------------------------- Prioritize Wireless/Manual Mode -----------------------------------
-
- if ( mPot.read() > 0.0 )
- {
- if (wifi_message [3] == '0' ) // Check: Manual mode for Master
- {
- master_manual = true;
- mPot_val = mPot.read(); //read in value from potentiometer
- pwm.write(mPot_val); //output potentiometer value to pwm
- }
-
- else if (wifi_message [3] == "1" ) //Check: Wireless for master
- {
- pwm.write((float)(mDimAmt/100)); //Send out dim value from parsed data wirelessly
-
- }
- }
-
- if ( sPot.read() > 0.0)
- {
- if (wifi_message [11] == "0") // Check: Manual mode for Slave
- {
- slave_manual = true;
- sPot_val = sPot.read();
- pwm.write(sPot_val);
- }
- else if (wifi_message [11] == "1" ) //Check: Wireless for slave
- {
- pwm.write((float)(sDimAmt/100)); //Send out dim value from parsed data wirelessly
-
- }
- }
+
/*
if (wifi_message [2] == 'D') { // if Dimming check if slave
@@ -185,7 +180,7 @@
{
// Send Dim level message from GSM (General Status Master)
while(1){
- wifi.printf("GSM%03d000S000000",M_Dim);
+ wifi.printf("GSM%03d000S000000",mDimAmt);
// Delay the OS by 3 seconds
osDelay(3000); // updating status every 3 seconds
}