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
00033 #pragma systemFile
00034
00035 #ifndef __MSRXMUX_H__
00036 #define __MSRXMUX_H__
00037
00038 #ifndef __COMMON_H__
00039 #include "common.h"
00040 #endif
00041
00042 #define MSRXMUX_I2C_ADDR 0x7E
00043 #define MSRXMUX_CHAN1 0xFE
00044 #define MSRXMUX_CHAN2 0xFD
00045 #define MSRXMUX_CHAN3 0xFB
00046 #define MSRXMUX_CHAN4 0xF7
00047 #define MSRXMUX_NONE 0xFF
00048
00049 tByteArray MSRXMUX_I2CRequest;
00050
00051 TSensorTypes RCXSensorTypes[4][4] = {{sensorNone, sensorNone, sensorNone, sensorNone},
00052 {sensorNone, sensorNone, sensorNone, sensorNone},
00053 {sensorNone, sensorNone, sensorNone, sensorNone},
00054 {sensorNone, sensorNone, sensorNone, sensorNone}};
00055 TSensorModes RCXSensorModes[4][4] = {{modeRaw, modeRaw, modeRaw, modeRaw},
00056 {modeRaw, modeRaw, modeRaw, modeRaw},
00057 {modeRaw, modeRaw, modeRaw, modeRaw},
00058 {modeRaw, modeRaw, modeRaw, modeRaw}};
00059 ubyte RCXSensorDelays[4][4] = {{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 void MSRXMUXsetupChan(tSensors link, ubyte chan, TSensorTypes chantype, TSensorModes chanmode, ubyte delay) {
00073 if (chan < 1 || chan > 4)
00074 return;
00075
00076 RCXSensorTypes[link][chan-1] = chantype;
00077 RCXSensorModes[link][chan-1] = chanmode;
00078 RCXSensorDelays[link][chan-1] = delay;
00079 }
00080
00081 int MSRXMUXreadChan(tSensors link, byte chan) {
00082 if (SensorType[link] != sensorI2CCustom9V) {
00083 SensorType[link] = sensorI2CCustom9V;
00084 wait1Msec(3);
00085 }
00086
00087 MSRXMUX_I2CRequest[0] = 2;
00088 MSRXMUX_I2CRequest[1] = MSRXMUX_I2C_ADDR;
00089 switch(chan) {
00090 case 0: MSRXMUX_I2CRequest[2] = MSRXMUX_NONE; break;
00091 case 1: MSRXMUX_I2CRequest[2] = MSRXMUX_CHAN1; break;
00092 case 2: MSRXMUX_I2CRequest[2] = MSRXMUX_CHAN2; break;
00093 case 3: MSRXMUX_I2CRequest[2] = MSRXMUX_CHAN3; break;
00094 case 4: MSRXMUX_I2CRequest[2] = MSRXMUX_CHAN4; break;
00095 default: MSRXMUX_I2CRequest[2] = MSRXMUX_NONE;
00096 }
00097
00098 if (!writeI2C(link, MSRXMUX_I2CRequest))
00099 return -1;
00100
00101 wait10Msec(3+RCXSensorDelays[link][chan-1]);
00102 SensorType[link] = RCXSensorTypes[link][chan-1];
00103 SensorMode[link] = RCXSensorModes[link][chan-1];
00104 return(SensorValue[link]);
00105 }
00106
00107 #endif // __MSRXMUX_H__
00108
00109
00110
00111
00112
00113