Skip to content

Commit f3ab38c

Browse files
authored
Merge pull request #21 from lgbrownjr/development
Development
2 parents de23a0b + a3b7bb5 commit f3ab38c

File tree

5 files changed

+60
-63
lines changed

5 files changed

+60
-63
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ This project is made up of a set of scripts, services and libraries "used loosel
1414
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.
1515
- 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.
1616
- The Bridge will always be discoverable, and will not require a pin to complete the pairing process.
17-
- This has been tested with *master* devices using the following Operating Systems: Linux, Android, Windows 10, and ChromeOS (with caveats).
18-
- When connecting to the bridge over bluetooth, the administrator will be auto logged-in as pi.
19-
- 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.
17+
- *ser2bt-bridge* has been tested with *master* devices using the following Operating Systems: Linux, Android, Windows 10, and ChromeOS (with caveats).
18+
- Although I do not own a mac, I have no reason to belive it won't work with *ser2bt-bridge*.
19+
- When connecting to the bridge over bluetooth, the administrator will be auto logged-in as user pi.
20+
- 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.
2021
- Connection between the *master* and the *bridge* will be 9600 Baud - this is to maximize range.
2122
- 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:
2223
- If the *bridge* was connected to a single *slave*, then it will open a *screen* session to that serial port outomagically.
23-
- 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.
24+
- 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.
2425
- 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.
2526
- 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.
2627
- 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.)

init_scr

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from PIL import Image, ImageDraw, ImageFont # Font handeling
55
from waveshare_epd import epd2in13_V2
66
import os
7+
from ser2bt_lib import line_pos, center_text
78
#user-changable settings.
89
screen_rotate = 180
910
foreground = 0
@@ -15,33 +16,11 @@ tmp_dir = "/tmp/"
1516
shut_file = "shut"
1617
title_msg = 'Loading:'
1718
msg = 'Serial to bluetooth bridge'
19+
np = True #New Page, True or False
1820
roboto_font_dir='/usr/share/fonts/truetype/roboto/unhinted/RobotoTTF/'
1921
f_title_font18 = ImageFont.truetype(roboto_font_dir+'Roboto-Bold.ttf', 18)
2022
f_title_font24 = ImageFont.truetype(roboto_font_dir+'Roboto-Bold.ttf', 24)
2123

22-
#location
23-
left_margin = 1 #Left margin.
24-
top_margin = 11 #Will start all text at the 11th pixel
25-
bottom_margen = epd.width - 1
26-
line_position = top_margin #initial line to start on.
27-
next_line_position = top_margin #initial line to start on.
28-
29-
def center_text(msg,font):
30-
w, h = boot_draw.textsize(msg, font)
31-
return (w)
32-
33-
def line_pos(msg,font):
34-
global line_position
35-
global next_line_position
36-
w, h = boot_draw.textsize(msg, font)
37-
if next_line_position == top_margin:
38-
next_line_position = line_position + h
39-
return (line_position)
40-
else:
41-
line_position = next_line_position
42-
next_line_position = line_position + h
43-
return (line_position)
44-
4524
#Check if battery file exists, create if it does not:
4625
if not os.path.exists(tmp_dir+shut_file):
4726
os.mknod(tmp_dir+shut_file)
@@ -58,8 +37,9 @@ boot_image = Image.new('1', (epd.height, epd.width), background) #clear the fra
5837
boot_draw = ImageDraw.Draw(boot_image)
5938

6039
#Plot the text:
61-
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)
62-
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)
40+
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)
41+
np = False
42+
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)
6343

6444
#Display the screen
6545
epd.display(epd.getbuffer(boot_image.rotate(screen_rotate)))

ser2bt_lib.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/python3
2+
3+
# -*- coding:utf-8 -*-
4+
#import:
5+
#from PIL import Image, ImageDraw, ImageFont # Font handeling
6+
from waveshare_epd import epd2in13_V2
7+
8+
# Variable decleration
9+
epd = epd2in13_V2.EPD()
10+
#location
11+
left_margin = 1 #Left margin.
12+
top_margin = 11 #Will start all text at the 11th pixel
13+
bottom_margen = epd.width - 1
14+
line_position = top_margin #initial line to start on.
15+
next_line_position = top_margin #initial line to start on.#location
16+
17+
def center_text(draw,msg,font):
18+
w, h = draw.textsize(msg, font)
19+
starting_point = (epd.height/2) - (w/2)
20+
return (starting_point)
21+
22+
def line_pos(new_page,draw,msg,font):
23+
global line_position
24+
global next_line_position
25+
w, h = draw.textsize(msg, font)
26+
if new_page is True:
27+
line_position = top_margin #initial line to start on.
28+
next_line_position = top_margin #initial line to start on.#location
29+
if next_line_position == top_margin:
30+
next_line_position = line_position + h
31+
return (line_position)
32+
else:
33+
line_position = next_line_position
34+
next_line_position = line_position + h
35+
return (line_position)
36+
#exit()

shutdown_scr

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from os.path import exists
99
import re
1010
import subprocess
1111
import configparser #to handle the config file.
12-
12+
from ser2bt_lib import center_text, line_pos
1313
#import configuration file:
1414
#Read ser2bt_config.ini file
1515
config_obj = configparser.ConfigParser()
@@ -28,6 +28,7 @@ title_msg = 'Serial 2 Bluetooth Bridge'
2828
tmp_dir='/tmp/'
2929
shut_file = 'shut'
3030
bat_file = 'bat'
31+
np = True #New page True or False
3132
host_name=os.uname()[1] # define host_name
3233
epd = epd2in13_V2.EPD()
3334
picdir='/usr/local/lib/ser2bt-bridge/'
@@ -40,26 +41,8 @@ bmp = Image.open(os.path.join(picdir, 'logo.bmp'))
4041
exit_image = Image.new('1', (epd.height, epd.width), int(background)) #clear the frame
4142
exit_draw = ImageDraw.Draw(exit_image)
4243
left_margin = 1 #Left margin.
43-
top_margin = 11 #Will start all text at the 11th pixel
44+
title_correction = 5 #Will start all text at the 6th pixel from the top on the shutdown screen only.
4445
bottom_margen = epd.width - 1
45-
line_position = top_margin #initial line to start on.
46-
next_line_position = top_margin #initial line to start on.
47-
48-
def center_text(msg,font):
49-
w, h = exit_draw.textsize(msg, font)
50-
return (w)
51-
52-
def line_pos(msg,font):
53-
global line_position
54-
global next_line_position
55-
w, h = exit_draw.textsize(msg, font)
56-
if next_line_position == top_margin:
57-
next_line_position = line_position + h
58-
return (line_position)
59-
else:
60-
line_position = next_line_position
61-
next_line_position = line_position + h
62-
return (line_position)
6346

6447
def shutdown_check():
6548
power_off = 'p' #flag to indicate that the bridge is being powered off.
@@ -84,8 +67,6 @@ def shutdown_check():
8467
msg = 'Shutdown'
8568
else:
8669
msg = 'Shutdown'
87-
# print (msg)
88-
# print (flag)
8970
return (msg)
9071

9172
def bat_lvl():
@@ -100,8 +81,9 @@ def bat_lvl():
10081
epd.init(epd.FULL_UPDATE)
10182

10283
#Draw out the boot screen
103-
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))
104-
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))
84+
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))
85+
np = False
86+
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))
10587
if shutdown_check() == "Exit":
10688
reason = "Is Exiting"
10789
elif shutdown_check() == "Upgrade":
@@ -113,17 +95,14 @@ elif shutdown_check() == "Shutdown":
11395
else:
11496
reason = "Is Exiting"
11597

116-
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))
98+
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))
11799
epd.display(epd.getbuffer(exit_image.rotate(screen_rotate)))
118100

119101
if shutdown_check() == "Shutdown":
120102
#new page, reset line_position.
121103
epd.sleep()
122104
time.sleep(2)
123-
top_margin = 6
124-
next_line_position = top_margin
125-
line_position = top_margin
126-
105+
np = True
127106
#compute and format uptime
128107
up_time = subprocess.check_output(['uptime', '-p']).decode("utf8").replace(',', '').replace("up ","")
129108
up_time = re.sub("hours?","hrs", up_time)
@@ -138,8 +117,8 @@ if shutdown_check() == "Shutdown":
138117

139118
icon_image.paste(bmp, (0,20)) #Display the background image
140119
#display the screen title"
141-
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))
142-
120+
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))
121+
np = False
143122
#Add the discriptions to the boxes in the image
144123
icon_draw.text((4,45), 'master', font=f_top_line_font16,fill = int(foreground)) #28 is the top of the square
145124
icon_draw.text((122,45), host_name, font=f_top_line_font16,fill = int(foreground))

upgrade

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ disable_svc=("keyboard-setup.service" "dphys-swapfile.service" "triggerhappy.ser
5252
"ser2net.service")
5353
base_package_install_list=("screen" "git" "minicom" "tio" "rfkill" "dnsutils" "xterm" "telnet" "telnetd" "ser2net" "spi-tools")
5454
base_bin_files=(ser2bt_bridge screen_bat_mon screen_get_baud)
55-
wavesh_bin_files=(ser2bt_status init_scr shutdown_scr)
55+
wavesh_bin_files=(ser2bt_status init_scr shutdown_scr ser2bt_lib.py)
5656
full_bin_files=( "${base_bin_files[@]}")
5757
pisugar2_bin_files=(button_detect bat_mon)
5858
ups_lite_bin_files=(bat_mon)
@@ -178,9 +178,9 @@ function upgrade_wiringpi() {
178178
fi
179179
dpkg -iE ${tmp_folder}${wiringpi} > /dev/null 2>&1
180180
if [ ${?} -eq 0 ]; then
181-
printf "${completed}"
181+
printf "${completed}\n"
182182
else
183-
printf "${bad_failed} ${continuing}"
183+
printf "${bad_failed} ${continuing}\n"
184184
fi
185185
}
186186

@@ -220,6 +220,7 @@ function system_update() {
220220
if [ ${?} -eq 0 ]; then
221221
packadge_count=$(echo ${apt_update_result} | grep -o "[0-9]* packages can be upgraded" 2> /dev/null | grep -o "[0-9]*")
222222
printf " \n ${grn}Update completed${nor}, ${yel}${packadge_count} ${nor} packadges will be upgraded.\n"
223+
apt list --upgradable 2> /dev/null | grep -oe "^[-\.0-9a-z]*" 2> /dev/null
223224
apt_update_flag=1 #True
224225
up_to_date_flag=0 #False
225226
elif [ ${?} -eq 1 ]; then

0 commit comments

Comments
 (0)