|
| 1 | +//=====[Libraries]============================================================= |
| 2 | + |
| 3 | +#include "mbed.h" |
| 4 | +#include "arm_book_lib.h" |
| 5 | + |
| 6 | +#include "buttons.h" |
| 7 | + |
| 8 | +//=====[Declaration of private defines]======================================== |
| 9 | + |
| 10 | +//=====[Declaration of private data types]===================================== |
| 11 | + |
| 12 | +//=====[Declaration and initialization of public global objects]=============== |
| 13 | + |
| 14 | +static DigitalIn changeModeButton(PG_1); |
| 15 | +static DigitalIn howOftenButton(PF_9); |
| 16 | +static DigitalIn howLongButton(PF_7); |
| 17 | +static DigitalIn moistureButton(PF_8); |
| 18 | + |
| 19 | +//=====[Declaration of external public global variables]======================= |
| 20 | + |
| 21 | +//=====[Declaration and initialization of public global variables]============= |
| 22 | + |
| 23 | +//=====[Declaration and initialization of private global variables]============ |
| 24 | + |
| 25 | +static buttonsStatus_t buttonsStatus; |
| 26 | + |
| 27 | +//=====[Implementations of public functions]=================================== |
| 28 | + |
| 29 | +void buttonsInit() |
| 30 | +{ |
| 31 | + changeModeButton.mode(PullUp); |
| 32 | + howOftenButton.mode(PullUp); |
| 33 | + howLongButton.mode(PullUp); |
| 34 | + moistureButton.mode(PullUp); |
| 35 | + |
| 36 | + buttonsStatus.changeMode = OFF; |
| 37 | + buttonsStatus.howOften = HOW_OFTEN_MIN; |
| 38 | + buttonsStatus.howLong = HOW_LONG_MIN; |
| 39 | + buttonsStatus.moisture = MOISTURE_MIN; |
| 40 | +} |
| 41 | + |
| 42 | +void buttonsUpdate() |
| 43 | +{ |
| 44 | + buttonsStatus.changeMode = !changeModeButton; |
| 45 | + |
| 46 | + if ( !howOftenButton ) { |
| 47 | + buttonsStatus.howOften = buttonsStatus.howOften + HOW_OFTEN_INCREMENT; |
| 48 | + if ( buttonsStatus.howOften >= HOW_OFTEN_MAX + HOW_OFTEN_INCREMENT) { |
| 49 | + buttonsStatus.howOften = HOW_OFTEN_MIN; |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + if ( !howLongButton ) { |
| 54 | + buttonsStatus.howLong = buttonsStatus.howLong + HOW_LONG_INCREMENT; |
| 55 | + if ( buttonsStatus.howLong >= HOW_LONG_MAX + HOW_LONG_INCREMENT) { |
| 56 | + buttonsStatus.howLong = HOW_LONG_MIN; |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + if ( !moistureButton ) { |
| 61 | + buttonsStatus.moisture = buttonsStatus.moisture + MOISTURE_INCREMENT; |
| 62 | + if ( buttonsStatus.moisture >= MOISTURE_MAX + MOISTURE_INCREMENT) { |
| 63 | + buttonsStatus.moisture = MOISTURE_MIN; |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +buttonsStatus_t buttonsRead() |
| 69 | +{ |
| 70 | + return buttonsStatus; |
| 71 | +} |
0 commit comments