Tekkx Posted August 15, 2015 Posted August 15, 2015 (edited) Hello, dear Community. Since I stimpled my first steps into the amazing world of DCS-BIOS, I want to ignite next stage and bring my CDU into REAL life. Thanks to [FSF]Ian, HMA and agrasyuk, they helped and inspired me to this decission. This CDU worked slightly well as a Keyboard, but it made me never really smile :) Due to hardware limitations (I don't want to rebuild a 65buttons/20LED-PCB) I need all 64 IOs of Centipede and all IOs of Arduino (there will come an AAP soon) So I did the following steps: (most code is based on the UFC Master_Caution_Button Example) What you have to know: My programmer's knowledges are not much more than copy_and_paste. I operate very close at my brain's border :) Late 80s to early 90s I did some Turbo-Pascal and Basic. I don't know what a serial-parser really does... The matter: Project consists of A10C-CDU.ino - main part consists of code from the example and includes following files BIOS_calls.h - just a text file with commands copied from control-reference Centpede.h - library DCSBios.h - library I created a new class in DCSBios.cpp // ---- Centipede void ButtonCS::init_(char* msg, char pin, bool reverse) { msg_ = msg; pin_ = pin; pinMode(pin_, INPUT_PULLUP); lastState_ = CS.digitalRead(pin_); reverse_ = reverse; } void ButtonCS::pollInput() { char state = CS.digitalRead(pin_); if (reverse_) state = !state; if (state != lastState_) { sendDcsBiosMessage(msg_, state == HIGH ? "0" : "1"); } lastState_ = state; } // ---- End Centipede */ and in DcsBios.h // -- Centipede ------------------------------- class ButtonCS : PollingInput { private: void pollInput(); char* msg_; char pin_; char lastState_; bool reverse_; void init_(char* msg, char pin, bool reverse); public: ButtonCS(char* msg, char pin, bool reverse) { init_(msg, pin, reverse); } ButtonCS(char* msg, char pin) { init_(msg, pin, false); } }; // -- End Centipede ------------------------------- Althow a Centipede Opject is created by Centipede CS; in A10C-CDU.ino, it failed to compile by error: 'CS' was not declared in this scope lastState_ = CS.digitalRead(pin_); Meanwhile something strange happen: While my last attept 2 hours ago fails, it compiles right now (I just wanted to copy the error message) w/o fail ????? Edit: Found reason for strange behavior: Removed for debugging 'CS.' from CS.digitalRead(pin_) in DcsBios.cpp and forgot to redo it. Anyway. Arduino's pins operating as expected. Key(s) send commands to DCS, LED (backlight atM) lights as expected. I attached complete A10C-CDU.ino and example code Include-File. Due to Forum's limitations renamed to .txt Is there anybody who knows what I did wrong?A10C-CDU.ino.txtBIOS_calls.h.txt Edited August 15, 2015 by Tekkx Manual for my version of RS485-Hardware, contact: tekkx@dresi.de Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.
FSFIan Posted August 15, 2015 Posted August 15, 2015 (edited) The reason for the "'CS' was not declared in this scope" error message is that you put your ButtonCS class into DcsBios.cpp/.h. Each .cpp file is compiled separately from everything else (this is called a "translation unit" in C++), so when compiling the ButtonCS class, it does not know about the 'CS' variable. Solution: revert changes to DcsBios.cpp/.h and put your ButtonCS class into the same file where you declare the CS variable, so the beginning of your A10C-CDU.ino looks like this: #include <Centipede.h> Centipede CS; // create Centipede Object #include <DcsBios.h> #include <Servo.h> #include <Wire.h> // order of these includes seems no matter - tried different [color=red] // declaring the ButtonCS class here ensures that it has access to 'CS' namespace DcsBios { class ButtonCS : PollingInput { private: void pollInput(); char* msg_; char pin_; char lastState_; bool reverse_; void init_(char* msg, char pin, bool reverse); public: ButtonCS(char* msg, char pin, bool reverse) { init_(msg, pin, reverse); } ButtonCS(char* msg, char pin) { init_(msg, pin, false); } }; void ButtonCS::init_(char* msg, char pin, bool reverse) { msg_ = msg; pin_ = pin; CS.pinMode(pin_, INPUT_PULLUP); lastState_ = CS.digitalRead(pin_); reverse_ = reverse; } void ButtonCS::pollInput() { char state = CS.digitalRead(pin_); if (reverse_) state = !state; if (state != lastState_) { sendDcsBiosMessage(msg_, state == HIGH ? "0" : "1"); } lastState_ = state; } } [/color] /**** Make your changes after this line ****/ #include "BIOS_calls.h" // here includes (to pull error-relevant code not too far) copy-and-pastes from the DCS-BIOS/doc/contr$ Alternatively, at the top of DcsBios.cpp (or your own Arduino library .cpp file), make a promise to the compiler that 'CS' will be defined in some other translation unit: #include <Centipede.h> extern Centipede CS; In general, you should avoid modifying DcsBios.cpp/.h, because that means that you cannot compile sketches for panels that don't make use of a Centipede shield. Edited August 15, 2015 by [FSF]Ian DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
Tekkx Posted August 16, 2015 Author Posted August 16, 2015 Ian;2452401'] In general, you should avoid modifying DcsBios.cpp/.h, ... This I understood after reading your first lines :) Hope, you'll become a teacher or Uni-Professor. So the next generation will be safe :D After I did recommended changes, Arduino IDE compiles w/o error. But PC lost connection to Leonardo. I'm afraid it died this night. Have to make further checks. I pray for a broken cable :unsure: Manual for my version of RS485-Hardware, contact: tekkx@dresi.de Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.
Tekkx Posted August 16, 2015 Author Posted August 16, 2015 (edited) My prayer for broken cables was rejected :( Sth's wrong with my sketch. After reset the Leo it apears a short time as Leonardo Bootloader at COMxx (different to recent). If I upload (timing is the goal!) an other shurely working sketch it behaves normal. Than I flash the A10C-CDU.ino and the board disappeares from the radar. Means: Device-manager. So has an old donkey to learn dancing. Means: Serial Communication. I'm now at Zero Level. Edited August 16, 2015 by Tekkx Manual for my version of RS485-Hardware, contact: tekkx@dresi.de Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.
FSFIan Posted August 16, 2015 Posted August 16, 2015 (edited) On the Leonardo, the USB connection is handled by the same chip that runs your sketch. That means if you manage to program a buffer overflow somewhere and mess up the rest of the memory, it also interferes with the code that communicates with the PC. Welcome to the world of embedded systems development, where sometimes your only way to debug stuff is to stare at your code until the error jumps out at you... EDIT: The good news is that your Leonardo board is not broken. Edited August 16, 2015 by [FSF]Ian DCS-BIOS | How to export CMSP, RWR, etc. through MonitorSetup.lua
Tekkx Posted August 16, 2015 Author Posted August 16, 2015 (edited) Ian;2452808']...where sometimes your only way to debug stuff is to stare at your code until the error jumps out at you... That's exactly what I'm doing right now (instead of managing the dishwasher) :) I found out (by deactivating different parts of code) COM-interface (sorry for this term) crashes if pointer(?) shows at example!: DcsBios::ButtonCS cdu1("CDU_1", 50); If I comment just these examples compiling runs fine. I suspect a interference between I2C and Serial??? (Just a naiv thought of a novice). Maybe Centipede needs some special treatment. Copying class is the wrong way, maybe. And: I never suspected Leonardo itself. :) Edited August 17, 2015 by Tekkx Manual for my version of RS485-Hardware, contact: tekkx@dresi.de Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.
Tekkx Posted August 17, 2015 Author Posted August 17, 2015 (edited) This morning (think, I dreamed about before) I made some other tests. I remember my first breakthru in Arduino: Converting an Leonardo into a Keyboard. But I don't remember, what and how I did :( So I tried to reflash original firmware - without success. What if a Leonardo isn't a good choice - ... So I took an UNO-clone with CH340 Chip from the stack. Flashing CDU.ino (with ButtonCS-function activated) ran like hell. :) So my next step is to unscrew my CDU an replace Arduino Board. Or I find a way to reflash my Leo. (shorter way, cause there are a lot of screws and keys to remove) Edit 10 hours later: UNO and MEGA (that's what I have on stock) swallowing sketch without complaining... but after this there is no communicaton with anything. So I am at Zero. Again. Today - while working some stuff - I made some thinking: What if I2C uses same pins as DCS-BIOS? And this causes the crash? How could (I - ha ha, very funny) exclude those pins from been written (or red) by DCS-BIOS? Hands off of matters, you know nothing about. And learning curve is relatively flat ;) Edited August 17, 2015 by Tekkx Manual for my version of RS485-Hardware, contact: tekkx@dresi.de Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.
Tekkx Posted August 20, 2015 Author Posted August 20, 2015 Digged some new(?) information. Sorry for pushing this Thread, but I can't stay calm with a problem I dream about :) Since Arduino's IDE gives his Compiler's messages (I found the checkbox) I copied some relevant (so I mean) parts. Maybe some Experts find some time to analyse? BIOS_calls.h is nothing but a list of Definitions of Buttons like "DcsBios::ButtonCS cdu0("CDU_0", 6);" Wrote source after // ... In file included from A10C-CDU.ino:44: /BIOS_calls.h:4: warning: deprecated conversion from string constant to 'char*' // DcsBios::ButtonCS cdu0("CDU_0", 6); /BIOS_calls.h:5: warning: deprecated conversion from string constant to 'char*' // DcsBios::ButtonCS cdu1("CDU_1", 0); /BIOS_calls.h:6: warning: deprecated conversion from string constant to 'char*' // a.s.o /BIOS_calls.h:7: warning: deprecated conversion from string constant to 'char*' /BIOS_calls.h:8: warning: deprecated conversion from string constant to 'char*' /BIOS_calls.h:9: warning: deprecated conversion from string constant to 'char*' /BIOS_calls.h:10: warning: deprecated conversion from string constant to 'char*' A10C-CDU.ino:45: warning: deprecated conversion from string constant to 'char*' // DcsBios::Switch2Pos ufcMasterCaution("UFC_MASTER_CAUTION", 7); ... C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\wiring.c:264:3: warning: #warning Timer 2 not finished (may not be present on this CPU) C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\wiring.c:273:3: warning: #warning Timer 2 not finished (may not be present on this CPU) C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\avr-gcc -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega32u4 -DF_CPU=16000000L -MMD -DUSB_VID=0x2a03 -DUSB_PID=0x8036 -DARDUINO=1061 -IC:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\variants\leonardo C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\wiring_analog.c -o C:\Users\DRESI\AppData\Local\Temp\build2894492727778002659.tmp\wiring_analog.c.o ... C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\wiring.c:264:3: warning: #warning Timer 2 not finished (may not be present on this CPU) C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\wiring.c:273:3: warning: #warning Timer 2 not finished (may not be present on this CPU) ... C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp: In function 'void store_char(unsigned char, ring_buffer*)': C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp:98: warning: comparison between signed and unsigned integer expressions C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp: In function 'void __vector_25()': C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp:153: warning: unused variable 'c' C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp: In member function 'void HardwareSerial::begin(long unsigned int, byte)': C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp:368: warning: unused variable 'current_config' C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp: In member function 'virtual size_t HardwareSerial::write(uint8_t)': C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino\HardwareSerial.cpp:467: warning: comparison between signed and unsigned integer expressions ... avrdude: ser_send(): write error: sorry no info avail Maybe it's irrelevant. But how will I know? There maybe some other interesting information inside this Log. So I attached complete output as a Textfile, althow reading this file is like counting stars... terrible.Compile-Errors.txt Manual for my version of RS485-Hardware, contact: tekkx@dresi.de Please do not PM me with DCS-BIOS-related questions. If the answer might also be useful to someone else, it belongs in a public thread where it can be discovered by everyone using the search function. Thank You.
Recommended Posts