Compare commits

..

1 Commits

Author SHA1 Message Date
Holger Frey ecd783053c added comment regarding pyinstaller 7 years ago
  1. 2
      .gitignore
  2. 4
      CHANGES.txt
  3. BIN
      Household-Mouse-Trap.ico
  4. 73
      README.md
  5. 108
      arduino_scripts/Servo-Magnetic-Trap/Servo-Magnetic-Trap.ino
  6. 41
      arduino_scripts/Test-Arduino-Timetable/Test-Arduino-Timetable.ino
  7. 2
      arduino_timetable/__init__.py
  8. BIN
      arduino_timetable/appicons/Household-Mouse-Trap.ico
  9. 17
      arduino_timetable/apps.py
  10. 8
      arduino_timetable/gui.py
  11. 4
      arduino_timetable/timetable.py
  12. 10
      pyinstaller_make.bat
  13. 9
      run_magnetic_trap.py
  14. 13
      setup.py

2
.gitignore vendored

@ -9,7 +9,6 @@ __pycache__/
# Distribution / packaging # Distribution / packaging
.Python .Python
arduino_timetable_env/
env/ env/
build/ build/
develop-eggs/ develop-eggs/
@ -58,3 +57,4 @@ docs/_build/
# PyBuilder # PyBuilder
target/ target/

4
CHANGES.txt

@ -1,4 +0,0 @@
Version 0.1.0 (19.09.2017)
==========================
- first relase, including library and GUI application

BIN
Household-Mouse-Trap.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 KiB

73
README.md

@ -1,72 +1,21 @@
arduino-timetable # arduino-timetable
=================
Module to send commands to an Arduino based on a time table. Module to send commands to an Arduino based on a time table.
Regarding Pyinstaller ### Regarding Pyinstaller
---------------------
As of September 2017 the Pyinstaller version on PyPi is not ready for As of September 2017 the Pyinstaller version on PyPi is not ready for
Python 3.6 and / or multiprocessing. I stopped trying to use Pyinstaller Python 3.6, the developementversion is needed:
for distribution. The experiment is still available in the `pyinstaller`
branch.
~~~
pip install https://github.com/pyinstaller/pyinstaller/tarball/develop
~~~
Installation But I found out that Pyintaller and multiprocessing on windows don't mix well.
------------ Even after some research and trying the [recipie from the pyinstaller wiki][1]
it just won't work.
As the only prerequisite, [Python (at least version 3.6)][python] must be I will try to investigate further, if I find the time for it [...]
installed. An added bonus points, if [git][git] is also available.
The installation should be performed in a python virtual environment. A virtual [1]: https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Multiprocessing
environment (short: venv) isolates your base python installation from the
application and vice versa. This procedure is considered a standard procedure
when working with python applications and scripts.
1. Choose the desired installation path (e.g. a folder in your home directory)
2. Create a python virtual environment with `python3 -m venv venv-ardunio-timetable`
3. Activate the environment:
- Posix: `source venv-ardunio-timetable/bin/activate`
- Windows: `venv-ardunio-timetable\Scripts\activate.bat`
4. [Download][download] the 'arduino-timetable' and unpack it or use git:
`git clone https://git.cpi.imtek.uni-freiburg.de/holgi/arduino-timetable.git`
5. Change to the new directory and install the software. I would recommend
to install the software as a 'development version', so that changes can be
made easily. Change to the folder where 'setup.py' is located and run
`pip install -e .`
As of Version 0.1.0, this will also install one GUI-like application called
'magnetictrap'. It is located at the following paths:
- Posix: `<path to virtual environment>/bin/magnetictrap`
- Windows: `<path to virtual environment>\Scripts\magnetictrap.exe`
Don't move this file around. If you want to have a shortcut on the desktop or
somewhere else, please create a shortcut, alias or symbolic link - whatever it
is called on your system.
Updating
--------
Find out if the installation was done using git:
- Open a command line and activate the environment.
- Change to the directory, where the 'setup.py' file of
the package is located
- Issue a `git status` command. If the result is something along the line
`fatal: Not a git repository`, git was not used for the installation
- Updating *with* git:
- Issue a `git pull origin` command to update the package
- Updating *without* git:
- Delete the folder that contains the 'setup.py' file
- [Download][download] the software again and unpack it
- Change to the folder where 'setup.py' is located and run
`pip install -e .` again to installe the applications
- Good Luck
[python]: https://www.python.org/
[git]: https://git-scm.com/
[download]: https://git.cpi.imtek.uni-freiburg.de/holgi/arduino-timetable/archive/master.tar.gz

108
arduino_scripts/Servo-Magnetic-Trap/Servo-Magnetic-Trap.ino

@ -1,108 +0,0 @@
// include the servo library
#include <Servo.h>
// create servo object to control a servo
Servo Servo_1;
Servo Servo_2;
// constants: input and output pins
const int SWITCH_PIN = 4;
const int SERVO_1_PIN = 9;
const int SERVO_2_PIN = 10;
// constants: the trap can be open or close.
// easier to understand than HIGH or LOW
const int CLOSED = LOW;
const int OPEN = HIGH;
// constants: positions of servo end points and positioning delay in microseconds
const int SERVO_1_CLOSED = 7;
const int SERVO_1_OPEN = 100;
const int SERVO_2_CLOSED = 159;
const int SERVO_2_OPEN = 64;
const int SERVO_DELAY = 10;
// variables
int switch_state = LOW; // the current state of the input pin
int trap_state = OPEN; // will a high switch state change the servo position
void setup() {
// setup code here, run once after reset or power on:
// setting pins to input, and output
pinMode(SWITCH_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
// initialize serial connection
Serial.begin(9600);
// attach the servos
Servo_1.attach(SERVO_1_PIN);
Servo_2.attach(SERVO_2_PIN);
// moving servos to defined position
Servo_1.write(SERVO_1_OPEN);
Servo_2.write(SERVO_2_OPEN);
// read the current switch state
switch_state = digitalRead(SWITCH_PIN);
}
void loop() {
// main code, run repeatedly:
// MANUAL SWITCH STATE
// -------------------
// read the current state of the input
int current_switch_state = digitalRead(SWITCH_PIN);
// change trap position if the switch state has changed
if (current_switch_state != switch_state) {
// register the change
switch_state = current_switch_state;
if (switch_state == HIGH) {
// show that there is currently a input signal
// and close the trap
digitalWrite(LED_BUILTIN, HIGH);
trap_state = close_trap();
} else {
// show that there is currently no input signal
// and open the trap
digitalWrite(LED_BUILTIN, LOW);
trap_state = open_trap();
}
}
// COMMANDS SEND OVER USB
// ----------------------
// read the incoming data
char inByte = Serial.read();
if (inByte == 'o') {
// the open trap command was sent
trap_state = open_trap();
} else if (inByte == 'c') {
// the close trap command was sent
trap_state = close_trap();
}
}
int open_trap() {
Servo_1.write(SERVO_1_OPEN);
Servo_2.write(SERVO_2_OPEN);
return OPEN;
}
int close_trap() {
Servo_1.write(SERVO_1_CLOSED);
Servo_2.write(SERVO_2_CLOSED);
return CLOSED;
}

41
arduino_scripts/Test-Arduino-Timetable/Test-Arduino-Timetable.ino

@ -1,41 +0,0 @@
/*
Reading a serial ASCII-encoded string.
This sketch demonstrates the Serial parseInt() function.
It looks for an ASCII string of comma-separated values.
It parses them into ints, and uses those to fade an RGB LED.
Circuit: Common-Cathode RGB LED wired like so:
* Red anode: digital pin 3
* Green anode: digital pin 5
* Blue anode: digital pin 6
* Cathode : GND
created 13 Apr 2012
by Tom Igoe
modified 14 Mar 2016
by Arturo Guadalupi
This example code is in the public domain.
*/
void setup() {
// initialize serial:
Serial.begin(9600);
// make the pins outputs:
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
}
void loop() {
char inByte = Serial.read(); // read the incoming data
if (inByte=='o'){
digitalWrite(LED_BUILTIN, LOW);
} else if (inByte=='c'){
digitalWrite(LED_BUILTIN, HIGH);
}
}

2
arduino_timetable/__init__.py

@ -10,4 +10,4 @@ from .timetable import (
TimedCommands TimedCommands
) )
__version__ = '0.1.0' __version__ = '0.0.1'

BIN
arduino_timetable/appicons/Household-Mouse-Trap.ico

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

17
arduino_timetable/apps.py

@ -1,17 +0,0 @@
import os
from . import run_application
def check_icon(icon_name):
own_path = os.path.abspath(__file__)
own_dir = os.path.dirname(own_path)
icon_path = os.path.join(own_dir, 'appicons', icon_name)
if os.path.isfile(icon_path):
return icon_path
return None
def run_magnetic_trap():
arduino_commands = {'open': 'o', 'close': 'c'}
icon = check_icon('Household-Mouse-Trap.ico')
run_application(arduino_commands, "It's a trap!", icon=icon)

8
arduino_timetable/gui.py

@ -129,11 +129,7 @@ class ParsedCommandsPanel(tk.Frame):
self._parent = parent self._parent = parent
self.label = tk.Label(self) self.label = tk.Label(self)
self.label.pack(fill=tk.X, pady=5, padx=5) self.label.pack(fill=tk.X, pady=5, padx=5)
self.messages = tk.Message(self, self.messages = tk.Message(self, text='', font=("Courier", 8))
text='',
font=("Courier", 8),
width=250
)
self.messages.pack(fill=tk.X, pady=5, padx=5) self.messages.pack(fill=tk.X, pady=5, padx=5)
self.pack(side=tk.TOP, fill=tk.X) self.pack(side=tk.TOP, fill=tk.X)
@ -279,7 +275,7 @@ class Application(tk.Frame):
''' selecting a new excel file with scheduled_commands ''' ''' selecting a new excel file with scheduled_commands '''
# open the file selection dialog # open the file selection dialog
opts = { opts = {
'initialdir': '~/Desktop', 'initialdir': '~/',
'filetypes': [('Excel Files', '.xlsx')], 'filetypes': [('Excel Files', '.xlsx')],
'multiple': False} 'multiple': False}
excel_file = tk.filedialog.askopenfilename(**opts) excel_file = tk.filedialog.askopenfilename(**opts)

4
arduino_timetable/timetable.py

@ -74,7 +74,7 @@ def parse_time_table(timetable, available_commands=None):
# add a ScheduledCommand to the resulting list # add a ScheduledCommand to the resulting list
tc = ScheduledCommand(delta, raw_command, cmd) tc = ScheduledCommand(delta, raw_command, cmd)
timed_commands.append(tc) timed_commands.append(tc)
return sorted(timed_commands, key=lambda tc: tc.delta) return timed_commands
def parse_excel_file(path, available_commands=None): def parse_excel_file(path, available_commands=None):
@ -122,7 +122,7 @@ def parse_excel_file(path, available_commands=None):
# add a ScheduledCommand to the resulting list # add a ScheduledCommand to the resulting list
tc = ScheduledCommand(delta, raw_command, cmd) tc = ScheduledCommand(delta, raw_command, cmd)
timed_commands.append(tc) timed_commands.append(tc)
return sorted(timed_commands, key=lambda tc: tc.delta) return timed_commands
def parse_time_cell(excel_cell): def parse_time_cell(excel_cell):

10
pyinstaller_make.bat

@ -0,0 +1,10 @@
pyinstaller ^
--noconfirm ^
--additional-hooks-dir=. ^
--hidden-import=packaging ^
--hidden-import=packaging.version ^
--hidden-import=packaging.specifiers ^
--hidden-import=packaging.requirements ^
--name MagneticTrap ^
--icon Household-Mouse-Trap.ico ^
run_magnetic_trap.py

9
run_magnetic_trap.py

@ -0,0 +1,9 @@
from arduino_timetable import run_application
if __name__=='__main__':
arduino_commands = {'open': 'o', 'close': 'c'}
run_application(
arduino_commands,
"It's a trap!",
icon='Household-Mouse-Trap.ico'
)

13
setup.py

@ -117,17 +117,4 @@ setup(
# 'test': ['pytest'], # 'test': ['pytest'],
# }, # },
# if and what non python files be included?
include_package_data=True,
package_data={
'arduino_timetable': ['appicons/*.ico'],
},
# defining entry points, escpecially console script:
entry_points={
'console_scripts': [
'magnetictrap = arduino_timetable.apps:run_magnetic_trap',
],
},
) )

Loading…
Cancel
Save