diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/ActiveBuzzerController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/ActiveBuzzerController.java index 8fbaaeba..6e1c9fe9 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/ActiveBuzzerController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/ActiveBuzzerController.java @@ -9,7 +9,6 @@ //tag::ex[] @Controller("/active-buzzer") public class ActiveBuzzerController { - private final ActiveBuzzerHelper activeBuzzerHelper; public ActiveBuzzerController(@Named("active-buzzer") Pwm activeBuzzerOutput){ @@ -29,7 +28,6 @@ public void enableActiveBuzzer(){ /** * Disables the active buzzer */ - @Get("/disable") public void disableActiveBuzzer(){ diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/LEDController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/LEDController.java index 5c037b5c..c211abe6 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/LEDController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/LEDController.java @@ -5,10 +5,13 @@ import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import jakarta.inject.Named; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; //tag::ex[] @Controller("/led") public class LEDController { + private static final Logger log = LoggerFactory.getLogger(LEDController.class); private final LEDHelper ledHelper; public LEDController(@Named("led")DigitalOutput led){ @@ -17,22 +20,38 @@ public LEDController(@Named("led")DigitalOutput led){ @Get("/ledOn") public void ledOn(){ - ledHelper.ledOn(); + try { + ledHelper.ledOn(); + } catch (Exception e) { + log.error("Error turning on LED", e); + } } @Get("/ledOff") public void ledOff(){ - ledHelper.ledOff(); + try { + ledHelper.ledOff(); + } catch (Exception e) { + log.error("Error turning off LED", e); + } } @Get("/switchState") public void switchState(){ - ledHelper.switchState(); + try { + ledHelper.switchState(); + } catch (Exception e) { + log.error("Error switching LED state", e); + } } @Get("/blink/{duration}/") public void blink(int duration){ - ledHelper.blink(duration); + try { + ledHelper.blink(duration); + } catch (Exception e) { + log.error("Error blinking LED", e); + } } } //end::ex[] \ No newline at end of file diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/MicroSwitchController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/MicroSwitchController.java index 4f7791ea..64226707 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/MicroSwitchController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/MicroSwitchController.java @@ -7,17 +7,17 @@ import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import jakarta.inject.Named; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; //tag::ex[] @Controller("/microSwitch") -public class MicroSwitchController { - +public class MicroSwitchController { + private static final Logger log = LoggerFactory.getLogger(MicroSwitchController.class); private final MicroSwitchHelper microSwitchHelper; - private final LEDHelper ledHelper1; private final LEDHelper ledHelper2; - public MicroSwitchController(@Named("micro-switch") DigitalInput microSwitch, @Named("led") DigitalOutput led1, @Named("led2") DigitalOutput led2) { @@ -25,18 +25,20 @@ public MicroSwitchController(@Named("micro-switch") DigitalInput microSwitch, this.ledHelper1 = new LEDHelper(led1); this.ledHelper2 = new LEDHelper(led2); } -//enables the micro switch. The LEDs will switch states as the switch is pressed + //enables the micro switch. The LEDs will switch states as the switch is pressed @Get("/enable") public void enableMicroSwitch() { microSwitchHelper.addEventListener(e -> { - if (microSwitchHelper.isPressed) { - ledHelper1.ledOff(); - ledHelper2.ledOn(); - - } - else { - ledHelper1.ledOn(); - ledHelper2.ledOff(); + try { + if (microSwitchHelper.isPressed) { + ledHelper1.ledOff(); + ledHelper2.ledOn(); + } else { + ledHelper1.ledOn(); + ledHelper2.ledOff(); + } + } catch (Exception ex) { + log.error("Error switching LED state", ex); } }); } diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/MultiCompController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/MultiCompController.java index 9291ae42..f918b408 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/MultiCompController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/MultiCompController.java @@ -14,13 +14,9 @@ @Controller("/multi") public class MultiCompController { private static final Logger log = LoggerFactory.getLogger(MultiCompController.class); - private final LEDHelper ledHelper; - private final LEDHelper ledHelper2; - private final PushButtonHelper button1; - private final PushButtonHelper button2; public MultiCompController(@Named("led") DigitalOutput led1, @@ -35,12 +31,20 @@ public MultiCompController(@Named("led") DigitalOutput led1, @Post("/led1") public void switch1(){ - ledHelper.switchState(); + try { + ledHelper.switchState(); + } catch (Exception e) { + log.error("Failed to switch LED1 state", e); + } } @Post("/led2") public void switch2(){ - ledHelper2.switchState(); + try { + ledHelper2.switchState(); + } catch (Exception e) { + log.error("Failed to switch LED2 state", e); + } } @Get("/button1") @@ -48,7 +52,11 @@ public void button1(){ button1.addEventListener(e ->{ log.info(String.valueOf(button1.isPressed)); if(button1.isPressed){ - ledHelper.switchState(); + try { + ledHelper.switchState(); + } catch (Exception ex) { + log.error("Failed to switch LED1 state via Button1", ex); + } } }); } @@ -57,7 +65,11 @@ public void button1(){ public void button2(){ button2.addEventListener(e ->{ if(button2.isPressed){ - ledHelper.switchState(); + try { + ledHelper2.switchState(); + } catch (Exception ex) { + log.error("Failed to switch LED2 state via Button2", ex); + } } }); } diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/PIRSensorController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/PIRSensorController.java index 4e0ded9a..563bcb89 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/PIRSensorController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/PIRSensorController.java @@ -11,12 +11,12 @@ /** * The PIRSensorController class is used with the PIRSensorHelper class and RGBHelper class to implement a PIR motion sensor with an RGB LED light. */ - //tag::ex[] @Controller("/pirSensor") public class PIRSensorController { private final PIRSensorHelper pirSensorHelper; private final RGBLEDHelper rgbledHelper; + /** * The PirSensorController constructor. * @param pirSensor A Pi4J DigitalInput object. diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/PassiveBuzzerController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/PassiveBuzzerController.java index eb695fdc..9748ab4b 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/PassiveBuzzerController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/PassiveBuzzerController.java @@ -9,11 +9,9 @@ //tag::ex[] @Controller("/passive-buzzer") public class PassiveBuzzerController { - private final PassiveBuzzerHelper passiveBuzzerHelper; protected int passBuzzFreq = 440; - protected int passBuzzDC = 50; public PassiveBuzzerController(@Named("passive-buzzer") Pwm passiveBuzzerOutput){ @@ -23,7 +21,6 @@ public PassiveBuzzerController(@Named("passive-buzzer") Pwm passiveBuzzerOutput) /** * Enables passive buzzer */ - @Get("/enable") public void enablePassiveBuzzer(){ @@ -45,7 +42,6 @@ public void disablePassiveBuzzer(){ * * Displays the current frequency of the passive buzzer. */ - @Get("/showFreq") public void passiveBuzzerFreq(){ diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/PhotoResistorController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/PhotoResistorController.java index c81dfcea..a8ec0704 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/PhotoResistorController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/PhotoResistorController.java @@ -9,12 +9,14 @@ import io.micronaut.http.annotation.Post; import jakarta.inject.Named; import javax.validation.constraints.Positive; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; //tag::ex[] @Controller("/photoResistor") public class PhotoResistorController { + private static final Logger log = LoggerFactory.getLogger(PhotoResistorController.class); private final LEDHelper ledHelper; - private final PhotoResistorHelper photoResistorHelper; public PhotoResistorController(@Named("photo-resistor-input")DigitalInput photoResistorIN, @@ -29,11 +31,14 @@ public PhotoResistorController(@Named("photo-resistor-input")DigitalInput photoR public int enableLightSensor(){ photoResistorHelper.initialize(); photoResistorHelper.addEventListener(e -> { - if (photoResistorHelper.isDark) { - ledHelper.ledOn(); - } - else { - ledHelper.ledOff(); + try { + if (photoResistorHelper.isDark) { + ledHelper.ledOn(); + } else { + ledHelper.ledOff(); + } + } catch (Exception ex) { + log.error("Error switching LED state", ex); } }); return photoResistorHelper.getDark(); diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/PushButtonController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/PushButtonController.java index 4c735a70..d1c6500c 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/PushButtonController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/PushButtonController.java @@ -7,13 +7,14 @@ import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import jakarta.inject.Named; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; //tag::ex[] @Controller("/pushButton") public class PushButtonController { - + private static final Logger log = LoggerFactory.getLogger(PushButtonController.class); private final PushButtonHelper pushButtonHelper; - private final LEDHelper ledHelper; public PushButtonController(@Named("button-input-3") DigitalInput pushButton, @@ -26,7 +27,11 @@ public PushButtonController(@Named("button-input-3") DigitalInput pushButton, public void initController(){ pushButtonHelper.addEventListener(e ->{ if(pushButtonHelper.isPressed){ - ledHelper.switchState(); + try { + ledHelper.switchState(); + } catch (Exception ex) { + log.error("Failed to switch LED state.", ex); + } } }); } diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/ServoMotorController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/ServoMotorController.java index 2d433690..20903f4a 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/ServoMotorController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/ServoMotorController.java @@ -9,7 +9,6 @@ //tag::ex[] @Controller("/servoMotor") public class ServoMotorController { - private final ServoMotorHelper servoMotorHelper; public ServoMotorController(@Named("servo-motor")Pwm servoMotor) { diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/SlideSwitchController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/SlideSwitchController.java index b4bf3cf0..930931a8 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/SlideSwitchController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/SlideSwitchController.java @@ -10,7 +10,6 @@ @Controller("/slideSwitch") public class SlideSwitchController { private final SlideSwitchHelper slideSwitchHelper; - private final SlideSwitchHelper slideSwitchHelper2; public SlideSwitchController(@Named("slide-switch-input")DigitalInput slideSwitch, diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/TiltSwitchController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/TiltSwitchController.java index 4a1847c8..ecebf253 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/TiltSwitchController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/TiltSwitchController.java @@ -7,11 +7,13 @@ import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import jakarta.inject.Named; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; //tag::ex[] @Controller("/tiltSwitch") public class TiltSwitchController { - + private static final Logger log = LoggerFactory.getLogger(TiltSwitchController.class); private final TiltSwitchHelper tiltSwitchHelper; // controls the tilt switch private final LEDHelper ledHelper; // controls the LED @@ -26,11 +28,14 @@ public TiltSwitchController(@Named("tilt-switch-input")DigitalInput tiltSwitch, @Get("/enable") public void enableTiltSwitch() { tiltSwitchHelper.addEventListener(e -> { - if (tiltSwitchHelper.isTilted) { - ledHelper.ledOn(); - } - else { - ledHelper.ledOff(); + try { + if (tiltSwitchHelper.isTilted) { + ledHelper.ledOn(); + } else { + ledHelper.ledOff(); + } + } catch (Exception ex) { + log.error("Error switching LED state", ex); } }); } diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/TouchSwitchController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/TouchSwitchController.java index fa1b8d29..644393d2 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/TouchSwitchController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/TouchSwitchController.java @@ -7,13 +7,14 @@ import io.micronaut.http.annotation.Controller; import io.micronaut.http.annotation.Get; import jakarta.inject.Named; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; //tag::ex[] @Controller("/touchSwitch") public class TouchSwitchController { - + private static final Logger log = LoggerFactory.getLogger(TouchSwitchController.class); private final TouchSwitchHelper touchSwitchHelper; - private final LEDHelper ledHelper; public TouchSwitchController(@Named("touch-switch-input") DigitalInput touchSwitch, @@ -25,11 +26,14 @@ public TouchSwitchController(@Named("touch-switch-input") DigitalInput touchSwit @Get("/enable") public void enableTouchSwitch() { touchSwitchHelper.addEventListener(e -> { - if (touchSwitchHelper.isTouched) { - ledHelper.ledOn(); - } - else { - ledHelper.ledOff(); + try { + if (touchSwitchHelper.isTouched) { + ledHelper.ledOn(); + } else { + ledHelper.ledOff(); + } + } catch (Exception ex) { + log.error("Error switching LED state", ex); } }); } diff --git a/components/src/main/java/com/opensourcewithslu/components/controllers/UltraSonicSensorController.java b/components/src/main/java/com/opensourcewithslu/components/controllers/UltraSonicSensorController.java index 664eed53..1661c13d 100644 --- a/components/src/main/java/com/opensourcewithslu/components/controllers/UltraSonicSensorController.java +++ b/components/src/main/java/com/opensourcewithslu/components/controllers/UltraSonicSensorController.java @@ -1,6 +1,5 @@ package com.opensourcewithslu.components.controllers; - import com.opensourcewithslu.inputdevices.UltraSonicSensorHelper; import com.pi4j.io.gpio.digital.DigitalInput; import com.pi4j.io.gpio.digital.DigitalOutput; @@ -8,11 +7,9 @@ import io.micronaut.http.annotation.Get; import jakarta.inject.Named; - //tag::ex[] @Controller("/ultraSound") public class UltraSonicSensorController { - private final UltraSonicSensorHelper ultraSonicSensorHelper; public UltraSonicSensorController(@Named("ultra-sonic-trig") DigitalOutput trig, @@ -21,7 +18,6 @@ public UltraSonicSensorController(@Named("ultra-sonic-trig") DigitalOutput trig, } - /** * Enables the ultrasonic sensor */ diff --git a/pi4micronaut-utils/build.gradle b/pi4micronaut-utils/build.gradle index 65c101ca..65f2680a 100644 --- a/pi4micronaut-utils/build.gradle +++ b/pi4micronaut-utils/build.gradle @@ -172,7 +172,8 @@ publishing { useInMemoryPgpKeys(System.getenv('GPG_KEY'), System.getenv('GPG_PASSWORD')) sign publishing.publications.mavenJava } - test{ + + test{ useJUnitPlatform() testLogging { events "passed", "skipped", "failed" diff --git a/pi4micronaut-utils/src/docs/javadoc/legal/COPYRIGHT b/pi4micronaut-utils/src/docs/javadoc/legal/COPYRIGHT index ca74fffd..945e19c1 100644 --- a/pi4micronaut-utils/src/docs/javadoc/legal/COPYRIGHT +++ b/pi4micronaut-utils/src/docs/javadoc/legal/COPYRIGHT @@ -1 +1,69 @@ -Please see ..\java.base\COPYRIGHT +Copyright © 1993, 2018, Oracle and/or its affiliates. +All rights reserved. + +This software and related documentation are provided under a +license agreement containing restrictions on use and +disclosure and are protected by intellectual property laws. +Except as expressly permitted in your license agreement or +allowed by law, you may not use, copy, reproduce, translate, +broadcast, modify, license, transmit, distribute, exhibit, +perform, publish, or display any part, in any form, or by +any means. Reverse engineering, disassembly, or +decompilation of this software, unless required by law for +interoperability, is prohibited. + +The information contained herein is subject to change +without notice and is not warranted to be error-free. If you +find any errors, please report them to us in writing. + +If this is software or related documentation that is +delivered to the U.S. Government or anyone licensing it on +behalf of the U.S. Government, the following notice is +applicable: + +U.S. GOVERNMENT END USERS: Oracle programs, including any +operating system, integrated software, any programs +installed on the hardware, and/or documentation, delivered +to U.S. Government end users are "commercial computer +software" pursuant to the applicable Federal Acquisition +Regulation and agency-specific supplemental regulations. As +such, use, duplication, disclosure, modification, and +adaptation of the programs, including any operating system, +integrated software, any programs installed on the hardware, +and/or documentation, shall be subject to license terms and +license restrictions applicable to the programs. No other +rights are granted to the U.S. Government. + +This software or hardware is developed for general use in a +variety of information management applications. It is not +developed or intended for use in any inherently dangerous +applications, including applications that may create a risk +of personal injury. If you use this software or hardware in +dangerous applications, then you shall be responsible to +take all appropriate fail-safe, backup, redundancy, and +other measures to ensure its safe use. Oracle Corporation +and its affiliates disclaim any liability for any damages +caused by use of this software or hardware in dangerous +applications. + +Oracle and Java are registered trademarks of Oracle and/or +its affiliates. Other names may be trademarks of their +respective owners. + +Intel and Intel Xeon are trademarks or registered trademarks +of Intel Corporation. All SPARC trademarks are used under +license and are trademarks or registered trademarks of SPARC +International, Inc. AMD, Opteron, the AMD logo, and the AMD +Opteron logo are trademarks or registered trademarks of +Advanced Micro Devices. UNIX is a registered trademark of +The Open Group. + +This software or hardware and documentation may provide +access to or information on content, products, and services +from third parties. Oracle Corporation and its affiliates +are not responsible for and expressly disclaim all +warranties of any kind with respect to third-party content, +products, and services. Oracle Corporation and its +affiliates will not be responsible for any loss, costs, or +damages incurred due to your access to or use of third-party +content, products, or services. diff --git a/pi4micronaut-utils/src/docs/javadoc/legal/LICENSE b/pi4micronaut-utils/src/docs/javadoc/legal/LICENSE index 4ad9fe40..ee860d38 100644 --- a/pi4micronaut-utils/src/docs/javadoc/legal/LICENSE +++ b/pi4micronaut-utils/src/docs/javadoc/legal/LICENSE @@ -1 +1,118 @@ -Please see ..\java.base\LICENSE +Your use of this Program is governed by the No-Fee Terms and Conditions set +forth below, unless you have received this Program (alone or as part of another +Oracle product) under an Oracle license agreement (including but not limited to +the Oracle Master Agreement), in which case your use of this Program is governed +solely by such license agreement with Oracle. + +Oracle No-Fee Terms and Conditions (NFTC) + +Definitions + +"Oracle" refers to Oracle America, Inc. "You" and "Your" refers to (a) a company +or organization (each an "Entity") accessing the Programs, if use of the +Programs will be on behalf of such Entity; or (b) an individual accessing the +Programs, if use of the Programs will not be on behalf of an Entity. +"Program(s)" refers to Oracle software provided by Oracle pursuant to the +following terms and any updates, error corrections, and/or Program Documentation +provided by Oracle. "Program Documentation" refers to Program user manuals and +Program installation manuals, if any. If available, Program Documentation may be +delivered with the Programs and/or may be accessed from +www.oracle.com/documentation. "Separate Terms" refers to separate license terms +that are specified in the Program Documentation, readmes or notice files and +that apply to Separately Licensed Technology. "Separately Licensed Technology" +refers to Oracle or third party technology that is licensed under Separate Terms +and not under the terms of this license. + +Separately Licensed Technology + +Oracle may provide certain notices to You in Program Documentation, readmes or +notice files in connection with Oracle or third party technology provided as or +with the Programs. If specified in the Program Documentation, readmes or notice +files, such technology will be licensed to You under Separate Terms. Your rights +to use Separately Licensed Technology under Separate Terms are not restricted in +any way by the terms herein. For clarity, notwithstanding the existence of a +notice, third party technology that is not Separately Licensed Technology shall +be deemed part of the Programs licensed to You under the terms of this license. + +Source Code for Open Source Software + +For software that You receive from Oracle in binary form that is licensed under +an open source license that gives You the right to receive the source code for +that binary, You can obtain a copy of the applicable source code from +https://oss.oracle.com/sources/ or http://www.oracle.com/goto/opensourcecode. If +the source code for such software was not provided to You with the binary, You +can also receive a copy of the source code on physical media by submitting a +written request pursuant to the instructions in the "Written Offer for Source +Code" section of the latter website. + +------------------------------------------------------------------------------- + +The following license terms apply to those Programs that are not provided to You +under Separate Terms. + +License Rights and Restrictions + +Oracle grants to You, as a recipient of this Program, subject to the conditions +stated herein, a nonexclusive, nontransferable, limited license to: + +(a) internally use the unmodified Programs for the purposes of developing, +testing, prototyping and demonstrating your applications, and running the +Program for Your own personal use or internal business operations; and + +(b) redistribute the unmodified Program and Program Documentation, under the +terms of this License, provided that You do not charge Your licensees any fees +associated with such distribution or use of the Program, including, without +limitation, fees for products that include or are bundled with a copy of the +Program or for services that involve the use of the distributed Program. + +You may make copies of the Programs to the extent reasonably necessary for +exercising the license rights granted herein and for backup purposes. You are +granted the right to use the Programs to provide third party training in the use +of the Programs and associated Separately Licensed Technology only if there is +express authorization of such use by Oracle on the Program's download page or in +the Program Documentation. + +Your license is contingent on compliance with the following conditions: + +- You do not remove markings or notices of either Oracle's or a licensor's + proprietary rights from the Programs or Program Documentation; + +- You comply with all U.S. and applicable export control and economic sanctions + laws and regulations that govern Your use of the Programs (including technical + data); + +- You do not cause or permit reverse engineering, disassembly or decompilation + of the Programs (except as allowed by law) by You nor allow an associated + party to do so. + +For clarity, any source code that may be included in the distribution with the +Programs is provided solely for reference purposes and may not be modified, +unless such source code is under Separate Terms permitting modification. + +Ownership + +Oracle or its licensors retain all ownership and intellectual property rights to +the Programs. + +Information Collection + +The Programs' installation and/or auto-update processes, if any, may transmit a +limited amount of data to Oracle or its service provider about those processes +to help Oracle understand and optimize them. Oracle does not associate the data +with personally identifiable information. Refer to Oracle's Privacy Policy at +www.oracle.com/privacy. + +Disclaimer of Warranties; Limitation of Liability + +THE PROGRAMS ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. ORACLE FURTHER +DISCLAIMS ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING WITHOUT LIMITATION, ANY +IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR +NONINFRINGEMENT. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL ORACLE BE LIABLE TO YOU FOR +DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES +ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT +LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. diff --git a/pi4micronaut-utils/src/test/java/com/opensourcewithslu/inputdevices/PushButtonHelperTests.java b/pi4micronaut-utils/src/test/java/com/opensourcewithslu/inputdevices/PushButtonHelperTests.java new file mode 100644 index 00000000..b9000bc2 --- /dev/null +++ b/pi4micronaut-utils/src/test/java/com/opensourcewithslu/inputdevices/PushButtonHelperTests.java @@ -0,0 +1,43 @@ +package com.opensourcewithslu.inputdevices; + +import static org.junit.jupiter.api.Assertions.*; + +import com.opensourcewithslu.mock.MockDigitalInput; +import com.pi4j.io.gpio.digital.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class PushButtonHelperTests { + + @org.junit.jupiter.api.Test + /* This test simulates the push button in a LOW state without connecting to the actual hardware. + It ensures that when the button input is LOW, the 'isPressed' state is correctly identified as false. + */ + void initializeStateLow() { + Logger log = LoggerFactory.getLogger(PushButtonHelper.class); // + MockDigitalInput input = new MockDigitalInput(); // Mock input for the button + input.SetState(DigitalState.LOW); // Simulate button in the LOW state + PushButtonHelper helper = new PushButtonHelper(input); // + assertFalse(helper.isPressed); // Button is not pressed when input is LOW + } + + @org.junit.jupiter.api.Test + /* + This test simulates the push button in a HIGH state. + It verifies that when the button input is HIGH, the 'IsPressed' state is correctly identified as true. + */ + void initializeStateHigh() { + MockDigitalInput input = new MockDigitalInput(); + input.SetState(DigitalState.HIGH); // Simulate button in the HIGH state + PushButtonHelper helper = new PushButtonHelper(input); + assertTrue(helper.isPressed); // Button is pressed when input is HIGH + } + + @org.junit.jupiter.api.Test + /* + Placeholder for testing even listener functionality. + */ + void addEventListener() { + + } +} \ No newline at end of file diff --git a/pi4micronaut-utils/src/test/java/com/opensourcewithslu/mock/MockDigitalInput.java b/pi4micronaut-utils/src/test/java/com/opensourcewithslu/mock/MockDigitalInput.java new file mode 100644 index 00000000..b8edee75 --- /dev/null +++ b/pi4micronaut-utils/src/test/java/com/opensourcewithslu/mock/MockDigitalInput.java @@ -0,0 +1,103 @@ +package com.opensourcewithslu.mock; +import com.pi4j.common.Metadata; +import com.pi4j.context.Context; +import com.pi4j.exception.InitializeException; +import com.pi4j.exception.ShutdownException; +import com.pi4j.io.binding.DigitalBinding; +import com.pi4j.io.gpio.digital.*; + +/* +The ockDigitalInput class implements the DigitalInput interface, which requires +all methods to be implemented, even if they are not used in the mock. +These methods have default or no operation implementations to fulfill the interface contract. +they provided an empty method("return null") because the methods are required by the interface, +yet for the mock implementation, it doesn't need to do anything. +*/ +public class MockDigitalInput implements DigitalInput { + DigitalState mockState; + public MockDigitalInput(){ + mockState = DigitalState.UNKNOWN; + } + public void SetState(DigitalState fakeState) { + mockState = fakeState; + } + @Override + public DigitalState state() { + return mockState; + } + + @Override + public DigitalInput addListener(DigitalStateChangeListener... digitalStateChangeListeners) { + return null; + } + + @Override + public DigitalInput removeListener(DigitalStateChangeListener... digitalStateChangeListeners) { + return null; + } + + @Override + public boolean isOn() { + return false; + } + + @Override + public DigitalInput bind(DigitalBinding... digitalBindings) { + return null; + } + + @Override + public DigitalInput unbind(DigitalBinding... digitalBindings) { + return null; + } + + @Override + public DigitalInputConfig config() { + return null; + } + + @Override + public DigitalInput name(String s) { + return null; + } + + @Override + public DigitalInput description(String s) { + return null; + } + + @Override + public DigitalInputProvider provider() { + return null; + } + + @Override + public String id() { + return ""; + } + + @Override + public String name() { + return "MockDigitalInput"; + } + + @Override + public String description() { + return ""; + } + + @Override + public Metadata metadata() { + return null; + } + + @Override + public Object initialize(Context context) throws InitializeException { + return null; + } + + @Override + public Object shutdown(Context context) throws ShutdownException { + return null; + } +}