- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 fragment Activity 和一个 fragment 类;我正在尝试设置,以便当用户点击我的 fragment 类中的 Switch 时,oncheckchangedlistener 将软重置 IOIO-OTG 板,以允许用户动态地将 IOIO 上的引脚从输出更改为输入或反之反之亦然。
但是我不确定如何调用 ioio_.softReset();来自外部类的方法。
这里是一些相关的代码:
//sets the listener for the mode switches
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
}
});
}
下一步:
@Override
protected IOIOLooper createIOIOLooper() {
return new Looper();
}
public IOIOLooper globalLooperRetriever(){
return l1;
}
下一步:
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 < pinDigArray.length; i++) {
// if(chosePin1.getValue() == i + 1){
// pinDigArray[i].write(true);
// }
}
public IOIO getIOIOBoardInstance() {
return ioio_;
}
}
编辑:*createIOIOLooper();
方法和 BASEIOIOLOOPER 类的代码:*
package ioio.lib.util;
import ioio.lib.api.IOIO;
import ioio.lib.api.exception.ConnectionLostException;
/**
* A convenience implementation of {@link IOIOLooper}.
*
* This base class provides no-op implementations for all methods and provides
* the {@link #ioio_} field for subclasses.
*
*/
public class BaseIOIOLooper implements IOIOLooper {
protected IOIO ioio_;
@Override
public final void setup(IOIO ioio) throws ConnectionLostException,
InterruptedException {
ioio_ = ioio;
setup();
}
/**
* This method will be called as soon as connection to the IOIO has been
* established. Typically, this will include opening pins and modules using
* the openXXX() methods of the {@link #ioio_} field.
*
* @throws ConnectionLostException
* The connection to the IOIO has been lost.
* @throws InterruptedException
* The thread has been interrupted.
*/
protected void setup() throws ConnectionLostException, InterruptedException {
}
@Override
public void loop() throws ConnectionLostException, InterruptedException {
Thread.sleep(20);
}
@Override
public void disconnected() {
}
@Override
public void incompatible() {
}
}
IOIOLOOPER 类:
package ioio.lib.util;
import ioio.lib.api.IOIO;
import ioio.lib.api.exception.ConnectionLostException;
/**
* A handler implementing interaction with a single IOIO over a single
* connection period. The interface utilizes a basic workflow for working with a
* IOIO instance: as soon as a connection is established, {@link #setup(IOIO)}
* will be called. Then, the {@link #loop()} method will be called repeatedly as
* long as the connection is alive. Last, the {@link #disconnected()} method
* will be called upon losing the connection (as result of physical
* disconnection, closing the application, etc). In case a IOIO with an
* incompatible firmware is encountered, {@link #incompatible()} will be called
* instead of {@link #setup(IOIO)}, and the IOIO instance is entirely useless,
* until eventually {@link #disconnected()} gets called.
*
*/
public interface IOIOLooper {
/**
* Subclasses should override this method for performing operations to be
* done once as soon as IOIO communication is established.
*/
public abstract void setup(IOIO ioio) throws ConnectionLostException,
InterruptedException;
/**
* Subclasses should override this method for performing operations to be
* done repetitively as long as IOIO communication persists. Typically, this
* will be the main logic of the application, processing inputs and
* producing outputs.
*/
public abstract void loop() throws ConnectionLostException,
InterruptedException;
/**
* Subclasses should override this method for performing operations to be
* done once as soon as IOIO communication is lost or closed. Typically,
* this will include GUI changes corresponding to the change. This method
* will only be called if setup() has been called. The ioio argument passed
* to {@link #setup(IOIO)} must not be used from within this method - it is
* invalid. This method should not block for long, since it may cause an
* ANR.
*/
public abstract void disconnected();
/**
* Subclasses should override this method for performing operations to be
* done if an incompatible IOIO firmware is detected. The ioio argument
* passed to {@link #setup(IOIO)} must not be used from within this method -
* it is invalid. This method will only be called once, until a compatible
* IOIO is connected (i.e. {@link #setup(IOIO)} gets called).
*/
public abstract void incompatible();
}
类的 IOIO-OTG GITHUB 和 WIKI 页面的相关链接:
有关此主题的 IOIOUSERS 页面的相关链接:FORUM PAGE
编辑 2:*有关 softReset() 的相关信息;来自 IOIO.JAVA 类的方法:*
public void softReset() throws ConnectionLostException;
/**
* Equivalent to disconnecting and reconnecting the board power supply.
* <p>
* The connection will be dropped and not reestablished. Full boot sequence will take place, so
* firmware upgrades can be performed. A connection must have been established prior to calling
* this method, by invoking {@link #waitForConnect()}.
*
* @throws ConnectionLostException
* Connection was lost before or during the execution of this method.
* @see #softReset()
*/
最佳答案
假设您的 Activity 中已经有一个循环器实例这是您需要做的
定义一个接口(interface)
public interface SoftResetListener
{
void softReset();
}
在您的 Activity 中实现该接口(interface)
public class MainActivity implements SoftResetListener
{
public void softReset()
{
//replace with your looper instance
looper.getIOIOBoardInstance().softReset();
}
}
在你的 fragment 中 onCheckedChanged()
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Activity looperActivity= getActivity();
if(looperActivity instanceof SoftResetListener) {
((SoftResetListener)looperActivity).softReset();
}
}
关于java - IOIO,有没有办法调用 softreset();来自另一个类(class)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22103519/
我正在扩展 BaseIOIOLooper 以打开 UART 设备并发送消息。我正在使用回读进行测试,其中我通过一条线路发送一个数据包,并在另一条线路上接收该数据包并将其打印出来。因为我不希望 Inpu
Closed. This question is off-topic。它当前不接受答案。
我和许多其他人一样,在从 Eclipse 构建时遇到了 IOIO OTG 与 PC 连接的问题。 我们使用的是 ADT 版本的 eclipse,所有库都已正确导入。当运行 HelloIOIOConso
我有一个 fragment Activity 和一个 fragment 类;我正在尝试设置,以便当用户点击我的 fragment 类中的 Switch 时,oncheckchangedlistener
规则文件名为 50-ioio.rules,文本为: ACTION=="add", SUBSYSTEM=="tty", SUBSYSTEMS=="usb", SYMLINK+="IOIO%n", MOD
我正在尝试制作一个简单的应用程序,它在 Android 设备(Alcatel One Touch 4030D,Android 4.1.1)上运行并从 IOIO Mint 的模拟输入引脚读取数据。通过蓝
我是一名优秀的程序员,十分优秀!