Home » 2015 » August

Need for Spring ?

I have a setupCar method which initializes the inputs (individual motors)I use on my RPD (Raspberry Pi Driven) Car.  When I look at the code I notice this is not ideal. Too much hardcoded dependencies and this is not really something I want.  Imagine I would like to swtich pins because a pin broke,  …  I would have to modify the method and do a new build.  If I was using Spring I would only have to change the bean xml file and up we go.  I prefer to have some flexibility. As mentioned, Spring might bring the solution but I need to have a look at that and try to find out if I can configure the PI4J depencies in a Spring bean xml file. The source code as it is now, smells dirty.

See source of the method setupCar as it is now here under :

     public void setupCar() {
        input1 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02,
        input2 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03,
        input3 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05,
        input4 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06,
        leftWheel = new Wheel(0, input1, input2);
        rightWheel = new Wheel(4, input3, input4);
        wheelAxle = new WheelAxle(leftWheel, rightWheel);
        car = new TwoWheelDriveRaspyCar(wheelAxle);

Continue reading »