-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-type: patch Signed-off-by: Ryan Cooke <[email protected]>
- Loading branch information
1 parent
dc56f6a
commit 5d767e0
Showing
5 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
lib/features/keyboard/implementations/dummy-keyboard/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export class DummyKeyboard implements Keyboard { | ||
constructor(){ | ||
} | ||
|
||
async setup(): Promise<void> { | ||
console.log(`Dummy keyboard setup`) | ||
} | ||
|
||
async pressKey(key: string): Promise<string | void> { | ||
console.log(`Dummy keyboard ${key} pressed!`) | ||
} | ||
|
||
async teardown(): Promise<void> { | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
lib/features/keyboard/implementations/rpi0-keyboard/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { SerialPort } from "serialport"; | ||
|
||
export class Rpi0Keyboard implements Keyboard { | ||
public DEV_SERIAL = '/dev/ttyUSB0' || process.env.DEV_SERIAL; | ||
public BAUD_RATE = 115200; | ||
public serial : SerialPort; | ||
|
||
constructor(){ | ||
this.serial = new SerialPort({ | ||
path: this.DEV_SERIAL, | ||
baudRate: this.BAUD_RATE, | ||
autoOpen: false, | ||
}); | ||
|
||
} | ||
|
||
async setup(): Promise<void> { | ||
if(this.serial.isOpen){ | ||
console.log(`Serial already open!`) | ||
} else { | ||
this.serial.open(); | ||
} | ||
} | ||
|
||
async pressKey(key: string): Promise<string | void> { | ||
if(this.serial.isOpen){ | ||
this.serial.write(`--${key} \r\n`); | ||
} else { | ||
return `Serial connection not open` | ||
} | ||
} | ||
|
||
async teardown(): Promise<void> { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { DummyKeyboard } from "./implementations/dummy-keyboard"; | ||
import { Rpi0Keyboard } from "./implementations/rpi0-keyboard"; | ||
|
||
const keyboardImplementations: {[key: string]: Type<Keyboard> } = { | ||
dummyKeyboard: DummyKeyboard, | ||
rpi0Keyboard: Rpi0Keyboard, | ||
}; | ||
|
||
export { keyboardImplementations } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters