![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
fork of StateScript
Fork of stateScript_v2 by
hardwareInterface.h@2:35266b266eaa, 2015-06-03 (annotated)
- Committer:
- mkarlsso
- Date:
- Wed Jun 03 23:41:16 2015 +0000
- Revision:
- 2:35266b266eaa
- Parent:
- 0:8dbd6bd9167f
- Child:
- 3:d7b0a0890d96
Working version with proper interrupt pausing during dIn update
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 | 0:8dbd6bd9167f | 6 | |
mkarlsso | 0:8dbd6bd9167f | 7 | #define PENDINGTRIGGERBUFFERSIZE 10 |
mkarlsso | 0:8dbd6bd9167f | 8 | |
mkarlsso | 0:8dbd6bd9167f | 9 | //#define NUMPORTS 8 //the number of ports available on the hardware |
mkarlsso | 0:8dbd6bd9167f | 10 | |
mkarlsso | 0:8dbd6bd9167f | 11 | using namespace std; |
mkarlsso | 0:8dbd6bd9167f | 12 | |
mkarlsso | 0:8dbd6bd9167f | 13 | //for debugging output |
mkarlsso | 0:8dbd6bd9167f | 14 | //#define DEBUGOUTPUT |
mkarlsso | 0:8dbd6bd9167f | 15 | |
mkarlsso | 0:8dbd6bd9167f | 16 | //used to organize digital change events |
mkarlsso | 0:8dbd6bd9167f | 17 | struct changeEvent { |
mkarlsso | 0:8dbd6bd9167f | 18 | uint32_t timeStamp; |
mkarlsso | 0:8dbd6bd9167f | 19 | bool triggered; |
mkarlsso | 0:8dbd6bd9167f | 20 | }; |
mkarlsso | 0:8dbd6bd9167f | 21 | |
mkarlsso | 0:8dbd6bd9167f | 22 | class sDigitalOut |
mkarlsso | 0:8dbd6bd9167f | 23 | { |
mkarlsso | 0:8dbd6bd9167f | 24 | public: |
mkarlsso | 0:8dbd6bd9167f | 25 | sDigitalOut(); |
mkarlsso | 0:8dbd6bd9167f | 26 | |
mkarlsso | 0:8dbd6bd9167f | 27 | virtual void init(int pin) = 0; |
mkarlsso | 0:8dbd6bd9167f | 28 | virtual void write(int value) = 0; |
mkarlsso | 0:8dbd6bd9167f | 29 | virtual int read() = 0; |
mkarlsso | 0:8dbd6bd9167f | 30 | protected: |
mkarlsso | 0:8dbd6bd9167f | 31 | |
mkarlsso | 0:8dbd6bd9167f | 32 | }; |
mkarlsso | 0:8dbd6bd9167f | 33 | |
mkarlsso | 0:8dbd6bd9167f | 34 | class sDigitalIn |
mkarlsso | 0:8dbd6bd9167f | 35 | { |
mkarlsso | 0:8dbd6bd9167f | 36 | public: |
mkarlsso | 0:8dbd6bd9167f | 37 | sDigitalIn(); |
mkarlsso | 0:8dbd6bd9167f | 38 | |
mkarlsso | 0:8dbd6bd9167f | 39 | virtual void init(int pin) = 0; |
mkarlsso | 0:8dbd6bd9167f | 40 | virtual int read() = 0; |
mkarlsso | 0:8dbd6bd9167f | 41 | virtual void interrupt_up_callback() = 0; |
mkarlsso | 0:8dbd6bd9167f | 42 | virtual void interrupt_down_callback() = 0; |
mkarlsso | 2:35266b266eaa | 43 | void setUpdate(bool); |
mkarlsso | 0:8dbd6bd9167f | 44 | |
mkarlsso | 0:8dbd6bd9167f | 45 | changeEvent lastUpEvent; |
mkarlsso | 0:8dbd6bd9167f | 46 | changeEvent lastDownEvent; |
mkarlsso | 0:8dbd6bd9167f | 47 | |
mkarlsso | 0:8dbd6bd9167f | 48 | protected: |
mkarlsso | 0:8dbd6bd9167f | 49 | |
mkarlsso | 2:35266b266eaa | 50 | bool updating; |
mkarlsso | 2:35266b266eaa | 51 | changeEvent bufferedUpEvent; |
mkarlsso | 2:35266b266eaa | 52 | changeEvent bufferedDownEvent; |
mkarlsso | 0:8dbd6bd9167f | 53 | void addStateChange(int newState, uint32_t timeStamp); |
mkarlsso | 0:8dbd6bd9167f | 54 | |
mkarlsso | 0:8dbd6bd9167f | 55 | }; |
mkarlsso | 0:8dbd6bd9167f | 56 | |
mkarlsso | 0:8dbd6bd9167f | 57 | class sSerialPort |
mkarlsso | 0:8dbd6bd9167f | 58 | { |
mkarlsso | 0:8dbd6bd9167f | 59 | public: |
mkarlsso | 0:8dbd6bd9167f | 60 | sSerialPort(); |
mkarlsso | 0:8dbd6bd9167f | 61 | |
mkarlsso | 0:8dbd6bd9167f | 62 | virtual void init() = 0; |
mkarlsso | 0:8dbd6bd9167f | 63 | virtual bool readable() = 0; |
mkarlsso | 0:8dbd6bd9167f | 64 | virtual char readChar() = 0; |
mkarlsso | 0:8dbd6bd9167f | 65 | virtual void writeChar(char s)= 0; |
mkarlsso | 0:8dbd6bd9167f | 66 | protected: |
mkarlsso | 0:8dbd6bd9167f | 67 | |
mkarlsso | 0:8dbd6bd9167f | 68 | |
mkarlsso | 0:8dbd6bd9167f | 69 | }; |
mkarlsso | 0:8dbd6bd9167f | 70 | |
mkarlsso | 0:8dbd6bd9167f | 71 | class sSound |
mkarlsso | 0:8dbd6bd9167f | 72 | { |
mkarlsso | 0:8dbd6bd9167f | 73 | public: |
mkarlsso | 0:8dbd6bd9167f | 74 | sSound(); |
mkarlsso | 0:8dbd6bd9167f | 75 | void setFile(string fileNameIn); |
mkarlsso | 0:8dbd6bd9167f | 76 | void setVolume(int* volumeIn); |
mkarlsso | 0:8dbd6bd9167f | 77 | void setVolume(int volumeIn); |
mkarlsso | 0:8dbd6bd9167f | 78 | void setPlayback(bool playIn); |
mkarlsso | 0:8dbd6bd9167f | 79 | void setReset(); |
mkarlsso | 0:8dbd6bd9167f | 80 | virtual void execute() = 0; |
mkarlsso | 0:8dbd6bd9167f | 81 | |
mkarlsso | 0:8dbd6bd9167f | 82 | protected: |
mkarlsso | 0:8dbd6bd9167f | 83 | char fileName[21]; |
mkarlsso | 0:8dbd6bd9167f | 84 | bool fileNameExists; |
mkarlsso | 0:8dbd6bd9167f | 85 | int* volumePtr; |
mkarlsso | 0:8dbd6bd9167f | 86 | int volume; |
mkarlsso | 0:8dbd6bd9167f | 87 | bool play; |
mkarlsso | 0:8dbd6bd9167f | 88 | bool reset; |
mkarlsso | 0:8dbd6bd9167f | 89 | }; |
mkarlsso | 0:8dbd6bd9167f | 90 | |
mkarlsso | 0:8dbd6bd9167f | 91 | class sSystem |
mkarlsso | 0:8dbd6bd9167f | 92 | { |
mkarlsso | 0:8dbd6bd9167f | 93 | public: |
mkarlsso | 0:8dbd6bd9167f | 94 | sSystem(); |
mkarlsso | 0:8dbd6bd9167f | 95 | virtual void timerinit() = 0; |
mkarlsso | 0:8dbd6bd9167f | 96 | virtual void setStandAloneClock() = 0; |
mkarlsso | 0:8dbd6bd9167f | 97 | virtual void setSlaveClock() = 0; |
mkarlsso | 0:8dbd6bd9167f | 98 | virtual sDigitalOut* getDigitalOutPtr(int portNum) = 0; |
mkarlsso | 0:8dbd6bd9167f | 99 | virtual sDigitalIn* getDigitalInPtr(int portNum) = 0; |
mkarlsso | 0:8dbd6bd9167f | 100 | virtual sSound* createNewSoundAction() = 0; |
mkarlsso | 0:8dbd6bd9167f | 101 | virtual void externalClockReset() = 0; //needs to reset harware timer before calling immediateClockReset(); |
mkarlsso | 0:8dbd6bd9167f | 102 | virtual void incrementClock() = 0; |
mkarlsso | 0:8dbd6bd9167f | 103 | virtual void mainLoopToDo(); |
mkarlsso | 0:8dbd6bd9167f | 104 | virtual void pauseInterrupts(); |
mkarlsso | 0:8dbd6bd9167f | 105 | virtual void resumeInterrupts(); |
mkarlsso | 0:8dbd6bd9167f | 106 | virtual int getPendingFunctionTriggers(uint16_t *bufferPtr); //Returns the number of pending shortcut triggers |
mkarlsso | 0:8dbd6bd9167f | 107 | virtual uint32_t getDigitalOutputChangeFlags(); |
mkarlsso | 0:8dbd6bd9167f | 108 | virtual uint32_t getDigitalInputChangeFlags(); |
mkarlsso | 0:8dbd6bd9167f | 109 | |
mkarlsso | 0:8dbd6bd9167f | 110 | |
mkarlsso | 0:8dbd6bd9167f | 111 | protected: |
mkarlsso | 0:8dbd6bd9167f | 112 | |
mkarlsso | 0:8dbd6bd9167f | 113 | //virtual void timerInterrupt() = 0; |
mkarlsso | 0:8dbd6bd9167f | 114 | |
mkarlsso | 0:8dbd6bd9167f | 115 | void immediateClockReset(); |
mkarlsso | 0:8dbd6bd9167f | 116 | int currentDINPin; |
mkarlsso | 0:8dbd6bd9167f | 117 | int currentDOUTPin; |
mkarlsso | 0:8dbd6bd9167f | 118 | uint32_t currentDigitalOuputStates; |
mkarlsso | 0:8dbd6bd9167f | 119 | uint32_t currentDigitalInputStates; |
mkarlsso | 0:8dbd6bd9167f | 120 | |
mkarlsso | 0:8dbd6bd9167f | 121 | |
mkarlsso | 0:8dbd6bd9167f | 122 | |
mkarlsso | 0:8dbd6bd9167f | 123 | |
mkarlsso | 0:8dbd6bd9167f | 124 | }; |
mkarlsso | 0:8dbd6bd9167f | 125 | |
mkarlsso | 0:8dbd6bd9167f | 126 | |
mkarlsso | 0:8dbd6bd9167f | 127 | //Used to buffer output text. Used mainly for 'display' commands within the script, |
mkarlsso | 0:8dbd6bd9167f | 128 | //and alloed the reset of the block to execute quickly instead. The text is then streamed out |
mkarlsso | 0:8dbd6bd9167f | 129 | //slowly via serial (one character per main loop execution). outputStream is a simple circular |
mkarlsso | 0:8dbd6bd9167f | 130 | //buffer that cannot be resized after initiation. |
mkarlsso | 0:8dbd6bd9167f | 131 | class outputStream { |
mkarlsso | 0:8dbd6bd9167f | 132 | |
mkarlsso | 0:8dbd6bd9167f | 133 | public: |
mkarlsso | 0:8dbd6bd9167f | 134 | outputStream(int bufferSizeIn); |
mkarlsso | 0:8dbd6bd9167f | 135 | ~outputStream(); |
mkarlsso | 0:8dbd6bd9167f | 136 | void setSerial(sSerialPort *s); |
mkarlsso | 0:8dbd6bd9167f | 137 | void send(string outputString); |
mkarlsso | 0:8dbd6bd9167f | 138 | void debug(const char* s); |
mkarlsso | 0:8dbd6bd9167f | 139 | outputStream &operator<<(string outputString); |
mkarlsso | 0:8dbd6bd9167f | 140 | outputStream &operator<<(int outputNum); |
mkarlsso | 0:8dbd6bd9167f | 141 | outputStream &operator<<(uint32_t outputNum); |
mkarlsso | 0:8dbd6bd9167f | 142 | outputStream &operator<<(const char* s); |
mkarlsso | 0:8dbd6bd9167f | 143 | char getNextChar(); |
mkarlsso | 0:8dbd6bd9167f | 144 | bool unsentData; |
mkarlsso | 0:8dbd6bd9167f | 145 | void flush(); |
mkarlsso | 0:8dbd6bd9167f | 146 | |
mkarlsso | 0:8dbd6bd9167f | 147 | private: |
mkarlsso | 0:8dbd6bd9167f | 148 | int readHead; |
mkarlsso | 0:8dbd6bd9167f | 149 | int writeHead; |
mkarlsso | 0:8dbd6bd9167f | 150 | int totalWriteHead; |
mkarlsso | 0:8dbd6bd9167f | 151 | int totalReadHead; |
mkarlsso | 0:8dbd6bd9167f | 152 | int bufferSize; |
mkarlsso | 0:8dbd6bd9167f | 153 | char tmpOut; |
mkarlsso | 0:8dbd6bd9167f | 154 | char* outputBuffer; |
mkarlsso | 0:8dbd6bd9167f | 155 | sSerialPort* serialPtr; |
mkarlsso | 0:8dbd6bd9167f | 156 | }; |
mkarlsso | 0:8dbd6bd9167f | 157 | |
mkarlsso | 0:8dbd6bd9167f | 158 | |
mkarlsso | 0:8dbd6bd9167f | 159 | |
mkarlsso | 0:8dbd6bd9167f | 160 | #endif // HARDWARWEINTERFACE_H |