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

Committer:
Bobty
Date:
Fri Oct 04 10:38:42 2013 +0000
Revision:
4:c593741df37e
Parent:
2:24fd130c3600
Cosmetic only - no functional changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Bobty 4:c593741df37e 1 /* WindowShade.cpp
Bobty 4:c593741df37e 2 Rob Dobson 2013
Bobty 4:c593741df37e 3 More details at http://robdobson.com/2013/10/moving-my-window-shades-control-to-mbed/
Bobty 4:c593741df37e 4 */
Bobty 4:c593741df37e 5
Bobty 2:24fd130c3600 6 #include "WindowShade.h"
Bobty 4:c593741df37e 7
Bobty 4:c593741df37e 8 WindowShade::WindowShade(char* name, PinName up, PinName stop, PinName down)
Bobty 4:c593741df37e 9 {
Bobty 4:c593741df37e 10 strncpy(_shadeName, name, MAX_SHADE_NAME_LEN);
Bobty 4:c593741df37e 11 _shadeName[MAX_SHADE_NAME_LEN-1] = '\0';
Bobty 4:c593741df37e 12 _pUpPin = new DigitalOut(up);
Bobty 4:c593741df37e 13 _pStopPin = new DigitalOut(stop);
Bobty 4:c593741df37e 14 _pDownPin = new DigitalOut(down);
Bobty 4:c593741df37e 15 _msTimeout = 0;
Bobty 4:c593741df37e 16 _tickCount = 0;
Bobty 4:c593741df37e 17
Bobty 4:c593741df37e 18 }
Bobty 4:c593741df37e 19
Bobty 4:c593741df37e 20 void WindowShade::ClearOutputs()
Bobty 4:c593741df37e 21 {
Bobty 4:c593741df37e 22 // Clear any existing command
Bobty 4:c593741df37e 23 _msTimeout = 0;
Bobty 4:c593741df37e 24 _tickCount = 0;
Bobty 4:c593741df37e 25 *_pUpPin = false;
Bobty 4:c593741df37e 26 *_pStopPin = false;
Bobty 4:c593741df37e 27 *_pDownPin = false;
Bobty 4:c593741df37e 28 }
Bobty 4:c593741df37e 29
Bobty 4:c593741df37e 30 void WindowShade::SetTimedOutput(DigitalOut* pPin, bool state, long msDuration, bool bClearExisting)
Bobty 4:c593741df37e 31 {
Bobty 4:c593741df37e 32 // printf("Setting %s %d %ld %d\n\r", _shadeName, state, msDuration, bClearExisting);
Bobty 4:c593741df37e 33
Bobty 4:c593741df37e 34 if (bClearExisting)
Bobty 4:c593741df37e 35 ClearOutputs();
Bobty 4:c593741df37e 36 *pPin = state;
Bobty 4:c593741df37e 37 if (msDuration != 0)
Bobty 4:c593741df37e 38 {
Bobty 4:c593741df37e 39 _msTimeout = msDuration;
Bobty 4:c593741df37e 40 _tickCount = 0;
Bobty 4:c593741df37e 41 }
Bobty 4:c593741df37e 42 }
Bobty 4:c593741df37e 43
Bobty 4:c593741df37e 44 void WindowShade::CheckTimeouts(int tickMs)
Bobty 4:c593741df37e 45 {
Bobty 4:c593741df37e 46 // Couldn't get Timer to work so doing with a tick-count
Bobty 4:c593741df37e 47 if (_msTimeout != 0)
Bobty 4:c593741df37e 48 {
Bobty 4:c593741df37e 49 _tickCount++;
Bobty 4:c593741df37e 50 if ((_tickCount-1)*tickMs > _msTimeout)
Bobty 4:c593741df37e 51 {
Bobty 4:c593741df37e 52 ClearOutputs();
Bobty 4:c593741df37e 53 _msTimeout = 0;
Bobty 4:c593741df37e 54 }
Bobty 4:c593741df37e 55 }
Bobty 4:c593741df37e 56 }
Bobty 4:c593741df37e 57
Bobty 4:c593741df37e 58 void WindowShade::DoCommand(char* pDirn, char* pDuration)
Bobty 4:c593741df37e 59 {
Bobty 4:c593741df37e 60 // printf("DoCommand %s %s %s\n\r", _shadeName, pDirn, pDuration);
Bobty 4:c593741df37e 61
Bobty 4:c593741df37e 62 // Duration and state
Bobty 4:c593741df37e 63 int state = false;
Bobty 4:c593741df37e 64 int msDuration = 0;
Bobty 4:c593741df37e 65 if (strcmp(pDuration, "on") == 0)
Bobty 4:c593741df37e 66 {
Bobty 4:c593741df37e 67 state = true;
Bobty 4:c593741df37e 68 msDuration = MAX_SHADE_ON_MILLSECS;
Bobty 4:c593741df37e 69 }
Bobty 4:c593741df37e 70 else if (strcmp(pDuration, "off") == 0)
Bobty 4:c593741df37e 71 {
Bobty 4:c593741df37e 72 state = false;
Bobty 4:c593741df37e 73 msDuration = 0;
Bobty 4:c593741df37e 74 }
Bobty 4:c593741df37e 75 else if (strcmp(pDuration, "pulse") == 0)
Bobty 4:c593741df37e 76 {
Bobty 4:c593741df37e 77 state = true;
Bobty 4:c593741df37e 78 msDuration = PULSE_ON_MILLISECS;
Bobty 4:c593741df37e 79 }
Bobty 4:c593741df37e 80
Bobty 4:c593741df37e 81 // Direction & config
Bobty 4:c593741df37e 82 if (strcmp(pDirn, "up") == 0)
Bobty 4:c593741df37e 83 {
Bobty 4:c593741df37e 84 SetTimedOutput(_pUpPin, state, msDuration, true);
Bobty 4:c593741df37e 85 }
Bobty 4:c593741df37e 86 else if (strcmp(pDirn, "stop") == 0)
Bobty 4:c593741df37e 87 {
Bobty 4:c593741df37e 88 SetTimedOutput(_pStopPin, state, msDuration, true);
Bobty 4:c593741df37e 89 }
Bobty 4:c593741df37e 90 else if (strcmp(pDirn, "down") == 0)
Bobty 4:c593741df37e 91 {
Bobty 4:c593741df37e 92 SetTimedOutput(_pDownPin, state, msDuration, true);
Bobty 4:c593741df37e 93 }
Bobty 4:c593741df37e 94 else if (strcmp(pDirn, "setuplimit") == 0)
Bobty 4:c593741df37e 95 {
Bobty 4:c593741df37e 96 SetTimedOutput(_pStopPin, state, 0, true);
Bobty 4:c593741df37e 97 SetTimedOutput(_pDownPin, state, msDuration, false);
Bobty 4:c593741df37e 98 }
Bobty 4:c593741df37e 99 else if (strcmp(pDirn, "setdownlimit") == 0)
Bobty 4:c593741df37e 100 {
Bobty 4:c593741df37e 101 SetTimedOutput(_pStopPin, state, 0, true);
Bobty 4:c593741df37e 102 SetTimedOutput(_pUpPin, state, msDuration, false);
Bobty 4:c593741df37e 103 }
Bobty 4:c593741df37e 104 else if (strcmp(pDirn, "resetmemory") == 0)
Bobty 4:c593741df37e 105 {
Bobty 4:c593741df37e 106 SetTimedOutput(_pStopPin, state, 0, true);
Bobty 4:c593741df37e 107 SetTimedOutput(_pDownPin, state, 0, false);
Bobty 4:c593741df37e 108 SetTimedOutput(_pUpPin, state, msDuration, false);
Bobty 4:c593741df37e 109 }
Bobty 4:c593741df37e 110
Bobty 4:c593741df37e 111 }