add fps output

This commit is contained in:
Fisch 2018-01-13 19:31:08 +01:00
parent 9519e9b876
commit 21733b6c6c
2 changed files with 13 additions and 8 deletions

View file

@ -32,8 +32,7 @@ class FlipdotSim():
self.udpHostSocket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) self.udpHostSocket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
self.udpHostSocket.bind(("", self.udpPort)) self.udpHostSocket.bind(("", self.udpPort))
self.timesincelastpacket=time.time() self.time_receivedpacket=0
self.timelastcalculation=0
self.bitsneeded=self.imageSize[0]*self.imageSize[1]*self.bitsperpixel self.bitsneeded=self.imageSize[0]*self.imageSize[1]*self.bitsperpixel
@ -46,11 +45,13 @@ class FlipdotSim():
try: try:
while True: while True:
rawData = self.udpHostSocket.recv(4096*2) rawData = self.udpHostSocket.recv(4096*2)
blafoo=time.time() _fps=1/(time.time()-self.time_receivedpacket)
self.time_receivedpacket=time.time()
self.flipdotMatrixSimulatorWidget.showFromRawData(rawData) #send to simulator display self.flipdotMatrixSimulatorWidget.showFromRawData(rawData) #send to simulator display
calctime=time.time()-blafoo
print(str(round(calctime,4))+"s, FPS="+str(round(1/calctime,2))) #calculate time it took for calculation and drawing calctime=time.time()-self.time_receivedpacket
print(str(round(calctime,4))+"s, maxFPS="+str(round(1/calctime,2))+", actual FPS="+str(round(_fps,2))) #calculate time it took for calculation and drawing
finally: finally:
self.udpHostSocket.close() self.udpHostSocket.close()

View file

@ -9,14 +9,17 @@ matrix = MatrixSender(udphost="localhost", udpport=2323, img_size=(160,24*6), bi
if __name__ == '__main__': if __name__ == '__main__':
_fps=0
_time_startsending=0
im = Image.new("RGBA", matrix._img_size, MatrixSender.C_BLACK) #create image im = Image.new("RGBA", matrix._img_size, MatrixSender.C_BLACK) #create image
draw = ImageDraw.Draw(im) #get draw instance draw = ImageDraw.Draw(im) #get draw instance
ball_pos=np.array((20,20)) ball_pos=np.array((20,20))
ball_size=10 ball_size=10
ball_vel=np.array((-5,5)) ball_vel=np.array((-5,5))
while(True): while(True):
#------- Update Movements ------ #------- Update Movements ------
#move ball #move ball
@ -34,10 +37,11 @@ if __name__ == '__main__':
#draw ball #draw ball
draw.ellipse((ball_pos[0]-ball_size/2,ball_pos[1]-ball_size/2,ball_pos[0]+ball_size/2,ball_pos[1]+ball_size/2,),fill=(255,255,255)) draw.ellipse((ball_pos[0]-ball_size/2,ball_pos[1]-ball_size/2,ball_pos[0]+ball_size/2,ball_pos[1]+ball_size/2,),fill=(255,255,255))
_fps=1/(time.time()-_time_startsending)
_time_startsending=time.time() _time_startsending=time.time()
matrix.send(im) #construct udp packet and send to matrix matrix.send(im) #construct udp packet and send to matrix
_time_endsending=time.time() _time_endsending=time.time()
print("Sendtime="+str(round(_time_endsending-_time_startsending,4))+"s, FPS="+str(round(1/(_time_endsending-_time_startsending),2))) print("Sendtime="+str(round(_time_endsending-_time_startsending,4))+"s, maxFPS="+str(round(1/(_time_endsending-_time_startsending),2))+", actual FPS="+str(round(_fps,2)))
time.sleep(.1) #wait #time.sleep(.1) #wait