6 Replies Latest reply on May 9, 2016 8:26 AM by Guimficus

    C++ library of touch display (4D systems) for edison

    Guimficus

      Hello guys,

       

      I'm trying to write a library to drive 4D systems touch display in c++ eclipse with intel Edison board Arduino.  But after written my code and exacuted mu program, nothing happens on the screen. Some one can tell me what is the problem in my code and how to resolve it, please? Here is my code below:

       

      ***********************GenieEdison.hpp**************************

      /*
      * GenieEdison.hpp
      *
      *  Created on: 28 avr. 2016
      *      Author: Utilisateur
      */
      
      #ifndef GENIEEDISON_HPP_
      #define GENIEEDISON_HPP_
      
      #include <iostream>
      #include "mraa.hpp"
      #include <stdint.h>
      #include "stdio.h"
      #include <sstream>
      #include <string>
      #include <stdlib.h>
      #undef  GENIE_DEBUG
      
      #define GENIE_VERSION   "GenieEdison 27-April-2016"
      
      // 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 void     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);
      
      
      
      
      #endif /* GENIEEDISON_HPP_ */
      

       

       

      *********************************GenieEdison.cpp**************************************************

      /*
      * GenieEdison.cpp
      *
      *  Created on: 28 avr. 2016
      *      Author: Utilisateur
      */
      
      #include "GenieEdison.hpp"
      using namespace std;
      mraa_uart_context Screen;
      
      void           _genieFlushEventQueue        (void);
      void           _handleError                        (void);
      void           _geniePutchar                        (uint8_t c);
      uint8_t        _genieGetchar                        (void);
      void           _genieSetLinkState                (uint16_t newstate);
      uint16_t       _genieGetLinkState                (void);
      bool           _genieEnqueueEvent                (uint8_t * data);
      //////////////////////////////////////////////////////////////
      // A structure to hold up to MAX_GENIE_EVENTS events receive
      // from the display
      //
      static genieEventQueueStruct _genieEventQueue;
      
      //////////////////////////////////////////////////////////////
      // Pointer to the user's event handler function
      //
      static genieUserEventHandlerPtr _genieUserHandler = NULL;
      
      
      //////////////////////////////////////////////////////////////
      // Simple 5-deep stack for the link state, this allows
      // genieDoEvents() to save the current state, receive a frame,
      // then restore the state
      //
      static uint8_t _genieLinkStates[5] = {GENIE_LINK_IDLE};
      //
      // Stack pointer
      //
      static uint8_t *_genieLinkState = &_genieLinkStates[0];
      
      
      //////////////////////////////////////////////////////////////
      // Number of mS the genieGetChar() function will wait before
      // giving up on the display
      static int _genieTimeout = TIMEOUT_PERIOD;
      
      
      //////////////////////////////////////////////////////////////
      // Number of times we have had a timeout
      //static int _genieTimeouts = 0;
      
      //////////////////////////////////////////////////////////////
      // Global error variable
      static int _genieError = ERROR_NONE;
      
      static uint8_t        rxframe_count = 0;
      
      
      //////////////////////////////////////////////////////////////
      // Number of fatal errors encountered
      //static int _genieFatalErrors = 0;
      ////////////////////// genieGetEventData ////////////////////////
      //
      // Returns the LSB and MSB of the event's data combined into
      // a single uint16
      //
      // The data is transmitted from the display in big-endian format
      // and stored the same so the user can't just access it as an int
      // directly from the structure.
      //
      uint16_t genieGetEventData (genieFrame * e) {
              return  (e->reportObject.data_msb << 8) + e->reportObject.data_lsb;
      }
      
      
      //////////////////////// genieEventIs ///////////////////////////
      //
      // Compares the cmd, object and index fields of the event's
      // structure.
      //
      // Returns:                TRUE if all the fields match the caller's parms
      //                                FALSE if any of them don't
      //
      bool genieEventIs(genieFrame * e, uint8_t cmd, uint8_t object, uint8_t index) {
      
      
              return (e->reportObject.cmd == cmd &&
                      e->reportObject.object == object &&
                      e->reportObject.index == index);
      
      
      }
      
      ////////////////////// _geniePushLinkState //////////////////////
      //
      // Push a link state onto a FILO stack
      //
      void _geniePushLinkState (uint8_t newstate) {
      
      
              _genieLinkState++;
              _genieSetLinkState(newstate);
      
      
      }
      
      
      ////////////////////// _geniePopLinkState //////////////////////
      //
      // Pop a link state from a FILO stack
      //
      void _geniePopLinkState (void) {
              if (_genieLinkState > &_genieLinkStates[0]) {
                      *_genieLinkState = 0xFF;
                      _genieLinkState--;
              }
      }
      
      ///////////////// _genieFlushSerialInput ///////////////////
      //
      // Removes and discards all characters from the currently
      // used serial port's Rx buffer.
      //
      void _genieFlushSerialInput(void) {
              do {
                      _genieGetchar();
              } while (_genieError != ERROR_NOCHAR);
      }
      
      ///////////////////////// _handleError /////////////////////////
      //
      // So far really just a debugging aid, but can be enhanced to
      // help recover from errors.
      //
      void _handleError (void) {
      //        Serial2.write (_genieError + (1<<5));
      //        if (_genieError == GENIE_NAK) genieResync();
      }
      
      
      
      
      ////////////////////// _genieFlushEventQueue ////////////////////
      //
      // Reset all the event queue variables and start from scratch.
      //
      void _genieFlushEventQueue(void) {
              _genieEventQueue.rd_index = 0;
              _genieEventQueue.wr_index = 0;
              _genieEventQueue.n_events = 0;
      }
      
      
      ///////////////////////// genieDoEvents /////////////////////////
      //
      // This is the heart of the Genie comms state machine.
      //
      uint16_t genieDoEvents (void) {
              uint8_t c;
              static uint8_t        rx_data[6];
              static uint8_t        checksum = 0;
              c = _genieGetchar();
      
      
                  ////////////////////////////////////////////
                  //
                  // If there are no characters to process and we have
                  // queued events call the user's handler function.
                  //
                  if (_genieError == ERROR_NOCHAR) {
                  //pc.printf("EventCalled!\n\r");
                          if (_genieEventQueue.n_events > 0 && _genieUserHandler!= NULL) (_genieUserHandler)();
                          return GENIE_EVENT_NONE;
                  }
      
                  ///////////////////////////////////////////
                  //
                  // Main state machine
                  //
                  switch (_genieGetLinkState()) {
                          case GENIE_LINK_IDLE:
                                  switch (c) {
                                          case GENIE_REPORT_EVENT:
                                          // event frame out of the blue, set the link state
                                          // and fall through to the frame-accumulate code
                                          // at the end of this function
                                          _geniePushLinkState(GENIE_LINK_RXEVENT);
                                          break;
      
                                          default:
                                          // error, bad character, no other character
                                          // is acceptable in this state
                                          return GENIE_EVENT_RXCHAR;
      
                                  }
                                  break;
      
                          case GENIE_LINK_WFAN:
                                  switch (c) {
      
      
                                          case GENIE_ACK:
                                                  _geniePopLinkState();
                                                  return GENIE_EVENT_RXCHAR;
      
      
                                          case GENIE_NAK:
                                                  _geniePopLinkState();
                                                  _genieError = ERROR_NAK;
                                                  _handleError();
                                                  return GENIE_EVENT_RXCHAR;
      
                                          case GENIE_REPORT_EVENT:
                                                  // event frame out of the blue while waiting for an ACK
                                                  // save/set the link state and fall through to the
                                                  // frame-accumulate code at the end of this function
                                                  _geniePushLinkState(GENIE_LINK_RXEVENT);
                                                  break;
      
      
                                          case GENIE_REPORT_OBJ:
                                          default:
                                                  // error, bad character
                                                  return GENIE_EVENT_RXCHAR;
                                  }
                                  break;
      
      
                          case GENIE_LINK_WF_RXREPORT: // waiting for the first byte of a report
                                  switch (c) {
      
                                          case GENIE_REPORT_EVENT:
                                          // event frame out of the blue while waiting for the first
                                          // byte of a report frame
                                          // save/set the link state and fall through to the
                                          // frame-accumulate code at the end of this function
                                          _geniePushLinkState(GENIE_LINK_RXEVENT);
                                          break;
                                          case GENIE_REPORT_OBJ:
                                          // first byte of a report frame
                                          // replace the GENIE_LINK_WF_RXREPORT link state
                                          // with GENIE_LINK_RXREPORT to indicate that we
                                          // are now receiving a report frame
                                          _geniePopLinkState();
                                          _geniePushLinkState(GENIE_LINK_RXREPORT);
                                          break;
                                          case GENIE_ACK:
                                              break;
                                          case GENIE_NAK:
                                              break;
                                          default:
                                          // error, bad character
                                          return GENIE_EVENT_RXCHAR;
                                          break;
                                  }
                              break;
      
                          case GENIE_LINK_RXREPORT:                // already receiving report
                              break;
                          case GENIE_LINK_RXEVENT:                // already receiving event
                              break;
                          default:
                                  break;
                  }
      
      
                  ///////////////////////////////////////////////////////
                  // We get here if we are in the process of receiving
                  // a report or event frame. Accumulate GENIE_FRAME_SIZE
                  // bytes into a local buffer then queue them as a frame
                  // into the event queue
                  //
                  if (_genieGetLinkState() == GENIE_LINK_RXREPORT || \
                          _genieGetLinkState() == GENIE_LINK_RXEVENT) {
      
                          checksum = (rxframe_count == 0) ? c : checksum ^ c;
      
                          rx_data[rxframe_count] = c;
      
                          if (rxframe_count == GENIE_FRAME_SIZE -1) {
                          //pc.printf("FrameReceived!\n\r");
                                  // all bytes received, if the CS is good
                                  // queue the frame and restore the link state
                                  if (checksum == 0) {
                                          _genieEnqueueEvent(rx_data);
                                          if (_genieEventQueue.n_events > 0 && _genieUserHandler!= NULL) (_genieUserHandler)();
                                          //return GENIE_EVENT_NONE;
                                          rxframe_count = 0;
                                          // revert the link state to whatever it was before
                                          // we started accumulating this frame
                                          _geniePopLinkState();
                                          return GENIE_EVENT_RXCHAR;
                                  } else {
                                          _genieError = ERROR_BAD_CS;
                                          _handleError();
                                  }
                          }
                          rxframe_count++;
                          return GENIE_EVENT_RXCHAR;
                  }
                  return NULL;
      }
      
      ////////////////////// genieDequeueEvent ///////////////////
      //
      // Copy the bytes from a queued input event to a buffer supplied
      // by the caller.
      //
      // Parms:        genieFrame * buff, a pointer to the user's buffer
      //
      // Returns:        TRUE if there was an event to copy
      //                        FALSE if not
      //
      bool genieDequeueEvent(genieFrame * buff) {
      
      
              if (_genieEventQueue.n_events > 0) {
                      memcpy (buff, &_genieEventQueue.frames[_genieEventQueue.rd_index],
                                      GENIE_FRAME_SIZE);
                      _genieEventQueue.rd_index++;
                      _genieEventQueue.rd_index &= MAX_GENIE_EVENTS -1;
                      _genieEventQueue.n_events--;
                      return TRUE;
              }
              return FALSE;
      }
      
      
      ////////////////////// _genieWaitForIdle ////////////////////////
      //
      // Wait for the link to become idle or for the timeout period,
      // whichever comes first.
      //
      void _genieWaitForIdle (void) {
              uint16_t do_event_result;
              time_t tps = time(0);
              long timeout = ((long)tps) * 1000 + _genieTimeout;
          for ( ; ((long)tps) * 1000 < timeout;) {
              do_event_result = genieDoEvents();
      
              // if there was a character received from the
              // display restart the timeout because doEvents
              // is in the process of receiving something
              if (do_event_result == GENIE_EVENT_RXCHAR) {
                  tps = time(0);
                  timeout = ((long)tps) * 1000 + _genieTimeout;
              }
      
              if (_genieGetLinkState() == GENIE_LINK_IDLE) {
                  return;
              }
          }
      
          _genieError = ERROR_TIMEOUT;
          _handleError();
          return;
      }
      
      ///////////////////////// genieWriteObject //////////////////////
      //
      // Write data to an object on the display
      //
      void genieWriteObject (uint16_t object, uint16_t index, uint16_t data)
      {
              uint16_t msb, lsb ;
              uint8_t checksum ;
              _genieWaitForIdle();
              lsb = data&0xFF;
              msb = (data>>8) & 0xFF;
              _genieError = ERROR_NONE;
              _geniePutchar(GENIE_WRITE_OBJ) ; checksum  = GENIE_WRITE_OBJ ;
              _geniePutchar(object) ;          checksum ^= object ;
              _geniePutchar(index) ;           checksum ^= index ;
              _geniePutchar(msb) ;             checksum ^= msb;
              _geniePutchar(lsb) ;             checksum ^= lsb;
              _geniePutchar(checksum) ;
              _geniePushLinkState(GENIE_LINK_WFAN);
      }
      
      /////////////////////// genieWriteContrast //////////////////////
      //
      // Alter the display contrast (backlight)
      //
      // Parms:        uint8_t value: The required contrast setting, only
      //                values from 0 to 15 are valid. 0 or 1 for most displays
      //      and 0 to 15 for the uLCD-43
      //
      void genieWriteContrast (uint16_t value) {
              unsigned int checksum ;
      
              _genieWaitForIdle();
      
              _geniePutchar(GENIE_WRITE_CONTRAST) ; checksum  = GENIE_WRITE_CONTRAST ;
              _geniePutchar(value) ;                checksum ^= value ;
              _geniePutchar(checksum) ;
      
              _geniePushLinkState(GENIE_LINK_WFAN);
      
      }
      
      //////////////////////// _genieWriteStrX ///////////////////////
      //
      // Non-user function used by genieWriteStr() and genieWriteStrU()
      //
      static int _genieWriteStrX (uint16_t code, uint16_t index, char *string)
      {
              char *p ;
              unsigned int checksum ;
              int len = strlen (string) ;
      
      
              if (len > 255)
              return -1 ;
      
              _genieWaitForIdle();
      
              _geniePutchar(code) ;               checksum  = code ;
              _geniePutchar(index) ;              checksum ^= index ;
              _geniePutchar((unsigned char)len) ; checksum ^= len ;
              for (p = string ; *p ; ++p)        {
                      _geniePutchar (*p) ;
                      checksum ^= *p ;
              }
              _geniePutchar(checksum) ;
      
      
              _geniePushLinkState(GENIE_LINK_WFAN);
      
      
              return 0 ;
      }
      
      /////////////////////// genieWriteStr ////////////////////////
      //
      // Write a string to the display (ASCII)
      //
      uint16_t genieWriteStr (uint16_t index, char *string) {
      
        return _genieWriteStrX (GENIE_WRITE_STR, index, string);
      }
      
      
      /////////////////////// genieWriteStrU ////////////////////////
      //
      // Write a string to the display (Unicode)
      //
      uint16_t genieWriteStrU (uint16_t index, char *string) {
      
      
        return _genieWriteStrX (GENIE_WRITE_STRU, index, string);
      
      
      }
      /////////////////// genieAttachEventHandler //////////////////////
      //
      // "Attaches" a pointer to the users event handler by writing
      // the pointer into the variable used by doEVents()
      //
      void genieAttachEventHandler (genieUserEventHandlerPtr handler) {
              _genieUserHandler = handler;
      }
      
      ////////////////////// _genieEnqueueEvent ///////////////////
      //
      // Copy the bytes from a buffer supplied by the caller
      // to the input queue
      //
      // Parms:        uint8_t * data, a pointer to the user's data
      //
      // Returns:        TRUE if there was an empty location in the queue
      //                                to copy the data into
      //                        FALSE if not
      // Sets:        ERROR_REPLY_OVR if there was no room in the queue
      //
      bool _genieEnqueueEvent (uint8_t * data) {
      
      
              if (_genieEventQueue.n_events < MAX_GENIE_EVENTS-2) {
                      memcpy (&_genieEventQueue.frames[_genieEventQueue.wr_index], data,
                                      GENIE_FRAME_SIZE);
                      _genieEventQueue.wr_index++;
                      _genieEventQueue.wr_index &= MAX_GENIE_EVENTS -1;
                      _genieEventQueue.n_events++;
                      return TRUE;
              } else {
                      _genieError = ERROR_REPLY_OVR;
                      _handleError();
                      return FALSE;
              }
      }
      
      ///////////////////// _genieSetLinkState ////////////////////////
      //
      // Set the logical state of the link to the display.
      //
      // Parms:        uint16_t newstate, a value to be written to the
      //                                link's _genieLinkState variable. Valid values are
      //                GENIE_LINK_IDLE                        0
      //                GENIE_LINK_WFAN                        1 // waiting for Ack or Nak
      //                GENIE_LINK_WF_RXREPORT        2 // waiting for a report frame
      //                GENIE_LINK_RXREPORT                3 // receiving a report frame
      //                GENIE_LINK_RXEVENT                4 // receiving an event frame
      //                GENIE_LINK_SHDN                        5
      //
      void _genieSetLinkState (uint16_t newstate) {
      
              *_genieLinkState = newstate;
      
      
              if (newstate == GENIE_LINK_RXREPORT || \
                      newstate == GENIE_LINK_RXEVENT)
                      rxframe_count = 0;
      }
      
      
      /////////////////////// _genieGetLinkState //////////////////////
      //
      // Get the current logical state of the link to the display.
      //
      uint16_t _genieGetLinkState (void) {
              return *_genieLinkState;
      }
      
      /////////////////////// _geniePutchar ///////////////////////////
      //
      // Output the supplied character to the Genie display over
      // the selected serial port
      //
      void _geniePutchar (uint8_t c) {
          if (Screen != NULL){
              char* chaine;
              memcpy(&c,chaine,sizeof(int));
              mraa_uart_write(Screen, chaine, sizeof(chaine));
          }
      
      }
      
      //////////////////////// _genieGetchar //////////////////////////
      //
      // Get a character from the selected Genie serial port
      //
      // Returns:        ERROR_NOHANDLER if an Rx handler has not
      //                                been defined
      //                        ERROR_NOCHAR if no bytes have beeb received
      //                        The char if there was one to get
      // Sets:        _genieError with any errors encountered
      //
      uint8_t _genieGetchar() {
              uint8_t result;
              _genieError = ERROR_NONE;
              char* chaine = {0};
              mraa_uart_read(Screen, chaine, sizeof(chaine));
              result = atoi(chaine);
              return result;
      }
      
      /*void RxIrqHandler(void)
      {
          do
          {
              genieDoEvents();
          }
          while(Screen == true);
      }*/
      
      void SetupGenie(void){
          Screen = mraa_uart_init_raw("/dev/ttyMFD1");
          if (Screen == NULL)
          {
               std::cout << "UART failed to setup\n" << endl;
          }
          else {
              mraa_uart_set_baudrate(Screen, 115200);
          }
      }
      

       

       

      ****************************************Main file***************************************************

      #include "GenieEdison.hpp"
      using namespace std;
      
      
      //Event handler for the 4d Systems display
      void myGenieEventHandler(void)
      {
        genieFrame Event;
        genieDequeueEvent(&Event);
        //event report from an object
        if(Event.reportObject.cmd == GENIE_REPORT_EVENT)
        {
          /*
          for example here we check if we received a message from 4dbuttons objects
          the index is the button number, refer to the 4dgenie project to know the index
          */
          if (Event.reportObject.object == GENIE_OBJ_4DBUTTON)    // If the Reported Message was from a button
          {
              if (Event.reportObject.index == 0)
              {
                   cout << "report0" << endl;
              }
              if (Event.reportObject.index == 1)
              {
                  cout << "report1" << endl;
              }
          }
        }
      }
      
      
      int main() {
        /* Setup your example here, code that should run once
         */
          SetupGenie();
          genieAttachEventHandler(&myGenieEventHandler);
      
        /* Code in this loop will run repeatedly
         */
        for (;;) {
            genieWriteObject(GENIE_OBJ_FORM, 0x00, 0);
            sleep(1);
            genieWriteObject(GENIE_OBJ_FORM, 0x04, 0);
              sleep(1);
            genieWriteObject(GENIE_OBJ_FORM, 0x05, 0);
        }
      
        return 0;
      }
      
        • 1. Re: C++ library of touch display (4D systems) for edison
          KurtE

          Sorry, not sure I can help much here as I have not done much with Edison for maybe a year, hoping the the SPI issues were resolved.   Hopefully some others might be able to give you a hand,

           

          It would probably help to have additional information, like: What display you have, how do you have it hooked up. 

           

          Also would help to know what have you tried?  Is this all brand new code or is it adapted from some other code base?

           

          If other code base, do they have a simple test program, that maybe just clears the screen and if color maybe fills screen with different colors?

           

          Is nothing being displayed or is the program hanging?  May want to add some debug outputs to see where the code goes.

           

          For example maybe you are calling the flush the input queue function, which calls read on the input stream and your code is assuming that the read is non blocking, but maybe the stream is blocking and as such you just hang there...

           

          Again sorry I can not help more.

           

          Good luck

          • 2. Re: C++ library of touch display (4D systems) for edison
            Intel Corporation
            This message was posted on behalf of Intel Corporation

            Hi Guimficus,

            As Kurt said, could you provide us more information regarding to your library, project, environment, sources and others? Let us know if you have been able to work on this and the outcome of it.

            Regads,
            Charlie
             

            • 3. Re: C++ library of touch display (4D systems) for edison
              Guimficus

              Hello Guys, sorry for my absence.

               

              The display I have is the uLCD 35-DT for 4D Systems. I controlled it by the serial communication using 5 wires (+5V, RX, TX, GND, RESET). With this touch screen, there are 4 maners to provide the objects and informations you want to display. I choose the Visie-Genie which I have to drag and drop the pre-coded objects and layout the screen as required. Il is similar to a visual development environment.

              Before I was using the Arduino card with his environment of programmation. But, in fact of lack of ressources and dimensions, I changed to the edison module and also the IDE to able to use the MRAA library. But I did not want to change the display. So I was looking for another library in C++ to control the display with Eclipse C++, but I did not find. I decided to adapt to my case, the library (for Arduino IDE) writen by the 4D system members. But I can just display the first window with is displayed by default when the screen is power supplied.This is an example on Arduino where some strings is displayed:


              /**********************************************************************************

              * Write String Test - Demo application

              * This demo simply illustrates the various ways you can now send data to a String

              * object in ViSi-Genie, from an Arduino.

              *

              * Demo uses Hardware Serial0 to communicate with the 4D Systems display module.

              * Simply create a Workshop4 Genie application for your 4D Systems display module,

              * and place a 'Strings' object on the display, and download it to your module.

              *

              * PLEASE NOTE: If you are using a non-AVR Arduino, such as a Due, or other variants

              * such as a Chipkit or Teensy, then you will need to comment out the Flash String

              * line below - Line 60, as it will prevent the demo from compiling.

              */

               

              #include <genieArduino.h>

               

              Genie genie;

               

              #define RESETLINE 4  // Change this if you are not using an Arduino Adaptor Shield Version 2 (see code below)

               

              // Setup function

              void setup()

              {

                // NOTE, the genieBegin function (e.g. genieBegin(GENIE_SERIAL_0, 115200)) no longer exists. 

                // Use a Serial Begin and serial port of your choice in your code and use the genie.Begin function to send

                // it to the Genie library (see this example below)

                // max of 200K Baud is good for most Arduinos. Galileo should use 115200 or below. 

                Serial.begin(9600);  // Serial0 @ 9600 Baud

                genie.Begin(Serial);   // Use Serial0 for talking to the Genie Library, and to the 4D Systems display

               

                // Reset the Display (change D4 to D2 if you have original 4D Arduino Adaptor)

                // THIS IS IMPORTANT AND CAN PREVENT OUT OF SYNC ISSUES, SLOW SPEED RESPONSE ETC

                // If NOT using a 4D Arduino Adaptor, digitalWrites must be reversed as Display Reset is Active Low, and

                // the 4D Arduino Adaptors invert this signal so must be Active High. 

                pinMode(RESETLINE, OUTPUT);  // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset)

                digitalWrite(RESETLINE, 1);  // Reset the Display via D4

                delay(100);

                digitalWrite(RESETLINE, 0);  // unReset the Display via D4

               

                delay (3500); //let the display start up after the reset (This is important)

              }

               

              // Main loop

              void loop()

              {

                //An optional third parameter specifies the base (format) to use; permitted values are BIN (binary, or base 2), OCT (octal, or base 8), DEC (decimal, or base 10), HEX (hexadecimal, or base 16).

                //For floating point numbers, this parameter specifies the number of decimal places to use.

                int x = -78;

                long y = 171;

                double z = 175.3456;

                int digits = 3;

                String Str = "This is string class";

                genie.WriteStr(0, "TEST");

                delay(1000);

                genie.WriteStr(0, z, digits); //3 decimal places

                delay(1000);

                genie.WriteStr(0, 123.45678, 5); // 5 decimal places

                delay(1000);

                genie.WriteStr(0, 123.45678); // 2 decimal places by default if no value is given to decimal place.

                delay(1000);

                genie.WriteStr(0, F("This string will be \n stored in flash memory")); // For AVR Arduinos only - Needs to be commented out for Due, Chipkit, Teensy etc.

                delay(1000);

                genie.WriteStr(0, "                                                        "); // Clear

                delay(10);

                genie.WriteStr(0, x); //prints negative integer

                delay(1000);

                genie.WriteStr(0, y);

                delay(1000);

                genie.WriteStr(0, -x, BIN); //base 2 of 78

                delay(1000);

                genie.WriteStr(0, y,16); //base 16

                delay(1000);

                genie.WriteStr(0, 10); //base 10 by default

                delay(1000);

                genie.WriteStr(0, 10,8); //base 8

                delay(1000);

                genie.WriteStr(0, Str); //prints String Class

                delay(1000);

                unsigned int zc = 123 ;

                genie.WriteStr(0, zc); //prints unsigned ints

                delay(1000);

                unsigned long e = 1234 ;

                genie.WriteStr(0, e); //prints unsigned long

                delay(1000);

              }

              For more examples you can look on the page: GitHub - 4dsystems/ViSi-Genie-Arduino-Library: ViSi-Genie - Arduino Library

              I think that my problem is coming on the setup of serial communication but I could be wrong. Tell me what you thing and if you have some ideas please.

               

              • 4. Re: C++ library of touch display (4D systems) for edison
                Guimficus

                This is a picture of my installation with the first window displayed by defauft when the screen is power supplied.

                IMG_20160509_111812.jpg

                • 5. Re: C++ library of touch display (4D systems) for edison
                  KurtE

                  Again I don't have any of the hardware to hook this up... As I mentioned my Edison Arduino board smoked...

                   

                  Again I would probably scatter some debug prints in key points in the code...   I would also hook up logic Analyzer to see what is being output to the UART and if anything is coming back and the state of the reset line... (But that is cheating :lol: -  I always keep a Saleae Logic analyzer handy for things like this ).

                   

                  Have you tried running this using the debugger with Eclipse?

                   

                  Like set a breakpoint at Main,  do you hit this breakpoint?

                  Set a breakpoint after your call to SetupGenie.  Did you hit this one?  ... Can probably also try debug step functions to see if the code is being executed or are you hanging somewhere.

                   

                  Good Luck

                   

                  Edit: Forgot to mention that MRAA with Uart has changed a lot since I last looked.  Back then it was more or less an empty class.   So I mostly did stuff using termios code.

                  If you are getting a hang, one of the things I would look at trying in your init code is to make sure the uart is not set to blocking...

                  SetNonBlocking(bool nonblock); 

                  • 6. Re: C++ library of touch display (4D systems) for edison
                    Guimficus

                    Hello KurtE, thks for reply.

                     

                    What you advice me is exactly what I intended to do when I will receive my order of the Logic analyzer. I don't have it for the moment.