Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __MSLSA_H__
00013 #define __MSLSA_H__
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #pragma systemFile
00035
00036 #ifndef __COMMON_H__
00037 #include "common.h"
00038 #endif
00039
00040 #define MSLSA_I2C_ADDR 0x14
00041 #define MSLSA_CMD_REG 0x41
00042
00043 #define MSLSA_CALIBRATED 0x42
00044 #define MSLSA_WHITE_LIMIT 0x4A
00045 #define MSLSA_BLACK LIMIT 0x52
00046 #define MSLSA_WHITE_CALIB_DATA 0x5A
00047 #define MSLSA_BLACK_CALIB_DATA 0x62
00048 #define MSLSA_UNCALIBRATED 0x6A
00049
00050 #define MSLSA_CMD_FREQ_US 'A'
00051 #define MSLSA_CMD_CALIB_BLACK 'B'
00052 #define MSLSA_CMD_POWERDOWN 'D'
00053 #define MSLSA_CMD_FREQ_EU 'E'
00054 #define MSLSA_CMD_POWERUP 'P'
00055 #define MSLSA_CMD_FREQ_UNI 'U'
00056 #define MSLDA_CMD_CALIB_WHITE 'W'
00057
00058 tByteArray MSLSA_I2CRequest;
00059 tByteArray MSLSA_I2CReply;
00060
00061 #define MSLSAwakeUp(X) _MSLSAsendCommand(X, MSLSA_CMD_POWERUP)
00062 #define MSLSASleep(X) _MSLSAsendCommand(X, MSLSA_CMD_POWERDOWN)
00063 #define MSLSAcalWhite(X) _MSLSAsendCommand(X, MSLDA_CMD_CALIB_WHITE)
00064 #define MSLSAcalBlack(X) _MSLSAsendCommand(X, MSLSA_CMD_CALIB_BLACK)
00065 #define MSLSAsetEU(X) _MSLSAsendCommand(X, MSLSA_CMD_FREQ_EU)
00066 #define MSLSAsetUS(X) _MSLSAsendCommand(X, MSLSA_CMD_FREQ_US)
00067 #define MSLSAsetUni(X) _MSLSAsendCommand(X, MSLSA_CMD_FREQ_UNI)
00068
00069
00070 bool MSLSAreadSensors(tSensors link, ubyte *values);
00071 bool MSLSAreadRawSensors(tSensors link, int *values);
00072 bool _MSLSAsendCommand(tSensors link, ubyte cmd);
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091 bool _MSLSAsendCommand(tSensors link, ubyte cmd) {
00092 MSLSA_I2CRequest[0] = 3;
00093 MSLSA_I2CRequest[1] = MSLSA_I2C_ADDR;
00094 MSLSA_I2CRequest[2] = MSLSA_CMD_REG;
00095 MSLSA_I2CRequest[3] = cmd;
00096
00097 return writeI2C(link, MSLSA_I2CRequest);
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107 bool MSLSAreadSensors(tSensors link, ubyte *values)
00108 {
00109 MSLSA_I2CRequest[0] = 2;
00110 MSLSA_I2CRequest[1] = MSLSA_I2C_ADDR;
00111 MSLSA_I2CRequest[2] = MSLSA_CALIBRATED;
00112
00113 if (!writeI2C(link, MSLSA_I2CRequest, MSLSA_I2CReply, 8))
00114 return false;
00115
00116
00117 memset(values, 0, sizeof(values));
00118
00119
00120 memcpy(values, MSLSA_I2CReply, 8);
00121
00122 return true;
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132 bool MSLSAreadRawSensors(tSensors link, int *values)
00133 {
00134 MSLSA_I2CRequest[0] = 2;
00135 MSLSA_I2CRequest[1] = MSLSA_I2C_ADDR;
00136 MSLSA_I2CRequest[2] = MSLSA_UNCALIBRATED;
00137
00138 if (!writeI2C(link, MSLSA_I2CRequest, MSLSA_I2CReply, 16))
00139 return false;
00140
00141
00142 memset(values, 0, sizeof(values));
00143
00144 for (int i = 0; i < 8; i++)
00145 {
00146 values[i] = MSLSA_I2CReply[i * 2] + (MSLSA_I2CReply[(i * 2) + 1] << 8);
00147 }
00148
00149
00150 memcpy(values, MSLSA_I2CReply, 8);
00151
00152 return true;
00153 }
00154
00155 #endif // __MSLSA_H__
00156
00157
00158
00159
00160
00161