Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __MSSMUX_H__
00013 #define __MSSMUX_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #pragma systemFile
00037
00038 #ifndef __COMMON_H__
00039 #include "common.h"
00040 #endif
00041
00042 #define MSMX_I2C_ADDR 0x24
00043 #define MSMX_REG_CHANSEL 0x42
00044 #define MSMX_REG_VOLTAGE 0x43
00045
00046
00047 tByteArray MSMX_I2CRequest;
00048 tByteArray MSMX_I2CReply;
00049
00050 void MSSMUXsetChan(tSensors link, int channel);
00051 int MSSMUXreadBattery(tSensors link);
00052
00053
00054
00055
00056
00057
00058
00059 int MSSMUXreadBattery(tSensors link)
00060 {
00061 TSensorTypes previous = SensorType[link];
00062 SensorType[link] = sensorI2CCustomFastSkipStates;
00063
00064
00065 MSSMUXsetChan(link, 0);
00066 wait1Msec(50);
00067
00068 memset(MSMX_I2CRequest, 0, sizeof(tByteArray));
00069
00070 MSMX_I2CRequest[0] = 2;
00071 MSMX_I2CRequest[1] = MSMX_I2C_ADDR;
00072 MSMX_I2CRequest[2] = MSMX_REG_VOLTAGE;
00073
00074 if (!writeI2C(link, MSMX_I2CRequest, MSMX_I2CReply, 1))
00075 {
00076 writeDebugStreamLine("error with i2c");
00077 return false;
00078 }
00079
00080 SensorType[link] = previous;
00081
00082 return (0x00FF & MSMX_I2CReply[0]) * 37;
00083 }
00084
00085
00086
00087
00088
00089
00090 void MSSMUXsetChan(tSensors link, int channel)
00091 {
00092 static int currChannel[4] = {-1, -1, -1, -1};
00093
00094
00095 ubyte MUXmsg[] = {0x55, 0xAA, 0x30 + (channel & 0xFF)};
00096
00097
00098 if (currChannel[link] == channel)
00099 return;
00100
00101 currChannel[link] = channel;
00102
00103 TSensorTypes previous = SensorType[link];
00104 writeDebugStreamLine("channel type: %d", previous);
00105
00106
00107
00108 SensorType[link] = sensorCustom;
00109
00110
00111
00112 switch (previous)
00113 {
00114 case sensorCOLORFULL:
00115 case sensorCOLORRED:
00116 case sensorCOLORGREEN:
00117 case sensorCOLORBLUE:
00118 case sensorCOLORNONE: wait1Msec(12); break;
00119 }
00120
00121
00122 DigitalPinDirection[link] = 0x03;
00123 wait1Msec(1);
00124
00125 for (int i = 0; i < 3; i++)
00126 {
00127 DigitalPinValue[link] = 0x00;
00128 wait1Msec(1);
00129
00130 for (int j = 0; j < 8; j++) {
00131 if ((MUXmsg[i] >> j) & 0x01)
00132 DigitalPinValue[link] = 0x00;
00133 else
00134 DigitalPinValue[link] = 0x01;
00135 wait1Msec(1);
00136 }
00137 DigitalPinValue[link] = 0x01;
00138 wait1Msec(1);
00139 }
00140 }
00141
00142 #endif // __MSSMUX_H__
00143
00144
00145
00146
00147
00148