We are almost ready to go public with CharLCD package. First some refactoring and next we will build dist package.
Our four files that are main classes (in charlcd package) have names that starts form lcd_ . I think lcd_ is not needed. It repeats package name. Lets remove it.
Next delete old piader_1, I wanted to keep it but still don’t know why 🙂
Rename and fix functions in demo/lcd_virtual_buffered.py
Next I found that function stream in buffered.py is not working correctly. I copied it from direct and one small change and function fixed.
Same problem with stream in virtual buffered.
Refactor function names in all demo files.
Add anti-multiple-initialization to I2C and gpio driver.
Lots of documentation fixes.
This game is a good demo but still needs some tweaking. First we need to change initialization so start points and width/height will be calculated from received lcd. One important thing, only screens with height above 2 and width above 5 can be used.
We are using two lcds, one for game and one for score. We will make second screen obligatory.
Finally we need to rebuild controls so it will work without another script but still will use network.
New file responsible for keyboard read (local_key.py):
#!/usr/bin/python # -*- coding: utf-8 -*- """Simple key read""" __author__ = 'Bartosz Kościów' import socket import termios, fcntl, sys, os fd = sys.stdin.fileno() oldterm = termios.tcgetattr(fd) newattr = termios.tcgetattr(fd) newattr = newattr &amp; ~termios.ICANON &amp; ~termios.ECHO termios.tcsetattr(fd, termios.TCSANOW, newattr) oldflags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK) TCP_IP = '127.0.0.1' TCP_PORT = 5005 BUFFER_SIZE = 1024 class Keyboard(object): """Read keyboard""" def __init__(self): self.conn_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.conn_socket.connect((TCP_IP, TCP_PORT)) def read(self): try: key = sys.stdin.read(1) if key == 'a': self.send('player.move.left') if key == 'd': self.send('player.move.right') if key == ' ': self.send('player.move.fire') except IOError: pass def send(self, event): """send event to game""" self.conn_socket.send(event) def shutdown(self): """restore console""" termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm) fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
Import this file in game.py and in __init__ add
self.local_keyboard = keyboard.Keyboard()
Last two changes go to game function, add read between time and tick:
start = time.time() self.local_keyboard.read() self.tick()
and into finally:
First question: where to keep package. For now bitbucket. Later I will move it to PyPi repository.
I thought that distributing is simple, easy and so. Wrong. It got some work required to be done.
We need to create setup.py, setup.cfg, MANIFEST.in and LICENSE file. But the most important of all, create good documentations.
Thanks to https://hynek.me/articles/sharing-your-labor-of-love-pypi-quick-and-dirty/ I was able to learn deploying.
Two most important commands:
python setup.py sdist
python setup.py bdist_wheel
Get with pip
Now we are able to install package by typing:
pip install git+https://bitbucket.org/kosci/charlcd.git
Package is alive ! If you want to use it just do it.
There is also a new section, see top menu.