Skip to content

Commit

Permalink
fix: fixed infrared data read process
Browse files Browse the repository at this point in the history
  • Loading branch information
YarikRevich committed Apr 7, 2024
1 parent fb1c8d4 commit abcdb31
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
4 changes: 1 addition & 3 deletions Core/External/Scheduler/Handler/scheduler_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ int SchedulerHandler::process_data_bus_request_content_of_infrared_data_type_res
if (TSL2591X::is_available()) {
data_bus_response_content.set_deviceId(TSL2591X::get_device_id());

TSL2591X::invoke_lux_interrupt(LUX_LOW, LUX_HIGH);

data_bus_response_content.set_value(TSL2591X::read_infrared());
} else {
data_bus_response_content.set_deviceId(0);
Expand All @@ -206,7 +204,7 @@ int SchedulerHandler::process_data_bus_request_content_of_visible_data_type_resp
if (TSL2591X::is_available()) {
data_bus_response_content.set_deviceId(TSL2591X::get_device_id());

TSL2591X::invoke_lux_interrupt(LUX_LOW, LUX_HIGH);
TSL2591X::invoke_raw_interrupt_threshold(LUX_LOW, LUX_HIGH);

data_bus_response_content.set_value(TSL2591X::read_visible());
} else {
Expand Down
29 changes: 25 additions & 4 deletions Core/External/Sensor/tsl2591x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ uint16_t TSL2591X::read_lux() {

uint16_t channel0 = read_channel0();
uint16_t channel1 = read_channel1();

disable();

enable();

write_byte(0xE7, 0x13);

disable();

uint16_t maxCounts;
Expand Down Expand Up @@ -101,11 +104,17 @@ uint16_t TSL2591X::read_lux() {
return lux1;
}

uint32_t TSL2591X::read_full() {
uint32_t result;
uint16_t TSL2591X::read_full() {
uint16_t result;

enable();

uint8_t externalIntegralTime = get_integral_time();

for (uint8_t i = 0; i < externalIntegralTime + 2; i++) {
HAL_Delay(100);
}

result = (read_channel1() << 16) | read_channel0();

disable();
Expand All @@ -118,16 +127,28 @@ uint16_t TSL2591X::read_infrared() {

enable();

uint8_t externalIntegralTime = get_integral_time();

for (uint8_t i = 0; i < externalIntegralTime + 2; i++) {
HAL_Delay(100);
}

result = read_channel0();

disable();

return result;
}

uint32_t TSL2591X::read_visible() {
uint16_t TSL2591X::read_visible() {
enable();

uint8_t externalIntegralTime = get_integral_time();

for (uint8_t i = 0; i < externalIntegralTime + 2; i++) {
HAL_Delay(100);
}

uint16_t channel1 = read_channel1();
uint16_t channel0 = read_channel0();

Expand Down Expand Up @@ -205,7 +226,7 @@ uint8_t TSL2591X::get_integral_time() {
return read_byte(CONTROL_REGISTER) & 0x07;
}

void TSL2591X::set_integral_time(uint8_t src) {
void TSL2591X::set_integral_time(uint8_t src) {
if (src < 0x06) {
uint8_t control = read_byte(CONTROL_REGISTER);
control &= 0xf8;
Expand Down
4 changes: 2 additions & 2 deletions Core/External/Sensor/tsl2591x.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class TSL2591X {
*
* @return read full data.
*/
static uint32_t read_full();
static uint16_t read_full();

/**
* Reads infrared data from the sensor.
Expand All @@ -116,7 +116,7 @@ class TSL2591X {
*
* @return read visible data.
*/
static uint32_t read_visible();
static uint16_t read_visible();

/**
* Sets raw interruption threshold.
Expand Down

0 comments on commit abcdb31

Please sign in to comment.