Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing new scenarios: wait-pin and wait-pin-change #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
new scenario wait pin change
rafaelcorsi committed Feb 2, 2024
commit 97551d43617395362ad0b8e817ec85e44c3d0ab6
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import { ExpectPinCommand } from './scenario/ExpectPinCommand.js';
import { SetControlCommand } from './scenario/SetControlCommand.js';
import { WaitSerialCommand } from './scenario/WaitSerialCommand.js';
import { WaitPinCommand } from './scenario/WaitPinCommand.js';
import { WaitPinChangeCommand } from './scenario/WaitPinChangeCommand.js';
import { uploadFirmware } from './uploadFirmware.js';

const millis = 1_000_000;
@@ -143,6 +144,7 @@ async function main() {
'set-control': new SetControlCommand(),
'wait-serial': new WaitSerialCommand(expectEngine),
'wait-pin': new WaitPinCommand(),
'wait-pin-change': new WaitPinChangeCommand(),
});
scenario.validate();
}
28 changes: 28 additions & 0 deletions src/scenario/WaitPinChangeCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import chalkTemplate from 'chalk-template';
import type { APIClient } from '../APIClient.js';
import type { IScenarioCommand, TestScenario } from '../TestScenario.js';

export interface IExpectPinParams {
'part-id': string;
pin: string;
value: number;
}

export class WaitPinChangeCommand implements IScenarioCommand {
async run(scenario: TestScenario, client: APIClient, params: IExpectPinParams) {
const partId = params['part-id'];
const pinName = params.pin;
const initalValue = (await client.pinRead(partId, pinName))?.value ? 1 : 0;

scenario.log(
chalkTemplate`wait-pin-toggle {yellow ${partId}}:{magenta ${pinName}} to change from {yellow ${initalValue}}`,
);


let value = (await client.pinRead(partId, pinName))?.value ? 1 : 0;

while (value == initalValue) {
value = (await client.pinRead(partId, pinName))?.value ? 1 : 0;
}
}
}