DCS-Skunkworks/dcs-bios-arduino-library

Syncronization

kstrance opened this issue · 6 comments

If possible, am looking for help in moving from DCSBIOS Hub version to the new FP fork. Specifically related to syncing physical switches to the game. The original code worked in HUB and have been porting the new arduino FP library as well. What it appears is that 'pollinputcurrent' is no longer available in the switches.h library. I do see the examples of the newer synchronization.ino in the new library, but it appears when trying to update to the newer examples, that 'resetallstates' is not a reference in the library either? Unfortunately, my current skillset ends there and have spent the better part of two weeks trying to figure out how this works between the HUB version and FP version, changes, etc... The code pasted below is what was referenced on DCS forums and created by Blue73 that I then used for my INT_LIGHTS panel originally on HUB. It is driven by the battery switch set to ON and polling the state of switches on that panel. With the latest release and updated arduino FP library, how would this port over to the new version? Thanks for any help, much appreciated. -Kye

//INTERIOR LIGHTS//

#define DCSBIOS_RS485_SLAVE 33
#define TXENABLE_PIN 2
#include <DcsBios.h>
#define DCSBIOS_IRQ_SERIAL

//Interior Lights Panel//
DcsBios::Switch3Pos cockkpitLightModeSw("COCKKPIT_LIGHT_MODE_SW", 3, 4);
DcsBios::Switch2Pos lightsTestSw("LIGHTS_TEST_SW", 5);
DcsBios::Potentiometer warnCautionDimmer("WARN_CAUTION_DIMMER", 6);

#define FORCEPOLLCYCLES 10
unsigned int g_iInitIntervalCounter = 0;
unsigned int g_iForcePollCycles = 0;

void setup() {
DcsBios::setup();
}

void loop() {

DcsBios::loop();

if ( g_iForcePollCycles > 0 )
{
//repeat poll for this many cycles
if ( ++g_iInitIntervalCounter == 0 )
{ PollAllControls(); //main loop 1->65535->0 then polls
g_iForcePollCycles--;
}

}

}

void onBatterySwChange(unsigned int newValue)
{
//Battery Switch change, start polling controls FORCEPOLLCYCLES times
g_iForcePollCycles = FORCEPOLLCYCLES;
}
DcsBios::IntegerBuffer batterySwBuffer(0x54b6, 0x0600, 9, onBatterySwChange);

void PollAllControls()
{
cockkpitLightModeSw.pollInputCurrent();
lightsTestSw.pollInputCurrent();
}

Did you solve this?

Maciej (of DCSBIOSKIT) just helped me get it figured out today. He is putting a request in for a fix on the file DcsBiosNgRS485Slave.cpp in the arduino library. Here is my code for the electrical panel which is now finally compiling using RS485 as a short term fix. The issue was modifying this line - DcsBios::PollingInput::resetAllStates(); from the original example.

//ELECTRICAL PANEL//

#define DCSBIOS_RS485_SLAVE 31
#define TXENABLE_PIN 2
#include <DcsBios.h>

DcsBios::Switch3Pos batterySw("BATTERY_SW", 11, 9);
DcsBios::Switch2Pos lGenSw("L_GEN_SW", 13, true);
DcsBios::Switch2Pos rGenSw("R_GEN_SW", 12, true);

DcsBios::ProtocolParser parser;

unsigned long uLastModelTimeS = 0xFFFFFFFF; // Start big, to ensure the first step triggers a resync

int ledState = true;

void onModTimeChange(char* newValue) {
unsigned long currentModelTimeS = atol(newValue);

if( currentModelTimeS < uLastModelTimeS )
{
if( currentModelTimeS > 20 )// Delay to give time for DCS to finish loading and become stable and responsive
{
DcsBios::PollingInput::resetAllStates();
uLastModelTimeS = currentModelTimeS;
ledState = !ledState;
digitalWrite(6, ledState);
}
}
else
{
uLastModelTimeS = currentModelTimeS;
}

}
DcsBios::StringBuffer<5> modTimeBuffer(0x043e, onModTimeChange);

void setup() {
pinMode(6, OUTPUT);
digitalWrite(6, true);
DcsBios::setup();
}

void loop() {
DcsBios::loop();
}

Excellent!