I/O Module explanation

Related to the development libraries, released by Curt Binder
Post Reply
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

I/O Module explanation

Post by binder »

I'm a little confused about the values that the I/O module return and how it is interpreted. I've found some example codes that show that if the value returned from IO.GetChannel(channel) is 1 (or greater than 0 for that matter), that an error has occurred or the channel has been tripped/activated/etc.
I follow that.

Now, my question has to do with displaying it inside an application (Android Reef Angel Status).
The libraries do a bitRead on the port to get the value. I have things separated out in the application and perform the same action. So if the value is 1 for the channel, I return true (same as 1) otherwise I return false (same as 0).

On my I/O page, I have a label set to be OFF if the value is 1 and ON if the value is 0. Is this correct or should I have things flipped?
Here's my code in question:

Code: Select all

public static boolean getIOChannel ( short ioChannels, byte channel ) {
	// channel is 0 based
	int v = (1 << channel);
	int w = (ioChannels & v);
	boolean f = w == v;
	return f;
}

//... other code goes here. 
if ( Controller.getIOChannel( ioports, channel ) ) {
	s = getString( R.string.labelOFF );
} else {
	s = getString( R.string.labelON );
}
The getIOChannel function call is listed at the top. Then at the bottom, my logic for displaying the values.
I just want to make sure that I have it coded and displaying properly for people using the I/O module.

Lastly, I'm adding in notifications and if getIOChannel returns true (or 1), I'm going to return 1 for comparison just like the other code samples are shown.
rimai
Posts: 12881
Joined: Fri Mar 18, 2011 6:47 pm

Re: I/O Module explanation

Post by rimai »

A 1 indicates the channel is open, which means not active. When the float is active, it will return 0.
So, it looks like your code is correct.
Roberto.
binder
Posts: 2871
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: I/O Module explanation

Post by binder »

rimai wrote:A 1 indicates the channel is open, which means not active. When the float is active, it will return 0.
So, it looks like your code is correct.
Excellent. I just wanted to have some clarification to make sure I was coding things properly and to make sure I fully understood. :)
Post Reply