use DEBUG option

This commit is contained in:
King Kévin 2015-01-07 19:48:01 +01:00
parent e2859b1080
commit bea4e707ac
1 changed files with 10 additions and 0 deletions

View File

@ -32,7 +32,9 @@
/* variables */
volatile uint8_t state_portD; // the state of port D
volatile bool scale_on = false; // is the scale on (based on the SCALE_ON PIN)
#ifdef DEBUG
volatile bool scale_old = false; // the previous state (to detect changes)
#endif
volatile bool pwm_high = false; // is the PWM for the weight measurement high
volatile bool measurement_flag = false; // is a PWM measurement value ready
volatile uint16_t measurement_value = 0; // the PWM measurement value from the timer
@ -146,25 +148,33 @@ int main(void)
printf(PSTR("welcome to the body scale weight reader\n")); // print welcome message
while (true) { // endless loop for micro-controller
#ifdef DEBUG
/* display if scale switches on */
if (scale_old!=scale_on && scale_on) {
printf(PSTR("scale start\n"));
scale_old=scale_on;
}
#endif
/* display value if available */
if (measurement_flag) {
if (pwm_high) {
#ifdef DEBUG
printf("high: %u\n",measurement_value);
#endif
} else {
#ifdef DEBUG
printf("low: %u\n",measurement_value);
#endif
}
measurement_flag = false;
}
#ifdef DEBUG
/* display if scale switches off */
if (scale_old!=scale_on && !scale_on) {
printf(PSTR("scale stop\n"));
scale_old=scale_on;
}
#endif
/* go to sleep and wait for next interrupt */
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_mode();