00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #pragma systemFile
00033
00034 #ifndef __MSPFM_H__
00035 #define __MSPFM_H__
00036
00037 #ifndef __COMMON_H__
00038 #include "common.h"
00039 #endif
00040
00041 #define MSPFM_I2C_ADDR 0x48
00042 #define MSPFM_CMD 0x41
00043 #define MSPFM_IRCHAN 0x42
00044 #define MSPFM_MSELECT 0x43
00045 #define MSPFM_MOTOPA 0x44
00046 #define MSPFM_MOTSPA 0x45
00047 #define MSPFM_MOTOPB 0x46
00048 #define MSPFM_MOTSPB 0x47
00049
00050 #define MSPFM_GOCMD 0x47
00051
00052 #define MSPFM_MOTORAB 0x00
00053 #define MSPFM_MOTORA 0x01
00054 #define MSPFM_MOTORB 0x02
00055
00056 #define MSPFM_FLOAT 0x00
00057 #define MSPFM_FORWARD 0x01
00058 #define MSPFM_REVERSE 0x02
00059 #define MSPFM_BRAKE 0x03
00060 #define MSPFM_NOOP 0x0F
00061
00062
00063 bool MSPFMcontrolMotorA(tSensors link, byte chan, byte motor_op, byte motor_speed, ubyte address = MSPFM_I2C_ADDR);
00064 bool MSPFMcontrolMotorB(tSensors link, byte chan, byte motor_op, byte motor_speed, ubyte address = MSPFM_I2C_ADDR);
00065 bool MSPFMcontrolMotorAB(tSensors link, byte chan, byte motorA_op, byte motorA_speed, byte motorB_op, byte motorB_speed, ubyte address = MSPFM_I2C_ADDR);
00066
00067
00068 tByteArray MSPFM_I2CRequest;
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 bool MSPFMcontrolMotorA(tSensors link, byte chan, byte motor_op, byte motor_speed, ubyte address) {
00082 return MSPFMcontrolMotorAB(link, chan, motor_op, motor_speed, MSPFM_NOOP, 0);
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 bool MSPFMcontrolMotorB(tSensors link, byte chan, byte motor_op, byte motor_speed, ubyte address) {
00097 return MSPFMcontrolMotorAB(link, chan, MSPFM_NOOP, 0, motor_op, motor_speed);
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 bool MSPFMcontrolMotorAB(tSensors link, byte chan, byte motorA_op, byte motorA_speed, byte motorB_op, byte motorB_speed, ubyte address) {
00114 byte mselect = MSPFM_MOTORAB;
00115
00116 if (motorA_op == MSPFM_NOOP)
00117 mselect = MSPFM_MOTORB;
00118 else if (motorB_op == MSPFM_NOOP)
00119 mselect = MSPFM_MOTORA;
00120
00121 memset(MSPFM_I2CRequest, 0, sizeof(tByteArray));
00122 MSPFM_I2CRequest[0] = 8;
00123 MSPFM_I2CRequest[1] = address;
00124 MSPFM_I2CRequest[2] = MSPFM_IRCHAN;
00125 MSPFM_I2CRequest[3] = chan;
00126 MSPFM_I2CRequest[4] = mselect;
00127 MSPFM_I2CRequest[5] = motorA_op;
00128 MSPFM_I2CRequest[6] = motorA_speed;
00129 MSPFM_I2CRequest[7] = motorB_op;
00130 MSPFM_I2CRequest[8] = motorB_speed;
00131
00132 if (!writeI2C(link, MSPFM_I2CRequest, 0))
00133 return false;
00134
00135 MSPFM_I2CRequest[0] = 3;
00136 MSPFM_I2CRequest[1] = address;
00137 MSPFM_I2CRequest[2] = MSPFM_CMD;
00138 MSPFM_I2CRequest[3] = MSPFM_GOCMD;
00139
00140 return writeI2C(link, MSPFM_I2CRequest, 0);
00141 }
00142
00143
00144 #endif // __MSPFM_H__
00145
00146
00147
00148
00149
00150