Skip to content

Commit

Permalink
tidied up and ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Preston committed Aug 6, 2013
1 parent 6114bf2 commit 218b55f
Show file tree
Hide file tree
Showing 12 changed files with 2,371 additions and 88 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ makedebpkg.sh
_build
*.log
MANIFEST
deb_dist

# databases
*.db
Expand Down
38 changes: 23 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
pifacedigital-emulator
======================

An emulator for the PiFace Digital board. Requires [pifacedigitalio](https://github.com/piface/pifacedigitalio) to be installed.
An emulator for the PiFace Digital I/O board.

[Screenshot](https://raw.github.com/piface/pifacedigital-emulator/master/images/pifacedigital_emulator_screenshot.png)

I built the UI with
[qt4-designer](http://doc.qt.digia.com/4.0/qt4-designer.html).

Install
=======

Download, build and install:

git clone https://github.com/piface/pifacedigital-emulator.git
cd pifacedigital-emulator/
Download the latest debian package from
[here](https://github.com/piface/pifacedigital-emulator/releases) and install with:

bin/build_ui.sh
$ dpkg -i python3-pifacedigital-emulator_1.2.0-1_all.deb

sudo python3 setup.py install
You may also need to install the latest releases of
[pifacedigitalio](https://github.com/piface/pifacedigitalio/releases) and
[pifacecommon](https://github.com/piface/pifacecommon/releases).

Or just install straight from PyPI:
Or you can install without using your package manager:

sudo easy_install3 pifacedigital-emulator
$ git clone https://github.com/piface/pifacedigitalio.git
$ cd pifacedigitalio
$ bin/build_ui.sh
$ sudo python3 setup.py install

Use
===
To run the emulator type:

$ pifacedigital-emulator

To use it with Python (just like pifacedigitalio):
To use it with Python (just like
[pifacedigitalio](https://github.com/piface/pifacedigitalio)):

$ python3
>>> import pifacedigital_emulator as emu
>>> emu.init() # a window should pop up
>>> emu.init() # a window should pop up
>>> pifacedigital = emu.PiFaceDigital()
>>> pifacedigital.leds[0].toggle()

See http://piface.github.io/pifacedigitalio/example.html


Development Notes
=================
UI built with [qt4-designer](http://doc.qt.digia.com/4.0/qt4-designer.html).
To generate the UI files, run:

bin/build_ui.sh
3 changes: 0 additions & 3 deletions bin/run-pifacedigital-emulator

This file was deleted.

2,309 changes: 2,309 additions & 0 deletions icons/piface.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/pi_jumper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/pifacedigital_emulator_screenshot.png
Binary file not shown.
Binary file removed images/pifacelogo.png
Binary file not shown.
Binary file removed images/pifacelogo_small.png
Binary file not shown.
35 changes: 0 additions & 35 deletions install.sh

This file was deleted.

7 changes: 4 additions & 3 deletions pifacedigital_emulator/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ def read_bit(bit_num, address, board_num=0):
global proc_comms_q_from_em

if address is INPUT_PORT:
proc_comms_q_to_em.put(('get_in', bit_num))
proc_comms_q_to_em.put(('get_in', bit_num, board_num))
return proc_comms_q_from_em.get(block=True)
elif address is OUTPUT_PORT:
proc_comms_q_to_em.put(('get_out', bit_num))
proc_comms_q_to_em.put(('get_out', bit_num, board_num))
return proc_comms_q_from_em.get(block=True)
else:
raise EmulatorAddressError(
Expand All @@ -172,7 +172,8 @@ def write_bit(value, bit_num, address, board_num=0):
global proc_comms_q_from_em

if address is OUTPUT_PORT:
proc_comms_q_to_em.put(('set_out', bit_num, True if value else False))
proc_comms_q_to_em.put(
('set_out', bit_num, True if value else False, board_num))
else:
raise EmulatorAddressError(
"Writing to 0x%X is not supported in the PiFace Digital "
Expand Down
32 changes: 19 additions & 13 deletions pifacedigital_emulator/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def set_as_board(self, board_num):
if i != board_num:
action.setChecked(False)

# self.board_actions[board_num].setChecked(True)
# check the one we want
self.current_pfd = board_num
self.update_emulator()
Expand Down Expand Up @@ -293,10 +294,11 @@ def output_overide(self, enable):
self.output_state[i] = button.isChecked()
self.update_emulator()

def set_output(self, index, enable):
def set_output(self, index, enable, board_num=None):
"""Sets the specified output on or off"""
board_num = self.current_pfd if board_num is None else board_num
if not self.output_override_enabled:
self.output_state[index] = enable
self._output_states[board_num][index] = enable

def set_input(self, index, enable, board_num=None):
# don't set the input if it is being held
Expand Down Expand Up @@ -406,13 +408,15 @@ def set_input_disable(self, value):
self.update_emulator()

@Slot(int)
def set_output_enable(self, pin):
self.set_output(pin, True)
def set_output_enable(self, value):
pin_num, board_num = single_val_to_small_nums(value)
self.set_output(pin_num, True, board_num)
self.update_emulator()

@Slot(int)
def set_output_disable(self, pin):
self.set_output(pin, False)
def set_output_disable(self, value):
pin_num, board_num = single_val_to_small_nums(value)
self.set_output(pin_num, False, board_num)
self.update_emulator()

send_input = Signal(int)
Expand Down Expand Up @@ -463,27 +467,29 @@ def check_queue(self):
self.perform[task](action[1:])

def set_out_pin(self, data):
pin, enable = data
pin, enable, board_num = data
if enable:
self.set_out_enable.emit(pin)
self.set_out_enable.emit(small_nums_to_single_val(pin, board_num))
else:
self.set_out_disable.emit(pin)
self.set_out_disable.emit(small_nums_to_single_val(pin, board_num))

def get_in_pin(self, data):
pin = data[0]
self.get_in.emit(pin)
pin, board_num = data[0], data[1]
self.get_in.emit(small_nums_to_single_val(pin, board_num))
# now we have to rely on the emulator getting back to us

@Slot(int)
def send_get_in_pin_result(self, value):
value, board_num = single_val_to_small_nums(value)
self.q_from_em.put(value)

def get_out_pin(self, data):
pin = data[0]
self.get_out.emit(pin)
pin, board_num = data[0], data[1]
self.get_out.emit(small_nums_to_single_val(pin, board_num))

@Slot(int)
def send_get_out_pin_result(self, value):
value, board_num = single_val_to_small_nums(value)
self.q_from_em.put(value)

def register_interrupt(self, data):
Expand Down
34 changes: 15 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
#!/usr/bin/env python3
import os
import sys
import stat
import shutil
from distutils.core import setup


MODULE_ONLY = False
EMULATOR_EXEC = "/usr/local/bin/run-pifacedigital-emulator"
PY3 = sys.version_info[0] >= 3
VERSION_FILE = "pifacedigital_emulator/version.py"


def install_executable():
print("Installing executable.")
shutil.copyfile("bin/run-pifacedigital-emulator", EMULATOR_EXEC)
os.chmod(
EMULATOR_EXEC,
stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
stat.S_IRGRP | stat.S_IXGRP |
stat.S_IROTH | stat.S_IXOTH)


if "install" in sys.argv and not MODULE_ONLY:
install_executable()
def get_version():
if PY3:
version_vars = {}
with open(VERSION_FILE) as f:
code = compile(f.read(), VERSION_FILE, 'exec')
exec(code, None, version_vars)
return version_vars['__version__']
else:
execfile(VERSION_FILE)
return __version__


setup(
name='pifacedigital_emulator',
version='1.2',
version=get_version(),
description='The PiFace Digital Emulator.',
author='Thomas Preston',
author_email='thomasmarkpreston@gmail.com',
author_email='thomas.preston@openlx.org.uk',
license='GPLv3+',
url='https://github.com/piface/pifacedigital_emulator',
packages=['pifacedigital_emulator'],
Expand All @@ -40,4 +35,5 @@ def install_executable():
"Development Status :: 5 - Production/Stable",
],
keywords='piface digital emulator raspberrypi openlx',
scripts=['bin/pifacedigital-emulator'],
)

0 comments on commit 218b55f

Please sign in to comment.