refactoring
This commit is contained in:
parent
ba64c92464
commit
c757788aee
@ -9,43 +9,15 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
|
|
||||||
const uint32_t DISPLAY_UPDATE_TIME = 5e5; // microseconds
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
lcd.begin(LCD_COLS, LCD_ROWS);
|
|
||||||
lcd.print("Teensy SMPS");
|
|
||||||
Serial.println("Teensy SMPS");
|
Serial.println("Teensy SMPS");
|
||||||
|
|
||||||
pwmInit();
|
pwmInit();
|
||||||
rotaryInit();
|
rotaryInit();
|
||||||
|
displayInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
static uint32_t lastDisplayCycle = 0;
|
displayLoop();
|
||||||
uint32_t currentTime = micros();
|
|
||||||
if ((lastDisplayCycle + DISPLAY_UPDATE_TIME <= currentTime) || (lastDisplayCycle > currentTime)) {
|
|
||||||
lastDisplayCycle = currentTime;
|
|
||||||
|
|
||||||
int rotaryCount = getAndResetRotaryCount();
|
|
||||||
if (rotaryCount != 0) {
|
|
||||||
setUDes(getUDes() + rotaryCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
lcd.clear();
|
|
||||||
lcd.setCursor(0, 0);
|
|
||||||
lcd.print(getUdes());
|
|
||||||
lcd.setCursor(8, 0);
|
|
||||||
lcd.print(getUCur());
|
|
||||||
lcd.setCursor(0, 1);
|
|
||||||
lcd.print(geDutyCycle());
|
|
||||||
lcd.print("%");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
40
display.cpp
Normal file
40
display.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "hardware.h"
|
||||||
|
#include "display.h"
|
||||||
|
#include "pwm.h"
|
||||||
|
#include "rotary.h"
|
||||||
|
|
||||||
|
|
||||||
|
LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
|
||||||
|
const uint32_t DISPLAY_UPDATE_TIME = 5e5; // microseconds
|
||||||
|
|
||||||
|
|
||||||
|
void displayInit() {
|
||||||
|
lcd.begin(LCD_COLS, LCD_ROWS);
|
||||||
|
lcd.print("Teensy SMPS");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void displayLoop() {
|
||||||
|
static uint32_t lastDisplayCycle = 0;
|
||||||
|
uint32_t currentTime = micros();
|
||||||
|
if ((lastDisplayCycle + DISPLAY_UPDATE_TIME <= currentTime) || (lastDisplayCycle > currentTime)) {
|
||||||
|
lastDisplayCycle = currentTime;
|
||||||
|
|
||||||
|
int rotaryCount = getAndResetRotaryCount();
|
||||||
|
if (rotaryCount != 0) {
|
||||||
|
setUDes(getUDes() + rotaryCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
lcd.clear();
|
||||||
|
lcd.setCursor(0, 0);
|
||||||
|
lcd.print(getUdes());
|
||||||
|
lcd.setCursor(8, 0);
|
||||||
|
lcd.print(getUCur());
|
||||||
|
lcd.setCursor(0, 1);
|
||||||
|
lcd.print(geDutyCycle());
|
||||||
|
lcd.print("%");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user