Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Open-Cube FW
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Cube
Open-Cube FW
Commits
e7a6685d
Commit
e7a6685d
authored
1 year ago
by
Václav Jelínek
Browse files
Options
Downloads
Patches
Plain Diff
Correct bug with ADC not measuring when only one NXT sensor connected
parent
b98ef684
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#78502
passed
1 year ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
micropython/modules/nxt_sensors/analog_sensor.c
+12
-6
12 additions, 6 deletions
micropython/modules/nxt_sensors/analog_sensor.c
with
12 additions
and
6 deletions
micropython/modules/nxt_sensors/analog_sensor.c
+
12
−
6
View file @
e7a6685d
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment