API Documentation v0.0.1
Loading...
Searching...
No Matches
2A3A1-AMPCD.ino File Reference

Controls the AMPCD. Adapted from Peter Sawka's original Nano code. More...

#include "DcsBios.h"
#include "Wire.h"
#include "TCA9534.h"

Go to the source code of this file.

Macros

#define DCSBIOS_DEFAULT_SERIAL
 This enables the default serial communication for DCS-BIOS. (Used with all other microcontrollers than the ATmega328P or ATmega2560.)
 
#define TXENABLE_PIN   5
 Sets TXENABLE_PIN to Arduino Pin 5.
 
#define UART1_SELECT
 Selects UART1 on Arduino for serial communication.
 
#define AMPCD_ROT_A   A0
 AMPCD Rotary Brightness.
 
#define AMPCD_ROT_OFF   A1
 AMPCD Off - No DCS Bios use.
 
#define HDG_P   8
 HDG +.
 
#define HDG_M   10
 HDG -.
 
#define CRS_P   4
 CRS +.
 
#define CRS_M   7
 CRS -.
 
#define AMPCD_BACK_LIGHT   9
 DDI Backlighting PWM, must be defined as digital pin #.
 
#define AMPCD_IRQ   6
 AMPCD IRQ Pin.
 

Functions

DcsBios::Potentiometer ampcdBrtCtl ("AMPCD_BRT_CTL", AMPCD_ROT_A)
 
DcsBios::Switch3Pos leftDdiCrsSw ("LEFT_DDI_CRS_SW", CRS_P, CRS_M)
 
DcsBios::Switch3Pos leftDdiHdgSw ("LEFT_DDI_HDG_SW", HDG_P, HDG_M)
 
void onInstrIntLtChange (unsigned int newValue)
 Setup DCS-BIOS control for DDI backlighting.
 
DcsBios::IntegerBuffer instrIntLtBuffer (FA_18C_hornet_INSTR_INT_LT, onInstrIntLtChange)
 
void setup ()
 
void loop ()
 

Variables

TCA9534 ampcdButtons [4]
 
bool lastBtnState [28]
 Array to hold the last state of the 20 AMPCD buttons, and 4 rocker switches.
 
bool buttonState [28]
 Array to hold the current state of the 20 AMPCD buttons, and 4 rocker switches.
 
uint8_t inputRegister [4]
 Input register for button read logic.
 
unsigned long lastDebounceTime [28]
 Array to hold last time of AMPCD button update for debounce.
 
unsigned long debounceDelay = 10
 The debounce delay duration in ms, increase if the output flickers.
 
int index
 
char * AMPCD_Btns []
 DCS Bios Messages for the 4 AMPCD rocker switches.
 
char btnName [20]
 

Detailed Description

Controls the AMPCD. Adapted from Peter Sawka's original Nano code.

Author
Peter Sawka, OH Community, Arribe, Ash
Date
02.29.2024
Version
0.1.0
  • Reference Designator: 2A3A1
  • Intended Board: CONTROLLER_AMPCD DDI
  • RS485 Bus Address: 2

Wiring diagram:

PIN Function
A0 AMPCD Rotary Brightness
A1 AMPCD Off - No DCS Bios use
8 HDG +
10 HDG -
4 CRS +
7 CRS -
9 DDI Backlighting PWM, must be defined as digital pin #
6 AMPCD IRQ Pin

following #define tells DCS-BIOS that this is a RS-485 slave device. It also sets the address of this slave device. The slave address should be between 1 and 126 and must be unique among all devices on the same bus.

Bug
Currently does not work with the Pro Micro (32U4), Fails to compile

#define DCSBIOS_RS485_SLAVE 2

Definition in file 2A3A1-AMPCD.ino.

Macro Definition Documentation

◆ DCSBIOS_DEFAULT_SERIAL

#define DCSBIOS_DEFAULT_SERIAL

This enables the default serial communication for DCS-BIOS. (Used with all other microcontrollers than the ATmega328P or ATmega2560.)

Check if we're on a Mega328 or Mega2560 and define the correct serial interface

Definition at line 79 of file 2A3A1-AMPCD.ino.

◆ TXENABLE_PIN

#define TXENABLE_PIN   5

Sets TXENABLE_PIN to Arduino Pin 5.

The Arduino pin that is connected to the RE and DE pins on the RS-485 transceiver.

Definition at line 91 of file 2A3A1-AMPCD.ino.

◆ UART1_SELECT

#define UART1_SELECT

Selects UART1 on Arduino for serial communication.

Definition at line 92 of file 2A3A1-AMPCD.ino.

◆ AMPCD_ROT_A

#define AMPCD_ROT_A   A0

AMPCD Rotary Brightness.

Definition at line 99 of file 2A3A1-AMPCD.ino.

◆ AMPCD_ROT_OFF

#define AMPCD_ROT_OFF   A1

AMPCD Off - No DCS Bios use.

Definition at line 100 of file 2A3A1-AMPCD.ino.

◆ HDG_P

#define HDG_P   8

HDG +.

Definition at line 101 of file 2A3A1-AMPCD.ino.

◆ HDG_M

#define HDG_M   10

HDG -.

Definition at line 102 of file 2A3A1-AMPCD.ino.

◆ CRS_P

#define CRS_P   4

CRS +.

Definition at line 103 of file 2A3A1-AMPCD.ino.

◆ CRS_M

#define CRS_M   7

CRS -.

Definition at line 104 of file 2A3A1-AMPCD.ino.

◆ AMPCD_BACK_LIGHT

#define AMPCD_BACK_LIGHT   9

DDI Backlighting PWM, must be defined as digital pin #.

Definition at line 105 of file 2A3A1-AMPCD.ino.

Referenced by onInstrIntLtChange(), and setup().

◆ AMPCD_IRQ

#define AMPCD_IRQ   6

AMPCD IRQ Pin.

Definition at line 106 of file 2A3A1-AMPCD.ino.

Referenced by setup().

Function Documentation

◆ onInstrIntLtChange()

void onInstrIntLtChange ( unsigned int newValue)

Setup DCS-BIOS control for DDI backlighting.

Definition at line 145 of file 2A3A1-AMPCD.ino.

145 {
146 analogWrite(AMPCD_BACK_LIGHT, map(newValue, 0, 65535, 0, 255));
147}
#define AMPCD_BACK_LIGHT
DDI Backlighting PWM, must be defined as digital pin #.

References AMPCD_BACK_LIGHT.

◆ setup()

void setup ( )

Arduino Setup Function

Arduino standard Setup Function. Code who should be executed only once at the program start, belongs in this function.

Initialize last button state array to all 0's.

For each TCA9534 chip 'Begin', and set all of its AMPCD buttons to PinMode = INPUT

Definition at line 156 of file 2A3A1-AMPCD.ino.

156 {
157
158 // Run DCS Bios setup function
159 DcsBios::setup();
160
161 pinMode(AMPCD_IRQ, OUTPUT);
162
163 pinMode(AMPCD_BACK_LIGHT, OUTPUT); // set backlight pinmode to output
164 analogWrite(AMPCD_BACK_LIGHT, 0); // turn-off backlighting
169 for (int i = 0; i < sizeof(lastBtnState) / sizeof(lastBtnState[0]); i++) {
170 lastBtnState[i] = 0;
171 }
172
177 for (int i = 0; i < sizeof(ampcdButtons) / sizeof(ampcdButtons[0]); i++) {
178 ampcdButtons[i].Begin();
179 for (int j = 0; j < 7; j++) {
180 ampcdButtons[i].PinMode(j, INPUT);
181 }
182 }
183}
#define AMPCD_IRQ
AMPCD IRQ Pin.
bool lastBtnState[28]
Array to hold the last state of the 20 AMPCD buttons, and 4 rocker switches.
TCA9534 ampcdButtons[4]

References AMPCD_BACK_LIGHT, AMPCD_IRQ, ampcdButtons, and lastBtnState.

◆ loop()

void loop ( )

Arduino Loop Function

Arduino standard Loop Function. Code who should be executed over and over in a loop, belongs in this function.

Attention
If AMPCD button output flickers increase debounceDelay.

Read all the AMPCD button states and send DCSBios Commands in the following TCA9534 order: Left, Top (buttons reversed), Right (buttons reversed), Bottom.

Fix button index for Top and Right buttons to be in the same order as Left and Bottom buttons.

Definition at line 193 of file 2A3A1-AMPCD.ino.

193 {
194
195 //Run DCS Bios loop function
196 DcsBios::loop();
197
203 for (int i = 0; i < sizeof(ampcdButtons) / sizeof(ampcdButtons[0]); i++) {
204 inputRegister[i] = ampcdButtons[i].ReadAll();
205
210 for (int j = 0; j < 7; j++) {
211
212 index = j + (7 * i);
213
214 bool btnState = (inputRegister[i] >> (6 - j)) & 1;
215
216 if (btnState != lastBtnState[index]) {
217 lastDebounceTime[index] = millis();
218 }
219
220 if ((millis() - lastDebounceTime[index]) > debounceDelay) {
221 if (btnState != buttonState[index]) {
222 buttonState[index] = btnState;
223 if (j > 4) { // one of the AMPCD NIGHT, GAIN, SYMBOLOGY, CONTRAST rockers.
224 if (btnState != 1) { // If one of the AMPCD rocker buttons determine if value to send to DCS 0 or 2.
225 if (i == 0 or i == 1) {
226 if (j == 5) { DcsBios::sendDcsBiosMessage(AMPCD_Btns[i], "2"); }
227 if (j == 6) { DcsBios::sendDcsBiosMessage(AMPCD_Btns[i], "0"); }
228 } else {
229 if (j == 5) { DcsBios::sendDcsBiosMessage(AMPCD_Btns[i], "0"); }
230 if (j == 6) { DcsBios::sendDcsBiosMessage(AMPCD_Btns[i], "2"); }
231 }
232 } else { // every AMPCD button has a "1" state.
233 DcsBios::sendDcsBiosMessage(AMPCD_Btns[i], "1");
234 }
235 } else { // One of the 20 push buttons.
236 int btnNum = 4 - j + 5 * i;
237 sprintf(btnName, "AMPCD_PB_%02d", btnNum + 1);
238 DcsBios::sendDcsBiosMessage(btnName, btnState == 1 ? "0" : "1");
239 }
240 }
241 }
242 lastBtnState[index] = btnState;
243 }
244 }
245}
int index
Index to track the button press states.
unsigned long debounceDelay
The debounce delay duration in ms, increase if the output flickers.
bool buttonState[28]
Array to hold the current state of the 20 AMPCD buttons, and 4 rocker switches.
uint8_t inputRegister[4]
Input register for button read logic.
unsigned long lastDebounceTime[28]
Array to hold last time of AMPCD button update for debounce.
char * AMPCD_Btns[]
DCS Bios Messages for the 4 AMPCD rocker switches.

References AMPCD_Btns, ampcdButtons, buttonState, debounceDelay, index, inputRegister, lastBtnState, and lastDebounceTime.

Variable Documentation

◆ ampcdButtons

TCA9534 ampcdButtons[4]
Initial value:
= {
TCA9534(0x23),
TCA9534(0x20),
TCA9534(0x22),
}

TCA9534 Chip Array Array for the 4 TCA9534 chips to read the DDI Buttons (indices): Left = 0, Top = 1, Right = 2, Bottom = 3

Definition at line 113 of file 2A3A1-AMPCD.ino.

113 {
114 TCA9534(0x23), //Left Row
115 TCA9534(0x20), //Top Row
116 TCA9534(0x22), // Right Row
117 TCA9534(0x21)
118}; // Bottom Row

Referenced by loop(), and setup().

◆ lastBtnState

bool lastBtnState[28]

Array to hold the last state of the 20 AMPCD buttons, and 4 rocker switches.

Definition at line 121 of file 2A3A1-AMPCD.ino.

Referenced by loop(), and setup().

◆ buttonState

bool buttonState[28]

Array to hold the current state of the 20 AMPCD buttons, and 4 rocker switches.

Definition at line 122 of file 2A3A1-AMPCD.ino.

Referenced by loop().

◆ inputRegister

uint8_t inputRegister[4]

Input register for button read logic.

Definition at line 123 of file 2A3A1-AMPCD.ino.

Referenced by loop().

◆ lastDebounceTime

unsigned long lastDebounceTime[28]

Array to hold last time of AMPCD button update for debounce.

Definition at line 124 of file 2A3A1-AMPCD.ino.

Referenced by loop().

◆ debounceDelay

unsigned long debounceDelay = 10

The debounce delay duration in ms, increase if the output flickers.

Definition at line 125 of file 2A3A1-AMPCD.ino.

Referenced by loop().

◆ index

int index

Definition at line 127 of file 2A3A1-AMPCD.ino.

◆ AMPCD_Btns

char* AMPCD_Btns[]
Initial value:
= { "AMPCD_GAIN_SW",
"AMPCD_NIGHT_DAY",
"AMPCD_SYM_SW",
"AMPCD_CONT_SW" }

DCS Bios Messages for the 4 AMPCD rocker switches.

Definition at line 130 of file 2A3A1-AMPCD.ino.

130 { "AMPCD_GAIN_SW",
131 "AMPCD_NIGHT_DAY",
132 "AMPCD_SYM_SW",
133 "AMPCD_CONT_SW" };

Referenced by loop().

◆ btnName

char btnName[20]

Definition at line 134 of file 2A3A1-AMPCD.ino.