import * as ts from "typescript"; import { TypeRegistry, NumberVarType } from "nativejs-compiler"; import { CodeTemplate, CodeTemplateFactory } from "nativejs-compiler"; import { HeaderRegistry } from "nativejs-compiler"; import { IScope } from "nativejs-compiler"; import { CExpression } from "nativejs-compiler"; import { Plugin } from "nativejs-compiler"; import { IOHeaderType } from "../headers/io"; @CodeTemplate(` do { if ({value}) PORT{port} |= (1<
node;
if (call.arguments.length < 3) {
throw new Error("Digital.read needs 3 arguments.");
}
const args = call.arguments.map(a => {
return CodeTemplateFactory.createForNode(scope, a);
});
this.port = args[0]
.resolve()
.replace(/[\"\']/g, "")
.toUpperCase();
this.pin = args[1].resolve();
this.value = args[2].resolve();
console.log(this.port, this.pin, this.value);
HeaderRegistry.declareDependency(IOHeaderType);
}
}
export class DigitalWritePlugin implements Plugin {
execute(scope: IScope, node: ts.Node, handler: Object): CExpression {
const call =