Hi everyone.
I've discovered dcsbios some time ago. Now i'm testing the stuff and i've got a problem.
I can connect my dcs to arduino board. A can display some values on the LCD display. I can attach some tact swich also. But when i'm trying to add 2 position swich to my code - arduino Leonardo gets disconnected (when uploading). I need to upload some "blink" sketch to get it work again. Why?
This is my code (without 2pos swiches - code works properly):
#include <DcsBios.h>
#include <Servo.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);
/**** Make your changes after this line ****/
DcsBios::LED lowRpmInd(0x1416, 0x0080, 13);
DcsBios::LED masterCautionInd(0x1416, 0x0100, 9);
DcsBios::LED fireInd(0x1416, 0x0040, 8);
//DcsBios::Switch2Pos batSw("BAT_SW", 12); //<<<<<<<<<<< this line commented
//DcsBios::Switch2Pos starterGenSw("STARTER_GEN_SW", 11); //<<<<< or this line
void onRaltDisplayChange(char* newValue) {
lcd.setCursor(0,1);
lcd.print(newValue);
}
void onVhfcommFreqChange(char* newValue) {
lcd.setCursor(0,0);
lcd.print(newValue);
}
DcsBios::StringBuffer<7> vhfcommFreqBuffer(0x14d4, onVhfcommFreqChange);
void onUhfFreqChange(char* newValue) {
lcd.setCursor(9,0);
lcd.print(newValue);
}
DcsBios::StringBuffer<6> uhfFreqBuffer(0x14e2, onUhfFreqChange);
void onVhfnavFreqChange(char* newValue) {
lcd.setCursor(9,1);
lcd.print(newValue);
}
DcsBios::StringBuffer<6> vhfnavFreqBuffer(0x14f0, onVhfnavFreqChange);
/**** In most cases, you do not have to change anything below this line ****/
/* Instantiate a ProtocolParser object to parse the DCS-BIOS export stream */
DcsBios::ProtocolParser parser;
void setup() {
Serial.begin(250000);
lcd.begin(16,2);
lcd.clear();
}
/*
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();
}
/*
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) {
if (address == 0x040a) {
unsigned int hdgDegValue = (value & 0x01ff) >> 0;
lcd.setCursor(1,1);
lcd.print(hdgDegValue);
}
}
And this code crashes my arduino.... why? :-)
#include <DcsBios.h>
#include <Servo.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2);
/**** Make your changes after this line ****/
DcsBios::LED lowRpmInd(0x1416, 0x0080, 13);
DcsBios::LED masterCautionInd(0x1416, 0x0100, 9);
DcsBios::LED fireInd(0x1416, 0x0040, 8);
DcsBios::Switch2Pos batSw("BAT_SW", 12); //<<<<<<< This line!!!!!!
//DcsBios::Switch2Pos starterGenSw("STARTER_GEN_SW", 11); //<<<<<<< or this line!!!!!
void onRaltDisplayChange(char* newValue) {
lcd.setCursor(0,1);
lcd.print(newValue);
}
void onVhfcommFreqChange(char* newValue) {
lcd.setCursor(0,0);
lcd.print(newValue);
}
DcsBios::StringBuffer<7> vhfcommFreqBuffer(0x14d4, onVhfcommFreqChange);
void onUhfFreqChange(char* newValue) {
lcd.setCursor(9,0);
lcd.print(newValue);
}
DcsBios::StringBuffer<6> uhfFreqBuffer(0x14e2, onUhfFreqChange);
void onVhfnavFreqChange(char* newValue) {
lcd.setCursor(9,1);
lcd.print(newValue);
}
DcsBios::StringBuffer<6> vhfnavFreqBuffer(0x14f0, onVhfnavFreqChange);
/**** In most cases, you do not have to change anything below this line ****/
/* Instantiate a ProtocolParser object to parse the DCS-BIOS export stream */
DcsBios::ProtocolParser parser;
void setup() {
Serial.begin(250000);
lcd.begin(16,2);
lcd.clear();
}
/*
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();
}
/*
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) {
if (address == 0x040a) {
unsigned int hdgDegValue = (value & 0x01ff) >> 0;
lcd.setCursor(1,1);
lcd.print(hdgDegValue);
}
}