
com.ociweb.iot.maker.Port 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.maker;
/**
* Enumeration for analog and digital ports on a device with GPIO.
*
* @author Nathan Tippy
*/
public enum Port {
A0(Port.IS_ANALOG, 0),
A1(Port.IS_ANALOG, 1),
A2(Port.IS_ANALOG, 2),
A3(Port.IS_ANALOG, 3),
D0(Port.IS_DIGITAL, 0),
D1(Port.IS_DIGITAL, 1),
D2(Port.IS_DIGITAL, 2),
D3(Port.IS_DIGITAL, 3),
D4(Port.IS_DIGITAL, 4),
D5(Port.IS_DIGITAL, 5),
D6(Port.IS_DIGITAL, 6),
D7(Port.IS_DIGITAL, 7),
D8(Port.IS_DIGITAL, 8);
public final byte port;
public final byte mask;
private Port(byte mask, int number) {
this.port = (byte) number;
this.mask = mask;
}
public static final byte IS_ANALOG = 1;
public static final byte IS_DIGITAL = 2;
/**
* @return True if this port is analog, and false otherwise.
*/
public boolean isAnalog() {
return 0 != (IS_ANALOG & mask);
}
public static Port nextPort(Port p) {
int ordinal = p.ordinal() + 1;
if (ordinal == Port.values().length) return null;
return Port.values()[ordinal];
}
/**
* Array of all standard analog ports.
*/
public final static Port[] ANALOGS = {A0, A1, A2, A3};
/**
* Array of all standard digital ports.
*/
public final static Port[] DIGITALS = {D0, D1, D2, D3, D4, D5, D6, D7, D8};
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy