SysFS GPIO Switch

Standup Records

2023-11-20

Requirements

Write a class SysFSGPIOSwitch that uses Intro: sysfs GPIO internally.

This class is going to be used to implement switches that software might want to use in real life.

Implementation

Attention

This task has a dependency on :doc:switch-interface! A real switch is used under real conditions, whereas a mocking switch is used for testing - code should not depend on implementations, but rather on interfaces.

Before you implement a switch interface (and derive your switch class from it), talk to the guys from (DONE) Boiling Pot (The Beginning). Or else it may happen that both groups do duplicate work which results in Git conflicts!

  • Write a class SysFSGPIOSwitch that has methods

    • (Constructor). Configures the GPIO.

      • Export the GPIO. Write 20 (or whatever the pin’s number is) into /sys/class/gpio/export. Note that one has to wait a bit until the gpio20 directory becomes visible. for output (exports the pin, write out into the IO’s direction file).

      • Configure for output. Write out into the GPIO’s direction file.

    • void set_state(bool);

      Write 0 or 1 to the IO’s value file, to control the pin’s output voltage.

Testing

It is hard to come up with automatic tests for real hardware. (Although the file operations could somehow be verified.)

Write a test program in bin/ that you use interactively/manually.

Future (Not Part Of This Development Cycle)

  • Should we do the configuration in the constructure? Or is it better to proide a configure() method that is called later in a program’s lifecycle?

  • An alternative GPIO interface, libgpiod (see Installation Notes). SysFS GPIO is deprecated!

Dependencies

cluster_fh2021 WS2023/24: Group Project - Tasks fh2021_boiling_pot (DONE) Boiling Pot (The Beginning) fh2021_switch_interface (DONE) Switch Interface fh2021_boiling_pot->fh2021_switch_interface fh2021_sensor_interface (DONE) Sensor Interface fh2021_boiling_pot->fh2021_sensor_interface fh2021_sysfs_gpio_switch SysFS GPIO Switch fh2021_sysfs_gpio_switch->fh2021_switch_interface