add enum for motor selection

This commit is contained in:
Mats van Reenen 2020-06-02 09:46:46 +02:00
parent a57832829f
commit ed1725c392
2 changed files with 9 additions and 13 deletions

View File

@ -172,21 +172,15 @@ void MCInit(){
MC_read(MC_AMax1); MC_read(MC_AMax1);
} }
void MCSetV(uchar m, int v){ void MCSetV(enum MC_motor m, int v){
uchar addr = MC_VTar1 | m;
// shorten the int
if(v < 0) if(v < 0)
v |= 0x0800; // set signed bit v |= 0x0800; // set signed bit
else else
v &= ~0x0800; // remove signed bit v &= ~0x0800; // remove signed bit
v &= 0x0FFF; // contraint to 12 bits v &= 0x0FFF; // contraint to 12 bits
switch (m){
case 1: MC_write(addr, v);
MC_write(MC_VTar1, v);
break;
case 2:
MC_write(MC_VTar2, v);
break;
case 3:
MC_write(MC_VTar3, v);
break;
}
} }

View File

@ -8,7 +8,9 @@
#ifndef MOTIONCONTROLLER_H_ #ifndef MOTIONCONTROLLER_H_
#define MOTIONCONTROLLER_H_ #define MOTIONCONTROLLER_H_
typedef enum MC_motor {MC_MotorR=0x00, MC_MotorL=0x20};
void MCInit(); void MCInit();
void MCSetV(uchar m, int v); void MCSetV(enum MC_motor m, int v);
#endif /* MOTIONCONTROLLER_H_ */ #endif /* MOTIONCONTROLLER_H_ */