-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separated user interface and display headers, made interface not be a…
… class
- Loading branch information
Showing
46 changed files
with
354 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,5 +116,8 @@ | |
"geometry": "cpp", | ||
"forward_list": "cpp", | ||
"regex": "cpp" | ||
} | ||
}, | ||
"java.project.sourcePaths": [ | ||
"test/native" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include "button.h" | ||
|
||
namespace Interface | ||
{ | ||
enum class EncoderDirection | ||
{ | ||
NONE = 0, | ||
CW = 1, | ||
CCW = -1, | ||
}; | ||
|
||
void begin(); | ||
void update(); | ||
EncoderDirection getEncoderDirection(); | ||
long getEncoderTicks(); | ||
void setEncoderTicks(long ticks); | ||
void resetEncoderTicks(); | ||
ClickType consumeEncoderClick(); | ||
ClickType getEncoderClick(); | ||
bool isEncoderPressed(); | ||
void buzzerTone(unsigned int durationMs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#pragma once | ||
|
||
namespace LoadCell | ||
{ | ||
void begin(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include "interface.h" | ||
|
||
namespace Interface | ||
{ | ||
extern ClickType encoderClick; | ||
extern ClickType bootClick; | ||
extern int encoderTicks; | ||
extern EncoderDirection encoderDirection; | ||
|
||
void reset(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#ifndef NATIVE | ||
|
||
#include <Arduino.h> | ||
#include <RotaryEncoder.h> | ||
#include "interface.h" | ||
#include "constants.h" | ||
#include "button.h" | ||
|
||
static RotaryEncoder encoder(PIN_ENC_A, PIN_ENC_B, RotaryEncoder::LatchMode::FOUR3); | ||
static Button encoderButton; | ||
static uint64_t lastBuzzerMillis; | ||
static uint32_t lastBuzzerDuration; | ||
|
||
|
||
void Interface::begin() { | ||
pinMode(PIN_ENC_BTN, INPUT_PULLUP); | ||
pinMode(PIN_BUZZER, OUTPUT); | ||
} | ||
|
||
void Interface::update() | ||
{ | ||
encoder.tick(); | ||
encoderButton.update(digitalRead(PIN_ENC_BTN) == LOW); | ||
|
||
if (lastBuzzerMillis + lastBuzzerDuration < millis()) | ||
{ | ||
digitalWrite(PIN_BUZZER, LOW); | ||
} | ||
} | ||
|
||
Interface::EncoderDirection Interface::getEncoderDirection() | ||
{ | ||
switch (encoder.getDirection()) | ||
{ | ||
case RotaryEncoder::Direction::NOROTATION: | ||
return EncoderDirection::NONE; | ||
case RotaryEncoder::Direction::CLOCKWISE: | ||
return EncoderDirection::CW; | ||
case RotaryEncoder::Direction::COUNTERCLOCKWISE: | ||
return EncoderDirection::CCW; | ||
default: | ||
return EncoderDirection::NONE; | ||
} | ||
} | ||
|
||
long Interface::getEncoderTicks() | ||
{ | ||
return encoder.getPosition(); | ||
} | ||
|
||
void Interface::setEncoderTicks(long ticks) | ||
{ | ||
encoder.setPosition(ticks); | ||
} | ||
|
||
void Interface::resetEncoderTicks() | ||
{ | ||
encoder.setPosition(0); | ||
} | ||
|
||
ClickType Interface::consumeEncoderClick() | ||
{ | ||
return encoderButton.consumeClickType(); | ||
} | ||
|
||
ClickType Interface::getEncoderClick() | ||
{ | ||
return encoderButton.getClickType(); | ||
} | ||
|
||
bool Interface::isEncoderPressed() | ||
{ | ||
return encoderButton.isPressed(); | ||
} | ||
|
||
void Interface::buzzerTone(unsigned int durationMs) | ||
{ | ||
digitalWrite(PIN_BUZZER, HIGH); | ||
lastBuzzerMillis = millis(); | ||
lastBuzzerDuration = durationMs; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.