I have a Timer CHOP which i attached a CHOP execute DAT to.
My goal is to read hour and minutes and trigger the recording of video from a camera for 1 minute.
Here is the python code i inserted in onValueChanged() :
if op(‘clock1’)[‘hour’] == 15 and op(‘clock1’)[‘min’] == 20:
op(‘moviefileout1’).par.record = 1
if op(‘clock1’)[‘hour’] == 15 and op(‘clock1’)[‘min’] == 21:
op(‘moviefileout1’).par.record = 0
So this works but i see there is channel, val etc… passed to the onValueChanged() function.
I thought about using the channel information to filter out ‘hour’ and ‘min’ values but i can’t understand how…
I typically use these to separate out actions for different channels, for example:
if val == 20:
print("it's hour 20")
That won’t totally work in your case as those callbacks are sequential, but if you wanted to limit your scope to hour changes something like this could work:
if op('clock1')['min'] == 20:
print("start recording")
As a slightly different course of action, what if you used your clock to trigger a timer instead? In this approach every hour a CHOP execute would trigger a timer CHOP. I think that does the same thing, but rather than having to compare hour and minute times to start and stop, you only worry about starting your timer - which is the thing in charge of starting and stopping your video recording.
Rather than every hour this runs every minute.
The clock CHOP is used to trigger the timer when the minute val changes, this then kicks off the timer. In the timer callbacks you’ll see the on start call, and the on done call. These would get used for any of your recording needs.
Using the timer callbacks for this means you can write more generalized code, rather than worrying about getting all of the logic right in the CHOP execute.
It might not be the right approach for what you’re doing, but it’s saved me serious time in the past when I’ve needed an event or clock based trigger to set off recording for a fixed period of time.