84 lines
2.3 KiB
Python
84 lines
2.3 KiB
Python
|
from helpfunctions import *
|
||
|
|
||
|
|
||
|
class UI:
|
||
|
#def __init__(self, name, age):
|
||
|
# self.name = name
|
||
|
# self.age = age
|
||
|
|
||
|
import curses
|
||
|
|
||
|
|
||
|
def __init__(self,_joint_min,_joint_max):
|
||
|
self.stdscr=None
|
||
|
self.debugtext=["","",""]
|
||
|
self.width=0
|
||
|
self.height=0
|
||
|
self.joint_min=None
|
||
|
self.joint_max=None
|
||
|
self.joint_min=_joint_min
|
||
|
self.joint_max=_joint_max
|
||
|
|
||
|
|
||
|
def setDebugtext(self,line,text):
|
||
|
self.debugtext[line]=text
|
||
|
|
||
|
|
||
|
def begin(self,_stdscr):
|
||
|
self.stdscr=_stdscr
|
||
|
|
||
|
# Clear and refresh the screen for a blank canvas
|
||
|
self.stdscr.clear()
|
||
|
self.stdscr.refresh()
|
||
|
|
||
|
self.curses.cbreak()
|
||
|
self.stdscr.keypad(1)
|
||
|
self.stdscr.nodelay(1)
|
||
|
|
||
|
|
||
|
# Start colors in curses
|
||
|
self.curses.start_color()
|
||
|
self.curses.init_pair(1, self.curses.COLOR_CYAN, self.curses.COLOR_BLACK)
|
||
|
self.curses.init_pair(2, self.curses.COLOR_RED, self.curses.COLOR_BLACK)
|
||
|
self.curses.init_pair(3, self.curses.COLOR_BLACK, self.curses.COLOR_WHITE)
|
||
|
|
||
|
|
||
|
self.height, self.width = self.stdscr.getmaxyx()
|
||
|
|
||
|
def update(self,q):
|
||
|
key = self.stdscr.getch()
|
||
|
self.stdscr.clear()
|
||
|
|
||
|
for i in range(3): #Print Debug text
|
||
|
self.stdscr.addstr(i, 0, self.debugtext[i], self.curses.color_pair(1))
|
||
|
|
||
|
startbarsx=10
|
||
|
endbarsx=self.width-1
|
||
|
for j in range(6):
|
||
|
posx=mapFromTo(q[j],self.joint_min[j],self.joint_max[j],startbarsx,endbarsx) #scale to screen width
|
||
|
for px in range(self.width):
|
||
|
diff=abs(posx-px)
|
||
|
poschar=''
|
||
|
|
||
|
if diff<3:
|
||
|
poschar='-'
|
||
|
if diff<0.5:
|
||
|
poschar='|'
|
||
|
|
||
|
if px==startbarsx:
|
||
|
poschar="["
|
||
|
if px==endbarsx:
|
||
|
poschar="]"
|
||
|
|
||
|
if (len(poschar)>0):
|
||
|
self.stdscr.addstr(3+j, px, poschar, self.curses.color_pair(1))
|
||
|
valuetext=str(round(toDeg(q[j]),2))
|
||
|
if q[j]>=0: #has no negative sign
|
||
|
valuetext=" "+valuetext
|
||
|
self.stdscr.addstr(3+j, 0, valuetext, self.curses.color_pair(1))
|
||
|
|
||
|
|
||
|
# Refresh the screen
|
||
|
self.stdscr.refresh()
|
||
|
|