
com.ociweb.iot.grove.simple_digital.SimpleDigitalTransducer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of foglight Show documentation
Show all versions of foglight Show documentation
FogLight is a lightweight runtime that enables makers of all ages and skill levels to create highly
performant apps for embedded devices like Raspberry Pi's.
The newest version!
package com.ociweb.iot.grove.simple_digital;
import java.util.ArrayList;
import com.ociweb.iot.maker.DigitalListener;
import com.ociweb.iot.maker.FogCommandChannel;
import com.ociweb.iot.maker.IODeviceTransducer;
import com.ociweb.iot.maker.Port;
/**
*
* @author Ray Lo
*
*/
public class SimpleDigitalTransducer implements IODeviceTransducer, DigitalListener {
private final FogCommandChannel ch;
private final Port p;
private final ArrayList simpleDigListeners;
public SimpleDigitalTransducer(FogCommandChannel ch, Port p, SimpleDigitalListener... dl){
ch.ensurePinWriting();
this.ch = ch;
this.p = p;
simpleDigListeners = new ArrayList();
int i = dl.length;
while (--i >= 0 ){
simpleDigListeners.add(dl[i]);
}
}
/**
* Puts onto the {@link FogCommandChannel} a high or low value for the simple digital device.
* @param val the boolean value to be sent, true is high and false is low.
* @return true if command was put onto the {@link FogCommandChannel}
*/
public boolean setValue(boolean val){
return ch.setValue(p, val);
}
/**
* Puts onto the {@link FogCommandChannel} a high or low value for the simple digital device and blocks the channel.
* @param val the boolean value to be sent, true is high and false is low.
* @param durationMillis the number of milliseconds to block the channel for. Other channels will be uanffected.
* @return true if command was put onto the {@link FogCommandChannel}
*/
public boolean setValueAndBlock(boolean val, long durationMillis){
return ch.setValueAndBlock(p, val, durationMillis);
}
@Override
public void digitalEvent(Port port, long time, long durationMillis, int value) {
int i = simpleDigListeners.size();
while (--i >= 0){
simpleDigListeners.get(i).simpleDigitalEvent(port, time, durationMillis, value);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy