This library provides classes and functions to manage Open Airbus Cockpit expansion cards. These cards enable the access to common ICs as digital shift registers, keyboard controllers, LED drivers, etc.

Class ExpansionCard

Use the ExpansionCard class in order to manage IO expansion cards to shift in and out digital data.

ExpansionCard is a very bad name for this class, and it is susceptible to be renamed in the future.

The basic usage of this class is shown in the following example:

#include <oacexp.h>

#define IN_CLOCK_PIN
#define IN_LATCH_PIN
#define IN_DATA_PIN
#define OUT_CLOCK_PIN
#define OUT_LATCH_PIN
#define OUT_DATA_PIN

#define LANDING_LIGHTS_BTN 0
#define TAXI_LIGHTS_BTN 1
#define STROBE_LIGHTS_BTN 2

#define LANDING_LIGHTS_LED 0
#define TAXI_LIGHTS_LED 1
#define STROBE_LIGHTS_LED 2

OAC::ExpansionCard card;
byte lights = 0;

void setup() {
  card.setPins(
    IN_CLOCK_PIN,
    IN_LATCH_PIN,
    IN_DATA_PIN,
    OUT_CLOCK_PIN,
    OUT_LATCH_PIN,
    OUT_DATA_PIN);
}

void loop() {
  card.readInput();
  if (card.inputActivated() & LANDING_LIGHTS_BTN) {
    // The landing lights on is detected in the input
    bitSet(lights, LANDING_LIGHTS_LED);
  } else if (card.inputDeactivated() & LANDING_LIGHTS_BTN) {
    // The landing lights off is detected in the input
    bitClear(lights, LANDING_LIGHTS_LED);
  }

  // Do the same for the rest of inputs...

  // And finally write the new status of the lights
  card.writeOutput(lights);
}

In this example, we are controlling the status of the aircraft lights. The corresponding expansion cards would have switches in its inputs to manage landing lights, taxi lights, strobe, and so on. The output is connected to the LEDs that indicate what light is turned on.

First of all, we declare an object of class ExpansionCard. We declare a variable lights as well to maintain the current status of the output LEDs. The setup() function prepares the expansion card by indicating what are the pins the card is connected to. The rest of the magic is in loop() function.

readInput() function may be used to shift-in one byte from the expansion card and store it in the internal state of the object. After that, inputActivated() and inputDeactivated() functions will operate over that byte that has been read. The first one would return what input bits has been set to 1 since last read, e.g., what inputs have been activated (switched on). The second function does the opposite: indicates what bits have been set to 0 since last read (deactivated or switched off).

In this example, we set the corresponding bit in the lights variable representing the LED indicator for that light. Finally, the writeOutput() function may be used to write a byte through the shift-out register of the expansion card, illuminating the right LEDs.

Leave a Reply

Your email address will not be published. Required fields are marked *