Skip to content

Commit

Permalink
Two step switch debouncing
Browse files Browse the repository at this point in the history
  • Loading branch information
pichenettes committed Apr 20, 2012
1 parent 2bd50de commit 60be9cd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions devices/switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ class DebouncedSwitches {
memset(state_, 0xff, sizeof(state_));
}

static inline T DummyRead() {
static inline T ReadRegister() {
return Register::Read();
}

static inline void Read() {
T value = Register::Read();
static inline void Process(T value) {
T mask = 1 << (num_inputs - 1);
for (uint8_t i = 0; i < num_inputs; ++i) {
state_[i] <<= 1;
Expand All @@ -96,6 +95,10 @@ class DebouncedSwitches {
}
}

static inline void Read() {
Process(ReadRegister());
}

static inline uint8_t lowered(uint8_t index) { return state_[index] == 0x80; }
static inline uint8_t raised(uint8_t index) { return state_[index] == 0x7f; }
static inline uint8_t high(uint8_t index) { return state_[index] == 0xff; }
Expand Down

0 comments on commit 60be9cd

Please sign in to comment.