本文整理汇总了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);
})();
开发者ID:Crevil,项目名称:DefinitelyTyped,代码行数:51,代码来源:pigpio-tests.ts
示例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);
}());
})();
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:99,代码来源:pigpio-tests.ts
示例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;
}
开发者ID:blafuente,项目名称:RaspberryPiCapstone,代码行数:31,代码来源:index.ts
注:本文中的pigpio.configureClock函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论