Make compile, finish button programming -- Still mid-refactor

This commit is contained in:
Mike C 2013-04-06 16:31:44 -04:00
parent fc8eb0773a
commit 59eeabc785
6 changed files with 77 additions and 64 deletions

View file

@ -11,11 +11,13 @@
#ifndef Project_h
#define Project_h
#define DEBUG true // For controlling debug output via serial
// Pinout / things that need configuration
#define okButtonPin 23
#define okButtonLed 22
#define cancelButtonPin 25
#define cancelButtonLed 24
#define okButtonPin 22
#define okButtonLed 23
#define cancelButtonPin 24
#define cancelButtonLed 25
#define pspXPin 0 // After GND / @ edge
#define pspYPin 1 // Between VCC and gnd
// LCD Pinouts
@ -56,7 +58,7 @@ enum voltage {
onePointEight,
threePointThree,
five,
zero=-1
negOne=-1
};
extern char* voltageToText[];

View file

@ -8,17 +8,11 @@
attribute.
*/
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)
Message to config (element + new value)
Message to UI (element + success/fail)
// 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)
// Message to config (element + new value)
// Message to UI (element + success/fail)
// Button's controlling UI
UIButton* okButton = new UIButton(22, 23);
UIButton* cancelButton = new UIButton(24, 25);
// Select / Enter
if (okButton->isPressed()) {
//FIXME: Re-enable once new LCD is online
//setMode(selectedMode);
}
// UIButton* okButton = new UIButton(22, 23);
// UIButton* cancelButton = new UIButton(24, 25);

View file

@ -10,10 +10,12 @@
#include "Arduino.h"
#include "UIButton.h"
#include "Project.h"
UIButton::UIButton(int buttonPin, int ledPin) {
this->buttonPin = buttonPin;
this->ledPin = ledPin;
setup();
}
void UIButton::setup() {
@ -24,13 +26,23 @@ void UIButton::setup() {
}
void UIButton::turnOnLed() {
if (DEBUG) {
Serial.print("Turning on pin: ");
Serial.println(ledPin);
}
digitalWrite(ledPin, HIGH);
}
void UIButton::turnOffLed() {
if (DEBUG) {
Serial.print("Turning off pin: ");
Serial.println(ledPin);
}
digitalWrite(ledPin, LOW);
}
bool UIButton::isPressed() {
return digitalRead(buttonPin);
bool pressed = digitalRead(buttonPin);
while (digitalRead(buttonPin)); // Wait for release
return pressed;
}

View file

@ -15,10 +15,10 @@ class UIButton {
private:
int buttonPin;
int ledPin;
void setup();
public:
UIButton(int buttonPin, int ledPin);
void setup();
void turnOnLed();
void turnOffLed();
bool isPressed();

View file

@ -9,43 +9,45 @@
*/
// PSP joystick tracking
long 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 pspUpCount = 0; // Used to slow down how fast we repeat up movement
int pspDownCount = 0; // Used to slow down how fast we repeat down movement
int pspXAxisValue;
int pspYAxisValue;
// Read the x/y values from the joystick
pspXAxisValue=map(analogRead(pspXPin), 0, 1023, 0, 10);
pspYAxisValue=map(analogRead(pspYPin), 0, 1023, 0, 10);
// void readPSPValues() {
// // Read the x/y values from the joystick
// pspXAxisValue=map(analogRead(pspXPin), 0, 1023, 0, 10);
// pspYAxisValue=map(analogRead(pspYPin), 0, 1023, 0, 10);
// Move cursor Up
if (pspYAxisValue > 6 ) {
pspUpCount++;
if (pspUpCount > 768) {
pspUpCount = 0;
serialmode newMode = (serialmode)(selectedMode - 1);
if (newMode >= 0) {
//FIXME: Re-enable once new LCD is online
//setSelection(newMode);
}
}
}
else {
pspUpCount = 0;
}
// // Move cursor Up
// if (pspYAxisValue > 6 ) {
// pspUpCount++;
// if (pspUpCount > 768) {
// pspUpCount = 0;
// serialmode newMode = (serialmode)(selectedMode - 1);
// if (newMode >= 0) {
// //FIXME: Re-enable once new LCD is online
// //setSelection(newMode);
// }
// }
// }
// else {
// pspUpCount = 0;
// }
// Move cursor Down
if (pspYAxisValue < 4 ) {
pspDownCount++;
if (pspDownCount > 768) {
serialmode newMode = (serialmode)(selectedMode + 1);
if (newMode <= modelinespeed) {
//FIXME: Re-enable once new LCD is online
//setSelection(newMode);
}
pspDownCount = 0;
}
}
else {
pspDownCount = 0;
}
// // Move cursor Down
// if (pspYAxisValue < 4 ) {
// pspDownCount++;
// if (pspDownCount > 768) {
// serialmode newMode = (serialmode)(selectedMode + 1);
// if (newMode <= modelinespeed) {
// //FIXME: Re-enable once new LCD is online
// //setSelection(newMode);
// }
// pspDownCount = 0;
// }
// }
// else {
// pspDownCount = 0;
// }
// }

View file

@ -10,13 +10,8 @@
#include "Project.h"
// Mode info needed
serialmode currentMode = none;
serialmode selectedMode = none;
linespeed currentLineSpeed = zero;
linespeed selectedLineSpeed = zero;
voltage currentVoltage = zero;
voltage selectedVoltage = zero;
UIButton* okButton;
UIButton* cancelButton;
// Defaults
void setDefaults() {
@ -27,14 +22,22 @@ void setDefaults() {
}
void setup() {
Serial.begin(9600);
Serial.println("Setup!");
// Setup defaults
setDefaults();
Serial.begin(9600);
Serial1.begin(9600);
okButton = new UIButton(okButtonPin, okButtonLed);
cancelButton = new UIButton(cancelButtonPin, cancelButtonLed);
}
void loop() {
if (okButton->isPressed()) {
Serial.println("OK Button Pressed");
}
if (cancelButton->isPressed()) {
Serial.println("Cancel button pressed");
}
}