-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
I succeeded being run this on rpi3 .
I used pigpio.
So,I made new own primitiveiopin.h , mitpi.h and mitpi.cpp ,which used pigpio.
And I got a problem.
printpi toggles PWM ,when I send command of "G1 ....".
It moves as intended.
However, To toggle PWM isn't end,that is,printipi doesn't move on next command.
Also "command: G1... "and"response:ok" are not outputted.
I think that printpi moves on next command ,when "exitEventLoop()" is called.
So, something problem have occured, then "exitEventLoop()" haven't called.
//////////////////////////////////////////////////////////////////////
#ifndef PLATFORMS_RPI_PRIMITIVEIOPIN_H
#define PLATFORMS_RPI_PRIMITIVEIOPIN_H
#include <cassert>
#include "mitpi.h" //for GpioPin
//#include "hardwarescheduler.h" //for ability to schedule PWM
#include "platforms/auto/chronoclock.h" //for EventClockT.
//for MAX_RPI_PIN_ID
#include "compileflags.h"
#include <pigpiod_if.h>
namespace plat {
namespace rpi2 {
class PrimitiveIoPin {
//logical index of this pin (0-53, I believe)
mitpi::GpioPin pinIdx;
public:
//@return a pin with an invalid output
//
//Note that it is undefined to call any function on a null pin except for <isNull> and <id>.
inline static PrimitiveIoPin null() {
return PrimitiveIoPin(mitpi::NULL_GPIO_PIN);
}
//@return true if the pin is equal to the one constructed by the <null> function.
inline bool isNull() const {
return pinIdx == mitpi::NULL_GPIO_PIN;
}
//@pinIdx *logical* index of the pin
//@pullUpDown direct this pin to either pull up to 3.3v, down to gnd, or no pull at all.
//Note that this pull direction will be applied **even when operating as an output pin**.
// The rpi's pull resistors preserve state across reboots.
// This makes it so that when the Pi resets, its pins will still be in a defined state (no runaway heater while the Pi is still booting)
// Of course, it's still a VERY GOOD IDEA to use hardware pull resistors as well.
//**Also note:** @pullUpDown acts the same regardless of the <IoPin>'s read/write inversions.
template <typename ...T> PrimitiveIoPin(mitpi::GpioPin pinIdx, mitpi::GpioPull pullUpDown = mitpi::GPIOPULL_NONE) {
assert((pinIdx == mitpi::NULL_GPIO_PIN || pinIdx <= MAX_RPI_PIN_ID) && "Make sure to appropriately set MAX_RPI_PIN_ID (see compileflags.h) or else some pins might not behave correctly");
if (pinIdx != mitpi::NULL_GPIO_PIN) {
mitpi::init();
//we CANNOT set the pin pull of a null gpio pin
mitpi::setPinPull(pinIdx, pullUpDown);
}
}
//@return the logical index of the pin (for use with other platform-specific functions)
inline mitpi::GpioPin id() const {
return pinIdx;
}
//configure the pin as an output, and set its output state
inline void makeDigitalOutput(IoLevel lev) {
mitpi::makeOutput(pinIdx);
digitalWrite(lev);
}
//configure the pin as a PWM output & set its duty cycle and period (if applicable)
inline void makePwmOutput(float duty, EventClockT::duration desiredPeriod) {
mitpi::makeOutput(pinIdx);
//mitpi::pwmWrite(pinIdx, duty, desiredPeriod);
pwmWrite(duty, desiredPeriod);
}
//configure the pin to be an input
inline void makeDigitalInput() {
mitpi::makeInput(pinIdx);
}
//read the pin's input value (must call makeDigitalInput beforehand)
inline IoLevel digitalRead() const {
return mitpi::readPinState(pinIdx);
}
//write a digital value to the pin. IoHigh = 3.3v, IoLow = 0v. Must call makeDigitalOutput beforehand
inline void digitalWrite(IoLevel lev) {
mitpi::setPinState(pinIdx, lev);
}
//set pwm duty cycle & period (if applicable). Must call makePwmOutput beforehand.
inline void pwmWrite(float duty, EventClockT::duration desiredPeriod) {
float minPeriod = std::chrono::duration_cast<std::chrono::duration<float>> (desiredPeriod).count();
int intMinPeriod = (int)minPeriod;
uint32_t intDuty = 1000000*duty;
hardware_PWM(this->id(), intMinPeriod, intDuty);
//mitpi::pwmWrite(pin, duty, desiredPeriod);
//HardwareScheduler().queuePwm(*this, duty, desiredPeriod);
}
};
}
}
#endif
///////////////////////////////////////////////////////////////
About pwmWrite(), I haven't understood very much yet.
You said you not actively developing Printipi ,so please reply to me, if it's OK with you..
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
