Your ROOT_URL in app.ini is https://source.parasitstudio.de:63000/ but you are visiting https://source.parasitstudio.de/wirtz/MicroDexed/src/commit/fad9c6f91b3e55b3bb235ad96d37f7bb615691cf/third-party/TeensyTimerTool/examples/03_Applications/DoubleExposure/PulseGenerator.h You should set ROOT_URL correctly, otherwise the web may not work correctly.

61 lines
1.7 KiB

#pragma once
#include "Arduino.h"
#include "TeensyTimerTool.h"
class PulseGenerator
{
public:
PulseGenerator(); // constructor, initializes non hardware related stuff
void begin(unsigned pin); // intializes hardware related stuff
void schedulePulse(float delay, float width); // schedules a 'width µs' wide pulse after a waiting time of 'delay µs'. Non blocking.
protected:
TeensyTimerTool::OneShotTimer pulseTimer; // used for generating the pulses
void callback();
uint32_t pin;
float width;
};
void PulseGenerator::begin(unsigned pin)
{
this->pin = pin;
pinMode(pin, OUTPUT);
digitalWriteFast(pin, LOW);
pulseTimer.begin([this] { this->callback(); });
}
void PulseGenerator::schedulePulse(float delay, float _width)
{
width = _width; // the timer callback needs to know the pulse width to generate the pulse
if (delay != 0)
{
pulseTimer.trigger(delay); // this triggers the oneShot timer to fire after 'delay µs'
}
else //delay == 0, directly generate the pulse
{
digitalWriteFast(pin, HIGH);
pulseTimer.trigger(width); // this triggers the oneShotTimer to fire after 'width µs'
}
}
void PulseGenerator::callback()
{
if (digitalReadFast(pin) == LOW)
{
digitalWriteFast(pin, HIGH);
pulseTimer.trigger(width); // retrigger
} else
{
digitalWriteFast(pin, LOW);
}
}
PulseGenerator::PulseGenerator()
: pulseTimer(TeensyTimerTool::FTM0) // use one of the 8 FTM0 channels
{}