mirror of https://github.com/ArduPilot/ardupilot
HAL_Linux: AnalogIn_IIO add init_pins
initializes all the available analog sources and stores the corresponding file descriptors in fd_analog_sources.
This commit is contained in:
parent
546fbd1f25
commit
da1b529415
|
@ -33,6 +33,21 @@ IIOAnalogSource::IIOAnalogSource(int16_t pin, float initial_value) :
|
|||
reopen_pin();
|
||||
}
|
||||
|
||||
void IIOAnalogSource::init_pins(void)
|
||||
{
|
||||
char buf[100];
|
||||
for (int i=0; i < IIO_ANALOG_IN_COUNT; i++) {
|
||||
// Construct the path by appending strings
|
||||
strncpy(buf, IIO_ANALOG_IN_DIR, sizeof(buf));
|
||||
strncat(buf, IIOAnalogSource::analog_sources[i], sizeof(buf));
|
||||
|
||||
fd_analog_sources[i] = open(buf, O_RDONLY | O_NONBLOCK);
|
||||
if (fd_analog_sources[i] == -1) {
|
||||
::printf("Failed to open analog pin %s\n", buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IIOAnalogSource::reopen_pin(void)
|
||||
{
|
||||
char buf[100];
|
||||
|
|
|
@ -44,8 +44,10 @@ private:
|
|||
int _pin_fd;
|
||||
|
||||
void reopen_pin(void);
|
||||
void init_pins(void);
|
||||
|
||||
static const char *analog_sources[IIO_ANALOG_IN_COUNT];
|
||||
static int fd_analog_sources[IIO_ANALOG_IN_COUNT];
|
||||
};
|
||||
|
||||
class IIOAnalogIn : public AP_HAL::AnalogIn {
|
||||
|
|
Loading…
Reference in New Issue