Skip to content
Snippets Groups Projects
Commit e7a6685d authored by Václav Jelínek's avatar Václav Jelínek
Browse files

Correct bug with ADC not measuring when only one NXT sensor connected

parent b98ef684
No related branches found
No related tags found
No related merge requests found
Pipeline #78502 passed
......@@ -43,7 +43,7 @@ typedef struct {
uint32_t cycle_period;
} analog_sensors;
static analog_sensors sensors;
static analog_sensors sensors = {.enabled = false};
static bool opencube_analog_sensor_continuous(repeating_timer_t *timer);
......@@ -53,6 +53,7 @@ void opencube_analog_sensors_init(void) {
}
for (int i = 0; i < NUM_SENSOR_PORTS; i++)
{
sensors.ports[i].enabled = false;
switch (i)
{
case OPENCUBE_SENSOR_1:
......@@ -85,6 +86,7 @@ void opencube_analog_sensors_init(void) {
ADS1119_set_data_rate(sensors.adc, 3);
ADS1119_write_config(sensors.adc);
opencube_unlock_i2c();
sensors.current_port = 255;
sensors.enabled = true;
}
......@@ -119,7 +121,13 @@ void opencube_analog_sensor_deinit(uint8_t port) {
sensors.ports[port].enabled = false;
opencube_analog_sensor_turn_off(port);
opencube_analog_sensor_set_switching(port, false);
opencube_analog_sensor_stop_continuous();
for (int i = 0; i < NUM_SENSOR_PORTS; i++)
{
if (sensors.ports[i].enabled) {
return;
}
}
sensors.current_port = 255;
}
void opencube_analog_sensor_turn_on(uint8_t port) {
......@@ -189,10 +197,8 @@ uint16_t opencube_analog_sensor_get_value(uint8_t port, bool pin_on) {
if (sensors.ports[port].enabled) {
// if not continuous get a measurement first
if (!sensors.continuous) {
if (sensors.current_port != port) {
// blocking read
opencube_analog_sensor_read_value(port);
}
// blocking read
opencube_analog_sensor_read_value(port);
}
// if switching mode is on it does not matter which value is returned
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment