add log to file in /var/log

This commit is contained in:
sinseman44
2020-11-15 09:21:08 +00:00
parent 537827bf37
commit 887807f289
2 changed files with 17 additions and 1 deletions
+5 -1
View File
@@ -3,6 +3,7 @@
import os import os
import sys import sys
import time import time
import logging
import RPi.GPIO as GPIO import RPi.GPIO as GPIO
from RPLCD.gpio import CharLCD from RPLCD.gpio import CharLCD
from piplot.config import * from piplot.config import *
@@ -76,14 +77,17 @@ def init():
GPIO.add_event_detect(PG_OK, GPIO.RISING, callback=pg_ok_cb, bouncetime=50) GPIO.add_event_detect(PG_OK, GPIO.RISING, callback=pg_ok_cb, bouncetime=50)
except: except:
e = sys.exc_info()[1] e = sys.exc_info()[1]
print("Error : {}".format(e)) logging.error("Error : {}".format(e))
sys.exit(1) sys.exit(1)
menu.init_menu() menu.init_menu()
def main(): def main():
logging.basicConfig(filename='/var/log/PiPlot2D.log', level=logging.INFO)
logging.info("*** Launch PiPlot2D Menu & Control ***")
init() init()
while True: while True:
time.sleep(1) time.sleep(1)
logging.info("*** Exit PiPlot2D Menu & Control ***")
lcd.close() lcd.close()
################################################################### ###################################################################
+12
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os, sys import os, sys
import logging
################################################################### ###################################################################
@@ -35,6 +36,8 @@ class menu:
self.max_rows = rows self.max_rows = rows
self.current_cursor = 0 self.current_cursor = 0
self.current_menu = self.main_menu self.current_menu = self.main_menu
logging.info("PyCNC path : {}".format(self.pycnc_path))
logging.info("Gcode repository path : {}".format(self.gcode_path))
for dirs,r,files in os.walk(self.gcode_path): for dirs,r,files in os.walk(self.gcode_path):
for f in files: for f in files:
if len(f) > 14: if len(f) > 14:
@@ -62,6 +65,7 @@ class menu:
self.lcd.home() self.lcd.home()
self.lcd.write_string(" drawing ...") self.lcd.write_string(" drawing ...")
os.system(self.pycnc_path + ' ' + os.path.join(self.gcode_path, filename)) os.system(self.pycnc_path + ' ' + os.path.join(self.gcode_path, filename))
logging.info("drawing : {}".format(os.path.join(self.gcode_path, filename)))
self.lcd.clear() self.lcd.clear()
self.lcd.cursor_pos = (self.current_cursor % self.max_rows, 0) self.lcd.cursor_pos = (self.current_cursor % self.max_rows, 0)
self.lcd.write_string('\x00') self.lcd.write_string('\x00')
@@ -83,6 +87,7 @@ class menu:
def __homing(self): def __homing(self):
''' set homing command ''' ''' set homing command '''
self.__pre_cmd() self.__pre_cmd()
logging.debug("homing")
with open("/tmp/homing.gcode", 'w') as f: with open("/tmp/homing.gcode", 'w') as f:
f.write("G28 (Homing)") f.write("G28 (Homing)")
os.system(self.pycnc_path + ' ' + os.path.join("/tmp/homing.gcode")) os.system(self.pycnc_path + ' ' + os.path.join("/tmp/homing.gcode"))
@@ -91,6 +96,7 @@ class menu:
def __set_up_pen(self): def __set_up_pen(self):
''' set up pen ''' ''' set up pen '''
self.__pre_cmd() self.__pre_cmd()
logging.debug("set up pen")
with open("/tmp/set_up_pen.gcode", 'w') as f: with open("/tmp/set_up_pen.gcode", 'w') as f:
f.write("M300 S50 (UP Pen)") f.write("M300 S50 (UP Pen)")
os.system(self.pycnc_path + ' ' + os.path.join("/tmp/set_up_pen.gcode")) os.system(self.pycnc_path + ' ' + os.path.join("/tmp/set_up_pen.gcode"))
@@ -99,6 +105,7 @@ class menu:
def __set_down_pen(self): def __set_down_pen(self):
''' set down pen ''' ''' set down pen '''
self.__pre_cmd() self.__pre_cmd()
logging.debug("set down pen")
with open("/tmp/set_down_pen.gcode", 'w') as f: with open("/tmp/set_down_pen.gcode", 'w') as f:
f.write("M300 S30 (DOWN Pen)") f.write("M300 S30 (DOWN Pen)")
os.system(self.pycnc_path + ' ' + os.path.join("/tmp/set_down_pen.gcode")) os.system(self.pycnc_path + ' ' + os.path.join("/tmp/set_down_pen.gcode"))
@@ -107,6 +114,7 @@ class menu:
def __set_line_1cm(self, axis='X'): def __set_line_1cm(self, axis='X'):
''' set a 1cm line in X or Y axis ''' ''' set a 1cm line in X or Y axis '''
self.__pre_cmd() self.__pre_cmd()
logging.debug("set 1cm Line")
with open("/tmp/set_line.gcode", 'w') as f: with open("/tmp/set_line.gcode", 'w') as f:
f.write("M300 S50 (UP Pen)\n") f.write("M300 S50 (UP Pen)\n")
f.write("G28 (Homing)\n") f.write("G28 (Homing)\n")
@@ -132,6 +140,7 @@ class menu:
def __set_rect(self): def __set_rect(self):
''' set a rectangle ''' ''' set a rectangle '''
self.__pre_cmd() self.__pre_cmd()
logging.debug("set rectangle")
with open("/tmp/set_rect.gcode", 'w') as f: with open("/tmp/set_rect.gcode", 'w') as f:
f.write("G28 (Homing)\n") f.write("G28 (Homing)\n")
f.write("G1 X30 Y0 F2000.0\n") f.write("G1 X30 Y0 F2000.0\n")
@@ -183,12 +192,14 @@ class menu:
self.lcd.clear() self.lcd.clear()
self.lcd.home() self.lcd.home()
self.lcd.write_string(" Bye Bye ...") self.lcd.write_string(" Bye Bye ...")
logging.info("poweroff")
os.system('sudo systemctl poweroff') os.system('sudo systemctl poweroff')
exit(0) exit(0)
elif self.current_menu[self.current_cursor].startswith('Reboot'): elif self.current_menu[self.current_cursor].startswith('Reboot'):
self.lcd.clear() self.lcd.clear()
self.lcd.home() self.lcd.home()
self.lcd.write_string(" Bye Bye ...") self.lcd.write_string(" Bye Bye ...")
logging.info("reboot")
os.system('sudo systemctl reboot') os.system('sudo systemctl reboot')
exit(0) exit(0)
self.current_cursor = 0 self.current_cursor = 0
@@ -209,6 +220,7 @@ class menu:
self.__set_rect() self.__set_rect()
elif self.current_menu == self.files_menu: elif self.current_menu == self.files_menu:
if not self.current_menu[self.current_cursor].startswith('..'): if not self.current_menu[self.current_cursor].startswith('..'):
logging.debug("choose : {}".format(self.current_menu[self.current_cursor]))
self.__drawing(self.current_menu[self.current_cursor]) self.__drawing(self.current_menu[self.current_cursor])
if self.current_menu[self.current_cursor].startswith('..'): if self.current_menu[self.current_cursor].startswith('..'):