diff --git a/examples/PPM-decoder/PPM.cpp b/examples/PPM-decoder/PPM.cpp index b7a7a81..92b0062 100644 --- a/examples/PPM-decoder/PPM.cpp +++ b/examples/PPM-decoder/PPM.cpp @@ -1,23 +1,39 @@ /* -This code is provided under the BSD license. +Example code is placed under the BSD license. +Written by Team Dark Water (team@darkwater.io) - based on original by Emlid Copyright (c) 2014, Emlid Limited. All rights reserved. Written by Mikhail Avkhimenia (mikhail.avkhimenia@emlid.com) twitter.com/emlidtech || www.emlid.com || info@emlid.com +All rights reserved. -Application: PPM to PWM decoder for Raspberry Pi with Navio. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Emlid Limited nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. -Requres pigpio library, please install it first - http://abyz.co.uk/rpi/pigpio/ -To run this app navigate to the directory containing it and run following commands: -make -sudo ./PPM +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL EMLID LIMITED BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include #include -#include -#include "darkwater/PCA9685.h" +#include "darkwater/DWESCAPE.h" #include "darkwater/Util.h" //================================ Options ===================================== @@ -31,7 +47,9 @@ bool verboseOutputEnabled = true; // Output channels values to console //============================ Objects & data ================================== -PCA9685 *pwm; +DWESCAPE *dw; +DW_SERVO *servos[6]; + float channels[8]; //============================== PPM decoder =================================== @@ -51,7 +69,7 @@ void ppmOnEdge(int gpio, int level, uint32_t tick) // RC output for (int i = 0; i < ppmChannelsNumber; i++) - pwm->setPWMuS(i + 3, channels[i]); // 1st Navio RC output is 3 + servos[i]->setPWMuS( channels[i] ); // Console output if (verboseOutputEnabled) { @@ -68,33 +86,26 @@ void ppmOnEdge(int gpio, int level, uint32_t tick) //================================== Main ====================================== -using namespace Navio; +using namespace DarkWater; int main(int argc, char *argv[]) { - static const uint8_t outputEnablePin = RPI_GPIO_27; - if (check_apm()) { return 1; } - Pin pin(outputEnablePin); + dw = new DWESCAPE(); + dw.initialize(); + dw.setFrequency(servoFrequency); - if (pin.init()) { - pin.setMode(Pin::GpioModeOutput); - pin.write(0); /* drive Output Enable low */ - } else { - fprintf(stderr, "Output Enable not set. Are you root?"); - } - - // Servo controller setup - - pwm = new PCA9685(); - pwm->initialize(); - pwm->setFrequency(servoFrequency); + servos[0] = dw.getServo(1); + servos[1] = dw.getServo(2); + servos[2] = dw.getServo(3); + servos[3] = dw.getServo(4); + servos[4] = dw.getServo(5); + servos[5] = dw.getServo(6); // GPIO setup - gpioCfgClock(samplingRate, PI_DEFAULT_CLK_PERIPHERAL, 0); /* last parameter is deprecated now */ gpioInitialise(); previousTick = gpioTick();