fork of StateScript

Dependencies:   mbed SOMO_II

Fork of stateScript_v2 by Mattias Karlsson

Committer:
mkarlsso
Date:
Tue Feb 07 18:45:25 2017 +0000
Revision:
7:5fe7329751d4
Parent:
3:d7b0a0890d96
Child:
8:872b843a3053
Fixed flip command for digital outputs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mkarlsso 0:8dbd6bd9167f 1 #ifndef HARDWARWEINTERFACE_H
mkarlsso 0:8dbd6bd9167f 2 #define HARDWARWEINTERFACE_H
mkarlsso 0:8dbd6bd9167f 3
mkarlsso 0:8dbd6bd9167f 4 #include <stdint.h>
mkarlsso 0:8dbd6bd9167f 5 #include <string>
mkarlsso 3:d7b0a0890d96 6 #include <cstdlib>
mkarlsso 3:d7b0a0890d96 7 #include <string.h>
mkarlsso 0:8dbd6bd9167f 8
mkarlsso 0:8dbd6bd9167f 9 #define PENDINGTRIGGERBUFFERSIZE 10
mkarlsso 0:8dbd6bd9167f 10
mkarlsso 0:8dbd6bd9167f 11 //#define NUMPORTS 8 //the number of ports available on the hardware
mkarlsso 0:8dbd6bd9167f 12
mkarlsso 0:8dbd6bd9167f 13 using namespace std;
mkarlsso 0:8dbd6bd9167f 14
mkarlsso 0:8dbd6bd9167f 15 //for debugging output
mkarlsso 0:8dbd6bd9167f 16 //#define DEBUGOUTPUT
mkarlsso 0:8dbd6bd9167f 17
mkarlsso 0:8dbd6bd9167f 18 //used to organize digital change events
mkarlsso 0:8dbd6bd9167f 19 struct changeEvent {
mkarlsso 0:8dbd6bd9167f 20 uint32_t timeStamp;
mkarlsso 0:8dbd6bd9167f 21 bool triggered;
mkarlsso 0:8dbd6bd9167f 22 };
mkarlsso 0:8dbd6bd9167f 23
mkarlsso 0:8dbd6bd9167f 24 class sDigitalOut
mkarlsso 0:8dbd6bd9167f 25 {
mkarlsso 0:8dbd6bd9167f 26 public:
mkarlsso 0:8dbd6bd9167f 27 sDigitalOut();
mkarlsso 0:8dbd6bd9167f 28
mkarlsso 0:8dbd6bd9167f 29 virtual void init(int pin) = 0;
mkarlsso 0:8dbd6bd9167f 30 virtual void write(int value) = 0;
mkarlsso 0:8dbd6bd9167f 31 virtual int read() = 0;
mkarlsso 0:8dbd6bd9167f 32 protected:
mkarlsso 0:8dbd6bd9167f 33
mkarlsso 0:8dbd6bd9167f 34 };
mkarlsso 0:8dbd6bd9167f 35
mkarlsso 7:5fe7329751d4 36 class sAnalogIn
mkarlsso 7:5fe7329751d4 37 {
mkarlsso 7:5fe7329751d4 38 public:
mkarlsso 7:5fe7329751d4 39 sAnalogIn();
mkarlsso 7:5fe7329751d4 40
mkarlsso 7:5fe7329751d4 41 virtual void init(int pin) = 0;
mkarlsso 7:5fe7329751d4 42 virtual int read() = 0;
mkarlsso 7:5fe7329751d4 43
mkarlsso 7:5fe7329751d4 44
mkarlsso 7:5fe7329751d4 45 protected:
mkarlsso 7:5fe7329751d4 46
mkarlsso 7:5fe7329751d4 47
mkarlsso 7:5fe7329751d4 48 };
mkarlsso 7:5fe7329751d4 49
mkarlsso 7:5fe7329751d4 50 class sAnalogOut
mkarlsso 7:5fe7329751d4 51 {
mkarlsso 7:5fe7329751d4 52 public:
mkarlsso 7:5fe7329751d4 53 sAnalogOut();
mkarlsso 7:5fe7329751d4 54
mkarlsso 7:5fe7329751d4 55 virtual void init(int pin) = 0;
mkarlsso 7:5fe7329751d4 56 virtual void write(int value) = 0;
mkarlsso 7:5fe7329751d4 57 virtual int read() = 0;
mkarlsso 7:5fe7329751d4 58 protected:
mkarlsso 7:5fe7329751d4 59
mkarlsso 7:5fe7329751d4 60 };
mkarlsso 7:5fe7329751d4 61
mkarlsso 7:5fe7329751d4 62
mkarlsso 7:5fe7329751d4 63
mkarlsso 0:8dbd6bd9167f 64 class sDigitalIn
mkarlsso 0:8dbd6bd9167f 65 {
mkarlsso 0:8dbd6bd9167f 66 public:
mkarlsso 0:8dbd6bd9167f 67 sDigitalIn();
mkarlsso 0:8dbd6bd9167f 68
mkarlsso 0:8dbd6bd9167f 69 virtual void init(int pin) = 0;
mkarlsso 0:8dbd6bd9167f 70 virtual int read() = 0;
mkarlsso 0:8dbd6bd9167f 71 virtual void interrupt_up_callback() = 0;
mkarlsso 0:8dbd6bd9167f 72 virtual void interrupt_down_callback() = 0;
mkarlsso 2:35266b266eaa 73 void setUpdate(bool);
mkarlsso 0:8dbd6bd9167f 74
mkarlsso 0:8dbd6bd9167f 75 changeEvent lastUpEvent;
mkarlsso 0:8dbd6bd9167f 76 changeEvent lastDownEvent;
mkarlsso 0:8dbd6bd9167f 77
mkarlsso 0:8dbd6bd9167f 78 protected:
mkarlsso 0:8dbd6bd9167f 79
mkarlsso 2:35266b266eaa 80 bool updating;
mkarlsso 2:35266b266eaa 81 changeEvent bufferedUpEvent;
mkarlsso 2:35266b266eaa 82 changeEvent bufferedDownEvent;
mkarlsso 0:8dbd6bd9167f 83 void addStateChange(int newState, uint32_t timeStamp);
mkarlsso 0:8dbd6bd9167f 84
mkarlsso 0:8dbd6bd9167f 85 };
mkarlsso 0:8dbd6bd9167f 86
mkarlsso 0:8dbd6bd9167f 87 class sSerialPort
mkarlsso 0:8dbd6bd9167f 88 {
mkarlsso 0:8dbd6bd9167f 89 public:
mkarlsso 0:8dbd6bd9167f 90 sSerialPort();
mkarlsso 0:8dbd6bd9167f 91
mkarlsso 0:8dbd6bd9167f 92 virtual void init() = 0;
mkarlsso 0:8dbd6bd9167f 93 virtual bool readable() = 0;
mkarlsso 0:8dbd6bd9167f 94 virtual char readChar() = 0;
mkarlsso 0:8dbd6bd9167f 95 virtual void writeChar(char s)= 0;
mkarlsso 3:d7b0a0890d96 96 virtual int requestToWriteString(char *s, int numBytes) = 0;
mkarlsso 3:d7b0a0890d96 97
mkarlsso 0:8dbd6bd9167f 98 protected:
mkarlsso 0:8dbd6bd9167f 99
mkarlsso 0:8dbd6bd9167f 100
mkarlsso 0:8dbd6bd9167f 101 };
mkarlsso 0:8dbd6bd9167f 102
mkarlsso 0:8dbd6bd9167f 103 class sSound
mkarlsso 0:8dbd6bd9167f 104 {
mkarlsso 0:8dbd6bd9167f 105 public:
mkarlsso 0:8dbd6bd9167f 106 sSound();
mkarlsso 0:8dbd6bd9167f 107 void setFile(string fileNameIn);
mkarlsso 0:8dbd6bd9167f 108 void setVolume(int* volumeIn);
mkarlsso 0:8dbd6bd9167f 109 void setVolume(int volumeIn);
mkarlsso 0:8dbd6bd9167f 110 void setPlayback(bool playIn);
mkarlsso 0:8dbd6bd9167f 111 void setReset();
mkarlsso 0:8dbd6bd9167f 112 virtual void execute() = 0;
mkarlsso 0:8dbd6bd9167f 113
mkarlsso 0:8dbd6bd9167f 114 protected:
mkarlsso 0:8dbd6bd9167f 115 char fileName[21];
mkarlsso 0:8dbd6bd9167f 116 bool fileNameExists;
mkarlsso 0:8dbd6bd9167f 117 int* volumePtr;
mkarlsso 0:8dbd6bd9167f 118 int volume;
mkarlsso 0:8dbd6bd9167f 119 bool play;
mkarlsso 0:8dbd6bd9167f 120 bool reset;
mkarlsso 0:8dbd6bd9167f 121 };
mkarlsso 0:8dbd6bd9167f 122
mkarlsso 0:8dbd6bd9167f 123 class sSystem
mkarlsso 0:8dbd6bd9167f 124 {
mkarlsso 0:8dbd6bd9167f 125 public:
mkarlsso 0:8dbd6bd9167f 126 sSystem();
mkarlsso 0:8dbd6bd9167f 127 virtual void timerinit() = 0;
mkarlsso 0:8dbd6bd9167f 128 virtual void setStandAloneClock() = 0;
mkarlsso 0:8dbd6bd9167f 129 virtual void setSlaveClock() = 0;
mkarlsso 0:8dbd6bd9167f 130 virtual sDigitalOut* getDigitalOutPtr(int portNum) = 0;
mkarlsso 0:8dbd6bd9167f 131 virtual sDigitalIn* getDigitalInPtr(int portNum) = 0;
mkarlsso 7:5fe7329751d4 132 virtual sAnalogOut* getAnalogOutPtr(int portNum) = 0;
mkarlsso 7:5fe7329751d4 133 virtual sAnalogIn* getAnalogInPtr(int portNum) = 0;
mkarlsso 0:8dbd6bd9167f 134 virtual sSound* createNewSoundAction() = 0;
mkarlsso 0:8dbd6bd9167f 135 virtual void externalClockReset() = 0; //needs to reset harware timer before calling immediateClockReset();
mkarlsso 0:8dbd6bd9167f 136 virtual void incrementClock() = 0;
mkarlsso 0:8dbd6bd9167f 137 virtual void mainLoopToDo();
mkarlsso 0:8dbd6bd9167f 138 virtual void pauseInterrupts();
mkarlsso 0:8dbd6bd9167f 139 virtual void resumeInterrupts();
mkarlsso 7:5fe7329751d4 140 virtual void reset();
mkarlsso 0:8dbd6bd9167f 141 virtual int getPendingFunctionTriggers(uint16_t *bufferPtr); //Returns the number of pending shortcut triggers
mkarlsso 0:8dbd6bd9167f 142 virtual uint32_t getDigitalOutputChangeFlags();
mkarlsso 0:8dbd6bd9167f 143 virtual uint32_t getDigitalInputChangeFlags();
mkarlsso 3:d7b0a0890d96 144 void setPortUpdatesOn(int portNum);
mkarlsso 3:d7b0a0890d96 145 void setPortUpdatesOff(int portNum);
mkarlsso 3:d7b0a0890d96 146 bool* getIgnoreUpdates();
mkarlsso 3:d7b0a0890d96 147
mkarlsso 0:8dbd6bd9167f 148
mkarlsso 0:8dbd6bd9167f 149
mkarlsso 0:8dbd6bd9167f 150 protected:
mkarlsso 0:8dbd6bd9167f 151
mkarlsso 0:8dbd6bd9167f 152 //virtual void timerInterrupt() = 0;
mkarlsso 0:8dbd6bd9167f 153
mkarlsso 3:d7b0a0890d96 154 void immediateClockReset();
mkarlsso 0:8dbd6bd9167f 155 int currentDINPin;
mkarlsso 0:8dbd6bd9167f 156 int currentDOUTPin;
mkarlsso 0:8dbd6bd9167f 157 uint32_t currentDigitalOuputStates;
mkarlsso 0:8dbd6bd9167f 158 uint32_t currentDigitalInputStates;
mkarlsso 3:d7b0a0890d96 159 bool ignorePortUpdates[32];
mkarlsso 0:8dbd6bd9167f 160
mkarlsso 0:8dbd6bd9167f 161
mkarlsso 0:8dbd6bd9167f 162
mkarlsso 0:8dbd6bd9167f 163
mkarlsso 0:8dbd6bd9167f 164 };
mkarlsso 0:8dbd6bd9167f 165
mkarlsso 0:8dbd6bd9167f 166
mkarlsso 0:8dbd6bd9167f 167 //Used to buffer output text. Used mainly for 'display' commands within the script,
mkarlsso 0:8dbd6bd9167f 168 //and alloed the reset of the block to execute quickly instead. The text is then streamed out
mkarlsso 0:8dbd6bd9167f 169 //slowly via serial (one character per main loop execution). outputStream is a simple circular
mkarlsso 0:8dbd6bd9167f 170 //buffer that cannot be resized after initiation.
mkarlsso 0:8dbd6bd9167f 171 class outputStream {
mkarlsso 0:8dbd6bd9167f 172
mkarlsso 0:8dbd6bd9167f 173 public:
mkarlsso 0:8dbd6bd9167f 174 outputStream(int bufferSizeIn);
mkarlsso 0:8dbd6bd9167f 175 ~outputStream();
mkarlsso 0:8dbd6bd9167f 176 void setSerial(sSerialPort *s);
mkarlsso 3:d7b0a0890d96 177 void send(const string &outputString);
mkarlsso 3:d7b0a0890d96 178 void send(const char* s);
mkarlsso 0:8dbd6bd9167f 179 void debug(const char* s);
mkarlsso 3:d7b0a0890d96 180 outputStream &operator<<(const string &outputString);
mkarlsso 0:8dbd6bd9167f 181 outputStream &operator<<(int outputNum);
mkarlsso 0:8dbd6bd9167f 182 outputStream &operator<<(uint32_t outputNum);
mkarlsso 0:8dbd6bd9167f 183 outputStream &operator<<(const char* s);
mkarlsso 0:8dbd6bd9167f 184 char getNextChar();
mkarlsso 0:8dbd6bd9167f 185 bool unsentData;
mkarlsso 0:8dbd6bd9167f 186 void flush();
mkarlsso 0:8dbd6bd9167f 187
mkarlsso 0:8dbd6bd9167f 188 private:
mkarlsso 0:8dbd6bd9167f 189 int readHead;
mkarlsso 0:8dbd6bd9167f 190 int writeHead;
mkarlsso 0:8dbd6bd9167f 191 int totalWriteHead;
mkarlsso 0:8dbd6bd9167f 192 int totalReadHead;
mkarlsso 0:8dbd6bd9167f 193 int bufferSize;
mkarlsso 0:8dbd6bd9167f 194 char tmpOut;
mkarlsso 0:8dbd6bd9167f 195 char* outputBuffer;
mkarlsso 0:8dbd6bd9167f 196 sSerialPort* serialPtr;
mkarlsso 0:8dbd6bd9167f 197 };
mkarlsso 0:8dbd6bd9167f 198
mkarlsso 0:8dbd6bd9167f 199
mkarlsso 0:8dbd6bd9167f 200
mkarlsso 0:8dbd6bd9167f 201 #endif // HARDWARWEINTERFACE_H