3 years, 7 months ago.

Real Time Clock function in the SmartGPU2 library - How do I call/ use it from main() ?

Hi. Can anyone give me some help with using the following RTC function from main()? I have tried several different ways of calling this function with several different errors from the mbed compiler. I am clearly getting confused re the struct TIME and how it passes the contents of each member from timeDate. The following info is taken from my main and the SMARTGPU2 . h and .cpp library files:

main()

main()
SMARTGPUREPLY res; // responses from GPU
res = lcd.getRTCTimeDate(TIME*); // res gets the result of the function call  
lcd.string(0,21,300,40, TIME.hour, &bytes);  //write a string on the tft screen with the RTC hours data   

SMARTGPU2.cpp

/****************************************************************/
//Real Time Clock Functions
/****************************************************************/          
SMARTGPUREPLY SMARTGPU2::setupRTC(STATE *state){
  putcharTX('R');              //RTC function - Real Time Clock
  putcharTX('S');              //Setup RTC
  *state = (STATE)getcharRX();  //Get state
  return (SMARTGPUREPLY)getcharRX();   
}
    
SMARTGPUREPLY SMARTGPU2::getRTCTimeDate(TIME *timeDate){
  unsigned int counter=0;
  
  putcharTX('R');              //RTC function - Real Time Clock
  putcharTX('P');              //Parameters
  putcharTX('G');              //Get
  timeDate->hour = getcharRX(); //hour
  timeDate->minute = getcharRX();   //min
  timeDate->second = getcharRX(); //sec
  timeDate->day = getcharRX();  //day
  timeDate->month = getcharRX();  //month
  ((unsigned char*)&counter)[1] = getcharRX();       //year upper
  ((unsigned char*)&counter)[0] = getcharRX();       //year lower
  timeDate->year = counter;         //year 
  return (SMARTGPUREPLY)getcharRX();
}

 SMARTGPU2.h


//Files Time and Date
typedef struct {
    unsigned char hour;
    unsigned char minute;
    unsigned char second;
    unsigned char day;
    unsigned char month;
    unsigned int  year; 
} TIME;    //to create a Time-Date info struct

/****************************************************************/
//Real Time Clock Functions
/****************************************************************/          
    SMARTGPUREPLY setupRTC(STATE*);
    
    SMARTGPUREPLY getRTCTimeDate(TIME*);
    
    SMARTGPUREPLY setRTCTimeDate(TIME*);

Question relating to:

1 Answer

3 years, 7 months ago.

Something like this might work (untested, as I don't have the board):

SMARTGPUREPLY res; // responses from GPU
TIME time;
res = lcd.getRTCTimeDate(&time); // res gets the result of the function call  
lcd.string(0,21,300,40, time.hour, &bytes);  //write a string on the tft screen with the RTC hours data   

Thanks Jan. That helped a lot. I now have a real time clock !

posted by Mike Pollock 21 Dec 2017