Results 1 to 3 of 3
  1. #1
    New Member
    Join Date
    Oct 2013
    Location
    Netherlands
    Posts
    2
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Working on simplified MCP

    Hi all, I'm playing around with link2fs and I really like this stuff! Arduino is not completely new to me, but I consider myself a beginner.
    I have a few questions I have not yet seen aswered.
    Let me describe the project a bit first... I use FS2004, and the Arduino UNO.
    I'm working on a very simple MCP, just one 5 digit display for altitude and a switchable 3-digit display for crs/hdg/ias/mch. That's 8 7-seg digits and a max7219 to drive 'em using SPI.
    SPI is also connected to 4x 74HC595 shift registers to give me a total of 8 digits and 32 digital outputs, using only 4 arduino pins.
    I use two additional rotary encoders to send controls to link2fs.
    I use 4x CD4021B's to give me 32 digital inputs, using another 3 arduino pins.
    (using the UNO, one gets creative )

    Maybe I didn't search right but here's my question.
    It's related to momentary/latching switches. Of course there's no problem using mom switches, If my sofware detects a switch state change it simply sends a keypress to Link2fs.

    But the AP Master switch is of the latching kind... So I want the autopilot to be engaged in one position, and disengaged in the other. I want to reach this goal using only fs2004 and link2fs.(so without FSUIPC or something)

    I try it like this:
    when the masterswitch is ON/changes state, I send a keypress to link2fs using
    Code:
    // NOT COMPLETE
    
    byte SWS1 = shiftIn(dataPin, clockPin); // i use 4 bytes (SWS1,SWS2,SWS3,SWS4) to 'save' 32 switch states.
    bool APmaster =    bitRead(SWS1,0);// hardware switchpositions come in bytes from CD4021.
    
    if(APmaster != APmasterOld){
    Serial.print("D100");
    APmasterOld=APmaster;
    }
    I make this (switch 10 low) toggle the AP in fs2004

    Then I read the serial data from link2fs and if it's "b", I check if its followed by a 1 or 0, if it return 0 and AP I send the keypress again.

    Code:
    if (Serial.available() > 0) {
    fsdata1 = Serial.read();
    if(fsdata1 == 'b'){
     delay(11);
     bool checkAP = Serial.read()- 48);
     if (APmaster != checkAP) Serial.print("D100");
    }
    I would realy like to work around the first "D100" keypress.

    In link2fs one could tick the 'refresh rate' box, but is there a posibility I could send a command to only update and send refreshed data if one of the 32 switches have changed state or one of the 4 bytes ?

    it would then change the first statement to something like this:
    Code:
    if(SWS1 !=SWS1old)
    {
    Serial.print("refresh?"); // dunno ;)
    SWS1old=SWS1;
    }
    catch my drift? haha, thanx in advance

  2. #2
    150+ Forum Groupie
    Join Date
    Apr 2011
    Location
    United States of America
    Posts
    232
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Working on simplified MCP

    Hello. Very nice read. Not only was it well written, but it was detailed about the hardware used and how it was used. Thank you. I learned a lot.


    Like yourself, I familiar with the arduino but also consider my self a noob; although, looking at your snippets, it reveals your advancement is above my level.


    At any rate, I assume you have to press the switch twice to obtain desired results only when the arduino & FS2004 are powered on or the sim is restarted. We'll just assume you didn't crash.


    Unfortunately, not as of yet, there is not a sync command from L2FS. But, what a grand idea!
    Hint.. Hint if (inBYTE = byte(2)){start sync} ; if (inBYTE = byte(3)){end sync}

    I began to write a generalized theory based on the fact that Jim's code systematically transmits each checked box in a predefined manner. That said, the refresh will always start with the same identifier - using AP as an example (i.e, "=a" for AP active) and with the same ending identifier (i.e., "=v" for AP take-off power active. )

    Knowing this, one could start a sync loop called on by demand and end it using the while statement. Unfortunately, you would have to rewrite your code because you must build a string to determine whether "=a" was sent to the arduino at the refresh; this force you to delete one serial read since the letter variable would no longer be available. You would then have to modify lines to read - if (string == "=a"){do this}

    Then, I processed it and began to wonder how would I handle if (string == "=a") outside of the refresh. Since I would be looking for "=v" to exit the refresh/sync loop, I suppose one could build a counter to exit the sync loop if it did not read "=v" in a predetermined interval.

    Therefore, unless someone produces a solution, the request for:
    if (inBYTE = byte(2)){start sync} ; if (inBYTE = byte(3)){end sync}
    may be an easier solution for the user. Perhaps not for the developer.

  3. Thanks Mattezz thanked for this post
  4. #3
    New Member
    Join Date
    Oct 2013
    Location
    Netherlands
    Posts
    2
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Working on simplified MCP

    Thanks for the reply, but since there is o command to sync we'll have to be creative.
    I know that answers might be found in 'string' usage, but I'm not very familiar with the use, so i like to convert incoming data to ints and booleans asap.

    There is another little problem I'm trying to work around...

    I use a rotary encoder to send keypresses, one press for CW rotation and one press for CCW. For example: I make the arduino send "D510" a make the keys-program type ctrl+shift+H+= to increase heading with CW rotation.
    Yes, this works great, but sure there is some delay in the readback on my 3-digit display.

    In steps this is what happens:
    1: Rotate encoder -if CW send "D510" -if CCW send "D520".

    2: if CW send keypress to fs9 to increase HDG, if CCW to decrease.

    3: if serial read of HDG changes, > update the 3-digit display

    In this matter there is a approx. 500mS delay between steps 2 and 3.

    To work around this I seem to need a lot of code, but maybe it's worth a try.

    If I turn the encoder I might set the 3-digit hardware HDG display to a value, say 185, and do a CW/CCW keypress. The keypress will update the link2fs serial output.
    If the Serial.read() returns a lower number (i.e. 184) I send the CW keypress again, if higher (i.e. 186) I send a CCW keypress. Have to repeat this untill the hardware display is in sync with the fs9-display.
    I think I will encounter a little time based problem, due to the lag of the readings from fs9, but will try to see if this works more intuitive.
    Ayone any experiebce with this issue?

    Why?
    Just to make the AP hdg easier to set for the user, me.