2024-05-10 08:14:29 +00:00
|
|
|
from helpfunctions import *
|
|
|
|
|
|
|
|
|
|
|
|
class UI:
|
|
|
|
import curses
|
|
|
|
|
|
|
|
|
2024-05-10 08:33:02 +00:00
|
|
|
def __init__(self,_joint_min,_joint_max,_frequency_scr=25):
|
2024-05-10 08:14:29 +00:00
|
|
|
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
|
2024-05-10 08:33:02 +00:00
|
|
|
self.frequency_scr=_frequency_scr
|
|
|
|
self.last_updatescr=0
|
2024-05-10 08:35:53 +00:00
|
|
|
self.key = ''
|
2024-05-10 08:14:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|
2024-05-10 08:35:53 +00:00
|
|
|
|
|
|
|
def getKey(self):
|
|
|
|
return self.key
|
2024-05-10 08:14:29 +00:00
|
|
|
|
2024-05-10 08:33:02 +00:00
|
|
|
def update(self,q,looptime):
|
|
|
|
|
|
|
|
if looptime-self.last_updatescr<1.0/self.frequency_scr:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.last_updatescr=looptime
|
|
|
|
|
2024-05-10 08:35:53 +00:00
|
|
|
self.key = self.stdscr.getch()
|
2024-05-10 08:14:29 +00:00
|
|
|
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()
|
|
|
|
|