本文整理匯總了TypeScript中pigpio.configureClock函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript configureClock函數的具體用法?TypeScript configureClock怎麽用?TypeScript configureClock使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了configureClock函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: alert_pwm_measurement
(function alert_pwm_measurement(): void {
const Gpio = pigpio.Gpio;
pigpio.configureClock(1, pigpio.CLOCK_PWM);
let led = new Gpio(18, {
mode: Gpio.OUTPUT,
alert: true
});
led.digitalWrite(0);
(function closure(): void {
let pulseCounts: number[] = [];
let pulses: number = 0;
let risingTick: number = 0;
let fallingTick: number;
let i: number;
led.on('alert', function event(level: number, tick: number): void {
let pulseLength: number;
if (level === 1) {
risingTick = tick;
} else {
fallingTick = tick;
pulseLength = fallingTick - risingTick;
if (pulseCounts[pulseLength] === undefined) {
pulseCounts[pulseLength] = 0;
}
pulseCounts[pulseLength] += 1;
pulses += 1;
if (pulses === 1000) {
for (i = 0; i !== pulseCounts.length; i += 1) {
if (pulseCounts[i] !== undefined) {
console.log(i + 'us - ' + pulseCounts[i]);
}
}
led.digitalWrite(0);
led.disableAlert();
}
}
});
}());
// frequency 250Hz, duty cycle 7us
led.hardwarePwmWrite(250, 250 * 7);
})();
示例2: notifier_stress
(function notifier_stress(): void {
const Gpio = pigpio.Gpio;
const Notifier = pigpio.Notifier;
const LED_GPIO = 18;
const FREQUENCY = 150000;
pigpio.configureClock(1, pigpio.CLOCK_PCM);
(function closure() {
const led = new Gpio(LED_GPIO, { mode: Gpio.OUTPUT });
led.hardwarePwmWrite(FREQUENCY, 500000);
}());
(function closure() {
const ledNotifier = new Notifier({ bits: 1 << LED_GPIO });
let notificationsReceived = 0;
let events = 0;
let seqnoErrors = 0;
let ledStateErrors = 0;
let lastSeqno: number;
let lastLedState: number;
let lastTick: number;
let minTickDiff = 0xffffffff;
let maxTickDiff = 0;
let restBuf: Buffer | null = null;
let iv: NodeJS.Timer;
function printInfo() {
console.log();
console.log(' events: %d', events);
console.log(' notifications: %d', notificationsReceived);
console.log(' seqno errors: %d', seqnoErrors);
console.log(' led state errors: %d', ledStateErrors);
console.log(' expected tick diff: %d us', 1000000 / (FREQUENCY * 2));
console.log(' min tick diff: %d us', minTickDiff);
console.log(' max tick diff: %d us', maxTickDiff);
minTickDiff = 0xffffffff;
maxTickDiff = 0;
}
ledNotifier.stream().on('data', function event(buf: Buffer) {
let entries: number;
events += 1;
if (restBuf !== null) {
buf = Buffer.concat([restBuf, buf]);
}
entries = Math.floor(buf.length / Notifier.NOTIFICATION_LENGTH);
const rest = buf.length % Notifier.NOTIFICATION_LENGTH;
restBuf = rest === 0 ? null : new Buffer(buf.slice(buf.length - rest));
for (let ix = 0; ix < buf.length - rest; ix += Notifier.NOTIFICATION_LENGTH) {
const seqno = buf.readUInt16LE(ix);
const tick = buf.readUInt32LE(ix + 4);
const level = buf.readUInt32LE(ix + 8);
if (notificationsReceived > 0) {
if (lastLedState === (level & (1 << LED_GPIO))) {
console.log(' unexpected led state');
ledStateErrors += 1;
}
if (((lastSeqno + 1) & 0xffff) !== seqno) {
console.log(' seqno error, was %d, expected %d', seqno, lastSeqno + 1);
seqnoErrors += 1;
}
if (tick - lastTick < minTickDiff) {
minTickDiff = tick - lastTick;
}
if (tick - lastTick > maxTickDiff) {
maxTickDiff = tick - lastTick;
}
}
notificationsReceived += 1;
lastSeqno = seqno;
lastLedState = level & (1 << LED_GPIO);
lastTick = tick;
}
if (notificationsReceived >= 1e9) {
ledNotifier.stream().pause();
ledNotifier.close();
clearInterval(iv);
printInfo();
}
});
iv = setInterval(printInfo, 5000);
}());
})();
示例3: configureClock
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { Gpio, configureClock, CLOCK_PWM } from 'pigpio';
import { Peripheral } from 'raspi-peripheral';
import { getGpioNumber } from 'raspi-board';
import { IPWM, IPWMModule, IPWMConfig } from 'j5-io-types';
const DEFAULT_FREQUENCY = 50;
const DEFAULT_RANGE = 40000;
export { IPWMConfig } from 'j5-io-types';
// Tell it to use the PWM clock for timing so that I2S still works. This does mean we can't use hardare PWM though.
configureClock(5, CLOCK_PWM);
export class SoftPWM extends Peripheral implements IPWM {
private _pwm: Gpio;
private _frequency: number;
private _range: number;
private _dutyCycle: number;
public get frequency() {
return this._frequency;
}
public get range() {
return this._range;
}