A port of the arduino voltmeter example for the mbed using the 4.3' PCT 4d systems touch screen display. Uses the mbed_genie library ported from the arduino visie-genie library by Christian B

Dependencies:   mbed

A test of the arduino voltmeter example using the 4.3' PCT 4d systems touch screen display.

This example program uses the mbed_genie library ported from the arduino Visi-Genie library by Christian B

The display serial TX and RX pins are connected to pin 9 and pin 10 of the mbed microcontroller

The reset pin is not connected as reset function is not implemented

Pin 15 of the mbed has a potentiometer wiper connected to it. The other connections of the potentiometer are connected to +3.3V and 0V - this is to provide some data for the demonstration and to ensure that we don't apply too much voltage to the analogue input pin

For setting up the display in Visie-Genie -

The display has an angular meter object, a LED digits object, two button objects and three static text objects.

The 4dButton0 (On) and the 4dButton1 (Off) button has been set to report on change within Visi-Genie object inspector

The serial baud rate of the display must be set to 115200 baud for this example to work. Ensure you have the settings correct in Visi-Genie when exporting the display program

The mbed program sends digital voltage readings to the LED digits and angular meter of the display module.

The volt readings will only be displayed if the appropriate button on the display is set!

I have written up a more in depth explanation on my blog here:

http://langster1980.blogspot.co.uk/2014/01/ulcd-43-display-mbed-tutorial.html

mbed_genie.h

Committer:
langster1980
Date:
2014-01-05
Revision:
1:9e8db53e04c9
Parent:
0:1ab681bd453e

File content as of revision 1:9e8db53e04c9:

#undef  GENIE_DEBUG

#define GENIE_VERSION   "GenieMbed 17-Nov-2013"

// Genie commands & replys:

#define GENIE_ACK       0x06
#define GENIE_NAK       0x15

#define TIMEOUT_PERIOD  500
#define RESYNC_PERIOD   100

#define GENIE_READ_OBJ          0
#define GENIE_WRITE_OBJ         1
#define GENIE_WRITE_STR         2
#define GENIE_WRITE_STRU        3
#define GENIE_WRITE_CONTRAST    4
#define GENIE_REPORT_OBJ        5
#define GENIE_REPORT_EVENT      7

// Objects
//  the manual says:
//      Note: Object IDs may change with future releases; it is not
//      advisable to code their values as constants.

#define GENIE_OBJ_DIPSW         0
#define GENIE_OBJ_KNOB          1
#define GENIE_OBJ_ROCKERSW      2
#define GENIE_OBJ_ROTARYSW      3
#define GENIE_OBJ_SLIDER        4
#define GENIE_OBJ_TRACKBAR      5
#define GENIE_OBJ_WINBUTTON     6
#define GENIE_OBJ_ANGULAR_METER 7
#define GENIE_OBJ_COOL_GAUGE    8
#define GENIE_OBJ_CUSTOM_DIGITS 9
#define GENIE_OBJ_FORM          10
#define GENIE_OBJ_GAUGE         11
#define GENIE_OBJ_IMAGE         12
#define GENIE_OBJ_KEYBOARD      13
#define GENIE_OBJ_LED           14
#define GENIE_OBJ_LED_DIGITS    15
#define GENIE_OBJ_METER         16
#define GENIE_OBJ_STRINGS       17
#define GENIE_OBJ_THERMOMETER   18
#define GENIE_OBJ_USER_LED      19
#define GENIE_OBJ_VIDEO         20
#define GENIE_OBJ_STATIC_TEXT   21
#define GENIE_OBJ_SOUND         22
#define GENIE_OBJ_TIMER         23
#define GENIE_OBJ_SPECTRUM      24
#define GENIE_OBJ_SCOPE         25
#define GENIE_OBJ_TANK          26
#define GENIE_OBJ_USERIMAGES    27
#define GENIE_OBJ_PINOUTPUT     28
#define GENIE_OBJ_PININPUT      29
#define GENIE_OBJ_4DBUTTON      30
#define GENIE_OBJ_ANIBUTTON     31
#define GENIE_OBJ_COLORPICKER   32
#define GENIE_OBJ_USERBUTTON    33

// Structure to store replys returned from a display

#define     GENIE_FRAME_SIZE    6
struct genieFrameReportObj {
    uint8_t     cmd;
    uint8_t     object;
    uint8_t     index;
    uint8_t     data_msb;
    uint8_t     data_lsb;
};
 
/////////////////////////////////////////////////////////////////////
// The Genie frame definition
//
// The union allows the data to be referenced as an array of uint8_t
// or a structure of type genieFrameReportObj, eg
//
//  genieFrame f;
//  f.bytes[4];
//  f.reportObject.data_lsb
//
//  both methods get the same byte
//
union genieFrame {
    uint8_t             bytes[GENIE_FRAME_SIZE];
    genieFrameReportObj reportObject;
};

#define MAX_GENIE_EVENTS    16  // MUST be a power of 2
#define MAX_GENIE_FATALS    10

struct genieEventQueueStruct {
    genieFrame  frames[MAX_GENIE_EVENTS];
    uint8_t     rd_index;
    uint8_t     wr_index;
    uint8_t     n_events;
};

typedef void        (*geniePutCharFuncPtr)      (uint8_t c, uint32_t baud);
typedef uint16_t    (*genieGetCharFuncPtr)      (void);
typedef void        (*genieUserEventHandlerPtr) (void);

#define ERROR_NONE          0
#define ERROR_TIMEOUT       -1  // 255  0xFF
#define ERROR_NOHANDLER     -2  // 254  0xFE
#define ERROR_NOCHAR        -3  // 253  0xFD
#define ERROR_NAK           -4  // 252  0xFC
#define ERROR_REPLY_OVR     -5  // 251  0xFB
#define ERROR_RESYNC        -6  // 250  0xFA
#define ERROR_NODISPLAY     -7  // 249  0xF9
#define ERROR_BAD_CS        -8  // 248  0xF8

#define GENIE_LINK_IDLE         0
#define GENIE_LINK_WFAN         1 // waiting for Ack or Nak
#define GENIE_LINK_WF_RXREPORT  2 // waiting for a report frame
#define GENIE_LINK_RXREPORT     3 // receiving a report frame
#define GENIE_LINK_RXEVENT      4 // receiving an event frame
#define GENIE_LINK_SHDN         5

#define GENIE_EVENT_NONE    0
#define GENIE_EVENT_RXCHAR  1

#ifndef        TRUE
#define        TRUE        (1==1)
#define        FALSE        (!TRUE)
#endif

void            SetupGenie(void);
void            genieAttachEventHandler     (genieUserEventHandlerPtr handler);
extern bool     genieDequeueEvent           (genieFrame * buff);
extern bool     genieEventIs                (genieFrame * e, uint8_t cmd, uint8_t object, uint8_t index);
extern uint16_t genieGetEventData           (genieFrame * e); 
extern uint16_t genieWriteObject            (uint16_t object, uint16_t index, uint16_t data);
extern uint16_t        genieWriteStr                        (uint16_t index, char *string);
extern void                genieWriteContrast                (uint16_t value);