96 lines
2.2 KiB
C++
96 lines
2.2 KiB
C++
#include "input.h"
|
|
#include "buzzer.h"
|
|
#include "screen.h"
|
|
#include "characters.h"
|
|
|
|
String wireDiameterInput = "";
|
|
int8_t dotPosition = -1;
|
|
|
|
#define ENCODER_STEP 0.1
|
|
|
|
void customize_setup();
|
|
void customize_update();
|
|
|
|
void customize() {
|
|
customize_setup();
|
|
while (true) {
|
|
auto input = handleInput();
|
|
|
|
if (input.key) {
|
|
auto len = wireDiameterInput.length();
|
|
auto digit = getPressedDigit(input.key);
|
|
if (input.key == KEY_HASH) {
|
|
if (len) {
|
|
if (dotPosition == len - 1) {
|
|
dotPosition = -1;
|
|
}
|
|
wireDiameterInput = wireDiameterInput.substring(0, len - 1);
|
|
tick();
|
|
} else {
|
|
beep();
|
|
}
|
|
} else if (wireDiameterInput.length() >= 8) {
|
|
beep();
|
|
} else if (digit != -1) {
|
|
wireDiameterInput += digit;
|
|
tick();
|
|
} else if (input.key == KEY_ASTERISK) {
|
|
if (dotPosition == -1 && len >= 1) {
|
|
dotPosition = wireDiameterInput.length();
|
|
wireDiameterInput += ".";
|
|
tick();
|
|
} else {
|
|
beep();
|
|
}
|
|
} else {
|
|
beep();
|
|
}
|
|
|
|
customize_update();
|
|
} else if (input.encoderEvent) {
|
|
if (wireDiameterInput.length() == 0) {
|
|
wireDiameterInput = "0";
|
|
}
|
|
|
|
auto len = wireDiameterInput.length();
|
|
auto previousDecimalPlaces = dotPosition == -1 ? 0 : len - dotPosition - 1;
|
|
|
|
auto wireDia = wireDiameterInput.toFloat();
|
|
wireDia += input.encoderEvent * ENCODER_STEP;
|
|
if (wireDia < 0) {
|
|
wireDia = 0;
|
|
beep();
|
|
} else {
|
|
tick();
|
|
}
|
|
|
|
wireDiameterInput = String(wireDia, max(previousDecimalPlaces, 1));
|
|
dotPosition = wireDiameterInput.indexOf('.');
|
|
|
|
customize_update();
|
|
} else if (input.hasInput && input.switchEvent != SWITCH_PRESSED) {
|
|
beep();
|
|
}
|
|
}
|
|
}
|
|
|
|
void customize_setup() {
|
|
wireDiameterInput = "";
|
|
dotPosition = -1;
|
|
|
|
lcd.clear();
|
|
lcd.print("Wire diameter:");
|
|
lcd.setCursor(14, 1);
|
|
lcd.print("mm");
|
|
lcd.cursor();
|
|
customize_update();
|
|
}
|
|
|
|
void customize_update() {
|
|
lcd.setCursor(0, 1);
|
|
lcd.print(wireDiameterInput);
|
|
// Delete following character (if backspace was pressed), then move cursor back to position
|
|
lcd.write(' ');
|
|
lcd.setCursor(wireDiameterInput.length(), 1);
|
|
}
|