From ed1725c392af32e865641b4e90f803703d9e008f Mon Sep 17 00:00:00 2001 From: Mats van Reenen Date: Tue, 2 Jun 2020 09:46:46 +0200 Subject: [PATCH] add enum for motor selection --- motionController.c | 18 ++++++------------ motionController.h | 4 +++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/motionController.c b/motionController.c index fbfcad9..9b2ae05 100644 --- a/motionController.c +++ b/motionController.c @@ -172,21 +172,15 @@ void MCInit(){ 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) v |= 0x0800; // set signed bit else v &= ~0x0800; // remove signed bit v &= 0x0FFF; // contraint to 12 bits - switch (m){ - case 1: - MC_write(MC_VTar1, v); - break; - case 2: - MC_write(MC_VTar2, v); - break; - case 3: - MC_write(MC_VTar3, v); - break; - } + + MC_write(addr, v); } diff --git a/motionController.h b/motionController.h index efaeb20..c391c14 100644 --- a/motionController.h +++ b/motionController.h @@ -8,7 +8,9 @@ #ifndef MOTIONCONTROLLER_H_ #define MOTIONCONTROLLER_H_ +typedef enum MC_motor {MC_MotorR=0x00, MC_MotorL=0x20}; + void MCInit(); -void MCSetV(uchar m, int v); +void MCSetV(enum MC_motor m, int v); #endif /* MOTIONCONTROLLER_H_ */