forked from simeon-walker/opusdac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirlearn.cpp
114 lines (98 loc) · 3.63 KB
/
irlearn.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* LCDduino Controller for Twisted Pear Opus DAC and Mux
* Simeon Walker 2011-2013
*
* Derived from Volu-Master(tm) by Bryan Levin (Linux-Works Labs)
* Copyright (c) 2009-2011 Bryan Levin
* Project website: http://www.amb.org/audio/lcduino-1/
*
* LICENSE
* -------
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "irlearn.h"
#include "irremote.h"
#include "lcd1.h"
#include "util.h"
#include "opusdac_defs.h"
unsigned long ir_code_cache[IFC_MAX];
void learn_key (int idx , const char *str) {
boolean blink_toggle = true;
byte blink_count = 0;
byte skip_this_key = 0;
lcd.clear_line(LCD_LINE2);
lcd.send_string(str, LCD_LINE2); // prompt the user for which key to press
/* non-blocking poll for a keypress */
while (!skip_this_key) {
key = get_IR_key();
if (key != 0) {
skip_this_key = 0;
break; // exit this blink-loop when we found a key
}
//irrecv.resume(); // we just consumed one key; 'start' to receive the next value
if (blink_toggle) {
lcd.clear_line(LCD_LINE2);
delay(150);
} else {
++blink_count;
lcd.send_string(str, LCD_LINE2);
delay(300);
}
blink_toggle = !blink_toggle;
if (scan_front_button() == 1) { // Skip code if front button pressed
skip_this_key = 1;
lcd.clear_line(LCD_LINE2);
lcd.send_string("Key Skipped.", LCD_LINE2);
delay(1000);
break;
}
} // while...waiting for key
if (!skip_this_key) { // Got key so show code and save
lcd.send_string(str, LCD_LINE2);
lcd.send_string("Code: ", LCD_LINE2);
lcd_print_long_hex(key);
EEwrite_long(EEPROM_IR_LEARNED_BASE + (idx * sizeof(long)), key);
}
delay(1000); // debounce a little more
//irrecv.resume(); // we just consumed one key; 'start' to receive the next value
}
void cache_ir_codes (void) {
// Read IR codes for each function into RAM
for (int idx=0; idx <= IFC_MAX; idx++) {
ir_code_cache[idx] = EEread_long(EEPROM_IR_LEARNED_BASE + (idx * sizeof(long)));
}
}
// IR learn prompts
void ir_learn () {
lcd.clear();
lcd.send_string("Learning IR:", LCD_LINE1);
delay(2000);
learn_key(IFC_VOLUME_UP, "Volume Up");
learn_key(IFC_VOLUME_DOWN, "Volume Down");
learn_key(IFC_MUTE, "Mute");
learn_key(IFC_POWER_TOGGLE, "Power Toggle");
learn_key(IFC_POWER_ON, "Power On");
learn_key(IFC_POWER_OFF, "Power Off");
learn_key(IFC_NEXT_FILTER, "Next Filter");
learn_key(IFC_INPUT1, "Input 1");
learn_key(IFC_INPUT2, "Input 2");
learn_key(IFC_INPUT3, "Input 3");
learn_key(IFC_INPUT4, "Input 4");
learn_key(IFC_SET_CLOCK, "Set Clock");
learn_key(IFC_BACKLIGHT, "Backlight");
cache_ir_codes();
lcd.clear();
lcd.restore_backlight();
lcd.send_string("Completed.", LCD_LINE1);
}