Make compile, finish button programming -- Still mid-refactor
This commit is contained in:
parent
fc8eb0773a
commit
59eeabc785
|
@ -11,11 +11,13 @@
|
||||||
#ifndef Project_h
|
#ifndef Project_h
|
||||||
#define Project_h
|
#define Project_h
|
||||||
|
|
||||||
|
#define DEBUG true // For controlling debug output via serial
|
||||||
|
|
||||||
// Pinout / things that need configuration
|
// Pinout / things that need configuration
|
||||||
#define okButtonPin 23
|
#define okButtonPin 22
|
||||||
#define okButtonLed 22
|
#define okButtonLed 23
|
||||||
#define cancelButtonPin 25
|
#define cancelButtonPin 24
|
||||||
#define cancelButtonLed 24
|
#define cancelButtonLed 25
|
||||||
#define pspXPin 0 // After GND / @ edge
|
#define pspXPin 0 // After GND / @ edge
|
||||||
#define pspYPin 1 // Between VCC and gnd
|
#define pspYPin 1 // Between VCC and gnd
|
||||||
// LCD Pinouts
|
// LCD Pinouts
|
||||||
|
@ -56,7 +58,7 @@ enum voltage {
|
||||||
onePointEight,
|
onePointEight,
|
||||||
threePointThree,
|
threePointThree,
|
||||||
five,
|
five,
|
||||||
zero=-1
|
negOne=-1
|
||||||
};
|
};
|
||||||
|
|
||||||
extern char* voltageToText[];
|
extern char* voltageToText[];
|
||||||
|
|
|
@ -8,17 +8,11 @@
|
||||||
attribute.
|
attribute.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
UI State machine (current element = config / stats / inline display of data)
|
// UI State machine (current element = config / stats / inline display of data)
|
||||||
Configuration state machine (speed, pinout, logic level, sd card on/off, boot logo on/off)
|
// Configuration state machine (speed, pinout, logic level, sd card on/off, boot logo on/off)
|
||||||
Message to config (element + new value)
|
// Message to config (element + new value)
|
||||||
Message to UI (element + success/fail)
|
// Message to UI (element + success/fail)
|
||||||
|
|
||||||
// Button's controlling UI
|
// Button's controlling UI
|
||||||
UIButton* okButton = new UIButton(22, 23);
|
// UIButton* okButton = new UIButton(22, 23);
|
||||||
UIButton* cancelButton = new UIButton(24, 25);
|
// UIButton* cancelButton = new UIButton(24, 25);
|
||||||
|
|
||||||
// Select / Enter
|
|
||||||
if (okButton->isPressed()) {
|
|
||||||
//FIXME: Re-enable once new LCD is online
|
|
||||||
//setMode(selectedMode);
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "UIButton.h"
|
#include "UIButton.h"
|
||||||
|
#include "Project.h"
|
||||||
|
|
||||||
UIButton::UIButton(int buttonPin, int ledPin) {
|
UIButton::UIButton(int buttonPin, int ledPin) {
|
||||||
this->buttonPin = buttonPin;
|
this->buttonPin = buttonPin;
|
||||||
this->ledPin = ledPin;
|
this->ledPin = ledPin;
|
||||||
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIButton::setup() {
|
void UIButton::setup() {
|
||||||
|
@ -24,13 +26,23 @@ void UIButton::setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIButton::turnOnLed() {
|
void UIButton::turnOnLed() {
|
||||||
|
if (DEBUG) {
|
||||||
|
Serial.print("Turning on pin: ");
|
||||||
|
Serial.println(ledPin);
|
||||||
|
}
|
||||||
digitalWrite(ledPin, HIGH);
|
digitalWrite(ledPin, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIButton::turnOffLed() {
|
void UIButton::turnOffLed() {
|
||||||
|
if (DEBUG) {
|
||||||
|
Serial.print("Turning off pin: ");
|
||||||
|
Serial.println(ledPin);
|
||||||
|
}
|
||||||
digitalWrite(ledPin, LOW);
|
digitalWrite(ledPin, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UIButton::isPressed() {
|
bool UIButton::isPressed() {
|
||||||
return digitalRead(buttonPin);
|
bool pressed = digitalRead(buttonPin);
|
||||||
|
while (digitalRead(buttonPin)); // Wait for release
|
||||||
|
return pressed;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,10 @@ class UIButton {
|
||||||
private:
|
private:
|
||||||
int buttonPin;
|
int buttonPin;
|
||||||
int ledPin;
|
int ledPin;
|
||||||
|
void setup();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UIButton(int buttonPin, int ledPin);
|
UIButton(int buttonPin, int ledPin);
|
||||||
void setup();
|
|
||||||
void turnOnLed();
|
void turnOnLed();
|
||||||
void turnOffLed();
|
void turnOffLed();
|
||||||
bool isPressed();
|
bool isPressed();
|
||||||
|
|
|
@ -9,43 +9,45 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// PSP joystick tracking
|
// PSP joystick tracking
|
||||||
long pspUpCount = 0; // Used to slow down how fast we repeat up movement
|
int pspUpCount = 0; // Used to slow down how fast we repeat up movement
|
||||||
long pspDownCount = 0; // Used to slow down how fast we repeat down movement
|
int pspDownCount = 0; // Used to slow down how fast we repeat down movement
|
||||||
int pspXAxisValue;
|
int pspXAxisValue;
|
||||||
int pspYAxisValue;
|
int pspYAxisValue;
|
||||||
|
|
||||||
// Read the x/y values from the joystick
|
// void readPSPValues() {
|
||||||
pspXAxisValue=map(analogRead(pspXPin), 0, 1023, 0, 10);
|
// // Read the x/y values from the joystick
|
||||||
pspYAxisValue=map(analogRead(pspYPin), 0, 1023, 0, 10);
|
// pspXAxisValue=map(analogRead(pspXPin), 0, 1023, 0, 10);
|
||||||
|
// pspYAxisValue=map(analogRead(pspYPin), 0, 1023, 0, 10);
|
||||||
|
|
||||||
// Move cursor Up
|
// // Move cursor Up
|
||||||
if (pspYAxisValue > 6 ) {
|
// if (pspYAxisValue > 6 ) {
|
||||||
pspUpCount++;
|
// pspUpCount++;
|
||||||
if (pspUpCount > 768) {
|
// if (pspUpCount > 768) {
|
||||||
pspUpCount = 0;
|
// pspUpCount = 0;
|
||||||
serialmode newMode = (serialmode)(selectedMode - 1);
|
// serialmode newMode = (serialmode)(selectedMode - 1);
|
||||||
if (newMode >= 0) {
|
// if (newMode >= 0) {
|
||||||
//FIXME: Re-enable once new LCD is online
|
// //FIXME: Re-enable once new LCD is online
|
||||||
//setSelection(newMode);
|
// //setSelection(newMode);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
pspUpCount = 0;
|
// pspUpCount = 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Move cursor Down
|
// // Move cursor Down
|
||||||
if (pspYAxisValue < 4 ) {
|
// if (pspYAxisValue < 4 ) {
|
||||||
pspDownCount++;
|
// pspDownCount++;
|
||||||
if (pspDownCount > 768) {
|
// if (pspDownCount > 768) {
|
||||||
serialmode newMode = (serialmode)(selectedMode + 1);
|
// serialmode newMode = (serialmode)(selectedMode + 1);
|
||||||
if (newMode <= modelinespeed) {
|
// if (newMode <= modelinespeed) {
|
||||||
//FIXME: Re-enable once new LCD is online
|
// //FIXME: Re-enable once new LCD is online
|
||||||
//setSelection(newMode);
|
// //setSelection(newMode);
|
||||||
}
|
// }
|
||||||
pspDownCount = 0;
|
// pspDownCount = 0;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
pspDownCount = 0;
|
// pspDownCount = 0;
|
||||||
}
|
// }
|
||||||
|
// }
|
|
@ -10,13 +10,8 @@
|
||||||
|
|
||||||
#include "Project.h"
|
#include "Project.h"
|
||||||
|
|
||||||
// Mode info needed
|
UIButton* okButton;
|
||||||
serialmode currentMode = none;
|
UIButton* cancelButton;
|
||||||
serialmode selectedMode = none;
|
|
||||||
linespeed currentLineSpeed = zero;
|
|
||||||
linespeed selectedLineSpeed = zero;
|
|
||||||
voltage currentVoltage = zero;
|
|
||||||
voltage selectedVoltage = zero;
|
|
||||||
|
|
||||||
// Defaults
|
// Defaults
|
||||||
void setDefaults() {
|
void setDefaults() {
|
||||||
|
@ -27,14 +22,22 @@ void setDefaults() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
Serial.println("Setup!");
|
||||||
|
|
||||||
// Setup defaults
|
// Setup defaults
|
||||||
setDefaults();
|
setDefaults();
|
||||||
|
|
||||||
Serial.begin(9600);
|
okButton = new UIButton(okButtonPin, okButtonLed);
|
||||||
Serial1.begin(9600);
|
cancelButton = new UIButton(cancelButtonPin, cancelButtonLed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
if (okButton->isPressed()) {
|
||||||
|
Serial.println("OK Button Pressed");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cancelButton->isPressed()) {
|
||||||
|
Serial.println("Cancel button pressed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue