Commit e3b1dd32 by rtn

now with (very basic) interactive input for the pager messages

parent fa7d14bc
# control the Arduino RF22 pager TX
# modified ON1ARF code
#
# 2017-06-23 Alex The Engineer
# The Rat's Nest, Ipswich UK
#
#
import serial
import pprint
import sys
from colorconsole import terminal
from colored import fg, bg, attr
import readline
# global colours
res=attr('reset')
# tty open now coded as a function
#
# colored module used here instead of colorconsole/screen object
......@@ -97,36 +101,114 @@ def header(scr):
scr.xterm256_set_bk_color(0x08)
scr.print_at(2,0,"rtn telecom : pagertest 1.00")
scr.xterm256_set_bk_color(0)
scr.xterm256_set_fg_color(7)
scr.gotoXY(2,3)
scr.xterm256_set_fg_color(0x20)
print('capcode:')
scr.xterm256_set_bk_color(0x08)
scr.xterm256_set_fg_color(0x78)
scr.gotoXY(10,3)
print(' ')
scr.xterm256_set_bk_color(0)
scr.gotoXY(20,3)
scr.xterm256_set_fg_color(0x20)
print('alert:')
scr.xterm256_set_bk_color(0x08)
scr.xterm256_set_fg_color(0x78)
scr.gotoXY(26,3)
print(' ')
scr.xterm256_set_bk_color(0)
scr.gotoXY(2,5)
scr.xterm256_set_fg_color(0x20)
print('message:')
scr.xterm256_set_bk_color(0x08)
scr.xterm256_set_fg_color(0x78)
scr.gotoXY(10,5)
print(' ')
scr.xterm256_set_bk_color(0)
scr.gotoXY(0,9)
scr.xterm256_set_fg_color(0x28)
# to be developed, input capcode
def get_capcode(scr,default):
pass
# display capcode in input box
def disp_capcode(scr,capcode):
scr.xterm256_set_bk_color(0x08)
scr.xterm256_set_fg_color(0x78)
scr.gotoXY(10,3)
print (str((b'%07d' % capcode),'utf-8'))
scr.xterm256_set_bk_color(0)
# display alert code in input box
def disp_alert(scr,alert):
scr.xterm256_set_bk_color(0x08)
scr.xterm256_set_fg_color(0x78)
scr.gotoXY(26,3)
print (str((b'%01d' % alert),'utf-8'))
scr.xterm256_set_bk_color(0)
# display message in input box
def disp_msg(scr,message):
scr.xterm256_set_bk_color(0x08)
scr.xterm256_set_fg_color(0x78)
scr.gotoXY(10,5)
print (str(message,'utf-8'))
scr.xterm256_set_bk_color(0)
scr.gotoXY(0,9)
#
# main code now starts here
#
#
#
# initialise the screen
#
screen = terminal.get_terminal(conEmu=False)
header(screen)
# 2017-06-23: now accepts interactive input of message
#
# a blank line transmits the hardcoded message
#
# 'q' exits the code
#
while True:
# refresh the header
screen = terminal.get_terminal(conEmu=False)
header(screen)
# message now split into capcode, function (0-3), repeats
# and 40 character bytearray
#
capcode = 20008
function = 2
repeats = 1
message = b'rtn: miauw naar de maan!<<<pagertest>>>'
ttydev="/dev/ttyACM0"
page(ttydev,capcode,function,repeats,message)
function = 3
repeats = 1
message = b'this is another test msg<<<pagertest>>>'
header(screen)
page(ttydev,capcode,function,repeats,message)
# hardcoded values
#
capcode = 20008
function = 2
repeats = 1
message = b'rtn: miauw naar de maan!<<<pagertest>>>'
ttydev="/dev/ttyACM0"
# display the capcode and alert that are currently hardcoded
# but leave the msg box blank as it now accepts user input
#
disp_capcode(screen,capcode)
disp_alert(screen,function)
#
# create a quick and dirty coloured prompt for the input
#
screen.gotoXY(2,7)
screen.xterm256_set_fg_color(0x38)
print('------>')
screen.gotoXY(10,7)
screen.xterm256_set_fg_color(0x68)
#
# this uses readline so has some basic editing functions
#
# anything over 40 character is clipped
#
ms1=input()
if ms1 !='':
message=ms1[0:40].encode('utf-8')
if ms1 =='q':
break
#
# display the msg in the top box and transmit it
#
disp_msg(screen,message)
page(ttydev,capcode,function,repeats,message)
#
# terminate script and reset all the console colours
#
print (fg(0xc8),'\n++ Script completed sucessfully ++\n',res)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment