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 4dGENIE by
mbed_genie.h@12:78b783968b74, 2016-03-29 (annotated)
- Committer:
- shakeeb
- Date:
- Tue Mar 29 11:51:37 2016 +0000
- Revision:
- 12:78b783968b74
- Parent:
- 11:9196f72fc325
Genie test based on christian b's code
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| chris215 | 7:6edb20845684 | 1 | |
| chris215 | 7:6edb20845684 | 2 | |
| chris215 | 0:d2ed5a44c802 | 3 | // Genie commands & replys: |
| chris215 | 0:d2ed5a44c802 | 4 | |
| chris215 | 0:d2ed5a44c802 | 5 | #define GENIE_ACK 0x06 |
| chris215 | 0:d2ed5a44c802 | 6 | #define GENIE_NAK 0x15 |
| chris215 | 0:d2ed5a44c802 | 7 | |
| chris215 | 0:d2ed5a44c802 | 8 | #define TIMEOUT_PERIOD 500 |
| chris215 | 0:d2ed5a44c802 | 9 | #define RESYNC_PERIOD 100 |
| chris215 | 0:d2ed5a44c802 | 10 | |
| chris215 | 0:d2ed5a44c802 | 11 | #define GENIE_READ_OBJ 0 |
| chris215 | 0:d2ed5a44c802 | 12 | #define GENIE_WRITE_OBJ 1 |
| chris215 | 0:d2ed5a44c802 | 13 | #define GENIE_WRITE_STR 2 |
| chris215 | 0:d2ed5a44c802 | 14 | #define GENIE_WRITE_STRU 3 |
| chris215 | 0:d2ed5a44c802 | 15 | #define GENIE_WRITE_CONTRAST 4 |
| chris215 | 0:d2ed5a44c802 | 16 | #define GENIE_REPORT_OBJ 5 |
| chris215 | 0:d2ed5a44c802 | 17 | #define GENIE_REPORT_EVENT 7 |
| chris215 | 0:d2ed5a44c802 | 18 | |
| chris215 | 0:d2ed5a44c802 | 19 | // Objects |
| chris215 | 0:d2ed5a44c802 | 20 | // the manual says: |
| chris215 | 0:d2ed5a44c802 | 21 | // Note: Object IDs may change with future releases; it is not |
| chris215 | 0:d2ed5a44c802 | 22 | // advisable to code their values as constants. |
| chris215 | 0:d2ed5a44c802 | 23 | |
| chris215 | 0:d2ed5a44c802 | 24 | #define GENIE_OBJ_DIPSW 0 |
| chris215 | 0:d2ed5a44c802 | 25 | #define GENIE_OBJ_KNOB 1 |
| chris215 | 0:d2ed5a44c802 | 26 | #define GENIE_OBJ_ROCKERSW 2 |
| chris215 | 0:d2ed5a44c802 | 27 | #define GENIE_OBJ_ROTARYSW 3 |
| chris215 | 0:d2ed5a44c802 | 28 | #define GENIE_OBJ_SLIDER 4 |
| chris215 | 0:d2ed5a44c802 | 29 | #define GENIE_OBJ_TRACKBAR 5 |
| chris215 | 0:d2ed5a44c802 | 30 | #define GENIE_OBJ_WINBUTTON 6 |
| chris215 | 0:d2ed5a44c802 | 31 | #define GENIE_OBJ_ANGULAR_METER 7 |
| chris215 | 0:d2ed5a44c802 | 32 | #define GENIE_OBJ_COOL_GAUGE 8 |
| chris215 | 0:d2ed5a44c802 | 33 | #define GENIE_OBJ_CUSTOM_DIGITS 9 |
| chris215 | 0:d2ed5a44c802 | 34 | #define GENIE_OBJ_FORM 10 |
| chris215 | 0:d2ed5a44c802 | 35 | #define GENIE_OBJ_GAUGE 11 |
| chris215 | 0:d2ed5a44c802 | 36 | #define GENIE_OBJ_IMAGE 12 |
| chris215 | 0:d2ed5a44c802 | 37 | #define GENIE_OBJ_KEYBOARD 13 |
| chris215 | 0:d2ed5a44c802 | 38 | #define GENIE_OBJ_LED 14 |
| chris215 | 0:d2ed5a44c802 | 39 | #define GENIE_OBJ_LED_DIGITS 15 |
| chris215 | 0:d2ed5a44c802 | 40 | #define GENIE_OBJ_METER 16 |
| chris215 | 0:d2ed5a44c802 | 41 | #define GENIE_OBJ_STRINGS 17 |
| chris215 | 0:d2ed5a44c802 | 42 | #define GENIE_OBJ_THERMOMETER 18 |
| chris215 | 0:d2ed5a44c802 | 43 | #define GENIE_OBJ_USER_LED 19 |
| chris215 | 0:d2ed5a44c802 | 44 | #define GENIE_OBJ_VIDEO 20 |
| chris215 | 0:d2ed5a44c802 | 45 | #define GENIE_OBJ_STATIC_TEXT 21 |
| chris215 | 0:d2ed5a44c802 | 46 | #define GENIE_OBJ_SOUND 22 |
| chris215 | 0:d2ed5a44c802 | 47 | #define GENIE_OBJ_TIMER 23 |
| chris215 | 0:d2ed5a44c802 | 48 | #define GENIE_OBJ_SPECTRUM 24 |
| chris215 | 0:d2ed5a44c802 | 49 | #define GENIE_OBJ_SCOPE 25 |
| chris215 | 0:d2ed5a44c802 | 50 | #define GENIE_OBJ_TANK 26 |
| chris215 | 0:d2ed5a44c802 | 51 | #define GENIE_OBJ_USERIMAGES 27 |
| chris215 | 0:d2ed5a44c802 | 52 | #define GENIE_OBJ_PINOUTPUT 28 |
| chris215 | 0:d2ed5a44c802 | 53 | #define GENIE_OBJ_PININPUT 29 |
| chris215 | 0:d2ed5a44c802 | 54 | #define GENIE_OBJ_4DBUTTON 30 |
| chris215 | 0:d2ed5a44c802 | 55 | #define GENIE_OBJ_ANIBUTTON 31 |
| chris215 | 0:d2ed5a44c802 | 56 | #define GENIE_OBJ_COLORPICKER 32 |
| chris215 | 0:d2ed5a44c802 | 57 | #define GENIE_OBJ_USERBUTTON 33 |
| chris215 | 0:d2ed5a44c802 | 58 | |
| chris215 | 0:d2ed5a44c802 | 59 | // Structure to store replys returned from a display |
| chris215 | 0:d2ed5a44c802 | 60 | |
| chris215 | 0:d2ed5a44c802 | 61 | #define GENIE_FRAME_SIZE 6 |
| chris215 | 0:d2ed5a44c802 | 62 | |
| chris215 | 0:d2ed5a44c802 | 63 | #define ERROR_NONE 0 |
| chris215 | 0:d2ed5a44c802 | 64 | #define ERROR_TIMEOUT -1 // 255 0xFF |
| chris215 | 0:d2ed5a44c802 | 65 | #define ERROR_NOHANDLER -2 // 254 0xFE |
| chris215 | 0:d2ed5a44c802 | 66 | #define ERROR_NOCHAR -3 // 253 0xFD |
| chris215 | 0:d2ed5a44c802 | 67 | #define ERROR_NAK -4 // 252 0xFC |
| chris215 | 0:d2ed5a44c802 | 68 | #define ERROR_REPLY_OVR -5 // 251 0xFB |
| chris215 | 0:d2ed5a44c802 | 69 | #define ERROR_RESYNC -6 // 250 0xFA |
| chris215 | 0:d2ed5a44c802 | 70 | #define ERROR_NODISPLAY -7 // 249 0xF9 |
| chris215 | 0:d2ed5a44c802 | 71 | #define ERROR_BAD_CS -8 // 248 0xF8 |
| chris215 | 0:d2ed5a44c802 | 72 | |
| chris215 | 0:d2ed5a44c802 | 73 | #define GENIE_LINK_IDLE 0 |
| chris215 | 0:d2ed5a44c802 | 74 | #define GENIE_LINK_WFAN 1 // waiting for Ack or Nak |
| chris215 | 0:d2ed5a44c802 | 75 | #define GENIE_LINK_WF_RXREPORT 2 // waiting for a report frame |
| chris215 | 0:d2ed5a44c802 | 76 | #define GENIE_LINK_RXREPORT 3 // receiving a report frame |
| chris215 | 0:d2ed5a44c802 | 77 | #define GENIE_LINK_RXEVENT 4 // receiving an event frame |
| chris215 | 0:d2ed5a44c802 | 78 | #define GENIE_LINK_SHDN 5 |
| chris215 | 0:d2ed5a44c802 | 79 | |
| chris215 | 0:d2ed5a44c802 | 80 | #define GENIE_EVENT_NONE 0 |
| chris215 | 0:d2ed5a44c802 | 81 | #define GENIE_EVENT_RXCHAR 1 |
| chris215 | 0:d2ed5a44c802 | 82 | |
| chris215 | 0:d2ed5a44c802 | 83 | #ifndef TRUE |
| chris215 | 0:d2ed5a44c802 | 84 | #define TRUE (1==1) |
| chris215 | 0:d2ed5a44c802 | 85 | #define FALSE (!TRUE) |
| chris215 | 0:d2ed5a44c802 | 86 | #endif |
| chris215 | 0:d2ed5a44c802 | 87 | |
| chris215 | 7:6edb20845684 | 88 | #define NO_RESPONSE 0 |
| chris215 | 7:6edb20845684 | 89 | |
| chris215 | 7:6edb20845684 | 90 | #define GENIE_FRAME_SIZE 6 |
| chris215 | 7:6edb20845684 | 91 | // Structure to store replys returned from a display |
| chris215 | 7:6edb20845684 | 92 | struct genieFrameReportObj { |
| chris215 | 7:6edb20845684 | 93 | uint8_t cmd; |
| chris215 | 7:6edb20845684 | 94 | uint8_t object; |
| chris215 | 7:6edb20845684 | 95 | uint8_t index; |
| chris215 | 7:6edb20845684 | 96 | uint8_t data_msb; |
| chris215 | 7:6edb20845684 | 97 | uint8_t data_lsb; |
| chris215 | 7:6edb20845684 | 98 | }; |
| chris215 | 7:6edb20845684 | 99 | ///////////////////////////////////////////////////////////////////// |
| chris215 | 7:6edb20845684 | 100 | // The Genie frame definition |
| chris215 | 7:6edb20845684 | 101 | // |
| chris215 | 7:6edb20845684 | 102 | // The union allows the data to be referenced as an array of uint8_t |
| chris215 | 7:6edb20845684 | 103 | // or a structure of type genieFrameReportObj, eg |
| chris215 | 7:6edb20845684 | 104 | // |
| chris215 | 7:6edb20845684 | 105 | // genieFrame f; |
| chris215 | 7:6edb20845684 | 106 | // f.bytes[4]; |
| chris215 | 7:6edb20845684 | 107 | // f.reportObject.data_lsb |
| chris215 | 7:6edb20845684 | 108 | // |
| chris215 | 7:6edb20845684 | 109 | // both methods get the same byte |
| chris215 | 7:6edb20845684 | 110 | // |
| chris215 | 7:6edb20845684 | 111 | union genieFrame { |
| chris215 | 7:6edb20845684 | 112 | uint8_t bytes[GENIE_FRAME_SIZE]; |
| chris215 | 7:6edb20845684 | 113 | genieFrameReportObj reportObject; |
| chris215 | 7:6edb20845684 | 114 | }; |
| chris215 | 7:6edb20845684 | 115 | #define MAX_GENIE_EVENTS 16 // MUST be a power of 2 |
| chris215 | 7:6edb20845684 | 116 | struct genieEventQueueStruct { |
| chris215 | 7:6edb20845684 | 117 | genieFrame frames[MAX_GENIE_EVENTS]; |
| chris215 | 7:6edb20845684 | 118 | uint8_t rd_index; |
| chris215 | 7:6edb20845684 | 119 | uint8_t wr_index; |
| chris215 | 7:6edb20845684 | 120 | uint8_t n_events; |
| chris215 | 7:6edb20845684 | 121 | }; |
| chris215 | 7:6edb20845684 | 122 | |
| chris215 | 7:6edb20845684 | 123 | typedef void (*genieUserEventHandlerPtr) (void); |
| chris215 | 7:6edb20845684 | 124 | |
| chris215 | 2:f283764fe9b7 | 125 | class Mbed4dGenie{ |
| chris215 | 2:f283764fe9b7 | 126 | public: |
| chris215 | 7:6edb20845684 | 127 | |
| chris215 | 7:6edb20845684 | 128 | typedef enum{ |
| chris215 | 7:6edb20845684 | 129 | CommIdle = 0, |
| chris215 | 7:6edb20845684 | 130 | CommInProgress = 1 |
| chris215 | 7:6edb20845684 | 131 | }CommState; |
| chris215 | 7:6edb20845684 | 132 | |
| chris215 | 6:f4d3977b0eae | 133 | /* |
| chris215 | 6:f4d3977b0eae | 134 | Constructor to initialise the pins used to control the lcd screen |
| chris215 | 6:f4d3977b0eae | 135 | Note: When the class is first initialised, the lcd screen will be put |
| chris215 | 6:f4d3977b0eae | 136 | in reset and kept reset until Start() is called |
| chris215 | 6:f4d3977b0eae | 137 | */ |
| chris215 | 3:11c49c49cd1a | 138 | Mbed4dGenie(PinName TxPin,PinName RxPin, PinName resetpin); |
| chris215 | 11:9196f72fc325 | 139 | Mbed4dGenie(PinName TxPin,PinName RxPin, PinName resetpin,uint32_t baud); |
| chris215 | 6:f4d3977b0eae | 140 | /* |
| chris215 | 6:f4d3977b0eae | 141 | Deassert the reset pin and give some time to the lcd to |
| chris215 | 6:f4d3977b0eae | 142 | initialise itself before sending any commands. |
| chris215 | 6:f4d3977b0eae | 143 | */ |
| chris215 | 7:6edb20845684 | 144 | void Start(); |
| chris215 | 7:6edb20845684 | 145 | void Reset(void); |
| chris215 | 6:f4d3977b0eae | 146 | /* |
| chris215 | 6:f4d3977b0eae | 147 | Generic command to write data to a Genie object |
| chris215 | 6:f4d3977b0eae | 148 | returns the status code of operation |
| chris215 | 6:f4d3977b0eae | 149 | */ |
| chris215 | 7:6edb20845684 | 150 | int8_t genieWriteObject (uint16_t object, uint16_t index, uint16_t data); |
| chris215 | 7:6edb20845684 | 151 | int8_t genieWriteStr (uint16_t index, char *string); |
| chris215 | 7:6edb20845684 | 152 | int8_t genieReadObj (uint16_t object, uint16_t index); |
| chris215 | 7:6edb20845684 | 153 | |
| chris215 | 7:6edb20845684 | 154 | bool genieDequeueEvent(genieFrame * buff); |
| chris215 | 7:6edb20845684 | 155 | void genieAttachEventHandler (genieUserEventHandlerPtr handler); |
| chris215 | 7:6edb20845684 | 156 | bool PendingFrames(void); |
| chris215 | 2:f283764fe9b7 | 157 | |
| chris215 | 10:4d9f1be4a901 | 158 | uint16_t genieGetEventData (genieFrame * e); //added by to read value of object (combine MSB and LSB in a single variable) |
| chris215 | 10:4d9f1be4a901 | 159 | |
| chris215 | 7:6edb20845684 | 160 | private: |
| chris215 | 7:6edb20845684 | 161 | void writec(char data); |
| chris215 | 7:6edb20845684 | 162 | void RxIrqHandler(void); |
| chris215 | 7:6edb20845684 | 163 | void ManageReceiveData(char data); |
| chris215 | 7:6edb20845684 | 164 | bool _genieEnqueueEvent (uint8_t * data); |
| chris215 | 7:6edb20845684 | 165 | void _genieFlushEventQueue(void); |
| chris215 | 6:f4d3977b0eae | 166 | /* |
| chris215 | 6:f4d3977b0eae | 167 | Wait for the screen to aknowledge the command |
| chris215 | 6:f4d3977b0eae | 168 | returns the status code of operation |
| chris215 | 6:f4d3977b0eae | 169 | */ |
| chris215 | 7:6edb20845684 | 170 | int8_t WaitForAnswer(); |
| chris215 | 8:b5ba0df2d0db | 171 | bool WaitForIdle(); |
| chris215 | 8:b5ba0df2d0db | 172 | int8_t WaitForReadAnswer(); |
| chris215 | 6:f4d3977b0eae | 173 | |
| chris215 | 7:6edb20845684 | 174 | ////////////////////////////////////////////////////////////// |
| chris215 | 7:6edb20845684 | 175 | // A structure to hold up to MAX_GENIE_EVENTS events receive |
| chris215 | 7:6edb20845684 | 176 | // from the display |
| chris215 | 7:6edb20845684 | 177 | // |
| chris215 | 7:6edb20845684 | 178 | genieEventQueueStruct _genieEventQueue; |
| chris215 | 7:6edb20845684 | 179 | uint8_t rxframe_count; |
| chris215 | 7:6edb20845684 | 180 | uint8_t rx_data[GENIE_FRAME_SIZE]; |
| chris215 | 7:6edb20845684 | 181 | uint8_t checksum; |
| chris215 | 7:6edb20845684 | 182 | ////////////////////////////////////////////////////////////// |
| chris215 | 7:6edb20845684 | 183 | // Pointer to the user's event handler function |
| chris215 | 7:6edb20845684 | 184 | // |
| chris215 | 7:6edb20845684 | 185 | genieUserEventHandlerPtr _genieUserHandler; |
| chris215 | 6:f4d3977b0eae | 186 | |
| shakeeb | 12:78b783968b74 | 187 | Serial _screen; |
| chris215 | 8:b5ba0df2d0db | 188 | DigitalOut _reset; |
| chris215 | 11:9196f72fc325 | 189 | Timer _waitTimer,_receptionTimer; |
| chris215 | 7:6edb20845684 | 190 | int state; |
| chris215 | 8:b5ba0df2d0db | 191 | int LastResponse; |
| chris215 | 8:b5ba0df2d0db | 192 | long RxMaxTimeout; |
| chris215 | 8:b5ba0df2d0db | 193 | long RxStateTimeoutErrors; |
| chris215 | 6:f4d3977b0eae | 194 | }; |
