I'm trying to write the following function,
#define CW 0
#define CCW 1
typedef struct
{
uint8_t dir;
uint8_t sr;
uint8_t pwml;
uint8_t en;
uint8_t state;
uint8_t runstate;
uint8_t endstop_status;
} Motor_Params;
Motor_Params Motor_M1;
Motor_Params Motor_M2;
Motor_Params Motor_M3;
Motor_Params Motor_M4;
void Home_Motor(Motor_Params *motor, uint8_t dir)
{
if (dir == CCW)
{
// Start moving motor towards the endstop.
while (motor->endstop_status != 1)
{
if (motor == Motor_M1)
Start_M1_CCW();
else if (motor == Motor_M2)
Start_M2_CCW();
else if (motor == Motor_M3)
Start_M3_CCW();
else if (motor == Motor_M4)
Start_M4_5_CCW();
}
}
}
I'm trying to compare Motor_Params *motor
to its instance declaration that way I can use this fn for multiple motors. When I try compiling this, I get,
error: invalid operands to binary == (have 'Motor_Params *' and 'Motor_Params')
if (motor == Motor_M1)
How do I compare Motor_Params *motor
to any of its instance declarations?
Read more here: https://stackoverflow.com/questions/66279122/compare-function-argument-of-typedef-struct-with-its-instance-declaration-in-c
Content Attribution
This content was originally published by electrophile at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.