Name | pytrain-ogr JSON |
Version |
0.9.46
JSON |
| download |
home_page | None |
Summary | Control Lionel TMCC/Legacy engines, switches, and accesseries from a Raspberry Pi |
upload_time | 2025-01-22 03:12:18 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. |
keywords |
automation
interactive
control
legacy
lionel
o-gauge
raspberry pi
tmcc
trains
|
VCS |
|
bugtrack_url |
|
requirements |
RPLCD
colorzero
gpiozero
pyserial
range-key-dict
setuptools
setuptools_scm
smbus2
zeroconf
lgpio
typing_extensions
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
This project contains software to operate and control trains and other equipment that utilize
Lionel's [TMCC and Legacy serial command protocol](https://ogrforum.com/fileSendAction/fcType/0/fcOid/156701992259624343/filePointer/156701992265497355/fodoid/156701992265497351/LCS-LEGACY-Protocol-Spec-v1.21.pdf).
Most Lionel engines produced after 2000 support either TMCC or Legacy, and all engines produced after 2010 do.
Additionally, Lionel makes track switches, operating accessories, as well as LCS modules that control your
layout that respond to Legacy commands (see
[Lionel Layout Control System: LCS](https://control.lionel.com/docs/lionel-layout-control-system-lcs/)).
**PyTrain** is developed in pure Python and can be run on Windows, Macs (Intel and M-series) as well as
inexpensive Raspberry Pi systems. My goal is to convert physical button presses on a Pi
to the corresponding
Legacy commands in response. This will facilitate the construction of operating control panels I will place
on my layout to fire routes, turn on and off power districts, operate accessories, and run trains.
Initial development focuses on the development of command-line tools (CLI) to operate engines
and trains, throw switches, operate accessories, and fire custom routes. This will be followed by
developing code to translate physical button presses on a Raspberry Pi to Legacy and TMCC command
actions, allowing the development of physical control panels to operate trains.
<div style="font-size: 16px; ">
<!-- TOC -->
* [Quick Start](#quick-start)
* [Concepts](#concepts)
* [Requirements](#requirements)
* [Installation](#installation)
* [Raspberry Pi Configuration](#raspberry-pi-configuration)
* [Audience](#audience)
* [Model Railroad Enthusiasts](#model-railroad-enthusiasts)
* [Simple Panel](#simple-panel)
* [Raspberry Pi GPIO Pins](#raspberry-pi-gpio-pins)
* [Lionel Legacy Gantry Crane and Yard](#lionel-legacy-gantry-crane-and-yard)
* [Developers](#developers)
* [Command-line Tools](#command-line-tools)
* [PyTrain](#pytrain)
* [PiConfig](#piconfig)
* [Contributing](#contributing)
* [Development](#development)
* [Requirements](#requirements-1)
* [Macintosh:](#macintosh)
* [Raspberry Pi and Pi Zero W 2](#raspberry-pi-and-pi-zero-w-2)
* [Installation and one time setup](#installation-and-one-time-setup)
* [Future Enhancements](#future-enhancements)
* [License](#license)
<!-- TOC -->
</div>
## Quick Start
If you are anxious to get going and take **Pytrain** for a spin, this section is for you.
If you want a more detailed overview of what **PyTrain** is, why it was written, and what
you can do with it, start with the [Audience](#audience) section below.
This section assumes you want to build a physical con
### Requirements
Minimum requirements to use **PyTrain** are:
* A Lionel Base 3 running the most current Lionel firmware
* One or more Raspberry Pi 4 or 5 Wi-Fi-equipped computers with at least 2 GB of RAM running
Raspberry PI OS 64-bit Bookworm
* A Mac or Windows computer to set up the Raspberry Pi(s)
* All hardware connected to the same Wi-Fi network
* Python 3.10 - 3.12 installed (Python 3.11 is standard with the Bookworm release of Raspberry Pi OS)
* Internet access (to download software)
Notes:
* It is recommended to have a Lionel LCS Ser2 module connected to your **PyTrain** server, as
the Lionel Base 3 **_does not_** broadcast all layout activity
* **PyTrain** is a command-line tool. It must be run from a Terminal window (macOS/Linux/Pi) or a Cmd
shell (Windows). **PyTrain** does _not_ have a GUI nor run as a native app.
* **PyTrain** _may_ work with an LCS Wi-Fi module, but this configuration hasn't been tested
* The **PyTrain** CLI can be run on a Mac or Windows system. It allows complete control of _all_ TMCC or
Legacy-equipped devices as well as allows you to monitor all TMCC and Legacy commands
### Installation
#### Create a Python Virtual Environment
**PyTrain** is a pure Python application designed to run under Python 3.10, 3.11, and 3.12.
To prevent conflicts between Python applications that use different versions of common support
libraries, most platforms (macOS and Raspberry) require new python packages to be installed into
[virtual environments](https://developer.vonage.com/en/blog/a-comprehensive-guide-on-working-with-python-virtual-environments#using-venv).
This step only needs to be done once, but it does need to happen on every system
where __PyTrain__ will be installed (macOS/Raspberry Pi/Linux example):
* Open a Terminal shell window and navigate to the folder/directory where you will install __PyTrain__
* Create the new virtual environment with the command:
```aiignore
python3 -m venv PyTrain
```
* In the same terminal window, `cd` into the directory you created above and activate the environment:
```aiignore
cd PyTrain
source ./bin/activate
```
Note: You will need to repeat these two commands any time you want to run **PyTrain**.
* Install **PyTrain**; this step only needs to be done once:
```aiignore
pip3 install pytrain-ogr
```
* Run **PyTrain** and connect to your Lionel Base 3:
```aiignore
(PyTrain) davids@CDS-Mac-Studio PyTrain % pytrain -base 192.168.1.124
Listening for client requests on port 5110...
Listening for Lionel Base broadcasts on 192.168.1.124:50001...
Sending commands directly to Lionel Base at 192.168.1.124:50001...
Registering listeners...
Loading roster from Lionel Base at 192.168.1.124 ...Done
PyTrain, v0.9.40
PyTrain Service registered successfully!
>>
```
### Raspberry Pi Configuration
Out of the box, as Raspberry Pi 4/5 supports **PyTrain** and can be installed and run as
detailed above. However, the Pi and its OS were developed to be low-cost, general purpose computers
capable of sending and receiving email, running web browsers, playing games, driving printers, etc.
Disabling and removing the unneeded software means there will be more of your Pi available for **PyTrain**.
**PiConfig** is a program that automatically disables and removes software
not needed to support **PyTrain**.It also can configure the hardware interfaces appropriately. Your
Pi will boot faster and use less memory if you remove all the suggested software. If you change
your mind, deleted packages can be reinstalled at any time.
**PiConfig** is installed alongside of **PyTrain**.
To run PiConfig:
* Open a Terminal shell window and navigate to the folder/directory where you installed **PyTrain**
* Activate the virtual environment:
```aiignore
source ./bin/activate
```
* Run **PiConfig** and display the `help` options:
```aiignore
(PyTrain) davids@PiZ2w:~/dev/PyTrain $ piconfig -h
usage: piconfig [-h] [-quiet] [-all] [-check] [-configuration] [-expand_file_system] [-packages] [-services] [-version]
options:
-h, --help show this help message and exit
-quiet Operate quietly and don't provide feedback
-all Perform all optimizations
-check Check Raspberry Pi configuration (no changes made; default option)
-configuration Enable/disable Raspberry Pi configuration options
-expand_file_system Expand file system and reboot
-packages Only remove unneeded packages
-services Only disable unneeded services
-version Show version and exit
(PyTrain) davids@PiZ2w:~/dev/PyTrain $
```
* Use the `-check` option (or run the program with no switches) what changes should be made
to your system:
```aiignore
piconfig -check
```
* Use the `-all` option to modify your Pi's configuration and remove unnecessary software (this may
take some time to complete). Note that removal of the squeekboard keyboard may generate errors; these
are of no concern:
```aiignore
piconfig -all
```
* Reboot your system to apply configuration changes:
```aiignore
sudo reboot
```
### Running **PyTrain**
**PyTrain** is the heart of the system. In addition to allowing you to control layout from
it's command-line interface, **PyTrain**:
* allows you to map physical button presses to Lionel TMCC commands, allowing you to build
simple to sophisticated control panels to run your layout
* monitors the state of every TMCC/Legacy-equipped component, including engines, switches, and accessories
* communicates and controls your LCS components, including the ASC2, BPC2, STM2, and all Sensor Tracks
* communicates with the LCS SER2, if available, allowing complete visibility of all TMCC command traffic
* communicates with your Base 3 and downloads your entire/train roster, allowing you to see the current
speed, labor, momentum, and train brake settings, along with road name and number
* the same for switches (turnouts) and TMCC/Legacy/LCS accessories
* operate as a server to other **PyTrain** clients running on other Raspberry Pis (or on your desktop)
relaying real-time state and forwarding command actions from your control panels
* can echo all TMCC and PDI command traffic
* logs all activity
* and much more!
#### Command-line Options
**PyTrain** has several startup switches that control what it does:
```aiignore
usage: pytrain [-h] [-base [BASE ...] | -client | -server SERVER]
[-ser2] [-baudrate {9600,19200,38400,57600,115200}] [-port PORT]
[-echo] [-headless] [-no_wait] [-ser2]
[-server_port SERVER_PORT] [-startup_script STARTUP_SCRIPT] [-version]
Send TMCC and Legacy-formatted commands to a Lionel Base 3 and/or LCS Ser2
options:
-h, --help show this help message and exit
-base [BASE ...] Connect to Lionel Base 2/3 or LCS Wi-Fi at IP address (Server mode)
-client Connect to an available PyTrain server (Client mode)
-server SERVER Connect to PyTrain server at IP address (Client mode)
-ser2 Send or receive TMCC commands from an LCS Ser2
-baudrate {9600,19200,38400,57600,115200}
Baud Rate used to communicate with LCS Ser2 (9600)
-port PORT Serial port for LCS Ser2 connection (/dev/ttyUSB0)
-echo Echo received TMCC/PDI commands to console
-headless Do not prompt for user input (run in background),
-no_wait Do not wait for roster download
-server_port SERVER_PORT
Port to use for remote connections, if client (default: 5110)
-startup_script STARTUP_SCRIPT
Run the commands in the specified file at start up (default: buttons.py)
-version Show version and exit
```
For example, to connect to a Lionel Base 3, you specify the Base 3's IP address on your local
network:
```aiignore
pytrain -base 192.168.1.124
```
If you also have an LCS Ser2 connected to a USB port on your Pi:
```aiignore
pytrain -base 192.168.1.124 -ser2
```
In this configuration, **PyTrain** will send all commands directly to the Base 3, but will monitor
the Ser2 for all TMCC command activity. This is important because currently, with Base 3 firmware
v1.32, the Base 3 broadcasts a limited subset of the TMCC command activity, whereas all activity is
reflected out of the LCS Ser2.
#### Miscellaneous
* To see a list of all **PyTrain** commands:
```aiignore
>> ?
usage: [h]
accessory | db | decode | dialogs | echo | effects | engine | train | halt | lighting |
pdi | quit | reboot | restart | route | shutdown | sounds | switch | update | upgrade |
uptime | version
Valid commands:
options:
h, help show this help message and exit
accessory Issue accessory commands
db Query engine/train/switch/accessory state
decode Decode TMCC command bytes
dialogs Trigger RailSounds dialogs
echo Enable/disable TMCC command echoing
effects Issue engine/train effects commands
engine Issue engine commands
train Issue train commands
halt Emergency stop
lighting Issue engine/train lighting effects commands
pdi Sent PDI commands
quit Quit PyTrain
reboot Quit PyTrain and reboot all nodes,
restart Quit PyTrain and restart on all nodes,
route Fire defined routes
shutdown Quit PyTrain and shutdown all nodes
sounds Issue engine/train RailSound effects commands
switch Throw switches
update Quit PyTrain and update all nodes to latest release,
upgrade Quit PyTrain, upgrade the OS on all nodes, and update to latest release,
uptime Elapsed time this instance of PyTrain has been active,
version Show current PyTrain version,
Commands can be abbreviated, so long as they are unique; e.g., 'en', or 'eng' are the same as typing
'engine'. Help on a specific command is also available by typing the command name (or abbreviation),
followed by '-h', e.g., 'sw -h'
```
* To echo TMCC/Lionel commands:
```aiignore
>> echo
TMCC command echoing ENABLED..
PDI command echoing ENABLED
>> en 67 -b
>> 17:16:09.202 [ENGINE 67 BLOW_HORN_ONE (0xf8871c)]
```
* To upgrade to new releases of **PyTrain**:
* from a Terminal window:
```aiignore
pip install -U pytrain-ogr
```
* From within **PyTrain** itself:
```aiignore
>> update
```
## Audience
The PyLegacy project is intended for:
* Model railroad enthusiasts wanting to add
physical control panels to run their layout, including:
* operating accessories
* switches (turnouts)
* power districts
* routes
* layout segments (e.g., yards, stations)
* engines, trains, and operating cars equipped with TMCC or Legacy technology
* control and recieve information from Lionel LCS Sensor Tracks
* LCS devices, including the ASC2, STM2, and BPC2
* Developers interested in:
* automated train control
* adding elements of randomness into their layouts (lights on & off, sounding horn or bell effects, etc.)
* building sequence commands that start up, ramp an engine to speed, then stop and shut down an engine
* integration with smart speakers and intelligent assistants (e.g., Alexa, Ok Google)
* console control of a layout via [ssh](https://www.raspberrypi.com/documentation/computers/remote-access.html#ssh)
* integrating model railroading and computer science
* learning the Lionel TMCC/Legacy command protocol
* continuing to develop software post retirement :smirk:
### Model Railroad Enthusiasts
For the first audience, model railroad enthusiasts, PyLegacy allows you to build
full functionality control panels that use physical switches, dials, and keypads to control
your layout and get real-time feedback on LEDs and multi-line LCD screens. The software,
called **_PyTrain_**, runs on small, low-cost [Raspberry Pis](https://www.raspberrypi.com). These are
inexpensive (< $100) single-board computers
that have connections (_pins_) to which you can attach physical controls (toggle switches, push buttons,
keypads, speed-control dials and levers, etc.), as well as LEDs, LCD screens, and other output devices.
An entire world of inexpensive hardware is available from Amazon and other online suppliers that let the
train enthusiast who is handy with a soldering iron build control interfaces limited only by their
imagination (and budget).
Rather than running wires from each control panel to the component(s) you want to control, you connect your
buttons, switches, LEDs, etc., to a Pi that you mount within your panel. The Raspberry Pi communicates with
your layout via Wi-Fi to a Lionel Base 3 or LCS Wi-Fi module. The only wire you need to connect to your panel
is power for the Pi itself!
What if you want multiple control panels situated near the layout elements you want to control? Simple!
Use multiple Raspberry Pis, mounting one in each control panel. The Pis communicate directly to a Base
3 (or LCS Wi-Fi module), or, you designate one of your Pi's as a _**server**_. This Pi will handle all
communication to and from your layout, and all the Pis that service your other panels, the _clients_,
communicate directly with the server over Wi-Fi.
PyTrain provides many tools to fire routes and operate turnouts, accessories, and even engines
right out of the box. All you need is to specify the TMCC ID of the component you want to operate and the
[pin(s)](https://gpiozero.readthedocs.io/en/latest/recipes.html#pin-numbering) on the Pi that the
physical buttons, LEDs, etc. connect to. **PyTrain** does the rest.
Let's say you want to control Lionel Turnout 12 (TMCC ID is 12).
The turnout can be a TMCC Command Controlled model or one that is wired to an LCS ASC2.
In this example, our panel would consist of a momentary (on)-off-(on) toggle switch and 2 bi-color red/green
LEDs. The LEDs show the active path a train would take when traversing the turnout from right to left. In the
panel below, the _through_ position is set, so the _through_ LED is green, and the _out_ LED is red. If we pull
down and release the toggle switch, the turnout changes to the _out_ position, and its LED lights green,
and the _through_ path turns red. The LEDs also respond to changes to the turnout caused by other controllers (Cab 2,
Cab 3), other control panels, and other software as well as to changes caused by the auto-derail feature of
FasTrack turnouts.
<div align="center">
![switch-example.png](https://github.com/cdswindell/PyLegacy/raw/master/doc/images/switch-example.png)
#### Simple Panel
</div>
To construct this panel, we connect the toggle switch and LEDs to pins on the Raspberry Pi. Below is a
schematic of a Pi pinout, taken from the [GPIO Zero](https://gpiozero.readthedocs.io/en/latest/index.html)
project, which is used by **PyTrain**:
<div align="center">
![pin_layout.png](https://gpiozero.readthedocs.io/en/latest/_images/pin_layout.svg)
#### Raspberry Pi GPIO Pins
</div>
To control and show the state of our turnout, we connect the center terminal of the toggle switch and
the common cathode lead of our Bi-Color LEDs to a GND pin on the Pi (any will do). We next pick
the pins we will connect the other two terminals of the toggle (up for _through_ and down for _out_), and
the 4 leads of the 2 LEDs. We can use any of the pins colored green above, as well as GPIO pins 7, 8, 9, 10, 11,
14, and 15. Pins GPIO 2 and GPIO 3 are reserved to communicate with expander boards that provide
additional GPIO pins, as are pins ID SD and ID SC.
Let's say we make the following connections:
| Pin | Component | Function |
|:---:|---------------|------------|
| 7 | Toggle (Up) | Through |
| 8 | Toggle (Down) | Out |
| 9 | Thru LED | Green Lead |
| 10 | Thru LED | Red Lead |
| 10 | Out LED | Green Lead |
| 9 | Out LED | Red Lead |
Here's the Python code to control the turnout:
```
from pytrain import GpioHandler
GpioHandler.switch(
address = 12, # TMCC ID of the turnout to control
thru_pin = 7,
out_pin = 8,
thru_led_pin = 9,
out_led_pin = 10
)
```
Note that the pins driving the 2 LEDs, 9 & 10 are connected to _both_ LEDs.
Because the LEDs in our example are bi-color, when power is applied to pin 9,
it simultaneously lights the green element in the _through_ LED and the red
element in the _out_ LED.
When we pull _down_ on the toggle switch, pin 8 is connected to GND. The **PyTrain**
sends the TMCC command to your Base 3 or LCS Wi-Fi to set the turnout to the _out_ position. It
also turns off the power to pin 9 and turns on the power to pin 10, causing the red element in
the "through" led to illuminate, and the green element in the _out_ led to illuminate. The **PyTrain**
software supports _**all**_ TMCC and Legacy commands, including almost all the
functionality available on the Cab 2 and Cab 3 controllers, including control of engine smoke, lights,
engine sounds, speed, momentum, volume, dialog, whistle and bell sounds, and much more.
It can also fire routes, control momentary and on/off accessories, rotate gantry cranes, etc.
Below is another control panel designed to operate a Lionel Command Control Gantry and the track and turnout
leading to it. This panel uses a 2-axis joystick
to move the gantry back and forth on the special GarGraves 5-rail track, as well as to lift the magnet
up and down. A Rotary Encoder is used to rotate the crane cab. The encoder I use has a push button
built in that turns the magnet on and off. A yellow LED is lit and blinks when the magnet is energized.
The panel also allows control of the two track power blocks in this part of my layout, as well
as the turnout to the two track segments.
<div align="center">
![gantry.jpg](https://github.com/cdswindell/PyLegacy/raw/master/doc/images/gantry.jpg)
#### Lionel Legacy Gantry Crane and Yard
</div>
Here's the corresponding Python code:
```
from pytrain import GpioHandler
GpioHandler.gantry_crane(
address=96, # TMCC ID of Gantry Crane
cab_pin_1=20, # Cab rotation controlled by a
cab_pin_2=21, # Rotary Encoder connected to pins 20 & 21
lift_chn=0, # Boom controlled by 1 axis of Joystick
roll_chn=1, # Lateral motion controlled by the other
mag_pin=16, # Turns magnet on when pressed
led_pin=24, # Blinks when magnet is energized
)
GpioHandler.switch(
address=1, # TMCC ID of the yard turnout
thru_pin=7,
out_pin=8,
thru_led_pin=9,
out_led_pin=10
)
GpioHandler.power_district(
address=5, # TMCC ID of North Yard Power District
on_pin=11, # Track Power On
off_pin=12, # Track Power Off
on_led=26, # Track power on when lit
)
GpioHandler.power_district(
address=6, # TMCC ID of South Yard Power District
on_pin=13, # Track Power On
off_pin=14, # Track Power Off
on_led=27, # Track power on when lit
)
```
### Developers
For developers...
## Command-line Tools
PyLegacy includes several command-line tools you
The `cli` directory contains a number of Python command line scripts allowing
you to operate engines, control switches and accessories, and fire custom routes.
### PyTrain
### PiConfig
## Contributing
## Development
### Requirements
#### Macintosh:
- Brew:
`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
- Python 3.12.6 (your version may be newer; Note: Python 3.13 is _**not**_ supported:
`brew install python@3.12`
- gh:
`brew install gh`
- git (if you plan to modify the code and issue pull requests):
`brew install git`
#### Raspberry Pi and Pi Zero W 2
- Python 3.11, gh, and git:
```
sudo apt update
sudo apt upgrade
sudo apt install python3
sudo apt install gh
sudo apt install git
```
For the Raspberry Pi Zero W (**NOT** the 2 W):
```
sudo apt-get install swig
```
**Note**: some or all of this software may already be installed on your pi
### Installation and one time setup
```
cd /where/you/like/your/source
# Make sure this says 3.11. or greater; don't keep going in these directions until it does
python3 --version
# authenticate gh/git:
gh auth login
# establish a virtual Python environment
# see: https://docs.python.org/3/library/venv.html
python3 -m venv PyLegacyEnv
cd PyLegacyEnv
gh repo clone cdswindell/PyLegacy
cd PyLegacy
# Activate virtual environment
source ../bin/activate; export PYTHONPATH=.
# Install 3rd-party dependencies
pip3 install -r requirements.txt
```
You will need to activate this local python environment every time you open a
new shell, after changing your working directory to the `PyLegacy` local directory by typing:
```
source ../bin/activate
export PYTHONPATH=.
```
You may wish to create a macro or alias to issue these commands for you.
## Future Enhancements
## License
This software and its use are governed by the GNU Lesser General Public License (LPGL).
Raw data
{
"_id": null,
"home_page": null,
"name": "pytrain-ogr",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "automation, interactive, control, legacy, lionel, o-gauge, raspberry pi, tmcc, trains",
"author": null,
"author_email": "Dave Swindell <pytraininfo@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/e1/7e/02b467e4aefba4a145cdd857d24964bd969c20f5787d47ccffa74f38b955/pytrain_ogr-0.9.46.tar.gz",
"platform": null,
"description": "This project contains software to operate and control trains and other equipment that utilize\nLionel's [TMCC and Legacy serial command protocol](https://ogrforum.com/fileSendAction/fcType/0/fcOid/156701992259624343/filePointer/156701992265497355/fodoid/156701992265497351/LCS-LEGACY-Protocol-Spec-v1.21.pdf).\nMost Lionel engines produced after 2000 support either TMCC or Legacy, and all engines produced after 2010 do.\nAdditionally, Lionel makes track switches, operating accessories, as well as LCS modules that control your\nlayout that respond to Legacy commands (see\n[Lionel Layout Control System: LCS](https://control.lionel.com/docs/lionel-layout-control-system-lcs/)).\n\n**PyTrain** is developed in pure Python and can be run on Windows, Macs (Intel and M-series) as well as\ninexpensive Raspberry Pi systems. My goal is to convert physical button presses on a Pi\nto the corresponding\nLegacy commands in response. This will facilitate the construction of operating control panels I will place\non my layout to fire routes, turn on and off power districts, operate accessories, and run trains.\n\nInitial development focuses on the development of command-line tools (CLI) to operate engines\nand trains, throw switches, operate accessories, and fire custom routes. This will be followed by\ndeveloping code to translate physical button presses on a Raspberry Pi to Legacy and TMCC command\nactions, allowing the development of physical control panels to operate trains.\n\n<div style=\"font-size: 16px; \">\n<!-- TOC -->\n * [Quick Start](#quick-start)\n * [Concepts](#concepts)\n * [Requirements](#requirements)\n * [Installation](#installation)\n * [Raspberry Pi Configuration](#raspberry-pi-configuration)\n * [Audience](#audience)\n * [Model Railroad Enthusiasts](#model-railroad-enthusiasts)\n * [Simple Panel](#simple-panel)\n * [Raspberry Pi GPIO Pins](#raspberry-pi-gpio-pins)\n * [Lionel Legacy Gantry Crane and Yard](#lionel-legacy-gantry-crane-and-yard)\n * [Developers](#developers)\n * [Command-line Tools](#command-line-tools)\n * [PyTrain](#pytrain)\n * [PiConfig](#piconfig)\n * [Contributing](#contributing)\n * [Development](#development)\n * [Requirements](#requirements-1)\n * [Macintosh:](#macintosh)\n * [Raspberry Pi and Pi Zero W 2](#raspberry-pi-and-pi-zero-w-2)\n * [Installation and one time setup](#installation-and-one-time-setup)\n * [Future Enhancements](#future-enhancements)\n * [License](#license)\n<!-- TOC -->\n</div>\n\n## Quick Start\n\nIf you are anxious to get going and take **Pytrain** for a spin, this section is for you.\nIf you want a more detailed overview of what **PyTrain** is, why it was written, and what\nyou can do with it, start with the [Audience](#audience) section below.\n\nThis section assumes you want to build a physical con\n\n### Requirements\n\nMinimum requirements to use **PyTrain** are:\n\n* A Lionel Base 3 running the most current Lionel firmware\n* One or more Raspberry Pi 4 or 5 Wi-Fi-equipped computers with at least 2 GB of RAM running\n Raspberry PI OS 64-bit Bookworm\n* A Mac or Windows computer to set up the Raspberry Pi(s)\n* All hardware connected to the same Wi-Fi network\n* Python 3.10 - 3.12 installed (Python 3.11 is standard with the Bookworm release of Raspberry Pi OS)\n* Internet access (to download software)\n\nNotes:\n\n* It is recommended to have a Lionel LCS Ser2 module connected to your **PyTrain** server, as\n the Lionel Base 3 **_does not_** broadcast all layout activity\n* **PyTrain** is a command-line tool. It must be run from a Terminal window (macOS/Linux/Pi) or a Cmd\n shell (Windows). **PyTrain** does _not_ have a GUI nor run as a native app.\n* **PyTrain** _may_ work with an LCS Wi-Fi module, but this configuration hasn't been tested\n* The **PyTrain** CLI can be run on a Mac or Windows system. It allows complete control of _all_ TMCC or\n Legacy-equipped devices as well as allows you to monitor all TMCC and Legacy commands\n\n### Installation\n\n#### Create a Python Virtual Environment\n\n**PyTrain** is a pure Python application designed to run under Python 3.10, 3.11, and 3.12.\nTo prevent conflicts between Python applications that use different versions of common support\nlibraries, most platforms (macOS and Raspberry) require new python packages to be installed into\n[virtual environments](https://developer.vonage.com/en/blog/a-comprehensive-guide-on-working-with-python-virtual-environments#using-venv).\nThis step only needs to be done once, but it does need to happen on every system\nwhere __PyTrain__ will be installed (macOS/Raspberry Pi/Linux example):\n\n* Open a Terminal shell window and navigate to the folder/directory where you will install __PyTrain__\n* Create the new virtual environment with the command:\n\n```aiignore\npython3 -m venv PyTrain\n```\n\n* In the same terminal window, `cd` into the directory you created above and activate the environment:\n\n```aiignore\ncd PyTrain\nsource ./bin/activate\n```\n\nNote: You will need to repeat these two commands any time you want to run **PyTrain**.\n\n* Install **PyTrain**; this step only needs to be done once:\n\n```aiignore\npip3 install pytrain-ogr\n```\n\n* Run **PyTrain** and connect to your Lionel Base 3:\n\n```aiignore\n(PyTrain) davids@CDS-Mac-Studio PyTrain % pytrain -base 192.168.1.124\nListening for client requests on port 5110...\nListening for Lionel Base broadcasts on 192.168.1.124:50001...\nSending commands directly to Lionel Base at 192.168.1.124:50001...\nRegistering listeners...\nLoading roster from Lionel Base at 192.168.1.124 ...Done\nPyTrain, v0.9.40\nPyTrain Service registered successfully!\n>> \n```\n\n### Raspberry Pi Configuration\n\nOut of the box, as Raspberry Pi 4/5 supports **PyTrain** and can be installed and run as\ndetailed above. However, the Pi and its OS were developed to be low-cost, general purpose computers\ncapable of sending and receiving email, running web browsers, playing games, driving printers, etc.\nDisabling and removing the unneeded software means there will be more of your Pi available for **PyTrain**.\n\n**PiConfig** is a program that automatically disables and removes software\nnot needed to support **PyTrain**.It also can configure the hardware interfaces appropriately. Your\nPi will boot faster and use less memory if you remove all the suggested software. If you change\nyour mind, deleted packages can be reinstalled at any time.\n**PiConfig** is installed alongside of **PyTrain**.\n\nTo run PiConfig:\n\n* Open a Terminal shell window and navigate to the folder/directory where you installed **PyTrain**\n* Activate the virtual environment:\n\n```aiignore\nsource ./bin/activate\n```\n\n* Run **PiConfig** and display the `help` options:\n\n```aiignore\n(PyTrain) davids@PiZ2w:~/dev/PyTrain $ piconfig -h\nusage: piconfig [-h] [-quiet] [-all] [-check] [-configuration] [-expand_file_system] [-packages] [-services] [-version]\n\noptions:\n -h, --help show this help message and exit\n -quiet Operate quietly and don't provide feedback\n -all Perform all optimizations\n -check Check Raspberry Pi configuration (no changes made; default option)\n -configuration Enable/disable Raspberry Pi configuration options\n -expand_file_system Expand file system and reboot\n -packages Only remove unneeded packages\n -services Only disable unneeded services\n -version Show version and exit\n(PyTrain) davids@PiZ2w:~/dev/PyTrain $ \n```\n\n* Use the `-check` option (or run the program with no switches) what changes should be made\n to your system:\n\n```aiignore\npiconfig -check\n```\n\n* Use the `-all` option to modify your Pi's configuration and remove unnecessary software (this may\n take some time to complete). Note that removal of the squeekboard keyboard may generate errors; these\n are of no concern:\n\n```aiignore\npiconfig -all\n```\n\n* Reboot your system to apply configuration changes:\n\n```aiignore\nsudo reboot\n```\n\n### Running **PyTrain**\n\n**PyTrain** is the heart of the system. In addition to allowing you to control layout from\nit's command-line interface, **PyTrain**:\n\n* allows you to map physical button presses to Lionel TMCC commands, allowing you to build\n simple to sophisticated control panels to run your layout\n* monitors the state of every TMCC/Legacy-equipped component, including engines, switches, and accessories\n* communicates and controls your LCS components, including the ASC2, BPC2, STM2, and all Sensor Tracks\n* communicates with the LCS SER2, if available, allowing complete visibility of all TMCC command traffic\n* communicates with your Base 3 and downloads your entire/train roster, allowing you to see the current\n speed, labor, momentum, and train brake settings, along with road name and number\n* the same for switches (turnouts) and TMCC/Legacy/LCS accessories\n* operate as a server to other **PyTrain** clients running on other Raspberry Pis (or on your desktop)\n relaying real-time state and forwarding command actions from your control panels\n* can echo all TMCC and PDI command traffic\n* logs all activity\n* and much more!\n\n#### Command-line Options\n\n**PyTrain** has several startup switches that control what it does:\n\n```aiignore\nusage: pytrain [-h] [-base [BASE ...] | -client | -server SERVER] \n [-ser2] [-baudrate {9600,19200,38400,57600,115200}] [-port PORT] \n [-echo] [-headless] [-no_wait] [-ser2]\n [-server_port SERVER_PORT] [-startup_script STARTUP_SCRIPT] [-version]\n\nSend TMCC and Legacy-formatted commands to a Lionel Base 3 and/or LCS Ser2\n\noptions:\n -h, --help show this help message and exit\n -base [BASE ...] Connect to Lionel Base 2/3 or LCS Wi-Fi at IP address (Server mode)\n -client Connect to an available PyTrain server (Client mode)\n -server SERVER Connect to PyTrain server at IP address (Client mode)\n -ser2 Send or receive TMCC commands from an LCS Ser2\n -baudrate {9600,19200,38400,57600,115200}\n Baud Rate used to communicate with LCS Ser2 (9600)\n -port PORT Serial port for LCS Ser2 connection (/dev/ttyUSB0)\n -echo Echo received TMCC/PDI commands to console\n -headless Do not prompt for user input (run in background),\n -no_wait Do not wait for roster download\n -server_port SERVER_PORT\n Port to use for remote connections, if client (default: 5110)\n -startup_script STARTUP_SCRIPT\n Run the commands in the specified file at start up (default: buttons.py)\n -version Show version and exit\n```\n\nFor example, to connect to a Lionel Base 3, you specify the Base 3's IP address on your local\nnetwork:\n\n```aiignore\npytrain -base 192.168.1.124\n```\n\nIf you also have an LCS Ser2 connected to a USB port on your Pi:\n\n```aiignore\npytrain -base 192.168.1.124 -ser2\n```\n\nIn this configuration, **PyTrain** will send all commands directly to the Base 3, but will monitor\nthe Ser2 for all TMCC command activity. This is important because currently, with Base 3 firmware\nv1.32, the Base 3 broadcasts a limited subset of the TMCC command activity, whereas all activity is\nreflected out of the LCS Ser2.\n\n#### Miscellaneous\n\n* To see a list of all **PyTrain** commands:\n\n```aiignore\n>> ?\nusage: [h]\n accessory | db | decode | dialogs | echo | effects | engine | train | halt | lighting |\n pdi | quit | reboot | restart | route | shutdown | sounds | switch | update | upgrade | \n uptime | version\n\nValid commands:\n\noptions:\n h, help show this help message and exit\n accessory Issue accessory commands\n db Query engine/train/switch/accessory state\n decode Decode TMCC command bytes\n dialogs Trigger RailSounds dialogs\n echo Enable/disable TMCC command echoing\n effects Issue engine/train effects commands\n engine Issue engine commands\n train Issue train commands\n halt Emergency stop\n lighting Issue engine/train lighting effects commands\n pdi Sent PDI commands\n quit Quit PyTrain\n reboot Quit PyTrain and reboot all nodes,\n restart Quit PyTrain and restart on all nodes,\n route Fire defined routes\n shutdown Quit PyTrain and shutdown all nodes\n sounds Issue engine/train RailSound effects commands\n switch Throw switches\n update Quit PyTrain and update all nodes to latest release,\n upgrade Quit PyTrain, upgrade the OS on all nodes, and update to latest release,\n uptime Elapsed time this instance of PyTrain has been active,\n version Show current PyTrain version,\n\nCommands can be abbreviated, so long as they are unique; e.g., 'en', or 'eng' are the same as typing \n'engine'. Help on a specific command is also available by typing the command name (or abbreviation), \nfollowed by '-h', e.g., 'sw -h'\n```\n\n* To echo TMCC/Lionel commands:\n\n```aiignore\n>> echo\nTMCC command echoing ENABLED..\nPDI command echoing ENABLED\n>> en 67 -b\n>> 17:16:09.202 [ENGINE 67 BLOW_HORN_ONE (0xf8871c)]\n```\n\n* To upgrade to new releases of **PyTrain**:\n * from a Terminal window:\n\n```aiignore\npip install -U pytrain-ogr\n```\n\n* From within **PyTrain** itself:\n\n```aiignore\n>> update\n```\n\n## Audience\n\nThe PyLegacy project is intended for:\n\n* Model railroad enthusiasts wanting to add\n physical control panels to run their layout, including:\n * operating accessories\n * switches (turnouts)\n * power districts\n * routes\n * layout segments (e.g., yards, stations)\n * engines, trains, and operating cars equipped with TMCC or Legacy technology\n * control and recieve information from Lionel LCS Sensor Tracks\n * LCS devices, including the ASC2, STM2, and BPC2\n* Developers interested in:\n * automated train control\n * adding elements of randomness into their layouts (lights on & off, sounding horn or bell effects, etc.)\n * building sequence commands that start up, ramp an engine to speed, then stop and shut down an engine\n * integration with smart speakers and intelligent assistants (e.g., Alexa, Ok Google)\n * console control of a layout via [ssh](https://www.raspberrypi.com/documentation/computers/remote-access.html#ssh)\n * integrating model railroading and computer science\n * learning the Lionel TMCC/Legacy command protocol\n * continuing to develop software post retirement :smirk:\n\n### Model Railroad Enthusiasts\n\nFor the first audience, model railroad enthusiasts, PyLegacy allows you to build\nfull functionality control panels that use physical switches, dials, and keypads to control\nyour layout and get real-time feedback on LEDs and multi-line LCD screens. The software,\ncalled **_PyTrain_**, runs on small, low-cost [Raspberry Pis](https://www.raspberrypi.com). These are\ninexpensive (< $100) single-board computers\nthat have connections (_pins_) to which you can attach physical controls (toggle switches, push buttons,\nkeypads, speed-control dials and levers, etc.), as well as LEDs, LCD screens, and other output devices.\nAn entire world of inexpensive hardware is available from Amazon and other online suppliers that let the\ntrain enthusiast who is handy with a soldering iron build control interfaces limited only by their\nimagination (and budget).\n\nRather than running wires from each control panel to the component(s) you want to control, you connect your\nbuttons, switches, LEDs, etc., to a Pi that you mount within your panel. The Raspberry Pi communicates with\nyour layout via Wi-Fi to a Lionel Base 3 or LCS Wi-Fi module. The only wire you need to connect to your panel\nis power for the Pi itself!\n\nWhat if you want multiple control panels situated near the layout elements you want to control? Simple!\nUse multiple Raspberry Pis, mounting one in each control panel. The Pis communicate directly to a Base\n3 (or LCS Wi-Fi module), or, you designate one of your Pi's as a _**server**_. This Pi will handle all\ncommunication to and from your layout, and all the Pis that service your other panels, the _clients_,\ncommunicate directly with the server over Wi-Fi.\n\nPyTrain provides many tools to fire routes and operate turnouts, accessories, and even engines\nright out of the box. All you need is to specify the TMCC ID of the component you want to operate and the\n[pin(s)](https://gpiozero.readthedocs.io/en/latest/recipes.html#pin-numbering) on the Pi that the\nphysical buttons, LEDs, etc. connect to. **PyTrain** does the rest.\n\nLet's say you want to control Lionel Turnout 12 (TMCC ID is 12).\nThe turnout can be a TMCC Command Controlled model or one that is wired to an LCS ASC2.\nIn this example, our panel would consist of a momentary (on)-off-(on) toggle switch and 2 bi-color red/green\nLEDs. The LEDs show the active path a train would take when traversing the turnout from right to left. In the\npanel below, the _through_ position is set, so the _through_ LED is green, and the _out_ LED is red. If we pull\ndown and release the toggle switch, the turnout changes to the _out_ position, and its LED lights green,\nand the _through_ path turns red. The LEDs also respond to changes to the turnout caused by other controllers (Cab 2,\nCab 3), other control panels, and other software as well as to changes caused by the auto-derail feature of\nFasTrack turnouts.\n\n<div align=\"center\">\n\n![switch-example.png](https://github.com/cdswindell/PyLegacy/raw/master/doc/images/switch-example.png)\n\n#### Simple Panel\n\n</div>\n\nTo construct this panel, we connect the toggle switch and LEDs to pins on the Raspberry Pi. Below is a\nschematic of a Pi pinout, taken from the [GPIO Zero](https://gpiozero.readthedocs.io/en/latest/index.html)\nproject, which is used by **PyTrain**:\n\n<div align=\"center\">\n\n![pin_layout.png](https://gpiozero.readthedocs.io/en/latest/_images/pin_layout.svg)\n\n#### Raspberry Pi GPIO Pins\n\n</div>\n\nTo control and show the state of our turnout, we connect the center terminal of the toggle switch and\nthe common cathode lead of our Bi-Color LEDs to a GND pin on the Pi (any will do). We next pick\nthe pins we will connect the other two terminals of the toggle (up for _through_ and down for _out_), and\nthe 4 leads of the 2 LEDs. We can use any of the pins colored green above, as well as GPIO pins 7, 8, 9, 10, 11,\n14, and 15. Pins GPIO 2 and GPIO 3 are reserved to communicate with expander boards that provide\nadditional GPIO pins, as are pins ID SD and ID SC.\n\nLet's say we make the following connections:\n\n| Pin | Component | Function |\n|:---:|---------------|------------|\n| 7 | Toggle (Up) | Through |\n| 8 | Toggle (Down) | Out |\n| 9 | Thru LED | Green Lead |\n| 10 | Thru LED | Red Lead |\n| 10 | Out LED | Green Lead |\n| 9 | Out LED | Red Lead |\n\nHere's the Python code to control the turnout:\n\n```\nfrom pytrain import GpioHandler\n\nGpioHandler.switch(\n address = 12, # TMCC ID of the turnout to control\n thru_pin = 7, \n out_pin = 8, \n thru_led_pin = 9,\n out_led_pin = 10\n)\n```\n\nNote that the pins driving the 2 LEDs, 9 & 10 are connected to _both_ LEDs.\nBecause the LEDs in our example are bi-color, when power is applied to pin 9,\nit simultaneously lights the green element in the _through_ LED and the red\nelement in the _out_ LED.\n\nWhen we pull _down_ on the toggle switch, pin 8 is connected to GND. The **PyTrain**\nsends the TMCC command to your Base 3 or LCS Wi-Fi to set the turnout to the _out_ position. It\nalso turns off the power to pin 9 and turns on the power to pin 10, causing the red element in\nthe \"through\" led to illuminate, and the green element in the _out_ led to illuminate. The **PyTrain**\nsoftware supports _**all**_ TMCC and Legacy commands, including almost all the\nfunctionality available on the Cab 2 and Cab 3 controllers, including control of engine smoke, lights,\nengine sounds, speed, momentum, volume, dialog, whistle and bell sounds, and much more.\nIt can also fire routes, control momentary and on/off accessories, rotate gantry cranes, etc.\n\nBelow is another control panel designed to operate a Lionel Command Control Gantry and the track and turnout\nleading to it. This panel uses a 2-axis joystick\nto move the gantry back and forth on the special GarGraves 5-rail track, as well as to lift the magnet\nup and down. A Rotary Encoder is used to rotate the crane cab. The encoder I use has a push button\nbuilt in that turns the magnet on and off. A yellow LED is lit and blinks when the magnet is energized.\nThe panel also allows control of the two track power blocks in this part of my layout, as well\nas the turnout to the two track segments.\n\n<div align=\"center\">\n\n![gantry.jpg](https://github.com/cdswindell/PyLegacy/raw/master/doc/images/gantry.jpg)\n\n#### Lionel Legacy Gantry Crane and Yard\n\n</div>\n\nHere's the corresponding Python code:\n\n```\nfrom pytrain import GpioHandler\n\nGpioHandler.gantry_crane(\n address=96, # TMCC ID of Gantry Crane\n cab_pin_1=20, # Cab rotation controlled by a \n cab_pin_2=21, # Rotary Encoder connected to pins 20 & 21\n lift_chn=0, # Boom controlled by 1 axis of Joystick\n roll_chn=1, # Lateral motion controlled by the other\n mag_pin=16, # Turns magnet on when pressed\n led_pin=24, # Blinks when magnet is energized\n) \n\nGpioHandler.switch(\n address=1, # TMCC ID of the yard turnout\n thru_pin=7, \n out_pin=8, \n thru_led_pin=9,\n out_led_pin=10\n)\n\nGpioHandler.power_district(\n address=5, # TMCC ID of North Yard Power District\n on_pin=11, # Track Power On\n off_pin=12, # Track Power Off\n on_led=26, # Track power on when lit\n)\n\nGpioHandler.power_district(\n address=6, # TMCC ID of South Yard Power District\n on_pin=13, # Track Power On\n off_pin=14, # Track Power Off\n on_led=27, # Track power on when lit\n)\n```\n\n### Developers\n\nFor developers...\n\n## Command-line Tools\n\nPyLegacy includes several command-line tools you\nThe `cli` directory contains a number of Python command line scripts allowing\nyou to operate engines, control switches and accessories, and fire custom routes.\n\n### PyTrain\n\n### PiConfig\n\n## Contributing\n\n## Development\n\n### Requirements\n\n#### Macintosh:\n\n- Brew:\n\n`/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"`\n\n- Python 3.12.6 (your version may be newer; Note: Python 3.13 is _**not**_ supported:\n\n`brew install python@3.12`\n\n- gh:\n\n`brew install gh`\n\n- git (if you plan to modify the code and issue pull requests):\n\n`brew install git`\n\n#### Raspberry Pi and Pi Zero W 2\n\n- Python 3.11, gh, and git:\n\n```\nsudo apt update\nsudo apt upgrade\n\nsudo apt install python3\nsudo apt install gh\nsudo apt install git\n```\n\nFor the Raspberry Pi Zero W (**NOT** the 2 W):\n\n```\nsudo apt-get install swig\n```\n\n**Note**: some or all of this software may already be installed on your pi\n\n### Installation and one time setup\n\n```\ncd /where/you/like/your/source\n\n# Make sure this says 3.11. or greater; don't keep going in these directions until it does\npython3 --version\n\n# authenticate gh/git:\ngh auth login\n\n# establish a virtual Python environment\n# see: https://docs.python.org/3/library/venv.html\npython3 -m venv PyLegacyEnv\ncd PyLegacyEnv\ngh repo clone cdswindell/PyLegacy\ncd PyLegacy\n\n# Activate virtual environment\nsource ../bin/activate; export PYTHONPATH=.\n\n# Install 3rd-party dependencies\npip3 install -r requirements.txt\n\n```\n\nYou will need to activate this local python environment every time you open a\nnew shell, after changing your working directory to the `PyLegacy` local directory by typing:\n\n```\nsource ../bin/activate\nexport PYTHONPATH=.\n```\n\nYou may wish to create a macro or alias to issue these commands for you.\n\n## Future Enhancements\n\n## License\n\nThis software and its use are governed by the GNU Lesser General Public License (LPGL).\n",
"bugtrack_url": null,
"license": "GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, \"this License\" refers to version 3 of the GNU Lesser General Public License, and the \"GNU GPL\" refers to version 3 of the GNU General Public License. \"The Library\" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An \"Application\" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A \"Combined Work\" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the \"Linked Version\". The \"Minimal Corresponding Source\" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The \"Corresponding Application Code\" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License \"or any later version\" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. ",
"summary": "Control Lionel TMCC/Legacy engines, switches, and accesseries from a Raspberry Pi",
"version": "0.9.46",
"project_urls": {
"Homepage": "https://github.com/cdswindell/PyLegacy",
"Issues": "https://github.com/cdswindell/PyLegacy/issues",
"Source": "https://github.com/cdswindell/PyLegacy"
},
"split_keywords": [
"automation",
" interactive",
" control",
" legacy",
" lionel",
" o-gauge",
" raspberry pi",
" tmcc",
" trains"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cd26729742ce234d6d5a9bb52dd3700a910cda9f54891757f69e4a6e673a42b8",
"md5": "d973ef67c7eab3069a685c2bc9a5ec7e",
"sha256": "40335f63673a3b70b0ad2036ae7838791f6b1c4d88b39a53724560c3b98cb1d5"
},
"downloads": -1,
"filename": "pytrain_ogr-0.9.46-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d973ef67c7eab3069a685c2bc9a5ec7e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 209071,
"upload_time": "2025-01-22T03:12:16",
"upload_time_iso_8601": "2025-01-22T03:12:16.617720Z",
"url": "https://files.pythonhosted.org/packages/cd/26/729742ce234d6d5a9bb52dd3700a910cda9f54891757f69e4a6e673a42b8/pytrain_ogr-0.9.46-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e17e02b467e4aefba4a145cdd857d24964bd969c20f5787d47ccffa74f38b955",
"md5": "5c872ec4ea305a7b23b5e1982d43895f",
"sha256": "9d882c9cf257bb40efc2ab73c3b379d9521602b34a33919a79d7dea4c356838c"
},
"downloads": -1,
"filename": "pytrain_ogr-0.9.46.tar.gz",
"has_sig": false,
"md5_digest": "5c872ec4ea305a7b23b5e1982d43895f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 394239,
"upload_time": "2025-01-22T03:12:18",
"upload_time_iso_8601": "2025-01-22T03:12:18.951588Z",
"url": "https://files.pythonhosted.org/packages/e1/7e/02b467e4aefba4a145cdd857d24964bd969c20f5787d47ccffa74f38b955/pytrain_ogr-0.9.46.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-22 03:12:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cdswindell",
"github_project": "PyLegacy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "RPLCD",
"specs": [
[
">=",
"1.3.1"
]
]
},
{
"name": "colorzero",
"specs": [
[
">=",
"2.0"
]
]
},
{
"name": "gpiozero",
"specs": [
[
">=",
"2.0.1"
]
]
},
{
"name": "pyserial",
"specs": [
[
">=",
"3.5"
]
]
},
{
"name": "range-key-dict",
"specs": [
[
">=",
"1.1"
]
]
},
{
"name": "setuptools",
"specs": [
[
">=",
"75.6.0"
]
]
},
{
"name": "setuptools_scm",
"specs": [
[
">=",
"8.1"
]
]
},
{
"name": "smbus2",
"specs": [
[
">=",
"0.5.0"
]
]
},
{
"name": "zeroconf",
"specs": [
[
">=",
"0.140.1"
]
]
},
{
"name": "lgpio",
"specs": [
[
">=",
"0.2.2.0"
]
]
},
{
"name": "typing_extensions",
"specs": []
}
],
"tox": true,
"lcname": "pytrain-ogr"
}