Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __DLIGHT_H__
00013 #define __DLIGHT_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
00039 #ifndef __COMMON_H__
00040 #include "common.h"
00041 #endif
00042
00043 #ifndef __COMMON_LIGHT_H__
00044 #include "drivers/common-light.h"
00045 #endif
00046
00047 #define DLIGHT_I2C_ADDR_ALL 0xE0
00048 #define DLIGHT_I2C_ADDR_1 0x04
00049 #define DLIGHT_I2C_ADDR_2 0x14
00050 #define DLIGHT_I2C_ADDR_3 0x24
00051 #define DLIGHT_I2C_ADDR_4 0x34
00052
00053 #define DLIGHT_REG_MODE1 0x80
00054 #define DLIGHT_REG_MODE2 0x81
00055 #define DLIGHT_REG_RED 0x82
00056 #define DLIGHT_REG_GREEN 0x83
00057 #define DLIGHT_REG_BLUE 0x84
00058 #define DLIGHT_REG_EXTERNAL 0x85
00059 #define DLIGHT_REG_BPCT 0x86
00060 #define DLIGHT_REG_BFREQ 0x87
00061 #define DLIGHT_REG_LEDOUT 0x88
00062
00063 #define DLIGHT_CMD_DISABLE_LEDS 0x00
00064 #define DLIGHT_CMD_DISABLE_BLINK 0xAA
00065 #define DLIGHT_CMD_ENABLE_BLINK 0xFF
00066
00067
00068 tByteArray DLIGHT_I2CRequest;
00069
00070
00071
00072
00073
00074
00075
00076 bool DLIGHTinit(tSensors link, ubyte addr){
00077 DLIGHT_I2CRequest[0] = 4;
00078 DLIGHT_I2CRequest[1] = addr;
00079 DLIGHT_I2CRequest[2] = DLIGHT_REG_MODE1;
00080 DLIGHT_I2CRequest[3] = 0x01;
00081 DLIGHT_I2CRequest[4] = 0x25;
00082
00083 if (!writeI2C(link, DLIGHT_I2CRequest))
00084 return false;
00085
00086 wait1Msec(50);
00087
00088 DLIGHT_I2CRequest[0] = 3;
00089 DLIGHT_I2CRequest[1] = addr;
00090 DLIGHT_I2CRequest[2] = DLIGHT_REG_LEDOUT;
00091 DLIGHT_I2CRequest[3] = DLIGHT_CMD_DISABLE_BLINK;
00092
00093 return writeI2C(link, DLIGHT_I2CRequest);
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 bool DLIGHTsetColor(tSensors link, ubyte addr, ubyte r, ubyte g, ubyte b){
00107 DLIGHT_I2CRequest[0] = 5;
00108 DLIGHT_I2CRequest[1] = addr;
00109 DLIGHT_I2CRequest[2] = DLIGHT_REG_RED;
00110 DLIGHT_I2CRequest[3] = r;
00111 DLIGHT_I2CRequest[4] = g;
00112 DLIGHT_I2CRequest[5] = b;
00113
00114 return writeI2C(link, DLIGHT_I2CRequest);
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 bool DLIGHTsetExternal(tSensors link, ubyte addr, ubyte external){
00126 DLIGHT_I2CRequest[0] = 3;
00127 DLIGHT_I2CRequest[1] = addr;
00128 DLIGHT_I2CRequest[2] = DLIGHT_REG_EXTERNAL;
00129 DLIGHT_I2CRequest[3] = external;
00130
00131 return writeI2C(link, DLIGHT_I2CRequest);
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 bool DLIGHTsetBlinking(tSensors link, ubyte addr, float BlinkRate, long DutyCycle){
00144 BlinkRate*= 24;
00145 BlinkRate--;
00146
00147 DLIGHT_I2CRequest[0] = 4;
00148 DLIGHT_I2CRequest[1] = addr;
00149 DLIGHT_I2CRequest[2] = DLIGHT_REG_BPCT;
00150 DLIGHT_I2CRequest[3] = (255 * DutyCycle) / 100;
00151 DLIGHT_I2CRequest[4] = round(BlinkRate);
00152 writeDebugStreamLine("rate: %d, duty: %d", DLIGHT_I2CRequest[4], DLIGHT_I2CRequest[3]);
00153 return writeI2C(link, DLIGHT_I2CRequest);
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163 bool DLIGHTstartBlinking(tSensors link, ubyte addr){
00164 DLIGHT_I2CRequest[0] = 3;
00165 DLIGHT_I2CRequest[1] = addr;
00166 DLIGHT_I2CRequest[2] = DLIGHT_REG_LEDOUT;
00167 DLIGHT_I2CRequest[3] = DLIGHT_CMD_ENABLE_BLINK;
00168 return writeI2C(link, DLIGHT_I2CRequest);
00169 }
00170
00171
00172
00173
00174
00175
00176
00177
00178 bool DLIGHTstopBlinking(tSensors link, ubyte addr){
00179 DLIGHT_I2CRequest[0] = 3;
00180 DLIGHT_I2CRequest[1] = addr;
00181 DLIGHT_I2CRequest[2] = DLIGHT_REG_LEDOUT;
00182 DLIGHT_I2CRequest[3] = DLIGHT_CMD_DISABLE_BLINK;
00183 return writeI2C(link, DLIGHT_I2CRequest);
00184 }
00185
00186
00187
00188
00189
00190
00191
00192
00193 bool DLIGHTdisable(tSensors link, ubyte addr)
00194 {
00195 DLIGHT_I2CRequest[0] = 3;
00196 DLIGHT_I2CRequest[1] = addr;
00197 DLIGHT_I2CRequest[2] = DLIGHT_REG_LEDOUT;
00198 DLIGHT_I2CRequest[3] = DLIGHT_CMD_DISABLE_LEDS;
00199 return writeI2C(link, DLIGHT_I2CRequest);
00200 }
00201
00202 #endif // __DLIGHT_H__
00203
00204
00205
00206
00207
00208