Skip to content
Snippets Groups Projects
Commit 529eb00b authored by Jan Grewe's avatar Jan Grewe
Browse files

add region switching via doubleclick

parent 99cc4fba
No related branches found
No related tags found
No related merge requests found
#include <Arduino.h>
#include <InterruptButton.h>
#include "config.h"
#include "main.h"
#include "button.h"
#include "utils.h"
#include "led.h"
......@@ -11,20 +12,38 @@ void handleShortButton()
{
if (!sendingEnabled)
{
logLine("Starting to send.");
logLine("Starting to send. (Region: "+ String(region)+")");
blink(1);
digitalWrite(PIN_LED, HIGH);
}
else
{
logLine("Restarting sending.");
blink(2);
blink(1);
digitalWrite(PIN_LED, HIGH);
cancelSending = true;
}
sendingEnabled = true;
}
void handleDoubleButton() {
digitalWrite(PIN_LED, LOW);
delay(500);
if (region == EU) {
region = NA;
blink(2);
} else {
region = EU;
blink(1);
}
logLine("Switching Region to: " + String(region));
if (sendingEnabled) {
digitalWrite(PIN_LED, HIGH);
}
cancelSending = true;
}
void handleLongButton()
{
if (sendingEnabled)
......@@ -40,5 +59,7 @@ void setupButton()
{
button.bind(Event_KeyPress, &handleShortButton);
button.bind(Event_LongKeyPress, &handleLongButton);
button.bind(Event_DoubleClick, &handleDoubleButton);
button.setLongPressInterval(1000);
button.setDoubleClickInterval(500);
}
extern bool sendingEnabled;
extern bool cancelSending;
extern uint8_t region;
void handleShortButton();
void handleLongButton();
......
......@@ -19,9 +19,9 @@ extern void callHandlers();
void xmitCodeElement(uint16_t ontime, uint16_t offtime, uint8_t PWM_code);
uint8_t read_bits(uint8_t count);
uint16_t rawData[300];
uint16_t ontime, offtime;
uint8_t i, num_codes;
uint8_t bitsleft_r = 0;
uint8_t bits_r = 0;
uint8_t code_ptr;
......@@ -53,10 +53,6 @@ uint8_t read_bits(uint8_t count)
return tmp;
}
uint16_t ontime, offtime;
uint8_t i, num_codes;
uint8_t region;
void delay_ten_us(uint16_t us)
{
uint8_t timer;
......@@ -74,26 +70,33 @@ void delay_ten_us(uint16_t us)
}
}
void sendAllCodes()
void sendAllCodes(uint8_t region)
{
region = EU;
if (region == EU)
{
num_codes = num_EUcodes;
}
else
{
num_codes = num_NAcodes;
}
// for every POWER code in our collection
for (i = 0; i < num_codes; i++)
{
// make sure all loop() handlers are still ran while sending
callHandlers();
// point to next POWER code, from the right database
if (region == NA)
if (region == EU)
{
powerCode = NApowerCodes[i];
powerCode = EUpowerCodes[i];
}
else
{
powerCode = EUpowerCodes[i];
powerCode = NApowerCodes[i];
}
// Read the carrier frequency from the first byte of code structure
......
......@@ -4,5 +4,5 @@
uint8_t read_bits(uint8_t count);
void delay_ten_us(uint16_t us);
void sendAllCodes();
void sendAllCodes(uint8_t region);
void setupIR();
......@@ -14,3 +14,8 @@ void blink(int count)
delay(200);
}
}
void setupLED() {
pinMode(PIN_LED, OUTPUT);
blink(1);
}
#include <Arduino.h>
void blink(int count);
void setupLED();
......@@ -11,6 +11,7 @@
bool sendingEnabled = false;
bool cancelSending = false;
uint8_t region = 0;
void setup()
{
......@@ -19,13 +20,14 @@ void setup()
setupWifi();
setupOTA();
setupTelnet();
setupLED();
setupButton();
setupIR();
logLine("");
logLine("Hool-B-Gone ready!");
logLine("");
blink(1);
logLine("Region: " + String(region));
}
void callHandlers()
......@@ -38,7 +40,7 @@ void loop()
{
if (sendingEnabled)
{
sendAllCodes();
sendAllCodes(region);
}
else
{
......
......@@ -10,8 +10,8 @@ By Anton Grimpelhuber (anton.grimpelhuber@gmail.com)
// NA is for North America, Asia, and the rest of the world not covered by EU
// Two regions!
#define NA 1 // set by a HIGH on REGIONSWITCH pin
#define EU 0 // set by a LOW on REGIONSWITCH pin
#define EU 0
#define NA 1
// Lets us calculate the size of the NA/EU databases
#define NUM_ELEM(x) (sizeof(x) / sizeof(*(x)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment