Browse files

pwm_example: Check if signal has value in signal callback.

  • Loading branch information...
1 parent 7ccc12a commit f1d87d3b895772ea98e04017ec3cb2f30ffe8de6 @malloch malloch committed Oct 16, 2012
Showing with 14 additions and 6 deletions.
  1. +14 −6 examples/pwm_example.cpp
View
20 examples/pwm_example.cpp
@@ -21,8 +21,10 @@ void handler_freq(mapper_signal msig,
int count,
mapper_timetag_t *timetag)
{
- float *pfreq = (float*)value;
- set_freq(*pfreq);
+ if (value) {
+ float *pfreq = (float*)value;
+ set_freq(*pfreq);
+ }
}
void handler_gain(mapper_signal msig,
@@ -32,8 +34,12 @@ void handler_gain(mapper_signal msig,
int count,
mapper_timetag_t *timetag)
{
- float *pgain = (float*)value;
- set_gain(*pgain);
+ if (value) {
+ float *pgain = (float*)value;
+ set_gain(*pgain);
+ }
+ else
+ set_gain(0);
}
void handler_duty(mapper_signal msig,
@@ -43,8 +49,10 @@ void handler_duty(mapper_signal msig,
int count,
mapper_timetag_t *timetag)
{
- float *pduty = (float*)value;
- set_duty(*pduty);
+ if (value) {
+ float *pduty = (float*)value;
+ set_duty(*pduty);
+ }
}
int main()

0 comments on commit f1d87d3

Please sign in to comment.