Serial library for Diablo4D. Tested with uLCD220RD
Diablo_Serial_4DLib.h@0:81cd913c5e43, 2017-05-09 (annotated)
- Committer:
- martin13
- Date:
- Tue May 09 14:16:16 2017 +0000
- Revision:
- 0:81cd913c5e43
- Child:
- 1:9a2c573adad6
Library for Diablo4D Serial comminucation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
martin13 | 0:81cd913c5e43 | 1 | /* |
martin13 | 0:81cd913c5e43 | 2 | 4DSerial - Library for 4D Systems Serial Environment. |
martin13 | 0:81cd913c5e43 | 3 | Released into the public domain. |
martin13 | 0:81cd913c5e43 | 4 | */ |
martin13 | 0:81cd913c5e43 | 5 | |
martin13 | 0:81cd913c5e43 | 6 | #ifndef Diablo_Serial_4DLib_h |
martin13 | 0:81cd913c5e43 | 7 | #define Diablo_Serial_4DLib_h |
martin13 | 0:81cd913c5e43 | 8 | |
martin13 | 0:81cd913c5e43 | 9 | #include "Diablo_Const4D.h" // Defines for 4dgl constants, generated by conversion of 4DGL constants to target language |
martin13 | 0:81cd913c5e43 | 10 | #include "mbed.h" |
martin13 | 0:81cd913c5e43 | 11 | //#include "millis.h" |
martin13 | 0:81cd913c5e43 | 12 | |
martin13 | 0:81cd913c5e43 | 13 | #include <string> |
martin13 | 0:81cd913c5e43 | 14 | #include <stdint.h> |
martin13 | 0:81cd913c5e43 | 15 | |
martin13 | 0:81cd913c5e43 | 16 | #define word uint16_t |
martin13 | 0:81cd913c5e43 | 17 | |
martin13 | 0:81cd913c5e43 | 18 | #define DEC 10 |
martin13 | 0:81cd913c5e43 | 19 | #define HEX 16 |
martin13 | 0:81cd913c5e43 | 20 | #define OCT 8 |
martin13 | 0:81cd913c5e43 | 21 | #define BIN 2 |
martin13 | 0:81cd913c5e43 | 22 | |
martin13 | 0:81cd913c5e43 | 23 | void init_clock(void); |
martin13 | 0:81cd913c5e43 | 24 | unsigned long get_millis(void); |
martin13 | 0:81cd913c5e43 | 25 | |
martin13 | 0:81cd913c5e43 | 26 | typedef void (*Tcallback4D)(int, unsigned char); |
martin13 | 0:81cd913c5e43 | 27 | |
martin13 | 0:81cd913c5e43 | 28 | class Diablo_Serial_4DLib |
martin13 | 0:81cd913c5e43 | 29 | { |
martin13 | 0:81cd913c5e43 | 30 | public: |
martin13 | 0:81cd913c5e43 | 31 | Diablo_Serial_4DLib(Serial *virtualPort, int timeout4D); |
martin13 | 0:81cd913c5e43 | 32 | Tcallback4D Callback4D; |
martin13 | 0:81cd913c5e43 | 33 | |
martin13 | 0:81cd913c5e43 | 34 | //Compound 4D Routines |
martin13 | 0:81cd913c5e43 | 35 | word bus_Read8(); |
martin13 | 0:81cd913c5e43 | 36 | void bus_Write8(word Bits); |
martin13 | 0:81cd913c5e43 | 37 | word charheight(char TestChar); |
martin13 | 0:81cd913c5e43 | 38 | word charwidth(char TestChar); |
martin13 | 0:81cd913c5e43 | 39 | word file_Close(word Handle); |
martin13 | 0:81cd913c5e43 | 40 | word file_Count(char * Filename); |
martin13 | 0:81cd913c5e43 | 41 | word file_Dir(char * Filename); |
martin13 | 0:81cd913c5e43 | 42 | word file_Erase(char * Filename); |
martin13 | 0:81cd913c5e43 | 43 | word file_Error(); |
martin13 | 0:81cd913c5e43 | 44 | word file_Exec(char * Filename, word GFX_ArgCount, GFX_t4DWordArray Args); |
martin13 | 0:81cd913c5e43 | 45 | word file_Exists(char * Filename); |
martin13 | 0:81cd913c5e43 | 46 | word file_FindFirst(char * Filename); |
martin13 | 0:81cd913c5e43 | 47 | word file_FindNext(); |
martin13 | 0:81cd913c5e43 | 48 | char file_GetC(word Handle); |
martin13 | 0:81cd913c5e43 | 49 | word file_GetS(char * StringIn, word Size, word Handle); |
martin13 | 0:81cd913c5e43 | 50 | word file_GetW(word Handle); |
martin13 | 0:81cd913c5e43 | 51 | word file_Image(word X, word Y, word Handle); |
martin13 | 0:81cd913c5e43 | 52 | word file_Index(word Handle, word HiSize, word LoSize, word Recordnum); |
martin13 | 0:81cd913c5e43 | 53 | word file_LoadFunction(char * Filename); |
martin13 | 0:81cd913c5e43 | 54 | word file_LoadImageControl(char * Datname, char * GCIName, word Mode); |
martin13 | 0:81cd913c5e43 | 55 | word file_Mount(); |
martin13 | 0:81cd913c5e43 | 56 | word file_Open(char * Filename, char Mode); |
martin13 | 0:81cd913c5e43 | 57 | word file_PlayWAV(char * Filename); |
martin13 | 0:81cd913c5e43 | 58 | word file_PutC(char Character, word Handle); |
martin13 | 0:81cd913c5e43 | 59 | word file_PutS(char * StringOut, word Handle); |
martin13 | 0:81cd913c5e43 | 60 | word file_PutW(word Word, word Handle); |
martin13 | 0:81cd913c5e43 | 61 | word file_Read(GFX_t4DByteArray Data, word Size, word Handle); |
martin13 | 0:81cd913c5e43 | 62 | word file_Rewind(word Handle); |
martin13 | 0:81cd913c5e43 | 63 | word file_Run(char * Filename, word ArgCount, GFX_t4DWordArray Args); |
martin13 | 0:81cd913c5e43 | 64 | word file_ScreenCapture(word X, word Y, word Width, word Height, word Handle); |
martin13 | 0:81cd913c5e43 | 65 | word file_Seek(word Handle, word HiWord, word LoWord); |
martin13 | 0:81cd913c5e43 | 66 | word file_Size(word Handle, word * HiWord, word * LoWord); |
martin13 | 0:81cd913c5e43 | 67 | word file_Tell(word Handle, word * HiWord, word * LoWord); |
martin13 | 0:81cd913c5e43 | 68 | void file_Unmount(); |
martin13 | 0:81cd913c5e43 | 69 | word file_Write(word Size, GFX_t4DByteArray Source, word Handle); |
martin13 | 0:81cd913c5e43 | 70 | word gfx_BevelShadow(word Value); |
martin13 | 0:81cd913c5e43 | 71 | word gfx_BevelWidth(word Value); |
martin13 | 0:81cd913c5e43 | 72 | word gfx_BGcolour(word Color); |
martin13 | 0:81cd913c5e43 | 73 | void gfx_Button(word Up, word x, word y, word buttonColour, word txtColour, word font, word txtWidth, word txtHeight, char * text); |
martin13 | 0:81cd913c5e43 | 74 | void gfx_ChangeColour(word OldColor, word NewColor); |
martin13 | 0:81cd913c5e43 | 75 | void gfx_Circle(word X, word Y, word Radius, word Color); |
martin13 | 0:81cd913c5e43 | 76 | void gfx_CircleFilled(word X, word Y, word Radius, word Color); |
martin13 | 0:81cd913c5e43 | 77 | void gfx_Clipping(word OnOff); |
martin13 | 0:81cd913c5e43 | 78 | void gfx_ClipWindow(word X1, word Y1, word X2, word Y2); |
martin13 | 0:81cd913c5e43 | 79 | void gfx_Cls(); |
martin13 | 0:81cd913c5e43 | 80 | word gfx_Contrast(word Contrast); |
martin13 | 0:81cd913c5e43 | 81 | void gfx_Ellipse(word X, word Y, word Xrad, word Yrad, word Color); |
martin13 | 0:81cd913c5e43 | 82 | void gfx_EllipseFilled(word X, word Y, word Xrad, word Yrad, word Color); |
martin13 | 0:81cd913c5e43 | 83 | word gfx_FrameDelay(word Msec); |
martin13 | 0:81cd913c5e43 | 84 | word gfx_Get(word Mode); |
martin13 | 0:81cd913c5e43 | 85 | word gfx_GetPixel(word X, word Y); |
martin13 | 0:81cd913c5e43 | 86 | void gfx_Line(word X1, word Y1, word X2, word Y2, word Color); |
martin13 | 0:81cd913c5e43 | 87 | word gfx_LinePattern(word Pattern); |
martin13 | 0:81cd913c5e43 | 88 | void gfx_LineTo(word X, word Y); |
martin13 | 0:81cd913c5e43 | 89 | void gfx_MoveTo(word X, word Y); |
martin13 | 0:81cd913c5e43 | 90 | word gfx_Orbit(word Angle, word Distance, word * Xdest, word * Ydest); |
martin13 | 0:81cd913c5e43 | 91 | word gfx_OutlineColour(word Color); |
martin13 | 0:81cd913c5e43 | 92 | void gfx_Panel(word Raised, word X, word Y, word Width, word Height, word Color); |
martin13 | 0:81cd913c5e43 | 93 | void gfx_Polygon(word n, GFX_t4DWordArray Xvalues, GFX_t4DWordArray Yvalues, word Color); |
martin13 | 0:81cd913c5e43 | 94 | void gfx_PolygonFilled(word n, GFX_t4DWordArray Xvalues, GFX_t4DWordArray Yvalues, word Color); |
martin13 | 0:81cd913c5e43 | 95 | void gfx_Polyline(word n, GFX_t4DWordArray Xvalues, GFX_t4DWordArray Yvalues, word Color); |
martin13 | 0:81cd913c5e43 | 96 | void gfx_PutPixel(word X, word Y, word Color); |
martin13 | 0:81cd913c5e43 | 97 | void gfx_Rectangle(word X1, word Y1, word X2, word Y2, word Color); |
martin13 | 0:81cd913c5e43 | 98 | void gfx_RectangleFilled(word X1, word Y1, word X2, word Y2, word Color); |
martin13 | 0:81cd913c5e43 | 99 | void gfx_ScreenCopyPaste(word Xs, word Ys, word Xd, word Yd, word Width, word Height); |
martin13 | 0:81cd913c5e43 | 100 | word gfx_ScreenMode(word ScreenMode); |
martin13 | 0:81cd913c5e43 | 101 | void gfx_Set(word Func, word Value); |
martin13 | 0:81cd913c5e43 | 102 | void gfx_SetClipRegion(); |
martin13 | 0:81cd913c5e43 | 103 | word gfx_Slider(word Mode, word X1, word Y1, word X2, word Y2, word Color, word Scale, word Value); |
martin13 | 0:81cd913c5e43 | 104 | word gfx_Transparency(word OnOff); |
martin13 | 0:81cd913c5e43 | 105 | word gfx_TransparentColour(word Color); |
martin13 | 0:81cd913c5e43 | 106 | void gfx_Triangle(word X1, word Y1, word X2, word Y2, word X3, word Y3, word Color); |
martin13 | 0:81cd913c5e43 | 107 | void gfx_TriangleFilled(word X1, word Y1, word X2, word Y2, word X3, word Y3, word Color); |
martin13 | 0:81cd913c5e43 | 108 | word img_ClearAttributes(word Handle, word Index, word Value); |
martin13 | 0:81cd913c5e43 | 109 | word img_Darken(word Handle, word Index); |
martin13 | 0:81cd913c5e43 | 110 | word img_Disable(word Handle, word Index); |
martin13 | 0:81cd913c5e43 | 111 | word img_Enable(word Handle, word Index); |
martin13 | 0:81cd913c5e43 | 112 | word img_GetWord(word Handle, word Index, word Offset ); |
martin13 | 0:81cd913c5e43 | 113 | word img_Lighten(word Handle, word Index); |
martin13 | 0:81cd913c5e43 | 114 | word img_SetAttributes(word Handle, word Index, word Value); |
martin13 | 0:81cd913c5e43 | 115 | word img_SetPosition(word Handle, word Index, word Xpos, word Ypos); |
martin13 | 0:81cd913c5e43 | 116 | word img_SetWord(word Handle, word Index, word Offset , word Word); |
martin13 | 0:81cd913c5e43 | 117 | word img_Show(word Handle, word Index); |
martin13 | 0:81cd913c5e43 | 118 | word img_Touched(word Handle, word Index); |
martin13 | 0:81cd913c5e43 | 119 | word media_Flush(); |
martin13 | 0:81cd913c5e43 | 120 | void media_Image(word X, word Y); |
martin13 | 0:81cd913c5e43 | 121 | word media_Init(); |
martin13 | 0:81cd913c5e43 | 122 | word media_RdSector(GFX_t4DSector SectorIn); |
martin13 | 0:81cd913c5e43 | 123 | word media_ReadByte(); |
martin13 | 0:81cd913c5e43 | 124 | word media_ReadWord(); |
martin13 | 0:81cd913c5e43 | 125 | void media_SetAdd(word HiWord, word LoWord); |
martin13 | 0:81cd913c5e43 | 126 | void media_SetSector(word HiWord, word LoWord); |
martin13 | 0:81cd913c5e43 | 127 | void media_Video(word X, word Y); |
martin13 | 0:81cd913c5e43 | 128 | void media_VideoFrame(word X, word Y, word Framenumber); |
martin13 | 0:81cd913c5e43 | 129 | word media_WriteByte(word Byte); |
martin13 | 0:81cd913c5e43 | 130 | word media_WriteWord(word Word); |
martin13 | 0:81cd913c5e43 | 131 | word media_WrSector(GFX_t4DSector SectorOut); |
martin13 | 0:81cd913c5e43 | 132 | word mem_Free(word Handle); |
martin13 | 0:81cd913c5e43 | 133 | word mem_Heap(); |
martin13 | 0:81cd913c5e43 | 134 | word peekM(word Address); |
martin13 | 0:81cd913c5e43 | 135 | word pin_HI(word Pin); |
martin13 | 0:81cd913c5e43 | 136 | word pin_LO(word Pin); |
martin13 | 0:81cd913c5e43 | 137 | word pin_Read(word Pin); |
martin13 | 0:81cd913c5e43 | 138 | word pin_Set(word Mode, word Pin); |
martin13 | 0:81cd913c5e43 | 139 | void pokeM(word Address, word WordValue); |
martin13 | 0:81cd913c5e43 | 140 | void putCH(word WordChar); |
martin13 | 0:81cd913c5e43 | 141 | word putstr(char * InString); |
martin13 | 0:81cd913c5e43 | 142 | //---------------------print----------------------/ |
martin13 | 0:81cd913c5e43 | 143 | |
martin13 | 0:81cd913c5e43 | 144 | //void print(const __FlashStringHelper *); |
martin13 | 0:81cd913c5e43 | 145 | void print(const string &); |
martin13 | 0:81cd913c5e43 | 146 | void print(const char[]); |
martin13 | 0:81cd913c5e43 | 147 | void print(char); |
martin13 | 0:81cd913c5e43 | 148 | void print(unsigned char, int = DEC); |
martin13 | 0:81cd913c5e43 | 149 | void print(int, int = DEC); |
martin13 | 0:81cd913c5e43 | 150 | void print(unsigned int, int = DEC); |
martin13 | 0:81cd913c5e43 | 151 | void print(long, int = DEC); |
martin13 | 0:81cd913c5e43 | 152 | void print(unsigned long n, int = DEC); |
martin13 | 0:81cd913c5e43 | 153 | void print(double, int = 2); |
martin13 | 0:81cd913c5e43 | 154 | |
martin13 | 0:81cd913c5e43 | 155 | //void println(const __FlashStringHelper *); |
martin13 | 0:81cd913c5e43 | 156 | void println(const string &); |
martin13 | 0:81cd913c5e43 | 157 | void println(const char[]); |
martin13 | 0:81cd913c5e43 | 158 | void println(char); |
martin13 | 0:81cd913c5e43 | 159 | void println(unsigned char, int = DEC); |
martin13 | 0:81cd913c5e43 | 160 | void println(int, int = DEC); |
martin13 | 0:81cd913c5e43 | 161 | void println(unsigned int, int = DEC); |
martin13 | 0:81cd913c5e43 | 162 | void println(long, int = DEC); |
martin13 | 0:81cd913c5e43 | 163 | void println(unsigned long, int = DEC); |
martin13 | 0:81cd913c5e43 | 164 | void println(double, int = 2); |
martin13 | 0:81cd913c5e43 | 165 | |
martin13 | 0:81cd913c5e43 | 166 | //------------------------------------------------/ |
martin13 | 0:81cd913c5e43 | 167 | void snd_BufSize(word Bufsize); |
martin13 | 0:81cd913c5e43 | 168 | void snd_Continue(); |
martin13 | 0:81cd913c5e43 | 169 | void snd_Pause(); |
martin13 | 0:81cd913c5e43 | 170 | word snd_Pitch(word Pitch); |
martin13 | 0:81cd913c5e43 | 171 | word snd_Playing(); |
martin13 | 0:81cd913c5e43 | 172 | void snd_Stop(); |
martin13 | 0:81cd913c5e43 | 173 | void snd_Volume(word Volume); |
martin13 | 0:81cd913c5e43 | 174 | word sys_Sleep(word Units); |
martin13 | 0:81cd913c5e43 | 175 | void touch_DetectRegion(word X1, word Y1, word X2, word Y2); |
martin13 | 0:81cd913c5e43 | 176 | word touch_Get(word Mode); |
martin13 | 0:81cd913c5e43 | 177 | void touch_Set(word Mode); |
martin13 | 0:81cd913c5e43 | 178 | word txt_Attributes(word Attribs); |
martin13 | 0:81cd913c5e43 | 179 | word txt_BGcolour(word Color); |
martin13 | 0:81cd913c5e43 | 180 | word txt_Bold(word Bold); |
martin13 | 0:81cd913c5e43 | 181 | word txt_FGcolour(word Color); |
martin13 | 0:81cd913c5e43 | 182 | word txt_FontID(word FontNumber); |
martin13 | 0:81cd913c5e43 | 183 | word txt_Height(word Multiplier); |
martin13 | 0:81cd913c5e43 | 184 | word txt_Inverse(word Inverse); |
martin13 | 0:81cd913c5e43 | 185 | word txt_Italic(word Italic); |
martin13 | 0:81cd913c5e43 | 186 | void txt_MoveCursor(word Line, word Column); |
martin13 | 0:81cd913c5e43 | 187 | word txt_Opacity(word TransparentOpaque); |
martin13 | 0:81cd913c5e43 | 188 | void txt_Set(word Func, word Value); |
martin13 | 0:81cd913c5e43 | 189 | word txt_Underline(word Underline); |
martin13 | 0:81cd913c5e43 | 190 | word txt_Width(word Multiplier); |
martin13 | 0:81cd913c5e43 | 191 | word txt_Wrap(word Position); |
martin13 | 0:81cd913c5e43 | 192 | word txt_Xgap(word Pixels); |
martin13 | 0:81cd913c5e43 | 193 | word txt_Ygap(word Pixels); |
martin13 | 0:81cd913c5e43 | 194 | word file_CallFunction(word Handle, word GFX_ArgCount, GFX_t4DWordArray Args); |
martin13 | 0:81cd913c5e43 | 195 | word sys_GetModel(char * ModelStr); |
martin13 | 0:81cd913c5e43 | 196 | word sys_GetVersion(); |
martin13 | 0:81cd913c5e43 | 197 | word sys_GetPmmC(); |
martin13 | 0:81cd913c5e43 | 198 | word writeString(word Handle, char * StringOut); |
martin13 | 0:81cd913c5e43 | 199 | word readString(word Handle, char * StringIn); |
martin13 | 0:81cd913c5e43 | 200 | void blitComtoDisplay(word X, word Y, word Width, word Height, GFX_t4DByteArray Pixels); |
martin13 | 0:81cd913c5e43 | 201 | word file_FindFirstRet(char * Filename, char * StringIn); |
martin13 | 0:81cd913c5e43 | 202 | word file_FindNextRet(char * StringIn); |
martin13 | 0:81cd913c5e43 | 203 | void setbaudWait(word Newrate); |
martin13 | 0:81cd913c5e43 | 204 | void GetAck(void); |
martin13 | 0:81cd913c5e43 | 205 | |
martin13 | 0:81cd913c5e43 | 206 | //4D Global Variables Used |
martin13 | 0:81cd913c5e43 | 207 | int Error4D; // Error indicator, used and set by Intrinsic routines |
martin13 | 0:81cd913c5e43 | 208 | unsigned char Error4D_Inv; // Error byte returned from com port, onl set if error = Err_Invalid |
martin13 | 0:81cd913c5e43 | 209 | // int Error_Abort4D; // if true routines will abort when detecting an error |
martin13 | 0:81cd913c5e43 | 210 | int TimeLimit4D; // time limit in ms for total serial command duration, 2000 (2 seconds) should be adequate for most commands |
martin13 | 0:81cd913c5e43 | 211 | // assuming a reasonable baud rate AND low latency AND 0 for the Serial Delay Parameter |
martin13 | 0:81cd913c5e43 | 212 | // temporary increase might be required for very long (bitmap write, large image file opens) |
martin13 | 0:81cd913c5e43 | 213 | // or indeterminate (eg file_exec, file_run, file_callFunction) commands |
martin13 | 0:81cd913c5e43 | 214 | |
martin13 | 0:81cd913c5e43 | 215 | private: |
martin13 | 0:81cd913c5e43 | 216 | Serial * _virtualPort; |
martin13 | 0:81cd913c5e43 | 217 | //Timer _timer; |
martin13 | 0:81cd913c5e43 | 218 | //unsigned long GetMillis(void); |
martin13 | 0:81cd913c5e43 | 219 | //Intrinsic 4D Routines |
martin13 | 0:81cd913c5e43 | 220 | void WriteGFX(word req); |
martin13 | 0:81cd913c5e43 | 221 | void WriteChars(char * charsout); |
martin13 | 0:81cd913c5e43 | 222 | void WriteBytes(char * Source, int Size); |
martin13 | 0:81cd913c5e43 | 223 | void WriteWords(word * Source, int Size); |
martin13 | 0:81cd913c5e43 | 224 | void getbytes(char * data, int size); |
martin13 | 0:81cd913c5e43 | 225 | word GetWord(void); |
martin13 | 0:81cd913c5e43 | 226 | void getString(char * outStr, int strLen); |
martin13 | 0:81cd913c5e43 | 227 | word GetAckResp(void); |
martin13 | 0:81cd913c5e43 | 228 | word GetAckRes2Words(word * word1, word * word2); |
martin13 | 0:81cd913c5e43 | 229 | void GetAck2Words(word * word1, word * word2); |
martin13 | 0:81cd913c5e43 | 230 | word GetAckResSector(GFX_t4DSector Sector); |
martin13 | 0:81cd913c5e43 | 231 | word GetAckResStr(char * OutStr); |
martin13 | 0:81cd913c5e43 | 232 | word GetAckResData(GFX_t4DByteArray OutData, word size); |
martin13 | 0:81cd913c5e43 | 233 | void SetThisBaudrate(int Newrate); |
martin13 | 0:81cd913c5e43 | 234 | |
martin13 | 0:81cd913c5e43 | 235 | void printNumber(unsigned long, uint8_t); |
martin13 | 0:81cd913c5e43 | 236 | void printFloat(double number, uint8_t digits); |
martin13 | 0:81cd913c5e43 | 237 | }; |
martin13 | 0:81cd913c5e43 | 238 | |
martin13 | 0:81cd913c5e43 | 239 | #endif |