Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <DcsBios.h>
- #include <Servo.h>
- //DcsBios::RotaryEncoderSR vhfamFreq1("VHFAM_FREQ1", "DEC", "INC", 2, 3);
- //const byte ahcpAltScePins[3] = {0, 1, 2};
- //DcsBios::SwitchMultiPosSR ahcpAltSce("AHCP_ALT_SCE", ahcpAltScePins, 3);
- //DcsBios::ActionButton ahcpHudModeToggle("AHCP_HUD_MODE", "TOGGLE", 44);
- //DcsBios::Switch2PosSR ahcpCicu("AHCP_CICU", 1);
- int ploadPin = 2; // Connects to Parallel load pin the 165
- int dataPin = 3; // Connects to the Q7 pin the 165
- int clockPin = 4; // Connects to the Clock pin the 165
- unsigned int pinValues = read_shift_regs();
- unsigned int oldPinValues;
- unsigned int read_shift_regs()
- {
- byte bitVal;
- unsigned int bytesVal = 0;
- /* Trigger a parallel Load to latch the state of the data lines,
- */
- digitalWrite(ploadPin, LOW);
- delayMicroseconds(5);
- digitalWrite(ploadPin, HIGH);
- /* Loop to read each bit value from the serial out line
- * of the SN74HC165N.
- */
- for(int i = 0; i < 8; i++)
- {
- bitVal = digitalRead(dataPin);
- /* Set the corresponding bit in bytesVal.
- */
- bytesVal |= (bitVal << ((8-1) - i));
- /* Pulse the Clock (rising edge shifts the next bit).
- */
- digitalWrite(clockPin, HIGH);
- delayMicroseconds(5);
- digitalWrite(clockPin, LOW);
- }
- return(bytesVal);
- }
- DcsBios::ProtocolParser parser;
- void setup() {
- Serial.begin(500000);
- /* Initialize our digital pins...
- */
- pinMode(ploadPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, INPUT);
- digitalWrite(clockPin, LOW);
- digitalWrite(ploadPin, HIGH);
- /* Read in and display the pin states at startup.
- */
- pinValues = read_shift_regs();
- oldPinValues = pinValues;
- }
- /*
- Your main loop needs to pass data from the DCS-BIOS export
- stream to the parser object you instantiated above.
- It also needs to call DcsBios::PollingInput::pollInputs()
- to detect changes in the state of connected controls and
- pass them on to DCS.
- */
- void loop() {
- // feed incoming data to the parser
- while (Serial.available()) {
- parser.processChar(Serial.read());
- }
- // poll inputs
- DcsBios::PollingInput::pollInputs();
- pinValues = read_shift_regs();
- oldPinValues = pinValues;
- }
- /*
- You need to define
- void sendDcsBiosMessage(const char* msg, const char* arg)
- so that the string msg, followed by a space, the string arg
- and a newline gets sent to the DCS-BIOS import stream.
- In this example we send it to the serial port, so you need to
- run socat to read the data from the serial port and send it
- over UDP to DCS-BIOS.
- If you are using an Ethernet Shield, you would probably want
- to send a UDP packet from this subroutine.
- */
- void sendDcsBiosMessage(const char* msg, const char* arg) {
- Serial.write(msg);
- Serial.write(' ');
- Serial.write(arg);
- Serial.write('\n');
- }
- /*
- This subroutine gets called every time a message is received
- from the export stream (you need to define it even if it
- does nothing).
- Use this to handle outputs which are not covered by the
- DcsBios Arduino library (e.g. displays).
- */
- void onDcsBiosWrite(unsigned int address, unsigned int value) {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement