Chiong Ching Lai do you have an example of this?

On Saturday, March 1, 2014 1:01:30 AM UTC-6, Chiong Ching Lai wrote:
>
> I have done the same thing, though slightly different. What you need to be 
> careful is:
> 1. Every time you switch between input and output, you need to close the 
> pin and reopen it in the new input/output mode.
> 2. Since the DigitalOutput/DigitalInput object will change depending on 
> your switches, you need to make sure that the pin are not being switched to 
> input/output when other thread is still reading/writing the pin.
>
>
>
> On Saturday, 1 March 2014 01:39:38 UTC+8, Tim Frisch wrote:
>>
>> I have some switches in a fragment page that are toggling a boolean value 
>> that should determine the pin's mode (Whether it be input or output).
>>
>> Here is some of the relevant code:
>>
>> *THE ARRAY OF SWITCHES AND THEIR LISTENER:*
>> for(int i = 0; i<digitalIOModeSwitchArray.length;i++){
>> digitalIOModeSwitchArray[i].setOnCheckedChangeListener(new 
>> OnCheckedChangeListener() {
>>  @Override
>> public void onCheckedChanged(CompoundButton buttonView, boolean 
>> isChecked) {
>> // TODO Auto-generated method stub
>> try {
>> MainActivity.globalLooperRetriever().getIOIOBoardInstance().hardReset();
>> } catch (ConnectionLostException e) {
>> // TODO Auto-generated catch block
>> e.printStackTrace();
>> }
>> }
>> });
>> }
>> __________________________________________________________
>> *THE globalLooperRetriever METHOD AND l1 LOOPER VARIABLE:*
>> *      IOIOLooper l1;*
>> protected IOIOLooper createIOIOLooper() {
>> l1 = new Looper();
>> return l1;
>> }
>>
>> public static Looper globalLooperRetriever(){
>> return l1;
>> }
>> __________________________________________________________
>> THE LOOPER.JAVA CLASS:
>> package com.example.ioiorun;
>>
>> import ioio.lib.api.DigitalInput;
>> import ioio.lib.api.DigitalOutput;
>> import ioio.lib.api.IOIO;
>> import ioio.lib.api.exception.ConnectionLostException;
>> import ioio.lib.util.BaseIOIOLooper;
>>
>> public class Looper extends BaseIOIOLooper {
>> digitalFragment digitalFragmentObject;
>> // The variable digitalIOs
>> private DigitalOutput digitalO0;
>> private DigitalInput digitalI0;
>> private DigitalOutput digitalO1;
>> private DigitalInput digitalI1;
>> private DigitalOutput digitalO2;
>> private DigitalInput digitalI2;
>> private DigitalOutput digitalO3;
>> private DigitalInput digitalI3;
>> private DigitalOutput digitalO4;
>> private DigitalInput digitalI4;
>> private DigitalOutput digitalO5;
>> private DigitalInput digitalI5;
>> private DigitalOutput digitalO6;
>> private DigitalInput digitalI6;
>> private DigitalOutput digitalO7;
>> private DigitalInput digitalI7;
>> private DigitalOutput digitalO8;
>> private DigitalInput digitalI8;
>> private DigitalOutput digitalO9;
>> private DigitalInput digitalI9;
>>
>> // The strictly digital-inputs.
>> private DigitalInput digitalInput0;
>> private DigitalInput digitalInput1;
>> private DigitalInput digitalInput2;
>> private DigitalInput digitalInput3;
>> private DigitalInput digitalInput4;
>>
>> private DigitalOutput[] digitalOArray = { digitalO0, digitalO1,
>> digitalO2, digitalO3, digitalO4, digitalO5, digitalO6,
>> digitalO7, digitalO8, digitalO9 };
>>
>> private DigitalInput[] digitalIArray = { digitalI0, digitalI1,
>> digitalI2, digitalI3, digitalI4, digitalI5, digitalI6,
>> digitalI7, digitalI8, digitalI9 };
>>
>> private DigitalInput[] digitalInputArray = { digitalInput0,
>> digitalInput1, digitalInput2, digitalInput3, digitalInput4 };
>>
>> /**
>>  * Called every time a connection with IOIO has been established.
>>  * Typically used to open pins.
>>  * 
>>  * @throws ConnectionLostException
>>  *             When IOIO connection is lost.
>>  * 
>>  * @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#setup()
>>  */
>> @Override
>> protected void setup() throws ConnectionLostException {
>> for(int i = 0; i<digitalOArray.length; i++){
>> if(digitalFragmentObject.getIOModeSwitch(i).isActivated()){
>> digitalOArray[i] = ioio_.openDigitalOutput(i + 9);
>> }else{
>> digitalIArray[i] = ioio_.openDigitalInput(i + 9);
>> }
>> }
>> for(int i = 0; i<digitalInputArray.length;i++){
>> digitalInputArray[i] = ioio_.openDigitalInput(i + 9);
>> }
>>  // for (int i = 0; i < pinArray.length; i++) {
>> // pinArray[i] = ioio_.openDigitalOutput(i + 1, false);
>> // }
>> }
>>
>> /**
>>  * Called repetitively while the IOIO is connected.
>>  * 
>>  * @throws ConnectionLostException
>>  *             When IOIO connection is lost.
>>  * 
>>  * @see ioio.lib.util.AbstractIOIOActivity.IOIOThread#loop()
>>  */
>> @Override
>> public void loop() throws ConnectionLostException {
>> // led_.write(!button_.isChecked());
>> try {
>> Thread.sleep(100);
>> } catch (InterruptedException e) {
>> }
>> for(int i = 0; i < digitalOArray.length;i++){
>>
>> digitalOArray[i].write(digitalFragmentObject.getIOPowerSwitch(i).isActivated());
>> }
>> // for (int i = 0; i < pinDigArray.length; i++) {
>> // if(chosePin1.getValue() == i + 1){
>> // pinDigArray[i].write(true);
>> // }
>>
>> }
>> public IOIO getIOIOBoardInstance(){
>> return ioio_;
>> }
>> }
>> __________________________________________________________________
>>
>>
>> Essentially I want to listen that the switches on the fragment page are 
>> changed and thus the looper should reset itself and re-open the pins as 
>> inputs or outputs corresponding to the switches... any ideas why this 
>> implementation does not work? Thanks.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"ioio-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/ioio-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to