Server for window shades - using Soffy DCT-30 motors - more details here http://robdobson.com/2013/10/moving-my-window-shades-control-to-mbed/
Dependencies: EthernetInterface RdWebServer mbed-rtos mbed
Revision 4:c593741df37e, committed 2013-10-04
- Comitter:
- Bobty
- Date:
- Fri Oct 04 10:38:42 2013 +0000
- Parent:
- 3:6014671e50ef
- Commit message:
- Cosmetic only - no functional changes
Changed in this revision
diff -r 6014671e50ef -r c593741df37e RdWebServer.lib --- a/RdWebServer.lib Fri Oct 04 10:12:16 2013 +0000 +++ b/RdWebServer.lib Fri Oct 04 10:38:42 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/Bobty/code/RdWebServer/#9d8793c23b46 +http://mbed.org/users/Bobty/code/RdWebServer/#594136d34a32
diff -r 6014671e50ef -r c593741df37e WindowShade.cpp --- a/WindowShade.cpp Fri Oct 04 10:12:16 2013 +0000 +++ b/WindowShade.cpp Fri Oct 04 10:38:42 2013 +0000 @@ -1,1 +1,111 @@ +/* WindowShade.cpp + Rob Dobson 2013 + More details at http://robdobson.com/2013/10/moving-my-window-shades-control-to-mbed/ +*/ + #include "WindowShade.h" + +WindowShade::WindowShade(char* name, PinName up, PinName stop, PinName down) +{ + strncpy(_shadeName, name, MAX_SHADE_NAME_LEN); + _shadeName[MAX_SHADE_NAME_LEN-1] = '\0'; + _pUpPin = new DigitalOut(up); + _pStopPin = new DigitalOut(stop); + _pDownPin = new DigitalOut(down); + _msTimeout = 0; + _tickCount = 0; + +} + +void WindowShade::ClearOutputs() +{ + // Clear any existing command + _msTimeout = 0; + _tickCount = 0; + *_pUpPin = false; + *_pStopPin = false; + *_pDownPin = false; +} + +void WindowShade::SetTimedOutput(DigitalOut* pPin, bool state, long msDuration, bool bClearExisting) +{ +// printf("Setting %s %d %ld %d\n\r", _shadeName, state, msDuration, bClearExisting); + + if (bClearExisting) + ClearOutputs(); + *pPin = state; + if (msDuration != 0) + { + _msTimeout = msDuration; + _tickCount = 0; + } +} + +void WindowShade::CheckTimeouts(int tickMs) +{ + // Couldn't get Timer to work so doing with a tick-count + if (_msTimeout != 0) + { + _tickCount++; + if ((_tickCount-1)*tickMs > _msTimeout) + { + ClearOutputs(); + _msTimeout = 0; + } + } +} + +void WindowShade::DoCommand(char* pDirn, char* pDuration) +{ +// printf("DoCommand %s %s %s\n\r", _shadeName, pDirn, pDuration); + + // Duration and state + int state = false; + int msDuration = 0; + if (strcmp(pDuration, "on") == 0) + { + state = true; + msDuration = MAX_SHADE_ON_MILLSECS; + } + else if (strcmp(pDuration, "off") == 0) + { + state = false; + msDuration = 0; + } + else if (strcmp(pDuration, "pulse") == 0) + { + state = true; + msDuration = PULSE_ON_MILLISECS; + } + + // Direction & config + if (strcmp(pDirn, "up") == 0) + { + SetTimedOutput(_pUpPin, state, msDuration, true); + } + else if (strcmp(pDirn, "stop") == 0) + { + SetTimedOutput(_pStopPin, state, msDuration, true); + } + else if (strcmp(pDirn, "down") == 0) + { + SetTimedOutput(_pDownPin, state, msDuration, true); + } + else if (strcmp(pDirn, "setuplimit") == 0) + { + SetTimedOutput(_pStopPin, state, 0, true); + SetTimedOutput(_pDownPin, state, msDuration, false); + } + else if (strcmp(pDirn, "setdownlimit") == 0) + { + SetTimedOutput(_pStopPin, state, 0, true); + SetTimedOutput(_pUpPin, state, msDuration, false); + } + else if (strcmp(pDirn, "resetmemory") == 0) + { + SetTimedOutput(_pStopPin, state, 0, true); + SetTimedOutput(_pDownPin, state, 0, false); + SetTimedOutput(_pUpPin, state, msDuration, false); + } + +} \ No newline at end of file
diff -r 6014671e50ef -r c593741df37e WindowShade.h --- a/WindowShade.h Fri Oct 04 10:12:16 2013 +0000 +++ b/WindowShade.h Fri Oct 04 10:38:42 2013 +0000 @@ -1,3 +1,8 @@ +/* WindowShade.h + Rob Dobson 2013 + More details at http://robdobson.com/2013/10/moving-my-window-shades-control-to-mbed/ +*/ + #ifndef RD_WIN_SHADE #define RD_WIN_SHADE @@ -10,111 +15,12 @@ static const long PULSE_ON_MILLISECS = 500; static const long MAX_SHADE_ON_MILLSECS = 60000; - WindowShade(char* name, PinName up, PinName stop, PinName down) - { - strncpy(_shadeName, name, MAX_SHADE_NAME_LEN); - _shadeName[MAX_SHADE_NAME_LEN-1] = '\0'; - _pUpPin = new DigitalOut(up); - _pStopPin = new DigitalOut(stop); - _pDownPin = new DigitalOut(down); - _msTimeout = 0; - _tickCount = 0; - - } - - void ClearOutputs() - { - // Clear any existing command - _msTimeout = 0; - _tickCount = 0; - *_pUpPin = false; - *_pStopPin = false; - *_pDownPin = false; - } - - void SetTimedOutput(DigitalOut* pPin, bool state, long msDuration, bool bClearExisting) - { -// printf("Setting %s %d %ld %d\n\r", _shadeName, state, msDuration, bClearExisting); - - if (bClearExisting) - ClearOutputs(); - *pPin = state; - if (msDuration != 0) - { - _msTimeout = msDuration; - _tickCount = 0; - } - } - - void CheckTimeouts(int tickMs) - { - // Couldn't get Timer to work so doing with a tick-count - if (_msTimeout != 0) - { - _tickCount++; - if ((_tickCount-1)*tickMs > _msTimeout) - { - ClearOutputs(); - _msTimeout = 0; - } - } - } - - void DoCommand(char* pDirn, char* pDuration) - { -// printf("DoCommand %s %s %s\n\r", _shadeName, pDirn, pDuration); - - // Duration and state - int state = false; - int msDuration = 0; - if (strcmp(pDuration, "on") == 0) - { - state = true; - msDuration = MAX_SHADE_ON_MILLSECS; - } - else if (strcmp(pDuration, "off") == 0) - { - state = false; - msDuration = 0; - } - else if (strcmp(pDuration, "pulse") == 0) - { - state = true; - msDuration = PULSE_ON_MILLISECS; - } - - // Direction & config - if (strcmp(pDirn, "up") == 0) - { - SetTimedOutput(_pUpPin, state, msDuration, true); - } - else if (strcmp(pDirn, "stop") == 0) - { - SetTimedOutput(_pStopPin, state, msDuration, true); - } - else if (strcmp(pDirn, "down") == 0) - { - SetTimedOutput(_pDownPin, state, msDuration, true); - } - else if (strcmp(pDirn, "setuplimit") == 0) - { - SetTimedOutput(_pStopPin, state, 0, true); - SetTimedOutput(_pDownPin, state, msDuration, false); - } - else if (strcmp(pDirn, "setdownlimit") == 0) - { - SetTimedOutput(_pStopPin, state, 0, true); - SetTimedOutput(_pUpPin, state, msDuration, false); - } - else if (strcmp(pDirn, "resetmemory") == 0) - { - SetTimedOutput(_pStopPin, state, 0, true); - SetTimedOutput(_pDownPin, state, 0, false); - SetTimedOutput(_pUpPin, state, msDuration, false); - } - - } - + WindowShade(char* name, PinName up, PinName stop, PinName down); + void ClearOutputs(); + void SetTimedOutput(DigitalOut* pPin, bool state, long msDuration, bool bClearExisting); + void CheckTimeouts(int tickMs); + void DoCommand(char* pDirn, char* pDuration); + private: char _shadeName[MAX_SHADE_NAME_LEN]; DigitalOut* _pUpPin; DigitalOut* _pStopPin;
diff -r 6014671e50ef -r c593741df37e main.cpp --- a/main.cpp Fri Oct 04 10:12:16 2013 +0000 +++ b/main.cpp Fri Oct 04 10:38:42 2013 +0000 @@ -1,3 +1,8 @@ +/* main.cpp + Rob Dobson 2013 + More details at http://robdobson.com/2013/10/moving-my-window-shades-control-to-mbed/ +*/ + #include "mbed.h" #include "EthernetInterface.h" #include <stdio.h>