Jump to content
The simFlight Network Forums
Abdullah Radwan

How to read radio audio switches

Recommended Posts

After playing a lot, here is working code:

byte audioSelection;

FSUIPC_Read(0x3122, 1, &audioSelection, &error);
int comSelection = 0;
if(audioSelection >= 128) comSelection = 1; //Com 1
else comSelection = 2; //Com 2

 

Share this post


Link to post
Share on other sites
1 hour ago, Abdullah Radwan said:

After playing a lot, here is working code:

Well done. But in general, when you want to test one "bit" in a byte, you'd use:

if (x & mask) ...

where x is the value you've read, and "mask" is the value of the bit( you want to test for. So in your case:

if (audioSelection & 128)
  for COM1, and

if (audioSelection & 64)
  for COM2

There are other bits for the other audio switches.

Bit values are derived from evaluation 2 to the power n, i.e. 2 times 2 'n' number of times, with the special-seeming case that 0 results always in the value 1. So:

bit 0 = 1
bit 1 = 2
bit 2 = 4
bit 3 = 8
bit 4 = 16
bit 5 = 32
bit 6 = 64
bit 7 = 128

For more about bits, see the FAQ subforum help thread entitled
About bits, numbers and hexadecimal

Pete

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.