Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of stateScript_v2 by
hardwareInterface.h
00001 #ifndef HARDWARWEINTERFACE_H 00002 #define HARDWARWEINTERFACE_H 00003 00004 #include <stdint.h> 00005 #include <string> 00006 #include <cstdlib> 00007 #include <string.h> 00008 00009 #define PENDINGTRIGGERBUFFERSIZE 10 00010 00011 //#define NUMPORTS 8 //the number of ports available on the hardware 00012 00013 using namespace std; 00014 00015 //for debugging output 00016 //#define DEBUGOUTPUT 00017 00018 //used to organize digital change events 00019 struct changeEvent { 00020 uint32_t timeStamp; 00021 bool triggered; 00022 }; 00023 00024 class sDigitalOut 00025 { 00026 public: 00027 sDigitalOut(); 00028 00029 virtual void init(int pin) = 0; 00030 virtual void write(int value) = 0; 00031 virtual int read() = 0; 00032 protected: 00033 00034 }; 00035 00036 class sDigitalIn 00037 { 00038 public: 00039 sDigitalIn(); 00040 00041 virtual void init(int pin) = 0; 00042 virtual int read() = 0; 00043 virtual void interrupt_up_callback() = 0; 00044 virtual void interrupt_down_callback() = 0; 00045 void setUpdate(bool); 00046 00047 changeEvent lastUpEvent; 00048 changeEvent lastDownEvent; 00049 00050 protected: 00051 00052 bool updating; 00053 changeEvent bufferedUpEvent; 00054 changeEvent bufferedDownEvent; 00055 void addStateChange(int newState, uint32_t timeStamp); 00056 00057 }; 00058 00059 class sSerialPort 00060 { 00061 public: 00062 sSerialPort(); 00063 00064 virtual void init() = 0; 00065 virtual bool readable() = 0; 00066 virtual char readChar() = 0; 00067 virtual void writeChar(char s)= 0; 00068 virtual int requestToWriteString(char *s, int numBytes) = 0; 00069 00070 protected: 00071 00072 00073 }; 00074 00075 class sSound 00076 { 00077 public: 00078 sSound(); 00079 void setFile(string fileNameIn); 00080 void setVolume(int* volumeIn); 00081 void setVolume(int volumeIn); 00082 void setPlayback(bool playIn); 00083 void setReset(); 00084 virtual void execute() = 0; 00085 00086 protected: 00087 char fileName[21]; 00088 bool fileNameExists; 00089 int* volumePtr; 00090 int volume; 00091 bool play; 00092 bool reset; 00093 }; 00094 00095 class sSystem 00096 { 00097 public: 00098 sSystem(); 00099 virtual void timerinit() = 0; 00100 virtual void setStandAloneClock() = 0; 00101 virtual void setSlaveClock() = 0; 00102 virtual sDigitalOut* getDigitalOutPtr(int portNum) = 0; 00103 virtual sDigitalIn* getDigitalInPtr(int portNum) = 0; 00104 virtual sSound* createNewSoundAction() = 0; 00105 virtual void externalClockReset() = 0; //needs to reset harware timer before calling immediateClockReset(); 00106 virtual void incrementClock() = 0; 00107 virtual void mainLoopToDo(); 00108 virtual void pauseInterrupts(); 00109 virtual void resumeInterrupts(); 00110 virtual int getPendingFunctionTriggers(uint16_t *bufferPtr); //Returns the number of pending shortcut triggers 00111 virtual uint32_t getDigitalOutputChangeFlags(); 00112 virtual uint32_t getDigitalInputChangeFlags(); 00113 void setPortUpdatesOn(int portNum); 00114 void setPortUpdatesOff(int portNum); 00115 bool* getIgnoreUpdates(); 00116 00117 00118 00119 protected: 00120 00121 //virtual void timerInterrupt() = 0; 00122 00123 void immediateClockReset(); 00124 int currentDINPin; 00125 int currentDOUTPin; 00126 uint32_t currentDigitalOuputStates; 00127 uint32_t currentDigitalInputStates; 00128 bool ignorePortUpdates[32]; 00129 00130 00131 00132 00133 }; 00134 00135 00136 //Used to buffer output text. Used mainly for 'display' commands within the script, 00137 //and alloed the reset of the block to execute quickly instead. The text is then streamed out 00138 //slowly via serial (one character per main loop execution). outputStream is a simple circular 00139 //buffer that cannot be resized after initiation. 00140 class outputStream { 00141 00142 public: 00143 outputStream(int bufferSizeIn); 00144 ~outputStream(); 00145 void setSerial(sSerialPort *s); 00146 void send(const string &outputString); 00147 void send(const char* s); 00148 void debug(const char* s); 00149 outputStream &operator<<(const string &outputString); 00150 outputStream &operator<<(int outputNum); 00151 outputStream &operator<<(uint32_t outputNum); 00152 outputStream &operator<<(const char* s); 00153 char getNextChar(); 00154 bool unsentData; 00155 void flush(); 00156 00157 private: 00158 int readHead; 00159 int writeHead; 00160 int totalWriteHead; 00161 int totalReadHead; 00162 int bufferSize; 00163 char tmpOut; 00164 char* outputBuffer; 00165 sSerialPort* serialPtr; 00166 }; 00167 00168 00169 00170 #endif // HARDWARWEINTERFACE_H
Generated on Tue Jul 12 2022 17:07:31 by
1.7.2
