Skip to content

Commit

Permalink
Resolved Merge Conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
yrlmanoharreddy committed Sep 22, 2024
2 parents eb18c0b + 9f93843 commit 32195aa
Show file tree
Hide file tree
Showing 18 changed files with 435 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//tag::ex[]
@Controller("/active-buzzer")
public class ActiveBuzzerController {

private final ActiveBuzzerHelper activeBuzzerHelper;

public ActiveBuzzerController(@Named("active-buzzer") Pwm activeBuzzerOutput){
Expand All @@ -29,7 +28,6 @@ public void enableActiveBuzzer(){
/**
* Disables the active buzzer
*/

@Get("/disable")
public void disableActiveBuzzer(){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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[]
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,38 @@
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) {
this.microSwitchHelper = new MicroSwitchHelper(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);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -35,20 +31,32 @@ 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")
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);
}
}
});
}
Expand All @@ -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);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -23,7 +21,6 @@ public PassiveBuzzerController(@Named("passive-buzzer") Pwm passiveBuzzerOutput)
/**
* Enables passive buzzer
*/

@Get("/enable")
public void enablePassiveBuzzer(){

Expand All @@ -45,7 +42,6 @@ public void disablePassiveBuzzer(){
*
* Displays the current frequency of the passive buzzer.
*/

@Get("/showFreq")
public void passiveBuzzerFreq(){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//tag::ex[]
@Controller("/servoMotor")
public class ServoMotorController {

private final ServoMotorHelper servoMotorHelper;

public ServoMotorController(@Named("servo-motor")Pwm servoMotor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
});
}
Expand Down
Loading

0 comments on commit 32195aa

Please sign in to comment.