C/C++ Question How to use a structure

janderkan

Well-Known Member
Licensed User
Longtime User
In RH_RF95.h is this struct
B4X:
    typedef struct {
        uint8_t    reg_1d;   ///< Value for register RH_RF95_REG_1D_MODEM_CONFIG1
        uint8_t    reg_1e;   ///< Value for register RH_RF95_REG_1E_MODEM_CONFIG2
        uint8_t    reg_26;   ///< Value for register RH_RF95_REG_26_MODEM_CONFIG3
    } ModemConfig;
and this function
B4X:
    void setModemRegisters(const ModemConfig* config);

I have tried with this wrap
B4X:
    void RF95::SetModemRegisters(byte Reg_1D, byte Reg_1E, Byte Reg26) {
        const RH_RF95->ModemConfig mc;
        mc.reg_1d = Reg_1D;
        mc.reg_1e = Reg_1D;
        mc.reg_26 = Reg26;
        rf95->setModemRegisters(mc);
    }
but I cannot figure out how to do it.
 

janderkan

Well-Known Member
Licensed User
Longtime User
It always help if you go to bed, next morning everything is easier.

B4X:
void RF95::SetModemRegisters(byte Reg_1D, byte Reg_1E, Byte Reg26) {
        RH_RF95::ModemConfig mc;
        mc.reg_1d = Reg_1D;
        mc.reg_1e = Reg_1E;
        mc.reg_26 = Reg26;
        rf95->setModemRegisters(&mc);
    }

There was 3 errors.
To reference a typedef struct, use the ::
Error when cut and paste
The function needs a pointer to the config &mc
 
Top