GPIO control.
Bug fix.
This commit is contained in:
@@ -79,6 +79,7 @@ public class GPIO {
|
|||||||
* @param pin GPIO pin number
|
* @param pin GPIO pin number
|
||||||
* @return "in" if the pin is input, "out" if the pin is output, "unknown" if the direction is unknown
|
* @return "in" if the pin is input, "out" if the pin is output, "unknown" if the direction is unknown
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public static String GetPinDirection(@NotNull RaspberryPi5BPins pin){
|
public static String GetPinDirection(@NotNull RaspberryPi5BPins pin){
|
||||||
Path pinPath = gpioPath.resolve("gpio"+pin.gpionumber).resolve("direction");
|
Path pinPath = gpioPath.resolve("gpio"+pin.gpionumber).resolve("direction");
|
||||||
if (pinPath.toFile().isFile()){
|
if (pinPath.toFile().isFile()){
|
||||||
@@ -124,13 +125,14 @@ public class GPIO {
|
|||||||
* @param isON true to set the pin value to 1, false to set the pin value to 0
|
* @param isON true to set the pin value to 1, false to set the pin value to 0
|
||||||
* @return true if the value is successfully set
|
* @return true if the value is successfully set
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
public static boolean SetValue(@NotNull RaspberryPi5BPins pin, boolean isON){
|
public static boolean SetValue(@NotNull RaspberryPi5BPins pin, boolean isON){
|
||||||
Path pinPath = gpioPath.resolve("gpio"+pin.gpionumber).resolve("value");
|
Path pinPath = gpioPath.resolve("gpio"+pin.gpionumber).resolve("value");
|
||||||
if (pinPath.toFile().isFile()){
|
if (pinPath.toFile().isFile()){
|
||||||
if (Files.isWritable(pinPath)){
|
if (Files.isWritable(pinPath)){
|
||||||
try{
|
try{
|
||||||
Files.write(pinPath, isON?"1".getBytes():"0".getBytes());
|
Files.write(pinPath, isON?"1".getBytes():"0".getBytes());
|
||||||
Logger.info("Pin "+pin.pin+" value set to "+(isON?"1":"0"));
|
//Logger.info("Pin "+pin.pin+" value set to "+(isON?"1":"0"));
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
Logger.error("Failed to set pin value: "+pin.pin+", Message: "+e.getMessage());
|
Logger.error("Failed to set pin value: "+pin.pin+", Message: "+e.getMessage());
|
||||||
@@ -145,6 +147,7 @@ public class GPIO {
|
|||||||
* @param pin GPIO pin number
|
* @param pin GPIO pin number
|
||||||
* @return "1" if the pin value is 1, "0" if the pin value is 0, "unknown" if the value is unknown
|
* @return "1" if the pin value is 1, "0" if the pin value is 0, "unknown" if the value is unknown
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public static String GetValue(@NotNull RaspberryPi5BPins pin){
|
public static String GetValue(@NotNull RaspberryPi5BPins pin){
|
||||||
Path pinPath = gpioPath.resolve("gpio"+pin.gpionumber).resolve("value");
|
Path pinPath = gpioPath.resolve("gpio"+pin.gpionumber).resolve("value");
|
||||||
if (pinPath.toFile().isFile()){
|
if (pinPath.toFile().isFile()){
|
||||||
|
|||||||
@@ -212,9 +212,11 @@ public class WebServer {
|
|||||||
socketConfig = new Configuration();
|
socketConfig = new Configuration();
|
||||||
socketConfig.setHostname("0.0.0.0");
|
socketConfig.setHostname("0.0.0.0");
|
||||||
socketConfig.setPort(3001);
|
socketConfig.setPort(3001);
|
||||||
|
|
||||||
socketServer = new SocketIOServer(socketConfig);
|
socketServer = new SocketIOServer(socketConfig);
|
||||||
socketServer.addConnectListener(connectListener);
|
socketServer.addConnectListener(connectListener);
|
||||||
socketServer.addDisconnectListener(disconnectListener);
|
socketServer.addDisconnectListener(disconnectListener);
|
||||||
|
|
||||||
socketServer.addNamespace("/socketio").addEventListener("message", String.class, (client, data, ackSender) -> {
|
socketServer.addNamespace("/socketio").addEventListener("message", String.class, (client, data, ackSender) -> {
|
||||||
//Logger.info("SocketIO message from namespace /socketio from {}: {}", client.getRemoteAddress(), data);
|
//Logger.info("SocketIO message from namespace /socketio from {}: {}", client.getRemoteAddress(), data);
|
||||||
WebsocketCommand command = gson.fromJson(data, WebsocketCommand.class);
|
WebsocketCommand command = gson.fromJson(data, WebsocketCommand.class);
|
||||||
|
|||||||
@@ -55,6 +55,22 @@ public class Main {
|
|||||||
if (vapixProtocol!=null) vapixProtocol.Close();
|
if (vapixProtocol!=null) vapixProtocol.Close();
|
||||||
if (timer!=null) timer.cancel();
|
if (timer!=null) timer.cancel();
|
||||||
if (gpioExecutor!=null) gpioExecutor.shutdown();
|
if (gpioExecutor!=null) gpioExecutor.shutdown();
|
||||||
|
if (AmplifierPower!=null) {
|
||||||
|
Logger.info("GPIO pin {} unexport : {}",AmplifierPower.pin, GPIO.UnexportPin(AmplifierPower));
|
||||||
|
}
|
||||||
|
if (LedWeb!=null) {
|
||||||
|
Logger.info("GPIO pin {} unexport : {}", LedWeb.pin,GPIO.UnexportPin(LedWeb));
|
||||||
|
}
|
||||||
|
if (LedIpCamera!=null) {
|
||||||
|
Logger.info("GPIO pin {} unexport : {}", LedIpCamera.pin, GPIO.UnexportPin(LedIpCamera));
|
||||||
|
}
|
||||||
|
if (LedPanTilt!=null) {
|
||||||
|
Logger.info("GPIO pin {} unexport : {}", LedPanTilt.pin,GPIO.UnexportPin(LedPanTilt));
|
||||||
|
}
|
||||||
|
if (Max485Direction!=null) {
|
||||||
|
Logger.info("GPIO pin {} unexport : {}", Max485Direction.pin, GPIO.UnexportPin(Max485Direction));
|
||||||
|
}
|
||||||
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
init_gpio();
|
init_gpio();
|
||||||
|
|||||||
Reference in New Issue
Block a user