How do I start the values as in the example C++ code?
struct Gains{ uint8_t totalGain = FORCE_FEEDBACK_MAXGAIN; uint8_t constantGain = FORCE_FEEDBACK_MAXGAIN; uint8_t rampGain = FORCE_FEEDBACK_MAXGAIN; uint8_t squareGain = FORCE_FEEDBACK_MAXGAIN; uint8_t sineGain = FORCE_FEEDBACK_MAXGAIN; uint8_t triangleGain = FORCE_FEEDBACK_MAXGAIN; uint8_t sawtoothdownGain = FORCE_FEEDBACK_MAXGAIN; uint8_t sawtoothupGain = FORCE_FEEDBACK_MAXGAIN; uint8_t springGain = FORCE_FEEDBACK_MAXGAIN; uint8_t damperGain = FORCE_FEEDBACK_MAXGAIN; uint8_t inertiaGain = FORCE_FEEDBACK_MAXGAIN; uint8_t frictionGain = FORCE_FEEDBACK_MAXGAIN; uint8_t customGain = FORCE_FEEDBACK_MAXGAIN; }; struct EffectParams{ int32_t springMaxPosition = 0; int32_t springPosition = 0; int32_t damperMaxVelocity = 0; int32_t damperVelocity = 0; int32_t inertiaMaxAcceleration = 0; int32_t inertiaAcceleration = 0; int32_t frictionMaxPositionChange = 0; int32_t frictionPositionChange = 0; }; //force feedback gain struct Gains* m_gains; //force feedback effect params struct EffectParams* m_effect_params;
> struct EffectParams* m_effect_params;
Note that that line declares a pointer, not the structure itself, so it doesn't initialize anything. malloc() won't either, but C++'s "new" might?
This comes close. sort of:
struct Gains{ uint8_t totalGain; uint8_t constantGain; uint8_t rampGain ; uint8_t squareGain; uint8_t sineGain ; uint8_t triangleGain; uint8_t sawtoothdownGain; uint8_t sawtoothupGain; uint8_t springGain; uint8_t damperGain; uint8_t inertiaGain; uint8_t frictionGain; uint8_t customGain;};#define Gains_inited(x) struct Gains x = { \ .totalGain = FORCE_FEEDBACK_MAXGAIN, \ .constantGain = FORCE_FEEDBACK_MAXGAIN, \ .rampGain = FORCE_FEEDBACK_MAXGAIN, \ .squareGain = FORCE_FEEDBACK_MAXGAIN, \ .sineGain = FORCE_FEEDBACK_MAXGAIN, \ .triangleGain = FORCE_FEEDBACK_MAXGAIN, \ .sawtoothdownGain = FORCE_FEEDBACK_MAXGAIN, \ .sawtoothupGain = FORCE_FEEDBACK_MAXGAIN, \ .springGain = FORCE_FEEDBACK_MAXGAIN, \ .damperGain = FORCE_FEEDBACK_MAXGAIN, \ .inertiaGain = FORCE_FEEDBACK_MAXGAIN, \ .frictionGain = FORCE_FEEDBACK_MAXGAIN, \ .customGain = FORCE_FEEDBACK_MAXGAIN, \ }Gains_inited(*m_gains);
struct Gains{
uint8_t totalGain;
uint8_t constantGain;
uint8_t rampGain ;
uint8_t squareGain;
uint8_t sineGain ;
uint8_t triangleGain;
uint8_t sawtoothdownGain;
uint8_t sawtoothupGain;
uint8_t springGain;
uint8_t damperGain;
uint8_t inertiaGain;
uint8_t frictionGain;
uint8_t customGain;
};
#define Gains_inited(x) struct Gains x = { \
.totalGain = FORCE_FEEDBACK_MAXGAIN, \
.constantGain = FORCE_FEEDBACK_MAXGAIN, \
.rampGain = FORCE_FEEDBACK_MAXGAIN, \
.squareGain = FORCE_FEEDBACK_MAXGAIN, \
.sineGain = FORCE_FEEDBACK_MAXGAIN, \
.triangleGain = FORCE_FEEDBACK_MAXGAIN, \
.sawtoothdownGain = FORCE_FEEDBACK_MAXGAIN, \
.sawtoothupGain = FORCE_FEEDBACK_MAXGAIN, \
.springGain = FORCE_FEEDBACK_MAXGAIN, \
.damperGain = FORCE_FEEDBACK_MAXGAIN, \
.inertiaGain = FORCE_FEEDBACK_MAXGAIN, \
.frictionGain = FORCE_FEEDBACK_MAXGAIN, \
.customGain = FORCE_FEEDBACK_MAXGAIN, \
}
Gains_inited(*m_gains);