From 21733b6c6c81b3c47a55196e7326ae73178a7ad4 Mon Sep 17 00:00:00 2001 From: Fisch Date: Sat, 13 Jan 2018 19:31:08 +0100 Subject: [PATCH] add fps output --- client_sw/matrixsimulator.py | 11 ++++++----- client_sw/movingball_example.py | 10 +++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/client_sw/matrixsimulator.py b/client_sw/matrixsimulator.py index ceace7f..7f19007 100644 --- a/client_sw/matrixsimulator.py +++ b/client_sw/matrixsimulator.py @@ -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() diff --git a/client_sw/movingball_example.py b/client_sw/movingball_example.py index d5d084d..e61b9e6 100644 --- a/client_sw/movingball_example.py +++ b/client_sw/movingball_example.py @@ -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