Announcement

Collapse
No announcement yet.

'hFont1' Was not Declared in this scope

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 'hFont1' Was not Declared in this scope

    New issue,

    I'm using a 4duino, and writing an updating variable to a text string on the display. This works fine with the default 4D Font3.

    If I click the 'strings' option in the right hand properties panel and change the font type to say, 'Arial' or 'Calibri', then I get a compile fail of 'hFont1' Was not Declared in this scope.

    Code related to the text string, as below...

    Code:
    Display.gfx_RectangleFilled(24, 216, 213, 271, BLACK);
      Display.txt_FontID(hFont1) ; // Font index correct at time of code generation... This is Selecting 'Arial', size 24.
      Display.txt_FGcolour(LIME) ;
      Display.txt_BGcolour(BLACK) ;
      Display.gfx_MoveTo(24 , 216) ;
      Display.putstr(strBuff) ;
    Can you please let me know what include file I should be putting where!?

    I can't seem to find a clear instruction for this in any of the application notes...

    My current includes are:

    Code:
    %%Display%%.Form1 ;  // Form1
    // Define LOG_MESSAGES to a serial port to send SPE errors messages to. Do not use the same Serial port as SPE
    //#define LOG_MESSAGES Serial
    
    %%Display%%.DefineResetLine ;      // *Replaced* at compile time with define for reset line connected to the display
    %%Display%%.DefineDisplaySerialx ; // *Replaced* at compile time with define the Serial Port connected to the display
    
    #include "_4Duino_Graphic_InterfaceConst.h"
    
    %%Display%%.IncludeSerial_4DLib ;          // *Replaced* at compile time with an Include the Serial Library relevant to the display
    #include "%%Display%%.Processor_PrintDisk.h"
    %%Display%%.IncludeSerial_Const4D ;        // *Replaced* at compile time with an Include the Constants file relevant to the display
    
    %%Display%%.AssignDisplaySerialtoLibrary ; // *Replaced* at compile time with an Assign of the correct Serial port to the correct library
    #include "%%Display%%.Processor_LedDigitsDisplay.h"
    I am no doubt missing one somewhere.

    Please advise?

    Thank you!

  • #2
    You must declare hFont1 as a word variable. You can try this tested Code

    // Define LOG_MESSAGES to a serial port to send SPE errors messages to. Do not use the same Serial port as SPE
    //#define LOG_MESSAGES Serial

    %%Display%%.DefineResetLine ; // *Replaced* at compile time with define for reset line connected to the display
    %%Display%%.DefineDisplaySerialx ; // *Replaced* at compile time with define the Serial Port connected to the display

    #include "FonttestConst.h"

    %%Display%%.IncludeSerial_4DLib ; // *Replaced* at compile time with an Include the Serial Library relevant to the display
    #include "%%Display%%.Processor_PrintDisk.h"
    %%Display%%.IncludeSerial_Const4D ; // *Replaced* at compile time with an Include the Constants file relevant to the display

    %%Display%%.AssignDisplaySerialtoLibrary ; // *Replaced* at compile time with an Assign of the correct Serial port to the correct library

    // Uncomment to use ESP8266
    //#define ESPRESET 17
    //#include <SoftwareSerial.h>
    //#define ESPserial SerialS
    //SoftwareSerial SerialS(8, 9) ;
    // Uncomment next 2 lines to use ESP8266 with ESP8266 library from https://github.com/itead/ITEADLIB_Arduino_WeeESP8266
    //#include "ESP8266.h"
    //ESP8266 wifi(SerialS,19200);

    // routine to handle Serial errors
    void mycallback(int ErrCode, unsigned char Errorbyte)
    {
    #ifdef LOG_MESSAGES
    const char *Error4DText[] = {"OK\0", "Timeout\0", "NAK\0", "Length\0", "Invalid\0"} ;
    LOG_MESSAGES.print(F("Serial 4D Library reports error ")) ;
    LOG_MESSAGES.print(Error4DText[ErrCode]) ;
    if (ErrCode == Err4D_NAK)
    {
    LOG_MESSAGES.print(F(" returned data= ")) ;
    LOG_MESSAGES.println(Errorbyte) ;
    }
    else
    LOG_MESSAGES.println(F("")) ;
    while (1) ; // you can return here, or you can loop
    #else
    // Pin 13 has an LED connected on most Arduino boards. Just give it a name
    #define led 13
    while (1)
    {
    digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
    delay(200); // wait for a second
    digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
    delay(200); // wait for a second
    }
    #endif
    }
    // end of routine to handle Serial errors

    word hndl ;
    word hFont1;
    int hstrings;

    void setup()
    {
    // Ucomment to use the Serial link to the PC for debugging
    // Serial.begin(115200) ; // serial to USB port
    // Note! The next statement will stop the sketch from running until the serial monitor is started
    // If it is not present the monitor will be missing the initial writes
    // while (!Serial) ; // wait for serial to be established

    pinMode(RESETLINE, OUTPUT); // Display reset pin
    %%Display%%.Toggle_Reset_On ; // *Replaced* at compile time with correct rest on logic for the attached display
    delay(100); // wait for it to be recognised
    %%Display%%.Toggle_Reset_Off ; // *Replaced* at compile time with correct rest off logic for the attached display
    // Uncomment when using ESP8266
    // pinMode(ESPRESET, OUTPUT); // ESP reset pin
    // digitalWrite(ESPRESET, 1); // Reset ESP
    // delay(100); // wait for it t
    // digitalWrite(ESPRESET, 0); // Release ESP reset
    delay(3000) ; // give display time to startup

    // now start display as Serial lines should have 'stabilised'
    %%Display%%.DisplaySerial.Begin_Speed ; // *Replaced* at compile time with command to start the serial port at the correct speed
    Display.TimeLimit4D = 5000 ; // 5 second timeout on all commands
    Display.Callback4D = mycallback ;

    // uncomment if using ESP8266
    // ESPserial.begin(115200) ; // assume esp set to 115200 baud, it's default setting
    // what we need to do is attempt to flip it to 19200
    // the maximum baud rate at which software serial actually works
    // if we run a program without resetting the ESP it will already be 19200
    // and hence the next command will not be understood or executed
    // ESPserial.println("AT+UART_CUR=19200,8,1,0,0\r\n") ;
    // ESPserial.end() ;
    // delay(10) ; // Necessary to allow for baud rate changes
    // ESPserial.begin(19200) ; // start again at a resonable baud rate
    Display.gfx_ScreenMode(PORTRAIT) ; // change manually if orientation change
    Display.putstr("Mounting...\n");
    if (!(Display.file_Mount()))
    {
    while(!(Display.file_Mount()))
    {
    Display.putstr("Drive not mounted...");
    delay(200);
    Display.gfx_Cls();
    delay(200);
    }
    }
    hFont1 = Display.file_LoadImageControl("Fonttest.da1", "Fonttest.gc1", 1); // Open handle to access uSD fonts, uncomment if required and change nn to font number
    hstrings = Display.file_Open("Fonttest.txf", 'r') ; // Open handle to access uSD strings, uncomment if required
    hndl = Display.file_LoadImageControl("Fonttest.dat", "Fonttest.gci", 1);
    // put your setup code here, to run once:
    } // end Setup **do not alter, remove or duplicate this line**

    void loop()
    {

    Display.gfx_RectangleFilled(32, 44, 211, 99, BLACK);
    Display.txt_FontID(hFont1) ; // Font index correct at time of code generation
    Display.txt_FGcolour(WHITE) ;
    Display.txt_BGcolour(BLACK) ;
    Display.gfx_MoveTo(32 , 44) ;

    Display.putstr("TEST");

    }

    Best regards,

    Comment

    Working...
    X