Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
6XGate committed Dec 27, 2019
2 parents 34ae027 + 4900b7f commit 94df34d
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 186 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bridgecmdr",
"productName": "BridgeCmdr",
"version": "1.0.0",
"version": "1.0.1",
"description": "Professional Raspberry Pi A/V switch and monitor controller for retro gaming",
"main": "dist/main/index.js",
"scripts": {
Expand Down
7 changes: 6 additions & 1 deletion render/app/Application.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
this.buttons = await makeButtons(button => this.onButtonActivated(button));
},
async powerOff() {
await Promise.all(Switch.all().map(_switch => _switch.powerOff()));
try {
await Promise.all(Switch.all().map(_switch => _switch.powerOff()));
} catch (error) {
console.error(error);
}

if (process.env.NODE_ENV === "production") {
await helpers.signalShutdown();
}
Expand Down
56 changes: 27 additions & 29 deletions render/drivers/extron-matrix-switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import stream from "stream";
import Driver, { DriverCapabilities, DriverDescriptor } from "../support/system/driver";
import { openStream, SerialBits, SerialParity, SerialStopBits, writeToStream } from "../support/stream";
import Driver, { DriverCapabilities, DriverDescriptor } from "../support/system/driver";
import { openStream, SerialBits, SerialParity, SerialStopBits } from "../support/streams/command";

const capabilities =
DriverCapabilities.HAS_MULTIPLE_OUTPUTS |
Expand All @@ -30,21 +29,14 @@ const about = {
};

export default class ExtronMatrixSwitch extends Driver {
private readonly connection: stream.Duplex;
private readonly path: string;

public static about(): DriverDescriptor {
return about;
}

public static async load(path: string): Promise<Driver> {
const connection = await openStream(path, {
baudReat: 9600,
bits: SerialBits.EIGHT,
parity: SerialParity.NONE,
stopBits: SerialStopBits.ONE,
});

return Promise.resolve(new ExtronMatrixSwitch(connection));
public static load(path: string): Promise<Driver> {
return Promise.resolve(new ExtronMatrixSwitch(path));
}

// eslint-disable-next-line class-methods-use-this
Expand All @@ -57,24 +49,34 @@ export default class ExtronMatrixSwitch extends Driver {
return about.title;
}

private constructor(connection: stream.Duplex) {
private constructor(path: string) {
super(capabilities);
this.connection = connection;
connection.setEncoding("ascii");

// TODO: Other situation handlers...
connection.on("data", data => console.debug(`DEBUG: ${about.title}: return: ${data}`));
connection.on("error", error => console.error(`ERROR: ${about.title}: ${error}`));
this.path = path;
}

public setTie(inputChannel: number, videoOutputChannel: number, audioOutputChannel: number): Promise<void> {
public async setTie(inputChannel: number, videoOutputChannel: number, audioOutputChannel: number): Promise<void> {
console.log(`Extron SIS: ${inputChannel}, ${videoOutputChannel}, ${audioOutputChannel}`);

const videoCommand = `${inputChannel}*${videoOutputChannel}%`;
const audioCommand = `${inputChannel}*${audioOutputChannel}$`;
const command = `${videoCommand}\r\n${audioCommand}\r\n`;

return writeToStream(this.connection, command);
const connection = await openStream(this.path, {
baudReat: 9600,
bits: SerialBits.EIGHT,
parity: SerialParity.NONE,
stopBits: SerialStopBits.ONE,
port: 23,
});

connection.setEncoding("ascii");

// TODO: Other situation handlers...
connection.on("data", data => console.debug(`DEBUG: ${about.title}: return: ${data}`));
connection.on("error", error => console.error(`ERROR: ${about.title}: ${error}`));

await connection.write(command);
await connection.close();
}

// eslint-disable-next-line class-methods-use-this
Expand All @@ -87,12 +89,8 @@ export default class ExtronMatrixSwitch extends Driver {
return Promise.resolve();
}

public async unload(): Promise<void> {
await new Promise((resolve, reject) => {
this.connection.once("error", error => reject(error));
this.connection.end(() => resolve());
});

this.connection.destroy();
// eslint-disable-next-line class-methods-use-this
public unload(): Promise<void> {
return Promise.resolve();
}
}
58 changes: 29 additions & 29 deletions render/drivers/sony-serial--monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import stream from "stream";
import Driver, { DriverCapabilities, DriverDescriptor } from "../support/system/driver";
import { openStream, SerialBits, SerialParity, SerialStopBits, writeToStream } from "../support/stream";
import { Address, AddressKind, Command, CommandBlock } from "../support/specialized/sony-bvm-support";
import Driver, { DriverCapabilities, DriverDescriptor } from "../support/system/driver";
import { openStream, SerialBits, SerialParity, SerialStopBits } from "../support/streams/command";
import { Address, AddressKind, Command, CommandBlock } from "../support/specialized/sony-bvm-support";

const capabilities = DriverCapabilities.NONE;
const about = Object.freeze({
Expand All @@ -29,21 +28,14 @@ const about = Object.freeze({
});

export default class SonySerialMonitor extends Driver {
private readonly connection: stream.Duplex;
private readonly path: string;

public static about(): DriverDescriptor {
return about;
}

public static async load(path: string): Promise<Driver> {
const connection = await openStream(path, {
baudReat: 38400,
bits: SerialBits.EIGHT,
parity: SerialParity.ODD,
stopBits: SerialStopBits.ONE,
});

return new SonySerialMonitor(connection);
public static load(path: string): Promise<Driver> {
return Promise.resolve(new SonySerialMonitor(path));
}

// eslint-disable-next-line class-methods-use-this
Expand All @@ -56,13 +48,9 @@ export default class SonySerialMonitor extends Driver {
return about.title;
}

private constructor(connection: stream.Duplex) {
private constructor(path: string) {
super(capabilities);
this.connection = connection;

// TODO: Other situation handlers...
connection.on("data", data => console.debug(`DEBUG: ${about.title}: return: ${data}`));
connection.on("error", error => console.error(`ERROR: ${about.title}: ${error}`));
this.path = path;
}

public setTie(inputChannel: number): Promise<void> {
Expand All @@ -72,29 +60,41 @@ export default class SonySerialMonitor extends Driver {
}

public powerOn(): Promise<void> {
console.log("Sony BVM: Power On");

return this.sendCommand(Command.POWER_ON);
}

public powerOff(): Promise<void> {
console.log("Sony BVM: Power Off");

return this.sendCommand(Command.POWER_OFF);
}

public async unload(): Promise<void> {
await new Promise((resolve, reject) => {
this.connection.once("error", error => reject(error));
this.connection.end(() => resolve());
});

this.connection.destroy();
// eslint-disable-next-line class-methods-use-this
public unload(): Promise<void> {
return Promise.resolve();
}

private sendCommand(command: Command, arg0 = -1, arg1 = -1): Promise<void> {
private async sendCommand(command: Command, arg0 = -1, arg1 = -1): Promise<void> {
const source = new Address(AddressKind.ALL, 0);
const destination = new Address(AddressKind.ALL, 0);

const block = new CommandBlock(destination, source, command, arg0, arg1);
const packet = block.package();

return writeToStream(this.connection, packet.package());
const connection = await openStream(this.path, {
baudReat: 38400,
bits: SerialBits.EIGHT,
parity: SerialParity.ODD,
stopBits: SerialStopBits.ONE,
});

// TODO: Other situation handlers...
connection.on("data", data => console.debug(`DEBUG: ${about.title}: return: ${data}`));
connection.on("error", error => console.error(`ERROR: ${about.title}: ${error}`));

await connection.write(packet.package());
await connection.close();
}
}
52 changes: 24 additions & 28 deletions render/drivers/tesla-smart-matrix-switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import stream from "stream";
import Driver, { DriverCapabilities, DriverDescriptor } from "../support/system/driver";
import { openStream, SerialBits, SerialParity, SerialStopBits, writeToStream } from "../support/stream";
import Driver, { DriverCapabilities, DriverDescriptor } from "../support/system/driver";
import { openStream, SerialBits, SerialParity, SerialStopBits } from "../support/streams/command";

const capabilities = DriverCapabilities.NONE;
const about = {
Expand All @@ -28,21 +27,14 @@ const about = {
};

export default class TeslaSmartMatrixSwitch extends Driver {
private readonly connection: stream.Duplex;
private readonly path: string;

public static about(): DriverDescriptor {
return about;
}

public static async load(path: string): Promise<Driver> {
const connection = await openStream(path, {
baudReat: 9600,
bits: SerialBits.EIGHT,
parity: SerialParity.NONE,
stopBits: SerialStopBits.ONE,
});

return new TeslaSmartMatrixSwitch(connection);
public static load(path: string): Promise<Driver> {
return Promise.resolve(new TeslaSmartMatrixSwitch(path));
}

// eslint-disable-next-line class-methods-use-this
Expand All @@ -55,21 +47,29 @@ export default class TeslaSmartMatrixSwitch extends Driver {
return about.title;
}

private constructor(connection: stream.Duplex) {
private constructor(path: string) {
super(capabilities);
this.connection = connection;

// TODO: Other situation handlers...
connection.on("data", data => console.debug(`DEBUG: ${about.title}: return: ${data}`));
connection.on("error", error => console.error(`ERROR: ${about.title}: ${error}`));
this.path = path;
}

public setTie(inputChannel: number): Promise<void> {
public async setTie(inputChannel: number): Promise<void> {
console.log(`Tesla: ${inputChannel}`);

const command = Buffer.from(Uint8Array.from([ 0xAA, 0xBB, 0x03, 0x01, inputChannel, 0xEE ]));

return writeToStream(this.connection, command);
const connection = await openStream(this.path, {
baudReat: 9600,
bits: SerialBits.EIGHT,
parity: SerialParity.NONE,
stopBits: SerialStopBits.ONE,
});

// TODO: Other situation handlers...
connection.on("data", data => console.debug(`DEBUG: ${about.title}: return: ${data}`));
connection.on("error", error => console.error(`ERROR: ${about.title}: ${error}`));

await connection.write(command);
await connection.close();
}

// eslint-disable-next-line class-methods-use-this
Expand All @@ -82,12 +82,8 @@ export default class TeslaSmartMatrixSwitch extends Driver {
return Promise.resolve();
}

public async unload(): Promise<void> {
await new Promise((resolve, reject) => {
this.connection.once("error", error => reject(error));
this.connection.end(() => resolve());
});

this.connection.destroy();
// eslint-disable-next-line class-methods-use-this
public unload(): Promise<void> {
return Promise.resolve();
}
}
Loading

0 comments on commit 94df34d

Please sign in to comment.