add sources and conf files

This commit is contained in:
sinseman44
2020-11-01 18:29:57 +00:00
parent 6ff1f6559e
commit 15b46ad259
7 changed files with 312 additions and 0 deletions

0
README.md Normal file
View File

6
piplotter Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env python3
import src.main
if __name__ == "__main__":
src.main.main()

26
setup.py Executable file
View File

@@ -0,0 +1,26 @@
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="PiPlot2D",
version="0.0.1",
author="sinseman44",
author_email="sinseman44@gmail.com",
description="Control PiPlot2D system",
long_description="Control PiPlot2D system",
long_description_content_type="text/markdown",
url="https://github.com/pypa/sampleproject",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: Linux",
],
install_requires=[
'RPi.GPIO',
'RPLCD',
],
python_requires='>=3.6',
)

0
src/__init__.py Normal file
View File

17
src/config.py Normal file
View File

@@ -0,0 +1,17 @@
# Hardware config.
# HD44780 LCD CONFIG
LCD_RS = 11
LCD_E = 5
LCD_DATA4 = 6
LCD_DATA5 = 13
LCD_DATA6 = 19
LCD_DATA7 = 26
NUM_COLS = 16
NUM_ROWS = 2
# BUTTONS CONFIG
PG_UP = 17
PG_DOWN = 22
PG_OK = 27

90
src/main.py Executable file
View File

@@ -0,0 +1,90 @@
#!/usr/bin/env python3
import os
import sys
import time
import RPi.GPIO as GPIO
from RPLCD.gpio import CharLCD
from src.config import *
from src.menu import menu
###################################################################
end_flag = False
GPIO.setwarnings(False)
lcd = CharLCD(pin_rs=LCD_RS,
pin_e=LCD_E,
pin_rw=None,
pins_data=[LCD_DATA4, LCD_DATA5, LCD_DATA6, LCD_DATA7],
pin_backlight=None,
numbering_mode=GPIO.BCM,
cols=NUM_COLS,
rows=NUM_ROWS,
dotsize=8,
charmap='A00')
arrow = (
0b00000,
0b10000,
0b11000,
0b11100,
0b11110,
0b11100,
0b11000,
0b10000,
)
tilde = (
0b00000,
0b00000,
0b00000,
0b01101,
0b10101,
0b10110,
0b00000,
0b00000,
)
lcd.create_char(0, arrow)
lcd.create_char(1, tilde)
menu = menu(lcd, cols=NUM_COLS, rows=NUM_ROWS)
def pg_up_cb(channel):
''' page up button callback '''
if GPIO.input(channel) == GPIO.HIGH:
menu.set_up()
def pg_down_cb(channel):
''' page down button callback '''
if GPIO.input(channel) == GPIO.HIGH:
menu.set_down()
def pg_ok_cb(channel):
''' page ok button callback '''
if GPIO.input(channel) == GPIO.HIGH:
menu.set_ok()
def init():
''' init pins and display main menu '''
try:
GPIO.setup(PG_UP, GPIO.IN)
GPIO.setup(PG_DOWN, GPIO.IN)
GPIO.setup(PG_OK, GPIO.IN)
GPIO.add_event_detect(PG_UP, GPIO.RISING, callback=pg_up_cb, bouncetime=50)
GPIO.add_event_detect(PG_DOWN, GPIO.RISING, callback=pg_down_cb, bouncetime=50)
GPIO.add_event_detect(PG_OK, GPIO.RISING, callback=pg_ok_cb, bouncetime=50)
except:
e = sys.exc_info()[1]
print("Error : {}".format(e))
sys.exit(1)
menu.init_menu()
def main():
init()
while True:
time.sleep(1)
lcd.close()
###################################################################
if __name__ == '__main__':
main()

173
src/menu.py Normal file
View File

@@ -0,0 +1,173 @@
#!/usr/bin/env python3
import os, sys
###################################################################
class menu:
# Main Menu :
# |-> Files : Display gcode files in FTP directory
# |-> Commands : Display custom commands (homing, setup pen, etc ...)
# |-> Poweroff : Power off the system
# |-> Reboot : Reboot the system
main_menu = ['Files',
'Commands',
'Poweroff',
'Reboot']
cmd_menu = ['..',
'Homing',
'Set up Pen',
'Set down Pen']
files_menu = ['..']
def __init__(self, lcd=None, cols=0, rows=0):
''' constructor '''
self.lcd = lcd
self.max_cols = cols
self.max_rows = rows
self.current_cursor = 0
self.current_menu = self.main_menu
for dirs,r,files in os.walk("/srv/ftp"):
for f in files:
if len(f) > 14:
f = f[:13]+'~'
self.files_menu.append(f)
def __refresh_menu(self):
''' refresh current menu '''
pos = 0
if self.current_cursor % self.max_rows == 0:
pos = self.current_cursor
else:
pos = self.current_cursor - 1
for idx, menu in enumerate(self.current_menu[pos:]):
self.lcd.cursor_pos = (idx, 2)
if menu.endswith('~'):
menu = menu[:-1]+'\x01'
self.lcd.write_string(menu)
if idx == self.max_rows - 1:
break
def __drawing(self, filename):
''' drawing gcode '''
self.lcd.clear()
self.lcd.home()
self.lcd.write_string(" drawing ...")
os.system("sudo python /home/pi/PyCNC/pycnc " + os.path.join("/srv/ftp/", filename))
self.lcd.clear()
self.lcd.cursor_pos = (self.current_cursor % self.max_rows, 0)
self.lcd.write_string('\x00')
self.__refresh_menu()
def __homing(self):
''' set homing command '''
self.lcd.clear()
self.lcd.home()
self.lcd.write_string(" waiting ...")
with open("/tmp/homing.gcode", 'w') as f:
f.write("G28 (Homing)")
os.system("sudo python /home/pi/PyCNC/pycnc /tmp/homing.gcode")
self.lcd.clear()
self.lcd.cursor_pos = (self.current_cursor % self.max_rows, 0)
self.lcd.write_string('\x00')
self.__refresh_menu()
def __set_up_pen(self):
''' set up pen '''
self.lcd.clear()
self.lcd.home()
self.lcd.write_string(" waiting ...")
with open("/tmp/set_up_pen.gcode", 'w') as f:
f.write("M300 S50 (UP Pen)")
os.system("sudo python /home/pi/PyCNC/pycnc /tmp/set_up_pen.gcode")
self.lcd.clear()
self.lcd.cursor_pos = (self.current_cursor % self.max_rows, 0)
self.lcd.write_string('\x00')
self.__refresh_menu()
def __set_down_pen(self):
''' set down pen '''
self.lcd.clear()
self.lcd.home()
self.lcd.write_string(" waiting ...")
with open("/tmp/set_down_pen.gcode", 'w') as f:
f.write("M300 S30 (DOWN Pen)")
os.system("sudo python /home/pi/PyCNC/pycnc /tmp/set_down_pen.gcode")
self.lcd.clear()
self.lcd.cursor_pos = (self.current_cursor % self.max_rows, 0)
self.lcd.write_string('\x00')
self.__refresh_menu()
def init_menu(self):
''' display menu '''
self.lcd.clear()
self.lcd.cursor_pos = (self.current_cursor, 0)
self.lcd.write_string('\x00')
self.__refresh_menu()
def set_down(self):
''' set down menu '''
if self.current_cursor < len(self.current_menu) - 1:
self.lcd.clear()
self.current_cursor += 1
self.lcd.cursor_pos = (self.current_cursor % self.max_rows, 0)
self.lcd.write_string('\x00')
self.__refresh_menu()
def set_up(self):
''' set up menu '''
if self.current_cursor > 0:
self.lcd.clear()
self.current_cursor -= 1
self.lcd.cursor_pos = (self.current_cursor % self.max_rows, 0)
self.lcd.write_string('\x00')
self.__refresh_menu()
def set_ok(self):
''' set ok '''
if self.current_menu == self.main_menu:
if self.current_menu[self.current_cursor].startswith('Commands'):
self.current_menu = self.cmd_menu
elif self.current_menu[self.current_cursor].startswith('Files'):
self.current_menu = self.files_menu
self.files_menu = ['..']
for dirs,r,files in os.walk("/srv/ftp"):
for f in files:
if len(f) > 14:
f = f[:13]+'~'
self.files_menu.append(f)
elif self.current_menu[self.current_cursor].startswith('Poweroff'):
self.lcd.clear()
self.lcd.home()
self.lcd.write_string(" Bye Bye ...")
os.system('sudo systemctl poweroff')
exit(0)
elif self.current_menu[self.current_cursor].startswith('Reboot'):
self.lcd.clear()
self.lcd.home()
self.lcd.write_string(" Bye Bye ...")
os.system('sudo systemctl reboot')
exit(0)
self.current_cursor = 0
self.init_menu()
else:
if self.current_menu == self.cmd_menu:
if self.current_menu[self.current_cursor].startswith('Homing'):
self.__homing()
elif self.current_menu[self.current_cursor].startswith('Set up Pen'):
self.__set_up_pen()
elif self.current_menu[self.current_cursor].startswith('Set down Pen'):
self.__set_down_pen()
elif self.current_menu == self.files_menu:
if not self.current_menu[self.current_cursor].startswith('..'):
self.__drawing(self.current_menu[self.current_cursor])
if self.current_menu[self.current_cursor].startswith('..'):
self.current_menu = self.main_menu
self.current_cursor = 0
self.init_menu()