add fps output

This commit is contained in:
interfisch 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.bind(("", self.udpPort))
self.timesincelastpacket=time.time()
self.timelastcalculation=0
self.time_receivedpacket=0
self.bitsneeded=self.imageSize[0]*self.imageSize[1]*self.bitsperpixel
@ -46,11 +45,13 @@ class FlipdotSim():
try:
while True:
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
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:
self.udpHostSocket.close()

View File

@ -9,14 +9,17 @@ matrix = MatrixSender(udphost="localhost", udpport=2323, img_size=(160,24*6), bi
if __name__ == '__main__':
_fps=0
_time_startsending=0
im = Image.new("RGBA", matrix._img_size, MatrixSender.C_BLACK) #create image
draw = ImageDraw.Draw(im) #get draw instance
ball_pos=np.array((20,20))
ball_size=10
ball_vel=np.array((-5,5))
while(True):
#------- Update Movements ------
#move ball
@ -34,10 +37,11 @@ if __name__ == '__main__':
#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))
_fps=1/(time.time()-_time_startsending)
_time_startsending=time.time()
matrix.send(im) #construct udp packet and send to matrix
_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