Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Help coding: adding functionality relying on MySensors-func/library (saveState/loadState) (c++)

Help coding: adding functionality relying on MySensors-func/library (saveState/loadState) (c++)

Scheduled Pinned Locked Moved Troubleshooting
5 Posts 3 Posters 34 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    perIpI
    wrote on last edited by
    #1

    Im using the mySensors functions saveState and loadState to read/write to EEPROM. To facilitate I have written some small functions that do the casting so that I can save uint16_T/float/other by single function call. I would like to organize these functions in a separate file so that I can add this functionality easily to each project. However I struggle to get the structure correct and overcome a compiler warning.

    I have collected the functions in .h-file and .cpp-file
    Example:

    //mysEeprom.h - declaration of my help-files
    void save_uint16(uint8_t position, uint16_t value)
    //mysEeprom.cpp
    void save_uint16(uint8_t position, uint16_t value) {
        saveState(position, (uint8_t)value);
        saveState(position+1, (uint8_t)(value>>8));
    }
    
    //Project file main.cpp 
    (Radio-declaration etc.) ie #define MY_RADIO_RFM69 
    #include <mysensors.h>
    #include <mysEeprom.h>
    
    save_uint16(position, value);
    

    The compiler responds that saveState "was not declared in this scope" (the saveState is decleared inside MySensors/core/MySensorsCore.h.).

    To tell the compiler where to look for saveState I add an #include <mySensors.h>-statement:

    //In MysEeprom.h-file
    #include "mySensors.h"
    

    This time the compiler seems to believe that I want to includes "double" mySensors.h and responds with:

    .pio\libdeps\pro8MHzatmega328\MySensors/mysensors.h:426:2: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
    

    I had this message earlier when the #include <mySensors.h>-statement was positioned before #define MY_RADIO_RFM69 . Putting MY_RADIO_RFM69-statement before include <mySensors.h> solved it (ie my include-statements are put after definitions, just before declaration of global variables).

    I have also experimented organizing my eeprom-functions inside a namespace and a class, but so far have not found a working solution. Help is appreciated, how should this be done, thanks!

    1 Reply Last reply
    0
    • boumB Offline
      boumB Offline
      boum
      wrote on last edited by
      #2

      If you cannot include the whole mysensors header, you maybe can just forward declare the function. (basically, just copy the line from the mysensors.h in your mysEeprom.cpp file.

      /*extern*/ void saveState(uint8_t pos, uint8_t value);
      // extern probably not needed, that's real old C, but you I have had 
      // surprises with the arduino compiler… You might need to add it.
      

      What's the issue with namespaces or classes?

      P 1 Reply Last reply
      2
      • boumB boum

        If you cannot include the whole mysensors header, you maybe can just forward declare the function. (basically, just copy the line from the mysensors.h in your mysEeprom.cpp file.

        /*extern*/ void saveState(uint8_t pos, uint8_t value);
        // extern probably not needed, that's real old C, but you I have had 
        // surprises with the arduino compiler… You might need to add it.
        

        What's the issue with namespaces or classes?

        P Offline
        P Offline
        perIpI
        wrote on last edited by
        #3

        @boum said in Help coding: adding functionality relying on MySensors-func/library (saveState/loadState) (c++):

        /extern/

        Wonderful, that did the trick! Thank you very much!

        For namespace/class basically the problem was the same, without "mySensors.h" couldnt find saveState and with "include <mySensors.h>" I had "#error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless."

        1 Reply Last reply
        0
        • electrikE Offline
          electrikE Offline
          electrik
          wrote on last edited by
          #4

          If you want to use library functions outside the main sketch, you can also just include the core header, e.g.

          #include "core/MySensorsCore.h"
          
          P 1 Reply Last reply
          3
          • electrikE electrik

            If you want to use library functions outside the main sketch, you can also just include the core header, e.g.

            #include "core/MySensorsCore.h"
            
            P Offline
            P Offline
            perIpI
            wrote on last edited by
            #5

            @electrik

            Tested and worked as well. I think this is preferable over the first solution (forward function declaration) as it gives a reference where the functions are defined. Thank you!

            1 Reply Last reply
            2
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            9

            Online

            11.7k

            Users

            11.2k

            Topics

            113.0k

            Posts


            Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • MySensors
            • OpenHardware.io
            • Categories
            • Recent
            • Tags
            • Popular