Skip to content

Commit

Permalink
Merge pull request #21 from lgbrownjr/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
lgbrownjr authored Oct 25, 2022
2 parents de23a0b + a3b7bb5 commit f3ab38c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 63 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
30 changes: 5 additions & 25 deletions init_scr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)))
Expand Down
36 changes: 36 additions & 0 deletions ser2bt_lib.py
Original file line number Diff line number Diff line change
@@ -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()
41 changes: 10 additions & 31 deletions shutdown_scr
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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/'
Expand All @@ -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.
Expand All @@ -84,8 +67,6 @@ def shutdown_check():
msg = 'Shutdown'
else:
msg = 'Shutdown'
# print (msg)
# print (flag)
return (msg)

def bat_lvl():
Expand All @@ -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":
Expand All @@ -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)
Expand All @@ -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))
Expand Down
7 changes: 4 additions & 3 deletions upgrade
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f3ab38c

Please sign in to comment.