4D display working with Gecko board STK3600

Dependents:   Genie_mbed_Gecko

Fork of 4dGENIE by christian b

Committer:
chris215
Date:
Fri Jul 04 02:44:49 2014 +0000
Revision:
6:f4d3977b0eae
Parent:
3:11c49c49cd1a
Child:
7:6edb20845684
Redesign of the 4dGENIE class. Right now, the class is only capable of writting to screen objects(excluding string objects)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris215 0:d2ed5a44c802 1 #include "mbed.h"
chris215 0:d2ed5a44c802 2 #include "mbed_genie.h"
chris215 0:d2ed5a44c802 3
chris215 3:11c49c49cd1a 4 Mbed4dGenie::Mbed4dGenie(PinName TxPin,PinName RxPin, PinName resetpin) : _screen(TxPin,RxPin) , _reset(resetpin)
chris215 2:f283764fe9b7 5 {
chris215 3:11c49c49cd1a 6 //reset the 4d screen
chris215 3:11c49c49cd1a 7 _reset = 0;
chris215 6:f4d3977b0eae 8 _screen.baud(9600);
chris215 2:f283764fe9b7 9 }
chris215 6:f4d3977b0eae 10 void Mbed4dGenie::Start()
chris215 6:f4d3977b0eae 11 {
chris215 6:f4d3977b0eae 12 _reset = 1;
chris215 6:f4d3977b0eae 13 wait(0.2); //wait some time to let the lcd screen intialised itself
chris215 6:f4d3977b0eae 14 //empty the uart buffer
chris215 6:f4d3977b0eae 15 while(_screen.readable())
chris215 6:f4d3977b0eae 16 _screen.getc();
chris215 2:f283764fe9b7 17
chris215 6:f4d3977b0eae 18 _t.start();
chris215 2:f283764fe9b7 19 }
chris215 2:f283764fe9b7 20
chris215 2:f283764fe9b7 21 ///////////////////////// genieWriteObject //////////////////////
chris215 0:d2ed5a44c802 22 //
chris215 2:f283764fe9b7 23 // Write data to an object on the display
chris215 0:d2ed5a44c802 24 //
chris215 6:f4d3977b0eae 25 int8_t Mbed4dGenie::genieWriteObject (uint16_t object, uint16_t index, uint16_t data)
chris215 2:f283764fe9b7 26 {
chris215 6:f4d3977b0eae 27 uint16_t msb, lsb ;
chris215 6:f4d3977b0eae 28 uint8_t checksum ;
chris215 6:f4d3977b0eae 29
chris215 6:f4d3977b0eae 30 lsb = data&0xFF;
chris215 6:f4d3977b0eae 31 msb = (data>>8) & 0xFF;
chris215 6:f4d3977b0eae 32
chris215 6:f4d3977b0eae 33 _screen.putc(GENIE_WRITE_OBJ) ;
chris215 6:f4d3977b0eae 34 checksum = GENIE_WRITE_OBJ ;
chris215 6:f4d3977b0eae 35 _screen.putc(object) ;
chris215 6:f4d3977b0eae 36 checksum ^= object ;
chris215 6:f4d3977b0eae 37 _screen.putc(index) ;
chris215 6:f4d3977b0eae 38 checksum ^= index ;
chris215 6:f4d3977b0eae 39 _screen.putc(msb) ;
chris215 6:f4d3977b0eae 40 checksum ^= msb;
chris215 6:f4d3977b0eae 41 _screen.putc(lsb) ;
chris215 6:f4d3977b0eae 42 checksum ^= lsb;
chris215 6:f4d3977b0eae 43 _screen.putc(checksum) ;
chris215 6:f4d3977b0eae 44
chris215 6:f4d3977b0eae 45
chris215 2:f283764fe9b7 46
chris215 6:f4d3977b0eae 47 return Mbed4dGenie::WaitForAnswer();
chris215 0:d2ed5a44c802 48 }
chris215 0:d2ed5a44c802 49
chris215 0:d2ed5a44c802 50
chris215 6:f4d3977b0eae 51 int8_t Mbed4dGenie::WaitForAnswer()
chris215 6:f4d3977b0eae 52 {
chris215 6:f4d3977b0eae 53 int8_t operation_result = 0;
chris215 0:d2ed5a44c802 54
chris215 6:f4d3977b0eae 55 long timeout = _t.read_ms() + TIMEOUT_PERIOD;
chris215 6:f4d3977b0eae 56 long timerReading = 0;
chris215 6:f4d3977b0eae 57 while(operation_result != GENIE_ACK && operation_result != ERROR_NAK && timerReading < timeout)
chris215 6:f4d3977b0eae 58 {
chris215 6:f4d3977b0eae 59 if(_screen.readable())
chris215 6:f4d3977b0eae 60 operation_result = _screen.getc();
chris215 6:f4d3977b0eae 61 timerReading = _t.read_ms();
chris215 6:f4d3977b0eae 62 }
chris215 6:f4d3977b0eae 63
chris215 6:f4d3977b0eae 64 if(operation_result == ERROR_NAK)
chris215 6:f4d3977b0eae 65 {
chris215 6:f4d3977b0eae 66 return ERROR_NONE;
chris215 6:f4d3977b0eae 67 }
chris215 6:f4d3977b0eae 68 else if(timerReading >= timeout)
chris215 6:f4d3977b0eae 69 {
chris215 6:f4d3977b0eae 70 return ERROR_TIMEOUT;
chris215 6:f4d3977b0eae 71 }
chris215 6:f4d3977b0eae 72 return ERROR_NONE;
chris215 2:f283764fe9b7 73 }