Serial library for Diablo4D. Tested with uLCD220RD

Committer:
martin13
Date:
Tue May 09 14:29:22 2017 +0000
Revision:
2:7cff98af2c68
Parent:
1:9a2c573adad6
Remove old func

Who changed what in which revision?

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