Using the HRMListener results

136 views
Skip to first unread message

Rob Jordan

unread,
Oct 13, 2013, 10:16:10 AM10/13/13
to python-ant-...@googlegroups.com
Hi All,

Firstly, great work on this project.  I'm pleased to say it all seems to be working nicely.

I'm wearing the garmin heart rate strap and have a USB2 garmin stick in the laptop.  The Eventlistener is printing the HR to the CMD ad infinitum and that is great.....

My question is how can I send the output of the HRMListener to another Class?  My knowledge of python is patchy to say the least and based on figuring things out on Stackover flow but this one has me a bit lost...

What I'm trying to achieve is to send the stream of hr information to pygame and update a moving bar graph.
Do I need to look at Threading? (running simultaneous classes?) Although this doesn't look like it handles the looping of the eventlistener?
The other idea was to figure out the pygame.get.event() as it is receiving constant input a bit like a mouse moving? But not sure as the examples are quite simlistic.

Ultimate aim is to hash some kind of racing game for my bike turbo trainer. If anyone has better places to send the data then I'm happy to hear about them.  pygame appeals as I can animate against the results of hr and speed from the garmin sensors etc.

Cheers,
Rob

below are the bones of the pygame code - http://karpathy.ca/phyces/tutorial1.php (learnt here)

from pygamehelper import *
from pygame import *
from pygame.locals import *
from vec2d import *
from math import e, pi, cos, sin, sqrt
from random import uniform

class Starter(PygameHelper):
    def __init__(self):
        self.w, self.h = 800, 600
        PygameHelper.__init__(self, size=(self.w, self.h), fill=((255,255,255)))

        
    def update(self):
        #print "draw hr "
        #y = 50 #start at hr of 50

        #self.screen.fill((255,255,255))
        #pygame.draw.line(self.screen, (0,0,0), (50,500), (50,500-(y*1.5)),20) # drawing the bar graph - this where the input from the HRMListener would likely end up
        
        pass
        
    def keyUp(self, key):
        pass
        
    def mouseUp(self, button, pos):
        
        pass
        
    def mouseMotion(self, buttons, pos, rel):
        pass
        
    def draw(self):
        pass

       
s = Starter()
s.mainLoop(40)


Rob Jordan

unread,
Oct 13, 2013, 2:46:45 PM10/13/13
to python-ant-...@googlegroups.com
Okay,

I solved it with Threading and making hr from the EventListener a global variable.
It's probably setting me up for an error further down the line...  Having just done a session on the turbo trainer I'm pretty happy with the bar showing hr increasing and decreasing.

Still interested to understand if anyone is still on this group and what tools people output their Ant+ data too.

thanks,
Rob

Martín Raúl Villalba

unread,
Oct 13, 2013, 4:36:16 PM10/13/13
to python-ant-...@googlegroups.com
Don't worry too much how you get the data; I'm going to replace most of the event-handling code with something better for the next release, which should happen relatively soon :-).

Cheers,
Martín


2013/10/14 Rob Jordan <rob.jo...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Python ANT+ Open Source" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-ant-open-s...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Martín Raúl Villalba
Reply all
Reply to author
Forward
0 new messages