MakeBlock Drive Updated Updated library for MakeBlock Ranger

Loading...
Searching...
No Matches
MeColorSensor.h
Go to the documentation of this file.
1
66/* Define to prevent recursive inclusion -------------------------------------*/
67#ifndef _MeColorSensor_H_
68#define _MeColorSensor_H_
69
70/* Includes ------------------------------------------------------------------*/
71#include <stdint.h>
72#include <stdbool.h>
73#include <Arduino.h>
74#include "MeConfig.h"
75
76 #ifdef ME_PORT_DEFINED
77#include "MePort.h"
78 #endif // ME_PORT_DEFINED
79
80/* Exported macro ------------------------------------------------------------*/
81#define I2C_ERROR (-1)
82#define COLORSENSOR_DEFAULT_ADDRESS (0x38)//0011 1000
83
84/* Register List define------------------------------------------------------------*/
85#define SYSTEM_CONTROL (0X40)
86#define MODE_CONTROL1 (0X41)
87#define MODE_CONTROL2 (0X42)
88#define MODE_CONTROL3 (0X44)
89#define RED_DATA_LSBs (0X50)
90#define RED_DATA_MSBs (0X51)
91#define GREEN_DATA_LSBs (0X52)
92#define GREEN_DATA_MSBs (0X53)
93#define BLUE_DATA_LSBs (0X54)
94#define BLUE_DATA_MSBs (0X55)
95#define CLEAR_DATA_LSBs (0X56)
96#define CLEAR_DATA_MSBs (0X57)
97#define DINT_DATA_LSBs (0X58)
98#define DINT_DATA_MSBs (0X59)
99#define INTERRUPT (0X60)
100#define PERSISTENCE (0X61)
101#define TH_LSBs (0X62)
102#define TH_MSBs (0X63)
103#define TL_LSBs (0X64)
104#define TL_MSBs (0X65)
105#define MANUFACTURER_ID (0X92)
106#define CHIP_ID (0XE0)
107
108#define SW_RESET (1 << 7)
109#define INT_RESET (1 << 6)
110
111/* REG_MODECONTROL1(0x41) */
112#define MEASURE_160MS (0x00)
113#define MEASURE_320MS (0x01)
114#define MEASURE_640MS (0x02)
115#define MEASURE_1280MS (0x03)
116#define MEASURE_2560MS (0x04)
117#define MEASUREMENT_MAX (0x05)
118
119/* Color result list*/
120 typedef enum
121{
122 WHITE = 0,
123 PINKE = 1,
124 RED = 2,
125 ORANGE= 3,
126 YELLOW= 4,
127 GREEN = 5,
128 CYAN = 6,
129 BLUE = 7,
130 PURPLE= 8,
131 BLACK = 9,
132 GOLD = 10,
133}COLORTYPES;
134
135/*
136 * Class: MeColorSensor
137 * \par Description
138 * Declaration of Class MeColorSensor
139 */
140
141#ifndef ME_PORT_DEFINED
142 class MeColorSensor
143#else // !ME_PORT_DEFINED
144class MeColorSensor : public MePort
145#endif // !ME_PORT_DEFINED
146{
147 public:
148#ifdef ME_PORT_DEFINED
153 MeColorSensor(void);
154
160 MeColorSensor(uint8_t port);
161
170 MeColorSensor(uint8_t port, uint8_t address);
171#else // ME_PORT_DEFINED
179 MeColorSensor(uint8_t _AD0, uint8_t _INT);
180
191 MeColorSensor(uint8_t _AD0, uint8_t _INT, uint8_t address);
192#endif /* ME_PORT_DEFINED */
193
208 void SensorInit(void);
209
224 uint8_t ReportId(void);
225
240 void ColorDataRead(void);
241
256 uint8_t ColorDataReadOnebyOne(void);
257
272 long ReturnColorCode(void);
273
288 uint8_t ColorIdentify(void);
289
304 uint8_t Returnresult(void);
305
321 uint8_t ReturnGrayscale(void);
322
337 uint16_t ReturnColorhue(void);
338
353uint16_t ReturnRedData(void);
354
369 uint16_t ReturnGreenData(void);
370
385 uint16_t ReturnBlueData(void);
386
401 uint16_t ReturnColorData(void);
402
417 void TurnOnLight(void);
418
433 void TurnOffLight(void);
434
449 void TurnOffmodule(void);
450
465 void TurnOnmodule(void);
466
488 int8_t writeReg(int16_t reg, uint8_t data);
489
515 int8_t readData(uint8_t start, uint8_t *buffer, uint8_t size);
516
542 int8_t writeData(uint8_t start, const uint8_t *pData, uint8_t size);
543
557 uint8_t MAX(uint8_t r,uint8_t g,uint8_t b);
558
572 uint8_t MIN(uint8_t r,uint8_t g,uint8_t b);
573
574/***********************************/
575 uint8_t Device_Address;
576
577 private:
578 volatile uint8_t _S1;
579 volatile uint8_t _S2;
580 volatile uint8_t _AD0;
581 volatile uint8_t _INT;
582 uint16_t Redvalue;
583 uint16_t Greenvalue;
584 uint16_t Bluevalue;
585 uint16_t Colorvalue;
586};
587#endif
588
MeConfig.h
Configuration file of library.
MePort.h
Header for MePort.cpp module.
MeColorSensor
Driver for MeColorSensor module.
Definition MeColorSensor.h:146
MeColorSensor::ReturnBlueData
uint16_t ReturnBlueData(void)
Definition MeColorSensor.cpp:724
MeColorSensor::ReportId
uint8_t ReportId(void)
Definition MeColorSensor.cpp:176
MeColorSensor::SensorInit
void SensorInit(void)
Definition MeColorSensor.cpp:149
MeColorSensor::ReturnGreenData
uint16_t ReturnGreenData(void)
Definition MeColorSensor.cpp:705
MeColorSensor::MAX
uint8_t MAX(uint8_t r, uint8_t g, uint8_t b)
Definition MeColorSensor.cpp:965
MeColorSensor::ColorIdentify
uint8_t ColorIdentify(void)
Definition MeColorSensor.cpp:287
MeColorSensor::ReturnColorCode
long ReturnColorCode(void)
Definition MeColorSensor.cpp:250
MeColorSensor::TurnOnmodule
void TurnOnmodule(void)
Definition MeColorSensor.cpp:819
MeColorSensor::TurnOnLight
void TurnOnLight(void)
Definition MeColorSensor.cpp:762
MeColorSensor::MIN
uint8_t MIN(uint8_t r, uint8_t g, uint8_t b)
Definition MeColorSensor.cpp:1003
MeColorSensor::TurnOffmodule
void TurnOffmodule(void)
Definition MeColorSensor.cpp:800
MeColorSensor::ColorDataReadOnebyOne
uint8_t ColorDataReadOnebyOne(void)
Definition MeColorSensor.cpp:221
MeColorSensor::Returnresult
uint8_t Returnresult(void)
Definition MeColorSensor.cpp:455
MeColorSensor::writeData
int8_t writeData(uint8_t start, const uint8_t *pData, uint8_t size)
Definition MeColorSensor.cpp:938
MeColorSensor::ColorDataRead
void ColorDataRead(void)
Definition MeColorSensor.cpp:197
MeColorSensor::writeReg
int8_t writeReg(int16_t reg, uint8_t data)
Definition MeColorSensor.cpp:845
MeColorSensor::ReturnRedData
uint16_t ReturnRedData(void)
Definition MeColorSensor.cpp:686
MeColorSensor::TurnOffLight
void TurnOffLight(void)
Definition MeColorSensor.cpp:781
MeColorSensor::ReturnColorhue
uint16_t ReturnColorhue(void)
Definition MeColorSensor.cpp:638
MeColorSensor::ReturnColorData
uint16_t ReturnColorData(void)
Definition MeColorSensor.cpp:743
MeColorSensor::readData
int8_t readData(uint8_t start, uint8_t *buffer, uint8_t size)
Definition MeColorSensor.cpp:879
MeColorSensor::ReturnGrayscale
uint8_t ReturnGrayscale(void)
Definition MeColorSensor.cpp:607
MeColorSensor::MeColorSensor
MeColorSensor(void)
Definition MeColorSensor.cpp:76
MePort
Port Mapping for RJ25.
Definition MePort.h:128