From df18c6749cc57b14f8d8c1ba65264956123e282f Mon Sep 17 00:00:00 2001 From: lgbrownjr Date: Tue, 12 Oct 2021 10:06:01 -0400 Subject: [PATCH 1/4] remove the center text and line position functions to a lib file, where the shutdown and init screen scripts import. --- init_scr | 30 +++++------------------------- ser2bt_lib.py | 36 ++++++++++++++++++++++++++++++++++++ shutdown_scr | 41 ++++++++++------------------------------- upgrade | 6 +++--- 4 files changed, 54 insertions(+), 59 deletions(-) create mode 100755 ser2bt_lib.py diff --git a/init_scr b/init_scr index 037d672..ed74693 100755 --- a/init_scr +++ b/init_scr @@ -4,6 +4,7 @@ from PIL import Image, ImageDraw, ImageFont # Font handeling from waveshare_epd import epd2in13_V2 import os +from ser2bt_lib import line_pos, center_text #user-changable settings. screen_rotate = 180 foreground = 0 @@ -15,33 +16,11 @@ tmp_dir = "/tmp/" shut_file = "shut" title_msg = 'Loading:' msg = 'Serial to bluetooth bridge' +np = True #New Page, True or False roboto_font_dir='/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/' f_title_font18 = ImageFont.truetype(roboto_font_dir+'Roboto-Bold.ttf', 18) f_title_font24 = ImageFont.truetype(roboto_font_dir+'Roboto-Bold.ttf', 24) -#location -left_margin = 1 #Left margin. -top_margin = 11 #Will start all text at the 11th pixel -bottom_margen = epd.width - 1 -line_position = top_margin #initial line to start on. -next_line_position = top_margin #initial line to start on. - -def center_text(msg,font): - w, h = boot_draw.textsize(msg, font) - return (w) - -def line_pos(msg,font): - global line_position - global next_line_position - w, h = boot_draw.textsize(msg, font) - if next_line_position == top_margin: - next_line_position = line_position + h - return (line_position) - else: - line_position = next_line_position - next_line_position = line_position + h - return (line_position) - #Check if battery file exists, create if it does not: if not os.path.exists(tmp_dir+shut_file): os.mknod(tmp_dir+shut_file) @@ -58,8 +37,9 @@ boot_image = Image.new('1', (epd.height, epd.width), background) #clear the fra boot_draw = ImageDraw.Draw(boot_image) #Plot the text: -boot_draw.text(((epd.height/2) - center_text(title_msg, f_title_font24)/2, line_pos(title_msg, f_title_font24)), title_msg, font=f_title_font24, fill = foreground) -boot_draw.text(((epd.height/2) - center_text(msg, f_title_font18)/2, line_pos(msg, f_title_font18)), msg, font=f_title_font18, fill = foreground) +boot_draw.text((center_text(boot_draw, title_msg, f_title_font24), line_pos(np,boot_draw, title_msg, f_title_font24)), title_msg, font=f_title_font24, fill = foreground) +np = False +boot_draw.text((center_text(boot_draw, msg, f_title_font18), line_pos(np,boot_draw, msg, f_title_font18)), msg, font=f_title_font18, fill = foreground) #Display the screen epd.display(epd.getbuffer(boot_image.rotate(screen_rotate))) diff --git a/ser2bt_lib.py b/ser2bt_lib.py new file mode 100755 index 0000000..f0978a9 --- /dev/null +++ b/ser2bt_lib.py @@ -0,0 +1,36 @@ +#!/usr/bin/python3 + +# -*- coding:utf-8 -*- +#import: +from PIL import Image, ImageDraw, ImageFont # Font handeling +from waveshare_epd import epd2in13_V2 + +# Variable decleration +epd = epd2in13_V2.EPD() +#location +left_margin = 1 #Left margin. +top_margin = 11 #Will start all text at the 11th pixel +bottom_margen = epd.width - 1 +line_position = top_margin #initial line to start on. +next_line_position = top_margin #initial line to start on.#location + +def center_text(draw,msg,font): + w, h = draw.textsize(msg, font) + starting_point = (epd.height/2) - (w/2) + return (starting_point) + +def line_pos(new_page,draw,msg,font): + global line_position + global next_line_position + w, h = draw.textsize(msg, font) + if new_page is True: + line_position = top_margin #initial line to start on. + next_line_position = top_margin #initial line to start on.#location + if next_line_position == top_margin: + next_line_position = line_position + h + return (line_position) + else: + line_position = next_line_position + next_line_position = line_position + h + return (line_position) +#exit() \ No newline at end of file diff --git a/shutdown_scr b/shutdown_scr index b9172f1..7d148a6 100755 --- a/shutdown_scr +++ b/shutdown_scr @@ -9,7 +9,7 @@ from os.path import exists import re import subprocess import configparser #to handle the config file. - +from ser2bt_lib import center_text, line_pos #import configuration file: #Read ser2bt_config.ini file config_obj = configparser.ConfigParser() @@ -28,6 +28,7 @@ title_msg = 'Serial 2 Bluetooth Bridge' tmp_dir='/tmp/' shut_file = 'shut' bat_file = 'bat' +np = True #New page True or False host_name=os.uname()[1] # define host_name epd = epd2in13_V2.EPD() picdir='/usr/local/lib/ser2bt-bridge/' @@ -40,26 +41,8 @@ bmp = Image.open(os.path.join(picdir, 'logo.bmp')) exit_image = Image.new('1', (epd.height, epd.width), int(background)) #clear the frame exit_draw = ImageDraw.Draw(exit_image) left_margin = 1 #Left margin. -top_margin = 11 #Will start all text at the 11th pixel +title_correction = 5 #Will start all text at the 6th pixel from the top on the shutdown screen only. bottom_margen = epd.width - 1 -line_position = top_margin #initial line to start on. -next_line_position = top_margin #initial line to start on. - -def center_text(msg,font): - w, h = exit_draw.textsize(msg, font) - return (w) - -def line_pos(msg,font): - global line_position - global next_line_position - w, h = exit_draw.textsize(msg, font) - if next_line_position == top_margin: - next_line_position = line_position + h - return (line_position) - else: - line_position = next_line_position - next_line_position = line_position + h - return (line_position) def shutdown_check(): power_off = 'p' #flag to indicate that the bridge is being powered off. @@ -84,8 +67,6 @@ def shutdown_check(): msg = 'Shutdown' else: msg = 'Shutdown' -# print (msg) -# print (flag) return (msg) def bat_lvl(): @@ -100,8 +81,9 @@ def bat_lvl(): epd.init(epd.FULL_UPDATE) #Draw out the boot screen -exit_draw.text(((epd.height/2) - (center_text(standby_msg,f_title_font24)/2), line_pos(standby_msg,f_title_font24)), standby_msg, font=f_title_font24, fill = int(foreground)) -exit_draw.text(((epd.height/2) - (center_text(title_msg,f_title_font18)/2), line_pos(title_msg,f_title_font18)), title_msg, font=f_title_font18, fill = int(foreground)) +exit_draw.text((center_text(exit_draw, standby_msg,f_title_font24), line_pos(np,exit_draw,standby_msg,f_title_font24)), standby_msg, font=f_title_font24, fill = int(foreground)) +np = False +exit_draw.text((center_text(exit_draw, title_msg,f_title_font18), line_pos(np,exit_draw,title_msg,f_title_font18)), title_msg, font=f_title_font18, fill = int(foreground)) if shutdown_check() == "Exit": reason = "Is Exiting" elif shutdown_check() == "Upgrade": @@ -113,17 +95,14 @@ elif shutdown_check() == "Shutdown": else: reason = "Is Exiting" -exit_draw.text(((epd.height/2) - (center_text(reason,f_title_font18)/2), line_pos(reason,f_title_font18)), reason, font=f_title_font18, fill = int(foreground)) +exit_draw.text((center_text(exit_draw,reason,f_title_font18), line_pos(np,exit_draw,standby_msg,f_title_font18)), reason, font=f_title_font18, fill = int(foreground)) epd.display(epd.getbuffer(exit_image.rotate(screen_rotate))) if shutdown_check() == "Shutdown": #new page, reset line_position. epd.sleep() time.sleep(2) - top_margin = 6 - next_line_position = top_margin - line_position = top_margin - + np = True #compute and format uptime up_time = subprocess.check_output(['uptime', '-p']).decode("utf8").replace(',', '').replace("up ","") up_time = re.sub("hours?","hrs", up_time) @@ -138,8 +117,8 @@ if shutdown_check() == "Shutdown": icon_image.paste(bmp, (0,20)) #Display the background image #display the screen title" - icon_draw.text(((epd.height/2) - (center_text(title_msg,f_title_font18)/2), line_pos(title_msg,f_title_font18)), title_msg, font=f_title_font18,fill = int(foreground)) - + icon_draw.text((center_text(icon_draw,title_msg,f_title_font18), line_pos(np,icon_draw,standby_msg,f_title_font18)-title_correction), title_msg, font=f_title_font18,fill = int(foreground)) + np = False #Add the discriptions to the boxes in the image icon_draw.text((4,45), 'master', font=f_top_line_font16,fill = int(foreground)) #28 is the top of the square icon_draw.text((122,45), host_name, font=f_top_line_font16,fill = int(foreground)) diff --git a/upgrade b/upgrade index 9604645..5d2d138 100755 --- a/upgrade +++ b/upgrade @@ -52,7 +52,7 @@ disable_svc=("keyboard-setup.service" "dphys-swapfile.service" "triggerhappy.ser "ser2net.service") base_package_install_list=("screen" "git" "minicom" "tio" "rfkill" "dnsutils" "xterm" "telnet" "telnetd" "ser2net" "spi-tools") base_bin_files=(ser2bt_bridge screen_bat_mon screen_get_baud) -wavesh_bin_files=(ser2bt_status init_scr shutdown_scr) +wavesh_bin_files=(ser2bt_status init_scr shutdown_scr ser2bt_lib.py) full_bin_files=( "${base_bin_files[@]}") pisugar2_bin_files=(button_detect bat_mon) ups_lite_bin_files=(bat_mon) @@ -178,9 +178,9 @@ function upgrade_wiringpi() { fi dpkg -iE ${tmp_folder}${wiringpi} > /dev/null 2>&1 if [ ${?} -eq 0 ]; then - printf "${completed}" + printf "${completed}\n" else - printf "${bad_failed} ${continuing}" + printf "${bad_failed} ${continuing}\n" fi } From 1444438e32c51235cc9f91d7debe960322e9b329 Mon Sep 17 00:00:00 2001 From: lgbrownjr Date: Tue, 12 Oct 2021 10:12:02 -0400 Subject: [PATCH 2/4] Remove an un needed include. --- ser2bt_lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ser2bt_lib.py b/ser2bt_lib.py index f0978a9..63dd7e9 100755 --- a/ser2bt_lib.py +++ b/ser2bt_lib.py @@ -2,7 +2,7 @@ # -*- coding:utf-8 -*- #import: -from PIL import Image, ImageDraw, ImageFont # Font handeling +#from PIL import Image, ImageDraw, ImageFont # Font handeling from waveshare_epd import epd2in13_V2 # Variable decleration From 26dd566d667340cf80b009575fcf7e976c3b03f5 Mon Sep 17 00:00:00 2001 From: lgbrownjr Date: Tue, 26 Oct 2021 15:43:17 -0400 Subject: [PATCH 3/4] Fixes with system upgrade --- upgrade | 1 + 1 file changed, 1 insertion(+) diff --git a/upgrade b/upgrade index 5d2d138..0e80d0c 100755 --- a/upgrade +++ b/upgrade @@ -220,6 +220,7 @@ function system_update() { if [ ${?} -eq 0 ]; then packadge_count=$(echo ${apt_update_result} | grep -o "[0-9]* packages can be upgraded" 2> /dev/null | grep -o "[0-9]*") printf " \n ${grn}Update completed${nor}, ${yel}${packadge_count} ${nor} packadges will be upgraded.\n" + apt list --upgradable 2> /dev/null | grep -oe "^[-\.0-9a-z]*" 2> /dev/null apt_update_flag=1 #True up_to_date_flag=0 #False elif [ ${?} -eq 1 ]; then From a3b7bb56aeca8f4077cbe202d821965fef1d56af Mon Sep 17 00:00:00 2001 From: Larry Brown Date: Mon, 4 Apr 2022 13:21:17 -0400 Subject: [PATCH 4/4] Update README.md Minor tweaks and grammatical corrections. --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5d90600..c3becd2 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,14 @@ This project is made up of a set of scripts, services and libraries "used loosel These scripts and services basicaly utilize *screen* and *rfcomm* to "bridge" a connection between the *master*, and the *slave* you are attempting to connect to. - By design, this prject does not have security in mind, preferring instead to focus on easy discovery, pairing, and connectivity to allow the network administrator to focus on getting their work done. - The Bridge will always be discoverable, and will not require a pin to complete the pairing process. - - This has been tested with *master* devices using the following Operating Systems: Linux, Android, Windows 10, and ChromeOS (with caveats). - - When connecting to the bridge over bluetooth, the administrator will be auto logged-in as pi. - - This will in no way affect access to the _slave_ device. If the _slave_ requires a username/password to access it, you will still be required to use those credentials. + - *ser2bt-bridge* has been tested with *master* devices using the following Operating Systems: Linux, Android, Windows 10, and ChromeOS (with caveats). + - Although I do not own a mac, I have no reason to belive it won't work with *ser2bt-bridge*. + - When connecting to the bridge over bluetooth, the administrator will be auto logged-in as user pi. + - This will in no way affect access to the _slave_ device. If the _slave_ requires a username/password to administer it, then you will still be required to use those credentials. - Connection between the *master* and the *bridge* will be 9600 Baud - this is to maximize range. - Once the *master* is connected to the *bridge*, it will attempt to look for any available serial (usb or acm) ports. At this point one of three things are expected to occur: - If the *bridge* was connected to a single *slave*, then it will open a *screen* session to that serial port outomagically. - - If the *bridge* was connected (via OTG usb hub), then it will create one *screen* session for each serial port it found, list them on your display, and exit to shell. + - If the *bridge* was connected (via OTG usb hub) to multiple switches, then it will create one *screen* session for each active serial port found, list them on your display, and exit to shell. - If the *bridge* does not detect any new usb/acm ports, then the it will state that fact and then drop to the *bridges* bash shell. - The connection between the *bidge* and the *slave* is set to 9600 Baud. I'm looking to set this as a configurable element in the future. - While connected to a *slave*, the *bridge* will begin logging all session traffic between the *master* and *slave*. (This is why it is important to make sure the *bridge* somehow either has its time set manually, or receives its time from an external source, such as ntp server and/or an onboard rtc.)