Skip to content

Instantly share code, notes, and snippets.

@amazingproducer
Last active January 8, 2018 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amazingproducer/7bb447f4d2ea2d4132712d9bbc51862d to your computer and use it in GitHub Desktop.
Save amazingproducer/7bb447f4d2ea2d4132712d9bbc51862d to your computer and use it in GitHub Desktop.
#include <Keypad.h>
#define KEY_POUND 0x21;
#define KEY_STAR 0x20;
#define OPCODE_SETFREQ 0x01;
#define MENU_SELECT 0;
#define FREQUENCY_INPUT 1;
#define TONE_INPUT 2;
#define OPCODE_SEND 3;
//TODO sort the decimal handling for MHz and Hz inputs
// decimal handling may prepend padding to buffers if the buffer's size is less than three
// decimal handling must fail if the buffer's size is more than three
// decimal handling for tones must fail if the buffer's size is less than two
void setup()
{
//Set up serial port, LED pin, and inactivity timer
//Can I set up the keypad in here too?
}
void menu_select(byte key)
{
if (key < 0x11)
{
input_state = FREQUENCY_INPUT;
//add key to buffer
frequency_input(key);
}
else
{
input_state = TONE_INPUT;
//add key to buffer
tone_input(key);
}
}
void frequency_input(byte key)
{
//if key is pound:
//opcode_send(frequency);
//if key is star:
//if star is in buffer:
//clear buffer
//input_state = MENU_SELECT;
//else
//add decimal
//if key is number:
//add key to buffer;
//if buffer is full;
//opcode_send(frequency);
}
void tone_input(byte key)
{
//if first input is # then tone flag is DECODER if first input is * then tone flag is ENCODER
//if buffer length is 1:
//if # is in buffer:
//TONE_FLAG = DECODE;
//if * is in buffer:
//TONE_FLAG = ENCODE;
//else: actually this neglects the possibility that the user may enter **
//TODO sort the doublestar problem
//if key is pound:
//opcode_send(tone);
//if key is star:
//if * is in buffer:
//clear buffer;
//input_state = MENU_SELECT;
//else
//add decimal
//else:
//add key to buffer;
//if buffer is full:
//opcode_send(tone);
}
void opcode_send() // should accept buffer; forms instruction from complete buffer and returns to start
{
//magically forms instruction
//magically sends instruction
//magically clears the buffers and unsets the tone flags
input_state = MENU_SELECT;
}
void loop()
{
if key()
{
//let's react to key input based on state:
switch (input_state)
{
case MENU_SELECT:
//Reset buffers and prepare for any key input
//do i call a function to process the key input, or do i process it here?
menu_select(key);
break;
case FREQUENCY_INPUT:
//Prepare for any key input
frequency_input(key);
break;
case TONE_INPUT:
//Maintain buffer; prepare for any key input
tone_input(key);
break;
case TONE_SET:
//user is attempting to enable or disable a tone feature
//TODO make Keypad function for TONE_SET hold-down events
tone_set(key);
case OPCODE_SEND:
//system is busy sending opcode.
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment