![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork of StateScript
Fork of stateScript_v2 by
hardwareInterface.h@3:d7b0a0890d96, 2015-10-10 (annotated)
- Committer:
- mkarlsso
- Date:
- Sat Oct 10 22:37:17 2015 +0000
- Revision:
- 3:d7b0a0890d96
- Parent:
- 2:35266b266eaa
- Child:
- 7:5fe7329751d4
Changes ports for new PCB board
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:8dbd6bd9167f | 36 | class sDigitalIn |
mkarlsso | 0:8dbd6bd9167f | 37 | { |
mkarlsso | 0:8dbd6bd9167f | 38 | public: |
mkarlsso | 0:8dbd6bd9167f | 39 | sDigitalIn(); |
mkarlsso | 0:8dbd6bd9167f | 40 | |
mkarlsso | 0:8dbd6bd9167f | 41 | virtual void init(int pin) = 0; |
mkarlsso | 0:8dbd6bd9167f | 42 | virtual int read() = 0; |
mkarlsso | 0:8dbd6bd9167f | 43 | virtual void interrupt_up_callback() = 0; |
mkarlsso | 0:8dbd6bd9167f | 44 | virtual void interrupt_down_callback() = 0; |
mkarlsso | 2:35266b266eaa | 45 | void setUpdate(bool); |
mkarlsso | 0:8dbd6bd9167f | 46 | |
mkarlsso | 0:8dbd6bd9167f | 47 | changeEvent lastUpEvent; |
mkarlsso | 0:8dbd6bd9167f | 48 | changeEvent lastDownEvent; |
mkarlsso | 0:8dbd6bd9167f | 49 | |
mkarlsso | 0:8dbd6bd9167f | 50 | protected: |
mkarlsso | 0:8dbd6bd9167f | 51 | |
mkarlsso | 2:35266b266eaa | 52 | bool updating; |
mkarlsso | 2:35266b266eaa | 53 | changeEvent bufferedUpEvent; |
mkarlsso | 2:35266b266eaa | 54 | changeEvent bufferedDownEvent; |
mkarlsso | 0:8dbd6bd9167f | 55 | void addStateChange(int newState, uint32_t timeStamp); |
mkarlsso | 0:8dbd6bd9167f | 56 | |
mkarlsso | 0:8dbd6bd9167f | 57 | }; |
mkarlsso | 0:8dbd6bd9167f | 58 | |
mkarlsso | 0:8dbd6bd9167f | 59 | class sSerialPort |
mkarlsso | 0:8dbd6bd9167f | 60 | { |
mkarlsso | 0:8dbd6bd9167f | 61 | public: |
mkarlsso | 0:8dbd6bd9167f | 62 | sSerialPort(); |
mkarlsso | 0:8dbd6bd9167f | 63 | |
mkarlsso | 0:8dbd6bd9167f | 64 | virtual void init() = 0; |
mkarlsso | 0:8dbd6bd9167f | 65 | virtual bool readable() = 0; |
mkarlsso | 0:8dbd6bd9167f | 66 | virtual char readChar() = 0; |
mkarlsso | 0:8dbd6bd9167f | 67 | virtual void writeChar(char s)= 0; |
mkarlsso | 3:d7b0a0890d96 | 68 | virtual int requestToWriteString(char *s, int numBytes) = 0; |
mkarlsso | 3:d7b0a0890d96 | 69 | |
mkarlsso | 0:8dbd6bd9167f | 70 | protected: |
mkarlsso | 0:8dbd6bd9167f | 71 | |
mkarlsso | 0:8dbd6bd9167f | 72 | |
mkarlsso | 0:8dbd6bd9167f | 73 | }; |
mkarlsso | 0:8dbd6bd9167f | 74 | |
mkarlsso | 0:8dbd6bd9167f | 75 | class sSound |
mkarlsso | 0:8dbd6bd9167f | 76 | { |
mkarlsso | 0:8dbd6bd9167f | 77 | public: |
mkarlsso | 0:8dbd6bd9167f | 78 | sSound(); |
mkarlsso | 0:8dbd6bd9167f | 79 | void setFile(string fileNameIn); |
mkarlsso | 0:8dbd6bd9167f | 80 | void setVolume(int* volumeIn); |
mkarlsso | 0:8dbd6bd9167f | 81 | void setVolume(int volumeIn); |
mkarlsso | 0:8dbd6bd9167f | 82 | void setPlayback(bool playIn); |
mkarlsso | 0:8dbd6bd9167f | 83 | void setReset(); |
mkarlsso | 0:8dbd6bd9167f | 84 | virtual void execute() = 0; |
mkarlsso | 0:8dbd6bd9167f | 85 | |
mkarlsso | 0:8dbd6bd9167f | 86 | protected: |
mkarlsso | 0:8dbd6bd9167f | 87 | char fileName[21]; |
mkarlsso | 0:8dbd6bd9167f | 88 | bool fileNameExists; |
mkarlsso | 0:8dbd6bd9167f | 89 | int* volumePtr; |
mkarlsso | 0:8dbd6bd9167f | 90 | int volume; |
mkarlsso | 0:8dbd6bd9167f | 91 | bool play; |
mkarlsso | 0:8dbd6bd9167f | 92 | bool reset; |
mkarlsso | 0:8dbd6bd9167f | 93 | }; |
mkarlsso | 0:8dbd6bd9167f | 94 | |
mkarlsso | 0:8dbd6bd9167f | 95 | class sSystem |
mkarlsso | 0:8dbd6bd9167f | 96 | { |
mkarlsso | 0:8dbd6bd9167f | 97 | public: |
mkarlsso | 0:8dbd6bd9167f | 98 | sSystem(); |
mkarlsso | 0:8dbd6bd9167f | 99 | virtual void timerinit() = 0; |
mkarlsso | 0:8dbd6bd9167f | 100 | virtual void setStandAloneClock() = 0; |
mkarlsso | 0:8dbd6bd9167f | 101 | virtual void setSlaveClock() = 0; |
mkarlsso | 0:8dbd6bd9167f | 102 | virtual sDigitalOut* getDigitalOutPtr(int portNum) = 0; |
mkarlsso | 0:8dbd6bd9167f | 103 | virtual sDigitalIn* getDigitalInPtr(int portNum) = 0; |
mkarlsso | 0:8dbd6bd9167f | 104 | virtual sSound* createNewSoundAction() = 0; |
mkarlsso | 0:8dbd6bd9167f | 105 | virtual void externalClockReset() = 0; //needs to reset harware timer before calling immediateClockReset(); |
mkarlsso | 0:8dbd6bd9167f | 106 | virtual void incrementClock() = 0; |
mkarlsso | 0:8dbd6bd9167f | 107 | virtual void mainLoopToDo(); |
mkarlsso | 0:8dbd6bd9167f | 108 | virtual void pauseInterrupts(); |
mkarlsso | 0:8dbd6bd9167f | 109 | virtual void resumeInterrupts(); |
mkarlsso | 0:8dbd6bd9167f | 110 | virtual int getPendingFunctionTriggers(uint16_t *bufferPtr); //Returns the number of pending shortcut triggers |
mkarlsso | 0:8dbd6bd9167f | 111 | virtual uint32_t getDigitalOutputChangeFlags(); |
mkarlsso | 0:8dbd6bd9167f | 112 | virtual uint32_t getDigitalInputChangeFlags(); |
mkarlsso | 3:d7b0a0890d96 | 113 | void setPortUpdatesOn(int portNum); |
mkarlsso | 3:d7b0a0890d96 | 114 | void setPortUpdatesOff(int portNum); |
mkarlsso | 3:d7b0a0890d96 | 115 | bool* getIgnoreUpdates(); |
mkarlsso | 3:d7b0a0890d96 | 116 | |
mkarlsso | 0:8dbd6bd9167f | 117 | |
mkarlsso | 0:8dbd6bd9167f | 118 | |
mkarlsso | 0:8dbd6bd9167f | 119 | protected: |
mkarlsso | 0:8dbd6bd9167f | 120 | |
mkarlsso | 0:8dbd6bd9167f | 121 | //virtual void timerInterrupt() = 0; |
mkarlsso | 0:8dbd6bd9167f | 122 | |
mkarlsso | 3:d7b0a0890d96 | 123 | void immediateClockReset(); |
mkarlsso | 0:8dbd6bd9167f | 124 | int currentDINPin; |
mkarlsso | 0:8dbd6bd9167f | 125 | int currentDOUTPin; |
mkarlsso | 0:8dbd6bd9167f | 126 | uint32_t currentDigitalOuputStates; |
mkarlsso | 0:8dbd6bd9167f | 127 | uint32_t currentDigitalInputStates; |
mkarlsso | 3:d7b0a0890d96 | 128 | bool ignorePortUpdates[32]; |
mkarlsso | 0:8dbd6bd9167f | 129 | |
mkarlsso | 0:8dbd6bd9167f | 130 | |
mkarlsso | 0:8dbd6bd9167f | 131 | |
mkarlsso | 0:8dbd6bd9167f | 132 | |
mkarlsso | 0:8dbd6bd9167f | 133 | }; |
mkarlsso | 0:8dbd6bd9167f | 134 | |
mkarlsso | 0:8dbd6bd9167f | 135 | |
mkarlsso | 0:8dbd6bd9167f | 136 | //Used to buffer output text. Used mainly for 'display' commands within the script, |
mkarlsso | 0:8dbd6bd9167f | 137 | //and alloed the reset of the block to execute quickly instead. The text is then streamed out |
mkarlsso | 0:8dbd6bd9167f | 138 | //slowly via serial (one character per main loop execution). outputStream is a simple circular |
mkarlsso | 0:8dbd6bd9167f | 139 | //buffer that cannot be resized after initiation. |
mkarlsso | 0:8dbd6bd9167f | 140 | class outputStream { |
mkarlsso | 0:8dbd6bd9167f | 141 | |
mkarlsso | 0:8dbd6bd9167f | 142 | public: |
mkarlsso | 0:8dbd6bd9167f | 143 | outputStream(int bufferSizeIn); |
mkarlsso | 0:8dbd6bd9167f | 144 | ~outputStream(); |
mkarlsso | 0:8dbd6bd9167f | 145 | void setSerial(sSerialPort *s); |
mkarlsso | 3:d7b0a0890d96 | 146 | void send(const string &outputString); |
mkarlsso | 3:d7b0a0890d96 | 147 | void send(const char* s); |
mkarlsso | 0:8dbd6bd9167f | 148 | void debug(const char* s); |
mkarlsso | 3:d7b0a0890d96 | 149 | outputStream &operator<<(const string &outputString); |
mkarlsso | 0:8dbd6bd9167f | 150 | outputStream &operator<<(int outputNum); |
mkarlsso | 0:8dbd6bd9167f | 151 | outputStream &operator<<(uint32_t outputNum); |
mkarlsso | 0:8dbd6bd9167f | 152 | outputStream &operator<<(const char* s); |
mkarlsso | 0:8dbd6bd9167f | 153 | char getNextChar(); |
mkarlsso | 0:8dbd6bd9167f | 154 | bool unsentData; |
mkarlsso | 0:8dbd6bd9167f | 155 | void flush(); |
mkarlsso | 0:8dbd6bd9167f | 156 | |
mkarlsso | 0:8dbd6bd9167f | 157 | private: |
mkarlsso | 0:8dbd6bd9167f | 158 | int readHead; |
mkarlsso | 0:8dbd6bd9167f | 159 | int writeHead; |
mkarlsso | 0:8dbd6bd9167f | 160 | int totalWriteHead; |
mkarlsso | 0:8dbd6bd9167f | 161 | int totalReadHead; |
mkarlsso | 0:8dbd6bd9167f | 162 | int bufferSize; |
mkarlsso | 0:8dbd6bd9167f | 163 | char tmpOut; |
mkarlsso | 0:8dbd6bd9167f | 164 | char* outputBuffer; |
mkarlsso | 0:8dbd6bd9167f | 165 | sSerialPort* serialPtr; |
mkarlsso | 0:8dbd6bd9167f | 166 | }; |
mkarlsso | 0:8dbd6bd9167f | 167 | |
mkarlsso | 0:8dbd6bd9167f | 168 | |
mkarlsso | 0:8dbd6bd9167f | 169 | |
mkarlsso | 0:8dbd6bd9167f | 170 | #endif // HARDWARWEINTERFACE_H |