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