Package jpigpio
Class Utils
java.lang.Object
jpigpio.Utils
public class Utils
extends java.lang.Object
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
Modifier and Type Method Description static void
addShutdown(JPigpio pigpio)
Add a handler to perform a clean termination of pigpio on termination.static int
bitMask(int bit)
Calculate a bitmask of the bit.static java.lang.String
bitString(boolean value)
Return a string representation of "0" or "1" as the value of a boolean.static byte[]
bytes2nibbles(byte[] bytes)
static java.lang.String
bytesToHex(byte[] bytes)
static java.lang.String
byteToBinary(byte value)
Return a binary string representation of the byte.static int
byteWordToInt(byte[] word)
Given an array of 2 bytes, return an int representation using the 1st byte as the MSByte.static byte
clearBit(byte value, int bit)
Clear the bit within the byte.static int
clearBit(int value, int bit)
Clear the bit within the int.static java.lang.String
dumpData(byte[] data)
Dump an array of bytesstatic java.lang.String
int16ToBinary(int value)
Return a binary string representation of the first 16 bits of the integer.static boolean
isSet(byte value, int bit)
Return true if the corresponding bit of the data is set.static boolean
isSet(int value, int bit)
Return true if the corresponding bit of the data is set.static java.lang.Long
LEint2Long(byte[] bytes)
static int
mapToInt(int value, int sourceLow, int sourceHigh, int targetLow, int targetHigh)
static byte[]
nibbles2bytes(byte[] nibb)
static byte
setBit(byte value, int bit)
Set the bit within the byte.static int
setBit(int value, int bit)
Set the bit within the int.static long
tickDiff(long olderTick, long tick)
Returns the microsecond difference between two ticks.
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
addShutdown
Add a handler to perform a clean termination of pigpio on termination.- Parameters:
pigpio
- pigpio object to terminate
-
mapToInt
public static int mapToInt(int value, int sourceLow, int sourceHigh, int targetLow, int targetHigh) -
byteToBinary
public static java.lang.String byteToBinary(byte value)Return a binary string representation of the byte.- Parameters:
value
- byte to convert- Returns:
- A binary string representation of the byte.
-
int16ToBinary
public static java.lang.String int16ToBinary(int value)Return a binary string representation of the first 16 bits of the integer.- Parameters:
value
- integer to convert- Returns:
- A binary string representation of the first 16 bits of the integer.
-
byteWordToInt
public static int byteWordToInt(byte[] word)Given an array of 2 bytes, return an int representation using the 1st byte as the MSByte.- Parameters:
word
- The 2 bytes of data.- Returns:
- An int representation of the two bytes of data.
-
setBit
public static int setBit(int value, int bit)Set the bit within the int.- Parameters:
value
- The value in which to set the bit.bit
- The bit to set.- Returns:
- The new value with the bit set.
-
setBit
public static byte setBit(byte value, int bit)Set the bit within the byte.- Parameters:
value
- The value in which to set the bit.bit
- The bit to set.- Returns:
- The new value with the bit set.
-
clearBit
public static int clearBit(int value, int bit)Clear the bit within the int.- Parameters:
value
- The value in which the bit is to be cleared.bit
- The bit to clear.- Returns:
- The value with the bit cleared.
-
clearBit
public static byte clearBit(byte value, int bit)Clear the bit within the byte.- Parameters:
value
- The value in which the bit is to be cleared.bit
- The bit to clear.- Returns:
- The value with the bit cleared.
-
bitMask
public static int bitMask(int bit)Calculate a bitmask of the bit.- Parameters:
bit
- The bit to be used to calculate the bitmask.- Returns:
- The value of the bitmask.
-
isSet
public static boolean isSet(int value, int bit)Return true if the corresponding bit of the data is set.- Parameters:
value
- The data to test.bit
- The bit to examine.- Returns:
- True if the corresponding bit in the data is set.
-
isSet
public static boolean isSet(byte value, int bit)Return true if the corresponding bit of the data is set.- Parameters:
value
- The data to test.bit
- The bit to examine.- Returns:
- True if the corresponding bit in the data is set.
-
dumpData
public static java.lang.String dumpData(byte[] data)Dump an array of bytes- Parameters:
data
- The data to dump- Returns:
- A string representation of the data.
-
bitString
public static java.lang.String bitString(boolean value)Return a string representation of "0" or "1" as the value of a boolean.- Parameters:
value
- A boolean to examine.- Returns:
- The string "1" is the boolean is true and "0" if the boolean is false.
-
tickDiff
public static long tickDiff(long olderTick, long tick)Returns the microsecond difference between two ticks. This function handles rollover of ticks as ticks are only 32bit. ... print(pigpio.tickDiff(4294967272, 12)) 36 ...- Parameters:
olderTick
- tick 1tick
- tick 2- Returns:
- difference between ticks
-
bytesToHex
public static java.lang.String bytesToHex(byte[] bytes) -
bytes2nibbles
public static byte[] bytes2nibbles(byte[] bytes) -
nibbles2bytes
public static byte[] nibbles2bytes(byte[] nibb) -
LEint2Long
public static java.lang.Long LEint2Long(byte[] bytes)
-