Skip to content
This repository has been archived by the owner on Dec 27, 2019. It is now read-only.

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
6XGate committed Feb 17, 2019
2 parents 70acb82 + 51adfd2 commit a56c24d
Show file tree
Hide file tree
Showing 19 changed files with 570 additions and 116 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@ for information on setting up, configuring, and using PiAvSwitchController.
## Change Log

See the [Project on GitHub](http://www.github.com/6XGate/PiAvSwitchController).

## Example Images

The example images where taken from Wikipedia pages for each console and the
trademarks and art belongs to their respective companies, no new license is
implied by their presence in this code-base. Their inclusion is simply an
educational example presumed under fair use.

## Interface Icons

Icons not defined by the configuration have the following license:

- _ui/res/poweroff.png_, CC BY-SA 3.0, canvas enlarged to 128x128,
[Source](https://upload.wikimedia.org/wikipedia/commons/7/72/Power_off_icon.png)
Binary file added config/example/images/gcn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 46 additions & 2 deletions config/example/piavswictrl.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"switches": {
"bvm": {
"title": "Sony BVM-D24E1WU",
"driver": "sony-bvm-d",
"config": {
"tty": "ttyUSB0"
}
},
"extron": {
"title": "Extron Crosspoint Plus 128HVA with DSVP",
"driver": "extron",
"config": {
"maxInputs": 12,
"maxOutputs": 8,
"tty": "ttyUSB0"
"tty": "ttyUSB1"
}
}
},
Expand All @@ -15,6 +22,9 @@
"title": "Nintendo",
"image": "./images/nes.png",
"ties": {
"bvm": {
"input": 4
},
"extron": {
"input": 9,
"output": {
Expand All @@ -28,6 +38,9 @@
"title": "Super Nintendo",
"image": "./images/snes.png",
"ties": {
"bvm": {
"input": 1
},
"extron": {
"input": 1,
"output": {
Expand All @@ -41,6 +54,9 @@
"title": "Nintendo 64",
"image": "./images/n64.png",
"ties": {
"bvm": {
"input": 3
},
"extron": {
"input": 8,
"output": {
Expand All @@ -50,10 +66,29 @@
}
}
},
{
"title": "GameCube",
"image": "./images/gcn.png",
"ties": {
"bvm": {
"input": 5
},
"extron": {
"input": 5,
"output": {
"video": 5,
"audio": 1
}
}
}
},
{
"title": "Wii",
"image": "./images/wii.png",
"ties": {
"bvm": {
"input": 2
},
"extron": {
"input": 5,
"output": {
Expand All @@ -67,6 +102,9 @@
"title": "Playstation 2",
"image": "./images/ps2.png",
"ties": {
"bvm": {
"input": 1
},
"extron": {
"input": 2,
"output": {
Expand All @@ -80,6 +118,9 @@
"title": "Playstation 3",
"image": "./images/ps3.png",
"ties": {
"bvm": {
"input": 2
},
"extron": {
"input": 6,
"output": {
Expand All @@ -93,6 +134,9 @@
"title": "XBox 360",
"image": "./images/xb360.png",
"ties": {
"bvm": {
"input": 2
},
"extron": {
"input": 7,
"output": {
Expand All @@ -102,5 +146,5 @@
}
}
}
],
]
}
23 changes: 13 additions & 10 deletions drivers/Extron.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from typing import Dict, Any
from serial import Serial
from support import Driver
import os
from typing import Dict, Any
from serial import Serial
from support import Driver
from support.validation import validate_arg


class Extron(Driver):
"""Extron SIS Driver for Extron matrix switches using RS-232 mode."""

Expand All @@ -14,17 +16,18 @@ def __init__(self, config: Dict[str, Any]):
Initializes a new instances of the Extron driver.
:param config: The configuration data from the configuration about the device.
"""

super().__init__(config, Driver.CAN_DECOUPLE_AUDIO_OUTPUT)

validate_arg('maxInputs' in self.config, 'Missing `maxInputs` for Extron switch')
validate_arg('maxInputs' in self.config, 'Missing `maxInputs` for Extron switch')
validate_arg('maxOutputs' in self.config, 'Missing `maxOutputs` for Extron switch')
validate_arg('tty' in self.config, 'Missing `tty` for Extron switch')
validate_arg('tty' in self.config, 'Missing `tty` for Extron switch')

tty_path = os.path.realpath("/dev/{}".format(self.config['tty']))

self.max_inputs = int(self.config['maxInputs'])
self.max_inputs = int(self.config['maxInputs'])
self.max_outputs = int(self.config['maxOutputs'])
self.tty = str(config['tty'])
self.serial = Serial("/dev/{}".format(self.tty))
self.tty = tty_path
self.serial = Serial(tty_path)

if self.max_outputs > 1:
self.capabilities = int(self.capabilities | Driver.HAS_MULTIPLE_OUTPUTS)
Expand All @@ -41,7 +44,7 @@ def set_tie(self, input_channel: int, video_output_channel: int, audio_output_ch
:param video_output_channel: The output video channel of the tie.
:param audio_output_channel: The output audio channel of the tie.
"""
validate_arg(1 <= input_channel <= self.max_inputs, 'Input channel is out of range')
validate_arg(1 <= input_channel <= self.max_inputs, 'Input channel is out of range')
validate_arg(1 <= video_output_channel <= self.max_outputs, 'Video output channel is out of range')
validate_arg(1 <= audio_output_channel <= self.max_outputs, 'Audio output channel is out of range')

Expand Down
72 changes: 72 additions & 0 deletions drivers/SonyMonitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
import serial
from typing import Dict, Any
from serial import Serial
from support import Driver
from support.validation import validate_arg
from drivers.libraries.sony_bvm_rs485.protocol import AddressKind, Address, Command, CommandBlock


class SonyBvmDSeries(Driver):
"""Sony BVM D-series Monitor Driver"""

def __init__(self, config: Dict[str, Any]):
"""
Initializes a new instance of the Sony BVM D-series monitor driver.
:param config: The device configuration.
"""
super().__init__(config, 0)

validate_arg('tty' in self.config, 'Missing `tty` for Sony D-series monitor')

tty_path = os.path.realpath("/dev/{}".format(self.config['tty']))

self.tty = tty_path
self.serial = Serial(tty_path, 38400, serial.EIGHTBITS, serial.PARITY_ODD, serial.STOPBITS_ONE)

def __del__(self):
"""Cleans up an instance of the Sony BVM D-series monitor driver."""
if isinstance(self.serial, Serial):
self.serial.close()

def set_tie(self, input_channel: int, video_output_channel: int, audio_output_channel: int) -> None:
"""
Sets input and output ties.
:param input_channel: The input channel of the tie.
:param video_output_channel: The output video channel of the tie.
:param audio_output_channel: The output audio channel of the tie.
"""
validate_arg(1 <= input_channel <= 99, 'Input channel is out of range')
validate_arg(video_output_channel == 0, 'Video output channel is out of range')
validate_arg(audio_output_channel == 0, 'Audio output channel is out of range')

self.__set_channel(input_channel)

def power_off(self) -> None:
"""Powers off the monitor."""
self.__power_off()

def __set_channel(self, channel: int) -> None:
"""
Sends a set channel command to the monitor.
:param channel:
"""
source = Address(AddressKind.ALL, 0)
destination = Address(AddressKind.ALL, 0)

# Not sure why, but all channel sets have 1 as their first argument.
command = CommandBlock(destination, source, Command.SET_CHANNEL, 1, channel)
packet = command.package()

packet.write(self.serial)

def __power_off(self) -> None:
"""Powers off the monitor."""
source = Address(AddressKind.ALL, 0)
destination = Address(AddressKind.ALL, 0)

# Not sure why, but all channel sets have 1 as their first argument.
command = CommandBlock(destination, source, Command.POWER_OFF)
packet = command.package()

packet.write(self.serial)
15 changes: 9 additions & 6 deletions drivers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from typing import Dict, Callable, Any
from support import Driver
from typing import Dict, Callable, Any
from support import Driver
from support.validation import validate_arg
from drivers.Extron import Extron
from .Extron import Extron
from .SonyMonitor import SonyBvmDSeries

# Registered drivers, a name mapped to a callable that will except the device configuration for the driver.
drivers = {
'extron': lambda config: Extron(config)
} # type: Dict[str, Callable[[Dict[str, Any]], Driver]]
'extron': lambda config: Extron(config),
'sony-bvm-d': lambda config: SonyBvmDSeries(config)
} # type: Dict[str, Callable[[Dict[str, Any]], Driver]]


def load_driver(switch_id: str, config: Dict[str, Any]) -> Driver:
"""
Expand All @@ -21,6 +24,6 @@ def load_driver(switch_id: str, config: Dict[str, Any]) -> Driver:
name = str(config['driver'])

# Now construct an instance of the driver for the switch.
validate_arg(name in drivers, "Driver `{0}` does not exist".format(name))
validate_arg(name in drivers, "Driver `{0}` does not exist".format(name))
validate_arg('config' in config, "Switch configuration not specified for `{0}`".format(switch_id))
return drivers[name](config['config'])
14 changes: 14 additions & 0 deletions drivers/libraries/sony_bvm_rs485/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class SonyDriverError(Exception):
pass


class PacketError(SonyDriverError):
pass


class ChecksumError(SonyDriverError):
pass


class CommandBlockError(SonyDriverError):
pass
Loading

0 comments on commit a56c24d

Please sign in to comment.