customize: wire diamater
parent
fe37eea8de
commit
3a5af46135
|
@ -0,0 +1,95 @@
|
|||
#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);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void customize();
|
|
@ -2,6 +2,7 @@
|
|||
#include "buzzer.h"
|
||||
#include "screen.h"
|
||||
#include "characters.h"
|
||||
#include "customize.h"
|
||||
|
||||
uint8_t menuPos = 0;
|
||||
#define MENU_ITEMS 2
|
||||
|
@ -24,8 +25,7 @@ void menu() {
|
|||
} else if (input.switchEvent == SWITCH_RELEASED) {
|
||||
switch (menuPos) {
|
||||
case 0:
|
||||
Serial.println("Unimplemented");
|
||||
sadBuzz();
|
||||
customize();
|
||||
break;
|
||||
case 1:
|
||||
help();
|
||||
|
@ -56,7 +56,7 @@ void menu_update() {
|
|||
|
||||
void help() {
|
||||
lcd.clear();
|
||||
lcd.print("Read the source");
|
||||
lcd.print("Use the source");
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("code, Luke ;^)");
|
||||
beep();
|
||||
|
|
Loading…
Reference in New Issue