refactoring

This commit is contained in:
Wolfgang Hottgenroth 2015-02-15 17:06:34 +01:00
parent ba64c92464
commit c757788aee
3 changed files with 52 additions and 30 deletions

View File

@ -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() {
Serial.begin(115200);
lcd.begin(LCD_COLS, LCD_ROWS);
lcd.print("Teensy SMPS");
Serial.println("Teensy SMPS");
pwmInit();
rotaryInit();
displayInit();
}
void loop() {
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("%");
}
displayLoop();
}

40
display.cpp Normal file
View 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("%");
}
}

10
display.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef DISPLAY_H_
#define DISPLAY_H_
void displayInit();
void displayExec();
#endif /* DISPLAY_H_ */