diff --git a/README.md b/README.md new file mode 100644 index 0000000..725a352 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# Deneyap Proximity&Light Sensor LTR553 Library +[FOR TURKISH VERSION](docs/README_tr.md) ![trflag](https://github.com/deneyapkart/deneyapkart-arduino-core/blob/master/docs/tr.png) + +***** Add photo **** + +Arduino library for Deneyap Proximity&Light Sensor LTR553 + +## :mag_right:Specifications +- `Product ID` **M28**, **mpv1.0** +- `MCU` LTR553 +- `Weight` +- `Module Dimension` +- `I2C address` 0x23 + +| Address | | +| :--- | :--- | +| 0x23 | default address | + +## :closed_book:Documentation +Deneyap Proximity&Light Sensor LTR553 + +[LTR553-datasheet](https://optoelectronics.liteon.com/upload/download/DS86-2014-0007/LTR-553ALS-01_DS_V1.pdf) + +[How to install a Arduino Library](https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries) + +## :pushpin:Deneyap Proximity&Light Sensor LTR553 +This Arduino library allows you to use Deneyap Proximity&Light Sensor LTR553 with I2C peripheral. You can use this library in your projects with any Arduino compatible board with I2C peripheral. + +## :globe_with_meridians:Repository Contents +- `/docs ` README_tr.md and product photos +- `/examples ` Examples with .ino extension sketches +- `/src ` Source files (.cpp .h) +- `keywords.txt ` Keywords from this library that will be highlighted in the Arduino IDE +- `library.properties ` General library properties for the Arduino package manager + +## Version History +1.0.0 - initial release + +## :rocket:Hardware Connections +- Deneyap Proximity&Light Sensor LTR553 and Board can be connected with I2C cable +- or 3V3, GND, SDA and SCL pins can be connected with jumper cables + +|Proximity&Light Sensor| Function | Board pins | +|:--- | :--- | :---| +|3.3V | Power |3.3V | +|GND | Ground | GND | +|SDA | I2C Data | SDA pin | +|SCL | I2C Clock | SCL pin | +|INT | Interrupt|any GPIO pin | + +## :bookmark_tabs:License Information +Please review the [LICENSE](https://github.com/deneyapkart/deneyap-mesafe-olcer-isik-algilayici-arduino-library/blob/master/LICENSE) file for license information. diff --git a/docs/README_tr.md b/docs/README_tr.md new file mode 100644 index 0000000..85ea83f --- /dev/null +++ b/docs/README_tr.md @@ -0,0 +1,51 @@ +# Deneyap Mesafe Ölçer&Işık Algılayıcısı LTR553 Arduino Kütüphanesi + +***** Fotoğraf eklenecek **** + +Deneyap Mesafe Ölçer&Işık Algılayıcısı LTR553 için Arduino kütüphanesidir. + +## :mag_right:Özellikler +- `Ürün ID` **M28**, **mpv1.0** +- `MCU` LTR553 +- `Ağırlık` +- `Modul Boyutları` +- `I2C Adres` 0x23 + +| Adres | | +| :--- | :--- | +| 0x23 | varsayılan adres | + +## :closed_book:Dokümanlar +Deneyap Mesafe Ölçer&Işık Algılayıcısı LTR553 + +[LTR553-datasheet](https://optoelectronics.liteon.com/upload/download/DS86-2014-0007/LTR-553ALS-01_DS_V1.pdf) + +[Arduino Kütüphanesi Nasıl İndirilir](https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries) + +## :pushpin:Deneyap Mesafe Ölçer&Işık Algılayıcısı LTR553 +Bu Arduino kütüphanesi Deneyap Mesafe Ölçer&Işık Algılayıcısı LTR553 I2C çevre birimi ile kullanılmasını sağlar. Arduino ile uyumlu, I2C çevre birimine sahip herhangi bir geliştirme kartı ile bu kütüphaneyi projelerinizde kullanabilirsiniz. + +## :globe_with_meridians:Repo İçeriği +- `/docs` README_tr.md ve ürün fotoğrafları +- `/examples` .ino uzantılı örnek uygulamalar +- `/src` kütüphane için .cpp ve .h uzantılı dosyalar +- `keywords.txt` Arduino IDE'de vurgulanacak anahtar kelimeler +- `library.properties` Arduino yöneticisi için genel kütüphane özellikleri + +## Sürüm Geçmişi +1.0.0 - ilk sürüm + +## :rocket:Donanım Bağlantıları +- Deneyap Mesafe Ölçer&Işık Algılayıcısı LTR553 ile kullanılan geliştirme kartı I2C kablosu ile bağlanabilir +- veya jumper kablolar ile 3V3, GND, SDA ve SCL bağlantıları yapılabilir. + +| Mesafe Ölçer&Işık Algılayıcısı | Fonksiyon| Kart pinleri | +| :--- | :--- | :--- | +| 3.3V | Güç | 3.3V | +| GND | Toprak |GND | +| SDA | I2C Data | SDA pini | +| SCL | I2C Clock | SCL pini| +| INT | Kesme | herhangi bir GPIO pini| + +## :bookmark_tabs:Lisans Bilgisi +Lisans bilgileri için [LICENSE](https://github.com/deneyapkart/deneyap-mesafe-olcer-isik-algilayici-arduino-library/blob/master/LICENSE) dosyasını inceleyin. diff --git a/examples/IsikYogunluguOkuma/IsikYogunluguOkuma.ino b/examples/IsikYogunluguOkuma/IsikYogunluguOkuma.ino new file mode 100644 index 0000000..36029c4 --- /dev/null +++ b/examples/IsikYogunluguOkuma/IsikYogunluguOkuma.ino @@ -0,0 +1,31 @@ +/* + * Yakınlık ve Işık Algılama Okuma örneği, + * + * Bu örnekte temel konfigürasyon ayarları yapılmaktadır. + * Sensörden gelen Işık Yoğunluğu verilerini almaktadır. Gelen verileri seri terminale yazdırmaktadır. + * + * Bu algılayıcı I2C haberleşme protokolü ile çalışmaktadır. + * + * Bu örnek Deneyap Mesafe Ölçer&Işık Algılayıcı için oluşturulmuştur + * ------> www.....com <------ //docs + * ------> https://github.com/deneyapkart/deneyap-mesafe-olcer-isik-algilayici-arduino-library <------ + * + */ +#include // Deneyap_MesafeOlcerIsikAlgilayici.h kütüphanesi eklenmesi + +ProximityAL IsikYogunlugu; // ProximityAL için class tanımlanması + +float IsikYogunluguDegeri; + +void setup() { + Serial.begin(115200); // Seri haberleşme başlatılması + IsikYogunlugu.begin(0x23); // begin(slaveAdress) fonksiyonu ile cihazların haberleşmesi başlatılması +} + +void loop() { + IsikYogunluguDegeri = IsikYogunlugu.getLuxValue(); // Işık Yogunlugunu degerinin alınması + Serial.print("Işık Yoğunluğu = "); + Serial.println(IsikYogunluguDegeri, 2); // Işık Yogunlugunu degerinin seri terminale yazdırılması + + delay(50); +} diff --git a/examples/YakinlikDegeriniOkuma/YakinlikDegeriniOkuma.ino b/examples/YakinlikDegeriniOkuma/YakinlikDegeriniOkuma.ino new file mode 100644 index 0000000..e6741fb --- /dev/null +++ b/examples/YakinlikDegeriniOkuma/YakinlikDegeriniOkuma.ino @@ -0,0 +1,31 @@ +/* + * Yakınlık ve Işık Algılama Okuma örneği, + * + * Bu örnekte temel konfigürasyon ayarları yapılmaktadır. + * Sensörden gelen Yakınlık değerlerini almaktadır. Gelen verileri seri terminale yazdırmaktadır. + * + * Bu algılayıcı I2C haberleşme protokolü ile çalışmaktadır. + * + * Bu örnek Deneyap Mesafe Ölçer&Işık Algılayıcı için oluşturulmuştur + * ------> www.....com <------ //docs + * ------> https://github.com/deneyapkart/deneyap-mesafe-olcer-isik-algilayici-arduino-library <------ + * + */ +#include // Deneyap_MesafeOlcerIsikAlgilayici.h kütüphanesi eklenmesi + +ProximityAL Yakinlik; // ProximityAL için class tanımlanması + +uint16_t yakinlikDegeri; + +void setup() { + Serial.begin(115200); // Seri haberleşme başlatılması + Yakinlik.begin(0x23); // begin(slaveAdress) fonksiyonu ile cihazların haberleşmesi başlatılması +} + +void loop() { + yakinlikDegeri = Yakinlik.getPSvalue(); // Yakınlık degerinin alınması + Serial.print("Yakınlık Değeri = "); + Serial.println(yakinlikDegeri); // Yakınlık degerinin seri terminale yazdırılması + + delay(50); +} diff --git a/examples/YakinlikIsikYogunluguOkuma/YakinlikIsikYogunluguOkuma.ino b/examples/YakinlikIsikYogunluguOkuma/YakinlikIsikYogunluguOkuma.ino new file mode 100644 index 0000000..67c7529 --- /dev/null +++ b/examples/YakinlikIsikYogunluguOkuma/YakinlikIsikYogunluguOkuma.ino @@ -0,0 +1,37 @@ +/* + * Yakınlık ve Işık Algılama Okuma örneği, + * + * Bu örnekte temel konfigürasyon ayarları yapılmaktadır. + * Sensörden gelen Yakınlık ve Işık Yoğunluğu verilerini almaktadır. Gelen verileri seri terminale yazdırmaktadır. + * + * Bu algılayıcı I2C haberleşme protokolü ile çalışmaktadır. + * + * Bu örnek Deneyap Mesafe Ölçer&Işık Algılayıcı için oluşturulmuştur + * ------> www.....com <------ //docs + * ------> https://github.com/deneyapkart/deneyap-mesafe-olcer-isik-algilayici-arduino-library <------ + * + */ +#include // Deneyap_MesafeOlcerIsikAlgilayici.h kütüphanesi eklenmesi + +ProximityAL YakinIsik; // ProximityAL için class tanımlanması + +uint16_t yakinlikDegeri; +float IsikYogunluguDegeri; + +void setup() { + Serial.begin(115200); // Seri haberleşme başlatılması + YakinIsik.begin(0x23); +} + +void loop() { + yakinlikDegeri = YakinIsik.getPSvalue(); // Yakınlık degerinin alınması + Serial.print("Yakınlık Değeri = "); + Serial.print(yakinlikDegeri); // Yakınlık degerinin seri terminale yazdırılması + delay(50); + + IsikYogunluguDegeri = YakinIsik.getLuxValue(); // Işık Yogunlugunu degerinin alınması + Serial.print("\tIşık Yoğunluğu = "); + Serial.print(IsikYogunluguDegeri, 2); // Işık Yogunlugunu degerinin seri terminale yazdırılması + Serial.print("\n"); + delay(50); +} diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..8396d11 --- /dev/null +++ b/keywords.txt @@ -0,0 +1,47 @@ +####################################### +# Syntax Coloring Map For Deneyap_MesafeOlcerIsikAlgilayici +####################################### + +####################################### +# Library (KEYWORD1) +####################################### + +Deneyap_MesafeOlcerIsikAlgilayici KEYWORD1 + +#################################### +# Class (KEYWORD1) +#################################### + +ProximityAL KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### +begin KEYWORD2 +init KEYWORD2 +startSensor KEYWORD2 +softwareReset KEYWORD2 +setALSmode KEYWORD2 +setALSgain KEYWORD2 +getALSgain KEYWORD2 +setPSmode KEYWORD2 +setPSsaturationIndicator KEYWORD2 +setPSledPulseFreq KEYWORD2 +setPSledDutyCycle KEYWORD2 +setPSledPeakCurrent KEYWORD2 +setPSledPulse KEYWORD2 +setPSmeasurementRate KEYWORD2 +setALSintegrationTime KEYWORD2 +getALSintegrationTime KEYWORD2 +setALSmeasurementRate KEYWORD2 +getPartNumberID KEYWORD2 +getRevisionID KEYWORD2 +getManufacturerID KEYWORD2 +getPSvalue KEYWORD2 +getALSCH0value KEYWORD2 +getALSCH1value KEYWORD2 +getLuxValue KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### \ No newline at end of file diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..32e4405 --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=Deneyap Mesafe Olcer Isik Algilayici +version=1.0.0 +author=RFtek Electronics +maintainer=Turkish Technnology Team Foundation (T3) +sentence=Arduino library for Deneyap Proximity Light Sensor LTR553 +paragraph=A simple and efficient library to use Deneyap Proximity Light Sensor LTR553 via I2C peripheral. +category=Sensors +url=https://github.com/deneyapkart/deneyap-mesafe-olcer-isik-algilayici-arduino-library +architectures=* diff --git a/src/Deneyap_MesafeOlcerIsikAlgilayici.cpp b/src/Deneyap_MesafeOlcerIsikAlgilayici.cpp new file mode 100644 index 0000000..b19cc38 --- /dev/null +++ b/src/Deneyap_MesafeOlcerIsikAlgilayici.cpp @@ -0,0 +1,340 @@ +/* +***************************************************************************** +@file Deneyap_MesafeOlcerIsikAlgilayici.cpp +@mainpage Deneyap Proximity&Light Sensor LTR553 Arduino library source file +@maintainer RFtek Electronics +@version v1.0.0 +@date June 24, 2022 +@brief Includes functions to control Deneyap Proximity&Light Sensor LTR553 + Arduino library + +Library includes: +--> Configuration functions +--> Data manipulation functions +--> I2C communication functions +***************************************************************************** +*/ + +#include "Deneyap_MesafeOlcerIsikAlgilayici.h" + +/** + * @brief I2C initialization and read check + * @param adress: Device adress + * @retval None + **/ +void ProximityAL::begin(uint8_t address) { + + _address = address; + Wire.begin(); + softwareReset(); + setPSledPulse(PS_LED_PULSES_15); + setALSmode(ALS_ACTIVE_MODE); + setPSmode(PS_ACTIVE_MODE); +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::setALSmode(uint8_t mode) { + uint8_t readValue, writeValue; + readRegs(LTR553_ALS_CONTR_REG, &readValue, 1); + readValue &= (~ALS_MODE_MASK); + writeValue = readValue | mode; + writeRegs(LTR553_ALS_CONTR_REG, writeValue); +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::setPSmode(uint8_t mode) { + uint8_t readValue, writeValue; + readRegs(LTR553_PS_CONTR_REG, &readValue, 1); + readValue &= (~PS_MODE_MASK); + writeValue = readValue | mode; + writeRegs(LTR553_PS_CONTR_REG, writeValue); +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::softwareReset(void) { + uint8_t readValue, writeValue; + readRegs(LTR553_ALS_CONTR_REG, &readValue, 1); + readValue &= (~ALS_SOFTWARE_RESET_MASK); + writeValue = readValue | 0x02; + writeRegs(LTR553_ALS_CONTR_REG, writeValue); +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::setALSgain(uint8_t gain) { + uint8_t readValue, writeValue; + readRegs(LTR553_ALS_CONTR_REG, &readValue, 1); + readValue &= (~ALS_GAIN_MASK); + writeValue = readValue | gain; + writeRegs(LTR553_ALS_CONTR_REG, writeValue); +} + +/** + * @brief + * @param + * @retval + **/ +uint8_t ProximityAL::getALSgain(void) { + uint8_t readValue, result; + readRegs(LTR553_ALS_CONTR_REG, &readValue, 1); + readValue &= ALS_GAIN_MASK; + return result = readValue; +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::setPSsaturationIndicator(uint8_t strIndicator) { + uint8_t readValue, writeValue; + readRegs(LTR553_PS_CONTR_REG, &readValue, 1); + readValue &= (~PS_SATURATION_INDICATOR_MASK); + writeValue = readValue | strIndicator; + writeRegs(LTR553_PS_CONTR_REG, writeValue); +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::setPSledPulseFreq(uint8_t ledPulseFreq) { + uint8_t readValue, writeValue; + readRegs(LTR553_PS_LED_REG, &readValue, 1); + readValue &= (~PS_LED_PULSE_FREQUENCY_MASK); + writeValue = readValue | ledPulseFreq; + writeRegs(LTR553_PS_LED_REG, writeValue); +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::setPSledDutyCycle(uint8_t ledDutyCycle) { + uint8_t readValue, writeValue; + readRegs(LTR553_PS_LED_REG, &readValue, 1); + readValue &= (~PS_LED_DUTY_CYCLE_MASK); + writeValue = readValue | ledDutyCycle; + writeRegs(LTR553_PS_LED_REG, writeValue); +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::setPSledPeakCurrent(uint8_t ledPeakCurrent) { + uint8_t readValue, writeValue; + readRegs(LTR553_PS_LED_REG, &readValue, 1); + readValue &= (~PS_LED_PEAK_CURRENT_MASK); + writeValue = readValue | ledPeakCurrent; + writeRegs(LTR553_PS_LED_REG, writeValue); +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::setPSledPulse(uint8_t ledPulse) { + uint8_t registerValue; + registerValue = ledPulse; + writeRegs(LTR553_PS_N_PULSES_REG, registerValue); +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::setPSmeasurementRate(uint8_t measRate) { + uint8_t registerValue; + registerValue = measRate; + writeRegs(LTR553_PS_MEAS_RATE_REG, registerValue); +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::setALSintegrationTime(uint8_t intTime) { + uint8_t readValue, writeValue; + readRegs(LTR553_ALS_MEAS_PATE_REG, &readValue, 1); + readValue &= (~ALS_INTEGRATION_TIME_MASK); + writeValue = readValue | intTime; + writeRegs(LTR553_ALS_MEAS_PATE_REG, writeValue); +} + +/** + * @brief + * @param + * @retval + **/ +uint8_t ProximityAL::getALSintegrationTime(void) { + uint8_t readValue, result; + readRegs(LTR553_ALS_MEAS_PATE_REG, &readValue, 1); + readValue &= ALS_INTEGRATION_TIME_MASK; + return result = readValue; +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::setALSmeasurementRate(uint8_t measRate) { + uint8_t readValue, writeValue; + readRegs(LTR553_ALS_MEAS_PATE_REG, &readValue, 1); + readValue &= (~ALS_MEAS_REPEAT_RATE_MASK); + writeValue = readValue | measRate; + writeRegs(LTR553_ALS_MEAS_PATE_REG, writeValue); +} + +/** + * @brief + * @param + * @retval + **/ +uint8_t ProximityAL::getPartNumberID(void) { + uint8_t readValue, result; + readRegs(LTR553_PART_ID_REG, &readValue, 1); + readValue &= PART_NUMBER_ID_MASK; + return result = readValue >> 4; +} + +/** + * @brief + * @param + * @retval + **/ +uint8_t ProximityAL::getRevisionID(void) { + uint8_t readValue, result; + readRegs(LTR553_PART_ID_REG, &readValue, 1); + readValue &= REVISION_ID_MASK; + return result = readValue; +} + +/** + * @brief + * @param + * @retval + **/ +uint8_t ProximityAL::getManufacturerID(void) { + uint8_t readValue, result; + readRegs(LTR553_MANUFAC_ID_REG, &readValue, 1); + return result = readValue; +} + +/** + * @brief + * @param + * @retval + **/ +uint16_t ProximityAL::getPSvalue(void) { + uint8_t buffer[2]; + uint16_t result; + readRegs(LTR553_PS_DATA_0_REG, &buffer[0], 2); + buffer[0] &= PS_DATA_LOW_MASK; + buffer[1] &= PS_DATA_HIGH_MASK; + result = (buffer[1] << 8) | buffer[0]; + return result; +} + +/** + * @brief + * @param + * @retval + **/ +uint16_t ProximityAL::getALSCH0value(void) { + uint8_t buffer[2]; + uint32_t result; + readRegs(LTR553_ALS_DATA_CH0_0_REG, &buffer[0], 2); + result = (buffer[1] << 8) | buffer[0]; + return result; +} + +/** + * @brief + * @param + * @retval + **/ +uint16_t ProximityAL::getALSCH1value(void) { + uint8_t buffer[2]; + uint32_t result; + readRegs(LTR553_ALS_DATA_CH1_0_REG, &buffer[0], 2); + result = (buffer[1] << 8) | buffer[0]; + return result; +} + +/** + * @brief + * @param + * @retval + **/ +float ProximityAL::getLuxValue(void) { + uint16_t CH0, CH1; + float ratio; + CH1 = getALSCH1value(); + CH0 = getALSCH0value(); + + ratio = ((float)(CH1 / ((float)CH1 + CH0))); + + if (ratio < 0.45) + return ((float)1.7743 * CH0) + ((float)1.1059 * CH1); + + else if (0.45 <= ratio && ratio < 0.64) + return ((float)4.2785 * CH0) - ((float)1.9548 * CH1); + + else if (0.64 <= ratio && ratio < 0.85) + return ((float)0.5926 * CH0) + ((float)0.1185 * CH1); + + else + return 0; +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::writeRegs(int registerAddress, uint8_t dataValue) { + Wire.beginTransmission(_address); + Wire.write(registerAddress); + Wire.write(dataValue); + Wire.endTransmission(); +} + +/** + * @brief + * @param + * @retval + **/ +void ProximityAL::readRegs(uint8_t start_reg_addr, uint8_t *pdata, uint8_t size) { + + Wire.beginTransmission(_address); + Wire.write(start_reg_addr); + Wire.endTransmission(); + Wire.requestFrom(_address, size); + + for (uint8_t i = 0; i < size; i++) { + *(pdata + i) = Wire.read(); + } +} diff --git a/src/Deneyap_MesafeOlcerIsikAlgilayici.h b/src/Deneyap_MesafeOlcerIsikAlgilayici.h new file mode 100644 index 0000000..002323e --- /dev/null +++ b/src/Deneyap_MesafeOlcerIsikAlgilayici.h @@ -0,0 +1,207 @@ +/* +***************************************************************************** +@file Deneyap_MesafeOlcerIsikAlgilayici.h +@mainpage Deneyap Proximity&Light Sensor LTR553 Arduino library header file +@version v1.0.0 +@date June 24, 2022 +@brief This file contains all function prototypes and macros + for Deneyap Proximity&Light Sensor LTR553 Arduino library +***************************************************************************** +*/ + +#ifndef __Deneyap_MesafeOlcerIsikAlgilayici_H__ +#define __Deneyap_MesafeOlcerIsikAlgilayici_H__ + +#include +#include + +#define LTR553_ADDR 0x23 + +#define LTR553_ALS_CONTR_REG 0x80 +#define LTR553_PS_CONTR_REG 0x81 +#define LTR553_PS_LED_REG 0x82 +#define LTR553_PS_N_PULSES_REG 0x83 +#define LTR553_PS_MEAS_RATE_REG 0x84 +#define LTR553_ALS_MEAS_PATE_REG 0x85 +#define LTR553_PART_ID_REG 0x86 +#define LTR553_MANUFAC_ID_REG 0x87 +#define LTR553_ALS_DATA_CH1_0_REG 0x88 +#define LTR553_ALS_DATA_CH1_1_REG 0x89 +#define LTR553_ALS_DATA_CH0_0_REG 0x8A +#define LTR553_ALS_DATA_CH0_1_REG 0x8B +#define LTR553_ALS_PS_STATUS_REG 0x8C +#define LTR553_PS_DATA_0_REG 0x8D +#define LTR553_PS_DATA_1_REG 0x8E +#define LTR553_INTERRUPT_REG 0x8F +#define LTR553_PS_THRES_UP_0_REG 0x90 +#define LTR553_PS_THRES_UP_1_REG 0x91 +#define LTR553_PS_THRES_LOW_0_REG 0x92 +#define LTR553_PS_THRES_LOW_1_REG 0x93 +#define LTR553_PS_OFFSET_1 0x94 +#define LTR553_PS_OFFSET_0 0x95 +#define LTR553_ALS_THRES_UP_0_REG 0x97 +#define LTR553_ALS_THRES_UP_1_REG 0x98 +#define LTR553_ALS_THRES_LOW_0_REG 0x99 +#define LTR553_ALS_THRES_LOW_1_REG 0x9A +#define LTR553_INTERRUPT_PERSIST_REG 0x9E + +/*===========================================================================*/ + +#define PS_ACTIVE_MODE 0x03 +#define PS_STANDBY_MODE 0x00 + +#define PS_LED_PULSE_FREQUENCY_30KHZ 0x00 +#define PS_LED_PULSE_FREQUENCY_40KHZ 0x20 +#define PS_LED_PULSE_FREQUENCY_50KHZ 0x40 +#define PS_LED_PULSE_FREQUENCY_60KHZ 0x60 +#define PS_LED_PULSE_FREQUENCY_70KHZ 0x80 +#define PS_LED_PULSE_FREQUENCY_80KHZ 0xA0 +#define PS_LED_PULSE_FREQUENCY_90KHZ 0xC0 +#define PS_LED_PULSE_FREQUENCY_100KHZ 0xE0 + +#define PS_LED_DUTY_CYCLE_25 0x00 +#define PS_LED_DUTY_CYCLE_50 0x08 +#define PS_LED_DUTY_CYCLE_75 0x10 +#define PS_LED_DUTY_CYCLE_100 0x18 + +#define PS_LED_PEAK_CURRENT_5MA 0x00 +#define PS_LED_PEAK_CURRENT_10MA 0x01 +#define PS_LED_PEAK_CURRENT_20MA 0x02 +#define PS_LED_PEAK_CURRENT_50MA 0x03 +#define PS_LED_PEAK_CURRENT_100MA 0x04 + +#define PS_LED_PULSES_1 0x01 +#define PS_LED_PULSES_2 0x02 +#define PS_LED_PULSES_3 0x03 +#define PS_LED_PULSES_4 0x04 +#define PS_LED_PULSES_5 0x05 +#define PS_LED_PULSES_6 0x06 +#define PS_LED_PULSES_7 0x07 +#define PS_LED_PULSES_8 0x08 +#define PS_LED_PULSES_9 0x09 +#define PS_LED_PULSES_10 0x0A +#define PS_LED_PULSES_11 0x0B +#define PS_LED_PULSES_12 0x0C +#define PS_LED_PULSES_13 0x0D +#define PS_LED_PULSES_14 0x0E +#define PS_LED_PULSES_15 0x0F + +#define PS_MEASUREMENT_REPEAT_RATE_10MS 0x08 +#define PS_MEASUREMENT_REPEAT_RATE_50MS 0x00 +#define PS_MEASUREMENT_REPEAT_RATE_70MS 0x01 +#define PS_MEASUREMENT_REPEAT_RATE_100MS 0x02 +#define PS_MEASUREMENT_REPEAT_RATE_200MS 0x03 +#define PS_MEASUREMENT_REPEAT_RATE_500MS 0x04 +#define PS_MEASUREMENT_REPEAT_RATE_1000MS 0x05 +#define PS_MEASUREMENT_REPEAT_RATE_2000MS 0x06 + +#define ALS_ACTIVE_MODE 0x01 +#define ALS_STANDBY_MODE 0x00 + +#define ALS_GAIN_1X 0x00 +#define ALS_GAIN_2X 0x04 +#define ALS_GAIN_4X 0x08 +#define ALS_GAIN_8X 0x0C +#define ALS_GAIN_48X 0x18 +#define ALS_GAIN_96X 0x1C + +#define ALS_SOFTWARE_RESET_DISABLE 0x00 +#define ALS_SOFTWARE_RESET_ENABLE 0x02 + +#define ALS_INTEGRATION_TIME_50MS 0x08 +#define ALS_INTEGRATION_TIME_100MS 0x00 +#define ALS_INTEGRATION_TIME_150MS 0x20 +#define ALS_INTEGRATION_TIME_200MS 0x10 +#define ALS_INTEGRATION_TIME_250MS 0x28 +#define ALS_INTEGRATION_TIME_300MS 0x30 +#define ALS_INTEGRATION_TIME_350MS 0x38 +#define ALS_INTEGRATION_TIME_400MS 0x18 + +#define ALS_MEAS_REPEAT_RATE_50MS 0x00 +#define ALS_MEAS_REPEAT_RATE_100MS 0x01 +#define ALS_MEAS_REPEAT_RATE_200MS 0x02 +#define ALS_MEAS_REPEAT_RATE_500MS 0x03 +#define ALS_MEAS_REPEAT_RATE_1000MS 0x04 +#define ALS_MEAS_REPEAT_RATE_2000MS 0x05 + +/*===========================================================================*/ + +#define ALS_MODE_MASK 0x01 +#define ALS_SOFTWARE_RESET_MASK 0x02 +#define ALS_GAIN_MASK 0x1C +#define ALS_INTEGRATION_TIME_MASK 0x38 +#define ALS_MEAS_REPEAT_RATE_MASK 0x07 + +#define ALS_CH1_DATA_LOW_MASK 0xF0 +#define ALS_CH1_DATA_MID_MASK 0xFF +#define ALS_CH1_DATA_HIGH_MASK 0xFF + +#define ALS_CH2_DATA_LOW_MASK 0xF0 +#define ALS_CH2_DATA_MID_MASK 0xFF +#define ALS_CH2_DATA_HIGH_MASK 0xFF + +#define PS_MODE_MASK 0x03 +#define PS_SATURATION_INDICATOR_MASK 0x20 +#define PS_LED_DUTY_CYCLE_MASK 0x18 +#define PS_LED_PEAK_CURRENT_MASK 0x07 +#define PS_LED_PULSE_FREQUENCY_MASK 0xE0 + +#define PS_DATA_LOW_MASK 0xFF +#define PS_DATA_HIGH_MASK 0x07 + +#define PART_NUMBER_ID_MASK 0xF0 +#define REVISION_ID_MASK 0x0F + +/*===========================================================================*/ + +#define GAIN_1X 1 +#define GAIN_2X 2 +#define GAIN_4X 4 +#define GAIN_8X 8 +#define GAIN_48X 48 +#define GAIN_96X 96 + +#define INTEGRATION_TIME_100 1 +#define INTEGRATION_TIME_150 1.5 +#define INTEGRATION_TIME_200 2 +#define INTEGRATION_TIME_250 2.5 +#define INTEGRATION_TIME_300 3 +#define INTEGRATION_TIME_350 3.5 +#define INTEGRATION_TIME_400 4 + +/*===========================================================================*/ + +class ProximityAL +{ +public: + void begin(uint8_t address); + void startSensor(uint8_t psMode, uint8_t alsMode); + void softwareReset(void); + void setALSmode(uint8_t mode); + void setALSgain(uint8_t gain); + uint8_t getALSgain(void); + void setPSmode(uint8_t mode); + void setPSsaturationIndicator(uint8_t strIndicator); + void setPSledPulseFreq(uint8_t ledPulseFreq); + void setPSledDutyCycle(uint8_t ledDutyCycle); + void setPSledPeakCurrent(uint8_t ledPeakCurrent); + void setPSledPulse(uint8_t ledPulse); + void setPSmeasurementRate(uint8_t measRate); + void setALSintegrationTime(uint8_t intTime); + uint8_t getALSintegrationTime(void); + void setALSmeasurementRate(uint8_t measRate); + uint8_t getPartNumberID(void); + uint8_t getRevisionID(void); + uint8_t getManufacturerID(void); + uint16_t getPSvalue(void); + uint16_t getALSCH0value(void); + uint16_t getALSCH1value(void); + float getLuxValue(void); + +private: + uint8_t _address; + void readRegs(uint8_t start_reg_addr, uint8_t *pdata, uint8_t size); + void writeRegs(int registerAddress, uint8_t dataValue); +}; + +#endif /* Deneyap_MesafeOlcerIsikAlgilayici_H */