Added comments.
This commit is contained in:
82
src/main.cpp
82
src/main.cpp
@ -32,6 +32,9 @@ int servoPosition = 0;
|
|||||||
// Timer setup
|
// Timer setup
|
||||||
auto timer = timer_create_default(); // create a timer with default settings
|
auto timer = timer_create_default(); // create a timer with default settings
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Shows the state of affairs to the serial interface.
|
||||||
|
*/
|
||||||
bool printSerialSetting(void *)
|
bool printSerialSetting(void *)
|
||||||
{
|
{
|
||||||
Serial.println("ACNH A button clicker, the debug interface.");
|
Serial.println("ACNH A button clicker, the debug interface.");
|
||||||
@ -62,6 +65,11 @@ bool printSerialSetting(void *)
|
|||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Shows the state of things to the LCD display.
|
||||||
|
** Top line is the setting (and buttons to adjust)
|
||||||
|
** Second line is the value.
|
||||||
|
*/
|
||||||
bool printLCDSettings(void *)
|
bool printLCDSettings(void *)
|
||||||
{
|
{
|
||||||
lcd.clear();
|
lcd.clear();
|
||||||
@ -100,6 +108,10 @@ bool printLCDSettings(void *)
|
|||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Actually press the button.
|
||||||
|
** TODO: Make this non-blockig.
|
||||||
|
*/
|
||||||
void doPulse()
|
void doPulse()
|
||||||
{
|
{
|
||||||
for (int i = 0; i <= iDeflection; i++)
|
for (int i = 0; i <= iDeflection; i++)
|
||||||
@ -115,6 +127,9 @@ void doPulse()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Setup activities..
|
||||||
|
*/
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
//set up the LCD's number of columns and rows:
|
//set up the LCD's number of columns and rows:
|
||||||
@ -137,52 +152,61 @@ void setup()
|
|||||||
timer.every(2500, printLCDSettings);
|
timer.every(2500, printLCDSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void parseInput(char c) {
|
/*
|
||||||
switch(c) {
|
** Handles keypresses from the keypad. Called from loop().
|
||||||
case '1':
|
*/
|
||||||
iDeflection++;
|
void parseInput(char c)
|
||||||
displayCycle = 0;
|
{
|
||||||
break;
|
switch (c)
|
||||||
case '4':
|
{
|
||||||
iDeflection--;
|
case '1':
|
||||||
displayCycle = 0;
|
iDeflection++;
|
||||||
break;
|
displayCycle = 0;
|
||||||
case '2':
|
break;
|
||||||
iSpeed++;
|
case '4':
|
||||||
displayCycle = 1;
|
iDeflection--;
|
||||||
break;
|
displayCycle = 0;
|
||||||
case '5':
|
break;
|
||||||
iSpeed--;
|
case '2':
|
||||||
displayCycle = 1;
|
iSpeed++;
|
||||||
break;
|
displayCycle = 1;
|
||||||
case '3':
|
break;
|
||||||
iDelay+=10;
|
case '5':
|
||||||
displayCycle = 2;
|
iSpeed--;
|
||||||
break;
|
displayCycle = 1;
|
||||||
case '6':
|
break;
|
||||||
iDelay-=10;
|
case '3':
|
||||||
displayCycle = 3;
|
iDelay += 10;
|
||||||
break;
|
displayCycle = 2;
|
||||||
|
break;
|
||||||
|
case '6':
|
||||||
|
iDelay -= 10;
|
||||||
|
displayCycle = 3;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
iDeflection = constrain(iDeflection,0,180);
|
// Make sure the values we've set are within sane limtes.
|
||||||
|
iDeflection = constrain(iDeflection, 0, 180);
|
||||||
iSpeed = constrain(iSpeed, 1, 1000);
|
iSpeed = constrain(iSpeed, 1, 1000);
|
||||||
iDelay = constrain(iDelay, 10, 10000);
|
iDelay = constrain(iDelay, 10, 10000);
|
||||||
|
|
||||||
|
// Update the LCD now. This is cheesed a bit by setting the displaycycle in the switch statement above. Sometimes this is a bit weird if the timer event triggers immediately after pressing a number on the keypad.
|
||||||
printLCDSettings(0);
|
printLCDSettings(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
// Tick the timer.
|
||||||
timer.tick();
|
timer.tick();
|
||||||
|
|
||||||
|
// Do keypad stuff.
|
||||||
char customKey = customKeypad.getKey();
|
char customKey = customKeypad.getKey();
|
||||||
|
|
||||||
if (customKey){
|
if (customKey)
|
||||||
|
{
|
||||||
Serial.print("Console received: ");
|
Serial.print("Console received: ");
|
||||||
Serial.println(customKey);
|
Serial.println(customKey);
|
||||||
parseInput(customKey);
|
parseInput(customKey);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user