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
00062 MSSMUXsetChan(link, 0);
00063 wait1Msec(50);
00064
00065 SensorType[link] = sensorI2CCustomFastSkipStates;
00066 memset(MSMX_I2CRequest, 0, sizeof(tByteArray));
00067
00068 MSMX_I2CRequest[0] = 2;
00069 MSMX_I2CRequest[1] = MSMX_I2C_ADDR;
00070 MSMX_I2CRequest[2] = MSMX_REG_VOLTAGE;
00071
00072 if (!writeI2C(link, MSMX_I2CRequest, MSMX_I2CReply, 1))
00073 {
00074 writeDebugStreamLine("error with i2c");
00075 return false;
00076 }
00077
00078 return (0x00FF & MSMX_I2CReply[0]) * 37;
00079 }
00080
00081
00082
00083
00084
00085
00086 void MSSMUXsetChan(tSensors link, int channel)
00087 {
00088 static int currChannel[4] = {-1, -1, -1, -1};
00089
00090
00091 ubyte MUXmsg[] = {0x55, 0xAA, 0x30 + (channel & 0xFF)};
00092
00093
00094 if (currChannel[link] == channel)
00095 return;
00096
00097 currChannel[link] = channel;
00098
00099 TSensorTypes previous = SensorType[link];
00100 writeDebugStreamLine("channel type: %d", previous);
00101
00102
00103
00104 SensorType[link] = sensorCustom;
00105
00106
00107
00108 switch (previous)
00109 {
00110 case sensorCOLORFULL:
00111 case sensorCOLORRED:
00112 case sensorCOLORGREEN:
00113 case sensorCOLORBLUE:
00114 case sensorCOLORNONE: wait1Msec(12); break;
00115 }
00116
00117
00118 DigitalPinDirection[link] = 0x03;
00119 wait1Msec(1);
00120
00121 for (int i = 0; i < 3; i++)
00122 {
00123 DigitalPinValue[link] = 0x00;
00124 wait1Msec(1);
00125
00126 for (int j = 0; j < 8; j++) {
00127 if ((MUXmsg[i] >> j) & 0x01)
00128 DigitalPinValue[link] = 0x00;
00129 else
00130 DigitalPinValue[link] = 0x01;
00131 wait1Msec(1);
00132 }
00133 DigitalPinValue[link] = 0x01;
00134 wait1Msec(1);
00135 }
00136 }
00137
00138 #endif // __MSSMUX_H__
00139
00140
00141
00142
00143
00144