Mbed 4dGenie class

Dependents:   Genie_Test 039847382-S3_DS1621_and_LCD_V1

This is a work in progress.

4dGenie class to use with 4dLCD screens that are using the genie environment.

There are still some rare occasions where the 4dLCD might crash, for now i have no solution to this except doing a reset of the 4dLCD.

Please make sure to have the most up to date PmmC loaded on the screen.

usage example :

Mbed4dGenie test program

#include "mbed.h"
#include "mbed_genie.h"

DigitalOut myled(LED1);
/*
    The Mbed4dGenie class requires 3 parameters
    1 - Tx pin
    2 - Rx pin
    3 - Reset pin
*/
Mbed4dGenie lcd4d(PTE0,PTE1,PTB9);



int main() {
    int temp = 0;
printf("Mbed Genie demo \n\r");
lcd4d.Start();


 /*
 for example, in this loop we increment the thermometer0 object from 0 to 100
 */
 
    while(1) {
        if(temp >= 100)
        {
            temp = -1;
        }
        else
        {
            temp++;
        }

        lcd4d.genieWriteObject(GENIE_OBJ_LED_DIGITS,1,temp);

        myled = 1;
        wait(0.05);
        myled = 0;
        wait(0.05);
    }
}

mbed_genie.cpp

Committer:
chris215
Date:
2014-07-04
Revision:
6:f4d3977b0eae
Parent:
3:11c49c49cd1a
Child:
7:6edb20845684

File content as of revision 6:f4d3977b0eae:

#include "mbed.h"
#include "mbed_genie.h"

Mbed4dGenie::Mbed4dGenie(PinName TxPin,PinName RxPin, PinName resetpin) : _screen(TxPin,RxPin) , _reset(resetpin)
{
    //reset the 4d screen
    _reset = 0;
    _screen.baud(9600);
}
void Mbed4dGenie::Start()
{
    _reset = 1;
    wait(0.2);  //wait some time to let the lcd screen intialised itself
    //empty the uart buffer
    while(_screen.readable())
        _screen.getc();
        
    _t.start();
}

///////////////////////// genieWriteObject //////////////////////
//
// Write data to an object on the display
//
int8_t Mbed4dGenie::genieWriteObject (uint16_t object, uint16_t index, uint16_t data)
{
    uint16_t msb, lsb ;
    uint8_t checksum ;
    
    lsb = data&0xFF;
    msb = (data>>8) & 0xFF;
    
    _screen.putc(GENIE_WRITE_OBJ) ; 
    checksum  = GENIE_WRITE_OBJ ;
    _screen.putc(object) ;          
    checksum ^= object ;
    _screen.putc(index) ;           
    checksum ^= index ;
    _screen.putc(msb) ;             
    checksum ^= msb;
    _screen.putc(lsb) ;             
    checksum ^= lsb;
    _screen.putc(checksum) ;
    
       

     return  Mbed4dGenie::WaitForAnswer();    
}


int8_t Mbed4dGenie::WaitForAnswer()
{
    int8_t operation_result = 0; 
    
    long timeout = _t.read_ms() + TIMEOUT_PERIOD;
    long timerReading = 0;
    while(operation_result != GENIE_ACK && operation_result != ERROR_NAK && timerReading < timeout)
    {
        if(_screen.readable())
            operation_result = _screen.getc();
        timerReading = _t.read_ms();
    }
           
    if(operation_result == ERROR_NAK)
    {
        return ERROR_NONE;
    }
    else if(timerReading >= timeout)
    {   
        return ERROR_TIMEOUT;
    }
    return ERROR_NONE;
}