Skip to content

Commit

Permalink
Use Button C for toggling fan to align with MAKE: article instruction…
Browse files Browse the repository at this point in the history
…s ("upper left button")
  • Loading branch information
kartben committed May 3, 2021
1 parent ffccfd3 commit ca92190
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ CircularBuffer<float, EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE> buffer;
uint64_t next_sampling_tick = micros();

#define INITIAL_FAN_STATE LOW
static int fan_state = INITIAL_FAN_STATE;

static bool debug_nn = false; // Set this to true to see e.g. features generated
// from the raw signal
Expand All @@ -289,16 +290,14 @@ void draw_chart();

enum class ButtonId
{
A = 0,
B,
C,
LEFT,
RIGHT,
UP,
DOWN,
PRESS
};
static const int ButtonNumber = 8;
static const int ButtonNumber = 6;
static AceButton Buttons[ButtonNumber];

static void ReceivedTwinDocument(const char* json, const char* requestId)
Expand Down Expand Up @@ -339,11 +338,10 @@ static void ButtonEventHandler(AceButton *button, uint8_t eventType, uint8_t but
switch (eventType) {
case AceButton::kEventReleased:
switch (static_cast<ButtonId>(id)) {
case ButtonId::A:
digitalWrite(D0, HIGH); // Turn fan ON
break;
case ButtonId::B:
digitalWrite(D0, LOW); // Turn fan OFF
case ButtonId::C:
// Toggle Fan
fan_state = (fan_state == HIGH) ? LOW : HIGH ;
digitalWrite(D0, fan_state); // Turn fan ON
break;
case ButtonId::PRESS:
mode = (mode == INFERENCE) ? TRAINING : INFERENCE;
Expand Down Expand Up @@ -376,10 +374,6 @@ static void ButtonEventHandler(AceButton *button, uint8_t eventType, uint8_t but

static void ButtonInit()
{
Buttons[static_cast<int>(ButtonId::A)].init(
WIO_KEY_A, HIGH, static_cast<uint8_t>(ButtonId::A));
Buttons[static_cast<int>(ButtonId::B)].init(
WIO_KEY_B, HIGH, static_cast<uint8_t>(ButtonId::B));
Buttons[static_cast<int>(ButtonId::C)].init(
WIO_KEY_C, HIGH, static_cast<uint8_t>(ButtonId::C));
Buttons[static_cast<int>(ButtonId::LEFT)].init(
Expand Down Expand Up @@ -414,7 +408,7 @@ void setup()
Serial.begin(115200);

pinMode(D0, OUTPUT);
digitalWrite(D0, INITIAL_FAN_STATE);
digitalWrite(D0, fan_state);

pinMode(WIO_KEY_A, INPUT_PULLUP);
pinMode(WIO_KEY_B, INPUT_PULLUP);
Expand Down

0 comments on commit ca92190

Please sign in to comment.