An RC5 decoder and preamp controller. Written on the LPC11U24, Ported to LPC1114 and now 100% stable (January 2016)
Dependents: AppleRemoteController_copy_Production_Version AppleRemoteController_Reference_Only
main.cpp@4:d900d90588d0, 23 months ago (annotated)
- Committer:
- andrewcrussell
- Date:
- Mon Nov 07 10:42:42 2022 +0000
- Revision:
- 4:d900d90588d0
- Parent:
- 3:f0cd7c22ca94
- Child:
- 9:c9fb1f8e2ab8
Original version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewcrussell | 4:d900d90588d0 | 1 | /****************************** Apple TV Remote Decoder and Preamp Controller V1.0 *************************/ |
andrewcrussell | 4:d900d90588d0 | 2 | /* Andrew C. Russell (c) 2022 */ |
andrewcrussell | 4:d900d90588d0 | 3 | /* This decoder works by reading in the Apple TV Remote IR data stream from one of the serial port lines */ |
andrewcrussell | 0:83d4a20e7bc7 | 4 | /* and saving the incoming stream into an array called stream, after which it is decoded and */ |
andrewcrussell | 4:d900d90588d0 | 5 | /* the command executed. . */ |
andrewcrussell | 0:83d4a20e7bc7 | 6 | |
andrewcrussell | 0:83d4a20e7bc7 | 7 | /* The following audio preamplifier facilities are catered for:- */ |
andrewcrussell | 0:83d4a20e7bc7 | 8 | /* 1. Manual volume control adjustment via ALPS RK27 motorized potentiometer */ |
andrewcrussell | 0:83d4a20e7bc7 | 9 | /* 2. Input select via rotary encoder */ |
andrewcrussell | 4:d900d90588d0 | 10 | /* 3. Output mute via remote controller only */ |
andrewcrussell | 4:d900d90588d0 | 11 | /* 4. Power ON output to drive the /standby input of a system power supply */ |
andrewcrussell | 4:d900d90588d0 | 12 | /* 5.Trigger output to power up an amplifier or other system components */ |
andrewcrussell | 0:83d4a20e7bc7 | 13 | /* Facilities 1,2,3 and 5 are supported by an RC5 compliant remote control for preamplifiers */ |
andrewcrussell | 3:f0cd7c22ca94 | 14 | /* The controller pin definitions are set in Pindef1114.h file. */ |
andrewcrussell | 3:f0cd7c22ca94 | 15 | |
andrewcrussell | 3:f0cd7c22ca94 | 16 | |
andrewcrussell | 3:f0cd7c22ca94 | 17 | // UPDATE 26 July 2018: tone functionality removed. The associated pin (dp25) has been sequestrated |
andrewcrussell | 3:f0cd7c22ca94 | 18 | // for the standby output to drive a power amplifier. Pin 8 on J2 (Controller board) |
andrewcrussell | 0:83d4a20e7bc7 | 19 | |
andrewcrussell | 0:83d4a20e7bc7 | 20 | #include "mbed.h" |
andrewcrussell | 4:d900d90588d0 | 21 | //#include "rc5codes.h" // RC code definitions - in this case for Apple TV Remote |
andrewcrussell | 4:d900d90588d0 | 22 | #include "Pindef1114.h" // all microcontroller I/O pin assignments defined here |
andrewcrussell | 4:d900d90588d0 | 23 | |
andrewcrussell | 4:d900d90588d0 | 24 | /************************************* Apple TV Remote control codes ****************************/ |
andrewcrussell | 4:d900d90588d0 | 25 | #define STANDBY 378 // toggle power ON and OFF |
andrewcrussell | 4:d900d90588d0 | 26 | #define MUTE 442 // toggle output signal on and off |
andrewcrussell | 4:d900d90588d0 | 27 | #define VUP 464 |
andrewcrussell | 4:d900d90588d0 | 28 | #define VDOWN 432 |
andrewcrussell | 4:d900d90588d0 | 29 | #define SELECT_R 480 // rotates input through inputs - must depress and then release each time |
andrewcrussell | 4:d900d90588d0 | 30 | #define SELECT_L 272 // rotates input through inputs - must depress and then release each time |
andrewcrussell | 4:d900d90588d0 | 31 | #define PREAMP 479 // this is the system code identifying an Apple Remote |
andrewcrussell | 4:d900d90588d0 | 32 | |
andrewcrussell | 4:d900d90588d0 | 33 | |
andrewcrussell | 4:d900d90588d0 | 34 | |
andrewcrussell | 4:d900d90588d0 | 35 | /*******************************************************************************************/ |
andrewcrussell | 0:83d4a20e7bc7 | 36 | |
andrewcrussell | 0:83d4a20e7bc7 | 37 | #define TRUE 1 |
andrewcrussell | 0:83d4a20e7bc7 | 38 | #define FALSE 0 |
andrewcrussell | 0:83d4a20e7bc7 | 39 | #define HIGH 1 |
andrewcrussell | 0:83d4a20e7bc7 | 40 | #define LOW 0 |
andrewcrussell | 3:f0cd7c22ca94 | 41 | #define tick 280 // quarter bit time in us |
andrewcrussell | 3:f0cd7c22ca94 | 42 | #define tock 1120 // one bit time in us |
andrewcrussell | 3:f0cd7c22ca94 | 43 | #define VUP_timeout 45 // defines max number of R/C cycles before the vol ctrl mtr drive stops |
andrewcrussell | 3:f0cd7c22ca94 | 44 | #define VDWN_timeout 45 // as above but for volume decrease |
andrewcrussell | 3:f0cd7c22ca94 | 45 | // Needed to ensure the motor is not burnt out |
andrewcrussell | 3:f0cd7c22ca94 | 46 | #define DEBOUNCE 20 // this is the switch debounce time |
andrewcrussell | 0:83d4a20e7bc7 | 47 | |
andrewcrussell | 3:f0cd7c22ca94 | 48 | // PHONO_ 1 // these are the input assignments written out |
andrewcrussell | 3:f0cd7c22ca94 | 49 | // CD 2 // on select_out - see thePindef1114.h file for details |
andrewcrussell | 3:f0cd7c22ca94 | 50 | // TUN 4 |
andrewcrussell | 3:f0cd7c22ca94 | 51 | // MSERV 8 |
andrewcrussell | 3:f0cd7c22ca94 | 52 | // AUX 16 |
andrewcrussell | 3:f0cd7c22ca94 | 53 | // RECORDER 32 |
andrewcrussell | 0:83d4a20e7bc7 | 54 | |
andrewcrussell | 0:83d4a20e7bc7 | 55 | int startbit; |
andrewcrussell | 3:f0cd7c22ca94 | 56 | int toggle; // this is the 3rd bit position in the input stream and checks for |
andrewcrussell | 3:f0cd7c22ca94 | 57 | // subsequent button depresses from the r/control |
andrewcrussell | 2:674e2dd56e7d | 58 | int toggle1; // temorary storage in the volume UP and volume DOWN functions |
andrewcrussell | 4:d900d90588d0 | 59 | //int toggle2; // temprary storage of the PB in the mute function |
andrewcrussell | 4:d900d90588d0 | 60 | //int toggle3; // temp storage for the r/control tone in-out function |
andrewcrussell | 0:83d4a20e7bc7 | 61 | int standby; |
andrewcrussell | 3:f0cd7c22ca94 | 62 | int command = 0; |
andrewcrussell | 3:f0cd7c22ca94 | 63 | int vendor_id = 0; |
andrewcrussell | 3:f0cd7c22ca94 | 64 | int pair_command = 0; |
andrewcrussell | 3:f0cd7c22ca94 | 65 | int address = 0; |
andrewcrussell | 3:f0cd7c22ca94 | 66 | int stop_bit = 0; |
andrewcrussell | 0:83d4a20e7bc7 | 67 | |
andrewcrussell | 0:83d4a20e7bc7 | 68 | int FLAG1; // this is used in the remote control input processing |
andrewcrussell | 0:83d4a20e7bc7 | 69 | int FLAG2; // this is used in the select input processing |
andrewcrussell | 0:83d4a20e7bc7 | 70 | int FLAG3; // this is for the mute pushbutton |
andrewcrussell | 0:83d4a20e7bc7 | 71 | int FLAG4; // this is for the standby pushbutton |
andrewcrussell | 4:d900d90588d0 | 72 | //int FLAG5; // this is the recloop flag |
andrewcrussell | 0:83d4a20e7bc7 | 73 | int RCFLAG = FALSE; // used to determine if the select command came via R/C |
andrewcrussell | 3:f0cd7c22ca94 | 74 | int REPEATFLAG; // repaet command flag used for volume control |
andrewcrussell | 3:f0cd7c22ca94 | 75 | int FLAGVOLUP; |
andrewcrussell | 3:f0cd7c22ca94 | 76 | int FLAGVOLDWN; |
andrewcrussell | 4:d900d90588d0 | 77 | //int FLAG7 = FALSE; // this flag is set to TRUE if recloop is active |
andrewcrussell | 0:83d4a20e7bc7 | 78 | int standbyflag; // used to save the standby condition |
andrewcrussell | 3:f0cd7c22ca94 | 79 | int RECLOOP1 = 16; // this is the bus address 1 before the Recorder |
andrewcrussell | 4:d900d90588d0 | 80 | int RECLOOP2 = 32; // this is the bus address for the Recorder input - last input |
andrewcrussell | 3:f0cd7c22ca94 | 81 | // and is used in the recloop service routine |
andrewcrussell | 3:f0cd7c22ca94 | 82 | int muteflag = FALSE; // use to control mute and mute indicatoe independently |
andrewcrussell | 4:d900d90588d0 | 83 | int recloop_status = 0; // this is the initial value. This variable is used |
andrewcrussell | 3:f0cd7c22ca94 | 84 | // in the select_out routine to indicate when the |
andrewcrussell | 3:f0cd7c22ca94 | 85 | // input select should wrap around dependent upon |
andrewcrussell | 3:f0cd7c22ca94 | 86 | // whether the record loop has been activated. |
andrewcrussell | 0:83d4a20e7bc7 | 87 | int relay; |
andrewcrussell | 0:83d4a20e7bc7 | 88 | int key_press = 1; // keeps track of key presses |
andrewcrussell | 0:83d4a20e7bc7 | 89 | |
andrewcrussell | 0:83d4a20e7bc7 | 90 | // delcarations below are all for the input select proceses |
andrewcrussell | 0:83d4a20e7bc7 | 91 | int select = 0; |
andrewcrussell | 3:f0cd7c22ca94 | 92 | int select_save = 2; // we save the status of select drive here. Initial setting is for CD |
andrewcrussell | 3:f0cd7c22ca94 | 93 | int select_rot; // rotary encoder pulse counter |
andrewcrussell | 2:674e2dd56e7d | 94 | |
andrewcrussell | 0:83d4a20e7bc7 | 95 | // declare function prototypes here |
andrewcrussell | 3:f0cd7c22ca94 | 96 | void select_out (void); // writes selected input out to the select_drv bus |
andrewcrussell | 3:f0cd7c22ca94 | 97 | void select_isr(void); |
andrewcrussell | 3:f0cd7c22ca94 | 98 | void rc5isr(void); // RC5 ISR for remote control |
andrewcrussell | 0:83d4a20e7bc7 | 99 | void mute_isr(void); |
andrewcrussell | 3:f0cd7c22ca94 | 100 | void mute_sel(void); //mutes select relays for a few ms during select |
andrewcrussell | 4:d900d90588d0 | 101 | //void recloop_isr(void); |
andrewcrussell | 0:83d4a20e7bc7 | 102 | void standby_out(void); |
andrewcrussell | 0:83d4a20e7bc7 | 103 | |
andrewcrussell | 0:83d4a20e7bc7 | 104 | /****************************** volume increase ***********************************/ |
andrewcrussell | 0:83d4a20e7bc7 | 105 | void vol_up (void) |
andrewcrussell | 0:83d4a20e7bc7 | 106 | { |
andrewcrussell | 0:83d4a20e7bc7 | 107 | if ((standbyflag == TRUE) && (key_press < VUP_timeout)) { |
andrewcrussell | 0:83d4a20e7bc7 | 108 | |
andrewcrussell | 0:83d4a20e7bc7 | 109 | FWD1 = HIGH; |
andrewcrussell | 0:83d4a20e7bc7 | 110 | wait(.1); //drive the motors for a short while |
andrewcrussell | 0:83d4a20e7bc7 | 111 | FWD1 = LOW; |
andrewcrussell | 3:f0cd7c22ca94 | 112 | |
andrewcrussell | 3:f0cd7c22ca94 | 113 | } |
andrewcrussell | 3:f0cd7c22ca94 | 114 | if (toggle1 != toggle) { |
andrewcrussell | 3:f0cd7c22ca94 | 115 | key_press = 0; // user released the button, so reset counter |
andrewcrussell | 3:f0cd7c22ca94 | 116 | } else if (toggle1 == toggle) { |
andrewcrussell | 3:f0cd7c22ca94 | 117 | key_press++; // button remained depressed, so increment counter |
andrewcrussell | 3:f0cd7c22ca94 | 118 | } |
andrewcrussell | 3:f0cd7c22ca94 | 119 | toggle1 = toggle; |
andrewcrussell | 3:f0cd7c22ca94 | 120 | // wait_ms(1); |
andrewcrussell | 3:f0cd7c22ca94 | 121 | } |
andrewcrussell | 3:f0cd7c22ca94 | 122 | |
andrewcrussell | 3:f0cd7c22ca94 | 123 | /******************************* volume decrease **********************************/ |
andrewcrussell | 3:f0cd7c22ca94 | 124 | void vol_dwn (void) |
andrewcrussell | 3:f0cd7c22ca94 | 125 | { |
andrewcrussell | 3:f0cd7c22ca94 | 126 | if ((standbyflag == TRUE) && (key_press < VDWN_timeout)) { |
andrewcrussell | 3:f0cd7c22ca94 | 127 | |
andrewcrussell | 3:f0cd7c22ca94 | 128 | REV1 = HIGH; |
andrewcrussell | 3:f0cd7c22ca94 | 129 | wait(.1); //drive the motors for a short while |
andrewcrussell | 3:f0cd7c22ca94 | 130 | REV1 = LOW; |
andrewcrussell | 0:83d4a20e7bc7 | 131 | } |
andrewcrussell | 0:83d4a20e7bc7 | 132 | if (toggle1 != toggle) { |
andrewcrussell | 0:83d4a20e7bc7 | 133 | key_press = 0; // user released the button, so reset counter |
andrewcrussell | 0:83d4a20e7bc7 | 134 | } else if (toggle1 == toggle) { |
andrewcrussell | 0:83d4a20e7bc7 | 135 | key_press++; // button remained depressed, so increment counter |
andrewcrussell | 0:83d4a20e7bc7 | 136 | } |
andrewcrussell | 0:83d4a20e7bc7 | 137 | toggle1 = toggle; |
andrewcrussell | 0:83d4a20e7bc7 | 138 | wait_ms(1); |
andrewcrussell | 0:83d4a20e7bc7 | 139 | } |
andrewcrussell | 0:83d4a20e7bc7 | 140 | |
andrewcrussell | 0:83d4a20e7bc7 | 141 | /********************************** stdby_isr *************************************/ |
andrewcrussell | 2:674e2dd56e7d | 142 | void stdby_isr(void) |
andrewcrussell | 0:83d4a20e7bc7 | 143 | { |
andrewcrussell | 0:83d4a20e7bc7 | 144 | FLAG4 = TRUE; |
andrewcrussell | 0:83d4a20e7bc7 | 145 | } |
andrewcrussell | 0:83d4a20e7bc7 | 146 | |
andrewcrussell | 0:83d4a20e7bc7 | 147 | /*********************************** standby **************************************/ |
andrewcrussell | 0:83d4a20e7bc7 | 148 | /* this will require supporting hardware functionality to power down the */ |
andrewcrussell | 0:83d4a20e7bc7 | 149 | /* analog board, LED's etc. Best option here is to use regulators with a */ |
andrewcrussell | 3:f0cd7c22ca94 | 150 | /* shutdown option. for now, all the LED's are just turned off */ |
andrewcrussell | 3:f0cd7c22ca94 | 151 | /* and input relays and mute relayes disabled. */ |
andrewcrussell | 0:83d4a20e7bc7 | 152 | |
andrewcrussell | 0:83d4a20e7bc7 | 153 | void standby_out(void) // both p/button and R/C come in here |
andrewcrussell | 0:83d4a20e7bc7 | 154 | { |
andrewcrussell | 3:f0cd7c22ca94 | 155 | __disable_irq(); |
andrewcrussell | 3:f0cd7c22ca94 | 156 | stdby_int.fall(NULL); // on first power up cycle NO interrupts are accepted |
andrewcrussell | 3:f0cd7c22ca94 | 157 | wait_ms(DEBOUNCE); // a very simple debounce |
andrewcrussell | 0:83d4a20e7bc7 | 158 | do { // that waits for the depressed button to be released |
andrewcrussell | 3:f0cd7c22ca94 | 159 | continue; //(1); |
andrewcrussell | 3:f0cd7c22ca94 | 160 | } while (stdby != 1); |
andrewcrussell | 0:83d4a20e7bc7 | 161 | |
andrewcrussell | 3:f0cd7c22ca94 | 162 | if (standbyflag == TRUE) { // was ON so now turn it OFF |
andrewcrussell | 3:f0cd7c22ca94 | 163 | stby_pa = LOW; |
andrewcrussell | 3:f0cd7c22ca94 | 164 | wait_ms(500); // make sure the power amp is OFF |
andrewcrussell | 4:d900d90588d0 | 165 | // muteind = LOW; |
andrewcrussell | 3:f0cd7c22ca94 | 166 | wait_ms(1000); // make sure the power amp output goes OFF |
andrewcrussell | 3:f0cd7c22ca94 | 167 | muteout = LOW; // now mute the preamp |
andrewcrussell | 0:83d4a20e7bc7 | 168 | // turn off all interrupts except the standby and rc5int |
andrewcrussell | 0:83d4a20e7bc7 | 169 | select_int.fall(NULL); |
andrewcrussell | 4:d900d90588d0 | 170 | // mute_int.fall(NULL); |
andrewcrussell | 4:d900d90588d0 | 171 | // recloop_int.fall(NULL); |
andrewcrussell | 4:d900d90588d0 | 172 | // recloop_out = LOW; // make sure the recloop is OFF [its active HIGH] |
andrewcrussell | 4:d900d90588d0 | 173 | // recloop_status = RECLOOP2; // reset the select so on subsequent power up it does |
andrewcrussell | 3:f0cd7c22ca94 | 174 | //not skip recorder input |
andrewcrussell | 3:f0cd7c22ca94 | 175 | select_save = select_drv; // save the status of select_drv |
andrewcrussell | 3:f0cd7c22ca94 | 176 | wait(.2); |
andrewcrussell | 3:f0cd7c22ca94 | 177 | select_drv = 0; // all input select relays are OFF |
andrewcrussell | 3:f0cd7c22ca94 | 178 | wait(3); |
andrewcrussell | 3:f0cd7c22ca94 | 179 | standbyflag = FALSE; |
andrewcrussell | 4:d900d90588d0 | 180 | // muteind = HIGH; |
andrewcrussell | 3:f0cd7c22ca94 | 181 | } |
andrewcrussell | 0:83d4a20e7bc7 | 182 | |
andrewcrussell | 2:674e2dd56e7d | 183 | |
andrewcrussell | 3:f0cd7c22ca94 | 184 | else if (standbyflag == FALSE) {// was OFF so we will turn it ON |
andrewcrussell | 2:674e2dd56e7d | 185 | |
andrewcrussell | 4:d900d90588d0 | 186 | muteLED = LOW; // turn the mute indicator ON |
andrewcrussell | 3:f0cd7c22ca94 | 187 | rc5int.rise(&rc5isr); // trigger int on rising edge - go service it at rc5dat |
andrewcrussell | 0:83d4a20e7bc7 | 188 | select_int.fall(&select_isr); // input from rotary encoder or input select |
andrewcrussell | 4:d900d90588d0 | 189 | // mute_int.fall(&mute_isr); |
andrewcrussell | 4:d900d90588d0 | 190 | // recloop_int.fall(&recloop_isr); |
andrewcrussell | 3:f0cd7c22ca94 | 191 | // tone_pb.fall(tone_isr); |
andrewcrussell | 4:d900d90588d0 | 192 | // recloop_out = LOW; // make sure the recloop is OFF [its active HIGH] |
andrewcrussell | 3:f0cd7c22ca94 | 193 | wait_ms(100); |
andrewcrussell | 3:f0cd7c22ca94 | 194 | select_drv = select_save; // recall the input select setting and write to output |
andrewcrussell | 3:f0cd7c22ca94 | 195 | wait(2); // let things settle a bit |
andrewcrussell | 3:f0cd7c22ca94 | 196 | muteout = HIGH; // enable output |
andrewcrussell | 3:f0cd7c22ca94 | 197 | muteflag = TRUE; |
andrewcrussell | 4:d900d90588d0 | 198 | muteLED = HIGH; // turn the mute indicator OFF |
andrewcrussell | 0:83d4a20e7bc7 | 199 | standbyflag = TRUE; |
andrewcrussell | 3:f0cd7c22ca94 | 200 | stby_pa = HIGH; // now power up the amplifier |
andrewcrussell | 0:83d4a20e7bc7 | 201 | } |
andrewcrussell | 3:f0cd7c22ca94 | 202 | wait_ms(500); // let things settle a bit |
andrewcrussell | 3:f0cd7c22ca94 | 203 | __enable_irq(); |
andrewcrussell | 3:f0cd7c22ca94 | 204 | stdby_int.fall(&stdby_isr); // re-enable the standby interrupt |
andrewcrussell | 3:f0cd7c22ca94 | 205 | |
andrewcrussell | 0:83d4a20e7bc7 | 206 | } |
andrewcrussell | 0:83d4a20e7bc7 | 207 | |
andrewcrussell | 0:83d4a20e7bc7 | 208 | /********************************** record loop isr *******************************/ |
andrewcrussell | 0:83d4a20e7bc7 | 209 | |
andrewcrussell | 4:d900d90588d0 | 210 | //void recloop_isr(void) |
andrewcrussell | 4:d900d90588d0 | 211 | //{ |
andrewcrussell | 4:d900d90588d0 | 212 | // FLAG5 = TRUE; |
andrewcrussell | 4:d900d90588d0 | 213 | //} |
andrewcrussell | 3:f0cd7c22ca94 | 214 | /********************************** recloop ***********************************/ |
andrewcrussell | 4:d900d90588d0 | 215 | //void recloop() |
andrewcrussell | 4:d900d90588d0 | 216 | //{ |
andrewcrussell | 4:d900d90588d0 | 217 | // |
andrewcrussell | 4:d900d90588d0 | 218 | // if (select_drv != RECLOOP2) { // if its anything other than recloop we can activate the recloop relay |
andrewcrussell | 4:d900d90588d0 | 219 | // recloop_int.fall(NULL); // to prevent re-entrance when coming here from the R/C |
andrewcrussell | 4:d900d90588d0 | 220 | // wait_ms(DEBOUNCE); // simple debounce for when mute is via the f/p p/b switch |
andrewcrussell | 4:d900d90588d0 | 221 | // |
andrewcrussell | 4:d900d90588d0 | 222 | // do { |
andrewcrussell | 4:d900d90588d0 | 223 | // continue; // wait here until the button is released |
andrewcrussell | 4:d900d90588d0 | 224 | // } while (recloop_in != 1); |
andrewcrussell | 4:d900d90588d0 | 225 | // |
andrewcrussell | 4:d900d90588d0 | 226 | // if (recloop_rly == HIGH) { // the recloop relay was activated |
andrewcrussell | 4:d900d90588d0 | 227 | // recloop_rly = LOW; // so turn it off |
andrewcrussell | 4:d900d90588d0 | 228 | // recloop_out = LOW; |
andrewcrussell | 4:d900d90588d0 | 229 | // FLAG7 = 0; |
andrewcrussell | 4:d900d90588d0 | 230 | // } |
andrewcrussell | 4:d900d90588d0 | 231 | // |
andrewcrussell | 4:d900d90588d0 | 232 | // else if (recloop_rly == LOW) { // it was OFF so activate it |
andrewcrussell | 4:d900d90588d0 | 233 | // recloop_rly = HIGH; |
andrewcrussell | 4:d900d90588d0 | 234 | // recloop_out = HIGH; |
andrewcrussell | 4:d900d90588d0 | 235 | // FLAG7 = 32; |
andrewcrussell | 4:d900d90588d0 | 236 | // } |
andrewcrussell | 4:d900d90588d0 | 237 | // |
andrewcrussell | 4:d900d90588d0 | 238 | // wait_ms(DEBOUNCE); |
andrewcrussell | 4:d900d90588d0 | 239 | // |
andrewcrussell | 4:d900d90588d0 | 240 | // } |
andrewcrussell | 4:d900d90588d0 | 241 | // |
andrewcrussell | 4:d900d90588d0 | 242 | // recloop_int.fall(&recloop_isr); |
andrewcrussell | 4:d900d90588d0 | 243 | // |
andrewcrussell | 4:d900d90588d0 | 244 | //} |
andrewcrussell | 0:83d4a20e7bc7 | 245 | /************************************ mute_isr ************************************/ |
andrewcrussell | 0:83d4a20e7bc7 | 246 | |
andrewcrussell | 4:d900d90588d0 | 247 | //void mute_isr(void) |
andrewcrussell | 4:d900d90588d0 | 248 | //{ |
andrewcrussell | 4:d900d90588d0 | 249 | // FLAG3 = TRUE; |
andrewcrussell | 4:d900d90588d0 | 250 | // toggle2 = !toggle2; // so the p/button input is recognized in mute_out() |
andrewcrussell | 3:f0cd7c22ca94 | 251 | |
andrewcrussell | 4:d900d90588d0 | 252 | //} |
andrewcrussell | 3:f0cd7c22ca94 | 253 | /************************************** mute ************************************/ |
andrewcrussell | 0:83d4a20e7bc7 | 254 | void mute_out() |
andrewcrussell | 0:83d4a20e7bc7 | 255 | { |
andrewcrussell | 4:d900d90588d0 | 256 | muteout = !muteout; |
andrewcrussell | 0:83d4a20e7bc7 | 257 | |
andrewcrussell | 4:d900d90588d0 | 258 | if (muteout == HIGH) { |
andrewcrussell | 4:d900d90588d0 | 259 | muteLED = LOW; |
andrewcrussell | 4:d900d90588d0 | 260 | } |
andrewcrussell | 4:d900d90588d0 | 261 | |
andrewcrussell | 4:d900d90588d0 | 262 | else if (muteout == LOW) { |
andrewcrussell | 4:d900d90588d0 | 263 | muteLED = HIGH; |
andrewcrussell | 0:83d4a20e7bc7 | 264 | } |
andrewcrussell | 3:f0cd7c22ca94 | 265 | |
andrewcrussell | 4:d900d90588d0 | 266 | wait_ms(100); |
andrewcrussell | 0:83d4a20e7bc7 | 267 | } |
andrewcrussell | 0:83d4a20e7bc7 | 268 | |
andrewcrussell | 4:d900d90588d0 | 269 | |
andrewcrussell | 4:d900d90588d0 | 270 | |
andrewcrussell | 4:d900d90588d0 | 271 | // mute_int.fall(NULL); // to prevent re-entance when coming here from the R/C |
andrewcrussell | 4:d900d90588d0 | 272 | // wait_ms(DEBOUNCE); //simple debounce for when mute is via the f/p p/b switch |
andrewcrussell | 4:d900d90588d0 | 273 | // do { |
andrewcrussell | 4:d900d90588d0 | 274 | // continue; //wait here until the button is released |
andrewcrussell | 4:d900d90588d0 | 275 | // } while (mute != 1); |
andrewcrussell | 4:d900d90588d0 | 276 | // |
andrewcrussell | 4:d900d90588d0 | 277 | // if (muteflag == FALSE) { // mute was inactive so it will now get activated |
andrewcrussell | 4:d900d90588d0 | 278 | // muteout = TRUE; |
andrewcrussell | 4:d900d90588d0 | 279 | // muteind = HIGH; |
andrewcrussell | 4:d900d90588d0 | 280 | // muteflag = TRUE; // indicate its been activated |
andrewcrussell | 4:d900d90588d0 | 281 | // } |
andrewcrussell | 4:d900d90588d0 | 282 | // |
andrewcrussell | 4:d900d90588d0 | 283 | // else if (muteflag == TRUE) { //it was active, so it must be deactivated here |
andrewcrussell | 4:d900d90588d0 | 284 | // muteout = FALSE; |
andrewcrussell | 4:d900d90588d0 | 285 | // muteind = LOW; |
andrewcrussell | 4:d900d90588d0 | 286 | // muteflag = FALSE; |
andrewcrussell | 4:d900d90588d0 | 287 | // } |
andrewcrussell | 4:d900d90588d0 | 288 | // |
andrewcrussell | 4:d900d90588d0 | 289 | // wait_ms(800); // make sure relay state is settled |
andrewcrussell | 4:d900d90588d0 | 290 | // |
andrewcrussell | 4:d900d90588d0 | 291 | // mute_int.fall(&mute_isr); |
andrewcrussell | 4:d900d90588d0 | 292 | //} |
andrewcrussell | 4:d900d90588d0 | 293 | // |
andrewcrussell | 0:83d4a20e7bc7 | 294 | /************************************ rc5isr **************************************/ |
andrewcrussell | 4:d900d90588d0 | 295 | /* Interrupt triggered by a rising edge on p18 which is R/C data in */ |
andrewcrussell | 0:83d4a20e7bc7 | 296 | |
andrewcrussell | 0:83d4a20e7bc7 | 297 | void rc5isr(void) |
andrewcrussell | 0:83d4a20e7bc7 | 298 | { |
andrewcrussell | 0:83d4a20e7bc7 | 299 | FLAG1 = TRUE; |
andrewcrussell | 3:f0cd7c22ca94 | 300 | RCFLAG = TRUE; |
andrewcrussell | 3:f0cd7c22ca94 | 301 | REPEATFLAG = TRUE; |
andrewcrussell | 0:83d4a20e7bc7 | 302 | } |
andrewcrussell | 3:f0cd7c22ca94 | 303 | |
andrewcrussell | 3:f0cd7c22ca94 | 304 | /******************* save bit stream from remote controller ***********************/ |
andrewcrussell | 3:f0cd7c22ca94 | 305 | /* This function reads the input data on pin rc5dat at 1120us ('tock')intervals */ |
andrewcrussell | 0:83d4a20e7bc7 | 306 | /* and saves the data into an array stream[i]. */ |
andrewcrussell | 0:83d4a20e7bc7 | 307 | |
andrewcrussell | 4:d900d90588d0 | 308 | void save_stream(void) { |
andrewcrussell | 4:d900d90588d0 | 309 | |
andrewcrussell | 3:f0cd7c22ca94 | 310 | if (RCFLAG == TRUE) { |
andrewcrussell | 4:d900d90588d0 | 311 | wait_us(13500); // this is the IR AGC header - wait until passed |
andrewcrussell | 4:d900d90588d0 | 312 | //} |
andrewcrussell | 3:f0cd7c22ca94 | 313 | |
andrewcrussell | 4:d900d90588d0 | 314 | bool stream[63];// the array is initialized each time it is used and is local only |
andrewcrussell | 4:d900d90588d0 | 315 | int bitloop = 0; // number of bit positions - local |
andrewcrussell | 0:83d4a20e7bc7 | 316 | int i = 0; // counter |
andrewcrussell | 0:83d4a20e7bc7 | 317 | int k = 0; // temp storage |
andrewcrussell | 3:f0cd7c22ca94 | 318 | vendor_id = 0; |
andrewcrussell | 3:f0cd7c22ca94 | 319 | pair_command = 0; |
andrewcrussell | 0:83d4a20e7bc7 | 320 | address = 0; |
andrewcrussell | 0:83d4a20e7bc7 | 321 | command = 0; |
andrewcrussell | 3:f0cd7c22ca94 | 322 | stop_bit = 0; //must always return a 1 to be valid, so reset it |
andrewcrussell | 3:f0cd7c22ca94 | 323 | wait_us(tick); // locate read point in middle of 1st half bit time of the 1st start bit |
andrewcrussell | 3:f0cd7c22ca94 | 324 | |
andrewcrussell | 4:d900d90588d0 | 325 | for (bitloop = 0; bitloop <64; bitloop ++) { |
andrewcrussell | 3:f0cd7c22ca94 | 326 | |
andrewcrussell | 0:83d4a20e7bc7 | 327 | stream[bitloop] = rc5dat; //read the data and save it to array position [i] |
andrewcrussell | 4:d900d90588d0 | 328 | // bitstreamsync = !bitstreamsync; // the recovered IR bitstream is output on p14 for debug |
andrewcrussell | 3:f0cd7c22ca94 | 329 | if (rc5dat == HIGH) { |
andrewcrussell | 4:d900d90588d0 | 330 | wait_us(tock); // wait for start of next bit time |
andrewcrussell | 3:f0cd7c22ca94 | 331 | } |
andrewcrussell | 4:d900d90588d0 | 332 | |
andrewcrussell | 4:d900d90588d0 | 333 | wait_us(tock); //wait here until ready to read the next bit in |
andrewcrussell | 4:d900d90588d0 | 334 | |
andrewcrussell | 4:d900d90588d0 | 335 | } // now have 32 bits loaded into stream[i] |
andrewcrussell | 3:f0cd7c22ca94 | 336 | |
andrewcrussell | 0:83d4a20e7bc7 | 337 | /* now put data in the array into the start, toggle, address and command variables - array counts from stream[0] */ |
andrewcrussell | 0:83d4a20e7bc7 | 338 | |
andrewcrussell | 4:d900d90588d0 | 339 | for (i=0; i<11; i++) { // first 11 bit positions are vendor ID |
andrewcrussell | 3:f0cd7c22ca94 | 340 | |
andrewcrussell | 3:f0cd7c22ca94 | 341 | k = stream[i]; // k will hold the vendor ID |
andrewcrussell | 3:f0cd7c22ca94 | 342 | vendor_id = (vendor_id << 1); |
andrewcrussell | 3:f0cd7c22ca94 | 343 | vendor_id = vendor_id|k; |
andrewcrussell | 3:f0cd7c22ca94 | 344 | |
andrewcrussell | 0:83d4a20e7bc7 | 345 | } |
andrewcrussell | 0:83d4a20e7bc7 | 346 | |
andrewcrussell | 3:f0cd7c22ca94 | 347 | for (i = 11; i <16; i++) { // command or pair |
andrewcrussell | 3:f0cd7c22ca94 | 348 | k = stream[i]; |
andrewcrussell | 3:f0cd7c22ca94 | 349 | pair_command = (pair_command << 1); |
andrewcrussell | 3:f0cd7c22ca94 | 350 | pair_command = pair_command|k; |
andrewcrussell | 3:f0cd7c22ca94 | 351 | } |
andrewcrussell | 0:83d4a20e7bc7 | 352 | |
andrewcrussell | 3:f0cd7c22ca94 | 353 | for (i = 16; i <25; i++) { // device pairing address |
andrewcrussell | 0:83d4a20e7bc7 | 354 | k = stream[i]; |
andrewcrussell | 0:83d4a20e7bc7 | 355 | address = (address << 1); |
andrewcrussell | 0:83d4a20e7bc7 | 356 | address = address|k; |
andrewcrussell | 0:83d4a20e7bc7 | 357 | } |
andrewcrussell | 0:83d4a20e7bc7 | 358 | |
andrewcrussell | 3:f0cd7c22ca94 | 359 | |
andrewcrussell | 3:f0cd7c22ca94 | 360 | for (i = 25; i <31; i++) { // bit positions 25 to 30 are the command - 7 bit positions |
andrewcrussell | 0:83d4a20e7bc7 | 361 | k = stream[i]; |
andrewcrussell | 0:83d4a20e7bc7 | 362 | command = (command << 1); |
andrewcrussell | 0:83d4a20e7bc7 | 363 | command = command|k; |
andrewcrussell | 4:d900d90588d0 | 364 | printf("\n here \r "); |
andrewcrussell | 0:83d4a20e7bc7 | 365 | } |
andrewcrussell | 4:d900d90588d0 | 366 | |
andrewcrussell | 3:f0cd7c22ca94 | 367 | stop_bit = stream[31]; |
andrewcrussell | 0:83d4a20e7bc7 | 368 | |
andrewcrussell | 3:f0cd7c22ca94 | 369 | printf("\n vendor_id = %d pair_command = %d address = %d command = %d stop_bit = %d \r", vendor_id, pair_command, address, command, stop_bit); |
andrewcrussell | 0:83d4a20e7bc7 | 370 | } |
andrewcrussell | 3:f0cd7c22ca94 | 371 | |
andrewcrussell | 4:d900d90588d0 | 372 | } |
andrewcrussell | 4:d900d90588d0 | 373 | |
andrewcrussell | 0:83d4a20e7bc7 | 374 | /********************************* process_stream() *******************************/ |
andrewcrussell | 0:83d4a20e7bc7 | 375 | /* handles commands coming in from the remote controller only */ |
andrewcrussell | 0:83d4a20e7bc7 | 376 | |
andrewcrussell | 0:83d4a20e7bc7 | 377 | void process_stream (void) |
andrewcrussell | 0:83d4a20e7bc7 | 378 | { |
andrewcrussell | 3:f0cd7c22ca94 | 379 | if ((RCFLAG == TRUE) && ((vendor_id == 479) || (vendor_id == 2047))) { |
andrewcrussell | 0:83d4a20e7bc7 | 380 | // basic error checking - must be preamp + startbit ok to get executed otherwise skip completly |
andrewcrussell | 3:f0cd7c22ca94 | 381 | switch (address) { |
andrewcrussell | 0:83d4a20e7bc7 | 382 | |
andrewcrussell | 0:83d4a20e7bc7 | 383 | case VUP: |
andrewcrussell | 0:83d4a20e7bc7 | 384 | vol_up(); |
andrewcrussell | 3:f0cd7c22ca94 | 385 | FLAGVOLUP = TRUE; |
andrewcrussell | 0:83d4a20e7bc7 | 386 | break; |
andrewcrussell | 0:83d4a20e7bc7 | 387 | |
andrewcrussell | 0:83d4a20e7bc7 | 388 | case VDOWN: |
andrewcrussell | 0:83d4a20e7bc7 | 389 | vol_dwn(); |
andrewcrussell | 3:f0cd7c22ca94 | 390 | FLAGVOLDWN = TRUE; |
andrewcrussell | 0:83d4a20e7bc7 | 391 | break; |
andrewcrussell | 0:83d4a20e7bc7 | 392 | |
andrewcrussell | 0:83d4a20e7bc7 | 393 | case MUTE: |
andrewcrussell | 0:83d4a20e7bc7 | 394 | mute_out(); |
andrewcrussell | 0:83d4a20e7bc7 | 395 | break; |
andrewcrussell | 0:83d4a20e7bc7 | 396 | |
andrewcrussell | 0:83d4a20e7bc7 | 397 | case SELECT_R: |
andrewcrussell | 0:83d4a20e7bc7 | 398 | select_out(); |
andrewcrussell | 0:83d4a20e7bc7 | 399 | break; |
andrewcrussell | 0:83d4a20e7bc7 | 400 | |
andrewcrussell | 3:f0cd7c22ca94 | 401 | case SELECT_L: |
andrewcrussell | 3:f0cd7c22ca94 | 402 | select_out(); |
andrewcrussell | 3:f0cd7c22ca94 | 403 | break; |
andrewcrussell | 3:f0cd7c22ca94 | 404 | |
andrewcrussell | 0:83d4a20e7bc7 | 405 | case STANDBY: |
andrewcrussell | 0:83d4a20e7bc7 | 406 | standby_out(); |
andrewcrussell | 0:83d4a20e7bc7 | 407 | break; |
andrewcrussell | 3:f0cd7c22ca94 | 408 | |
andrewcrussell | 0:83d4a20e7bc7 | 409 | } |
andrewcrussell | 3:f0cd7c22ca94 | 410 | |
andrewcrussell | 3:f0cd7c22ca94 | 411 | if ((FLAGVOLUP == TRUE) && (vendor_id == 2047)) { |
andrewcrussell | 3:f0cd7c22ca94 | 412 | vol_up(); |
andrewcrussell | 3:f0cd7c22ca94 | 413 | } |
andrewcrussell | 3:f0cd7c22ca94 | 414 | |
andrewcrussell | 3:f0cd7c22ca94 | 415 | if ((FLAGVOLDWN == TRUE) && (vendor_id ==2047)) { |
andrewcrussell | 3:f0cd7c22ca94 | 416 | vol_dwn(); |
andrewcrussell | 3:f0cd7c22ca94 | 417 | } |
andrewcrussell | 3:f0cd7c22ca94 | 418 | |
andrewcrussell | 0:83d4a20e7bc7 | 419 | } |
andrewcrussell | 3:f0cd7c22ca94 | 420 | RCFLAG = FALSE; |
andrewcrussell | 3:f0cd7c22ca94 | 421 | |
andrewcrussell | 0:83d4a20e7bc7 | 422 | } |
andrewcrussell | 0:83d4a20e7bc7 | 423 | /*********************************** select_isr ***********************************/ |
andrewcrussell | 0:83d4a20e7bc7 | 424 | |
andrewcrussell | 0:83d4a20e7bc7 | 425 | void select_isr(void) |
andrewcrussell | 0:83d4a20e7bc7 | 426 | { |
andrewcrussell | 0:83d4a20e7bc7 | 427 | FLAG2 = TRUE; |
andrewcrussell | 0:83d4a20e7bc7 | 428 | } |
andrewcrussell | 0:83d4a20e7bc7 | 429 | |
andrewcrussell | 3:f0cd7c22ca94 | 430 | /****************************** mute inter select*********************************/ |
andrewcrussell | 3:f0cd7c22ca94 | 431 | |
andrewcrussell | 4:d900d90588d0 | 432 | //void mute_sel(void) |
andrewcrussell | 4:d900d90588d0 | 433 | //{ |
andrewcrussell | 4:d900d90588d0 | 434 | // select_drv = 0; |
andrewcrussell | 4:d900d90588d0 | 435 | // wait_ms(2); |
andrewcrussell | 4:d900d90588d0 | 436 | //} |
andrewcrussell | 3:f0cd7c22ca94 | 437 | |
andrewcrussell | 0:83d4a20e7bc7 | 438 | /********************************* select_process *********************************/ |
andrewcrussell | 3:f0cd7c22ca94 | 439 | /* Used for selecting the input source. This function is used by the */ |
andrewcrussell | 3:f0cd7c22ca94 | 440 | /* rotary encoder only */ |
andrewcrussell | 0:83d4a20e7bc7 | 441 | |
andrewcrussell | 0:83d4a20e7bc7 | 442 | void select_process(void) |
andrewcrussell | 0:83d4a20e7bc7 | 443 | { |
andrewcrussell | 3:f0cd7c22ca94 | 444 | |
andrewcrussell | 3:f0cd7c22ca94 | 445 | if (RCFLAG == FALSE) { // if used R/C skip completely - extra safety check |
andrewcrussell | 3:f0cd7c22ca94 | 446 | wait_ms(5); // debounce - very short for the rotary encoder |
andrewcrussell | 0:83d4a20e7bc7 | 447 | select = 0; // flush select |
andrewcrussell | 0:83d4a20e7bc7 | 448 | |
andrewcrussell | 0:83d4a20e7bc7 | 449 | select = (select | sela) <<1; // read the two port lines associated with the select rotary encoder |
andrewcrussell | 0:83d4a20e7bc7 | 450 | select = (select | selb); |
andrewcrussell | 3:f0cd7c22ca94 | 451 | |
andrewcrussell | 3:f0cd7c22ca94 | 452 | |
andrewcrussell | 3:f0cd7c22ca94 | 453 | switch (select) { |
andrewcrussell | 3:f0cd7c22ca94 | 454 | case 1: // select encoder is being rotated CW so increment select_rot |
andrewcrussell | 3:f0cd7c22ca94 | 455 | select_rot <<= 1; |
andrewcrussell | 3:f0cd7c22ca94 | 456 | if (select_rot > recloop_status ) { |
andrewcrussell | 3:f0cd7c22ca94 | 457 | select_rot = 1; // wrap around to 1 |
andrewcrussell | 3:f0cd7c22ca94 | 458 | } |
andrewcrussell | 3:f0cd7c22ca94 | 459 | |
andrewcrussell | 3:f0cd7c22ca94 | 460 | break; |
andrewcrussell | 3:f0cd7c22ca94 | 461 | |
andrewcrussell | 3:f0cd7c22ca94 | 462 | case 0: |
andrewcrussell | 3:f0cd7c22ca94 | 463 | select_rot >>= 1; // encoder is being rotated CCW so decrement select_rot |
andrewcrussell | 3:f0cd7c22ca94 | 464 | if (select_rot < 1) { |
andrewcrussell | 3:f0cd7c22ca94 | 465 | select_rot = recloop_status; //wrap around to 32 |
andrewcrussell | 3:f0cd7c22ca94 | 466 | } |
andrewcrussell | 3:f0cd7c22ca94 | 467 | |
andrewcrussell | 3:f0cd7c22ca94 | 468 | break; |
andrewcrussell | 3:f0cd7c22ca94 | 469 | |
andrewcrussell | 3:f0cd7c22ca94 | 470 | case 2: |
andrewcrussell | 3:f0cd7c22ca94 | 471 | break; // indeterminate fall through values - ignore |
andrewcrussell | 3:f0cd7c22ca94 | 472 | case 3: |
andrewcrussell | 3:f0cd7c22ca94 | 473 | break; // and do not change the output |
andrewcrussell | 3:f0cd7c22ca94 | 474 | } |
andrewcrussell | 0:83d4a20e7bc7 | 475 | } |
andrewcrussell | 0:83d4a20e7bc7 | 476 | |
andrewcrussell | 4:d900d90588d0 | 477 | // select_rot = (select_rot | FLAG7); |
andrewcrussell | 3:f0cd7c22ca94 | 478 | select_drv = select_rot; // write the value out to the bus |
andrewcrussell | 0:83d4a20e7bc7 | 479 | |
andrewcrussell | 3:f0cd7c22ca94 | 480 | // printf("\n RCFLAG %d \r", RCFLAG); |
andrewcrussell | 0:83d4a20e7bc7 | 481 | } |
andrewcrussell | 0:83d4a20e7bc7 | 482 | |
andrewcrussell | 0:83d4a20e7bc7 | 483 | |
andrewcrussell | 3:f0cd7c22ca94 | 484 | |
andrewcrussell | 3:f0cd7c22ca94 | 485 | |
andrewcrussell | 3:f0cd7c22ca94 | 486 | /********************************* select_out *********************************/ |
andrewcrussell | 3:f0cd7c22ca94 | 487 | // this is only used by the IR remote |
andrewcrussell | 3:f0cd7c22ca94 | 488 | |
andrewcrussell | 0:83d4a20e7bc7 | 489 | void select_out (void) |
andrewcrussell | 0:83d4a20e7bc7 | 490 | { |
andrewcrussell | 3:f0cd7c22ca94 | 491 | |
andrewcrussell | 3:f0cd7c22ca94 | 492 | if (address == SELECT_L) { |
andrewcrussell | 3:f0cd7c22ca94 | 493 | select_rot >>= 1; |
andrewcrussell | 3:f0cd7c22ca94 | 494 | if (select_rot <1) { |
andrewcrussell | 3:f0cd7c22ca94 | 495 | select_rot = 32; |
andrewcrussell | 3:f0cd7c22ca94 | 496 | } |
andrewcrussell | 0:83d4a20e7bc7 | 497 | } |
andrewcrussell | 3:f0cd7c22ca94 | 498 | |
andrewcrussell | 3:f0cd7c22ca94 | 499 | |
andrewcrussell | 3:f0cd7c22ca94 | 500 | if (address == SELECT_R) { |
andrewcrussell | 3:f0cd7c22ca94 | 501 | select_rot <<= 1; |
andrewcrussell | 3:f0cd7c22ca94 | 502 | if (select_rot >32) { |
andrewcrussell | 3:f0cd7c22ca94 | 503 | select_rot = 1; |
andrewcrussell | 3:f0cd7c22ca94 | 504 | } |
andrewcrussell | 3:f0cd7c22ca94 | 505 | |
andrewcrussell | 3:f0cd7c22ca94 | 506 | } |
andrewcrussell | 3:f0cd7c22ca94 | 507 | |
andrewcrussell | 4:d900d90588d0 | 508 | select_drv = select_rot; |
andrewcrussell | 3:f0cd7c22ca94 | 509 | |
andrewcrussell | 4:d900d90588d0 | 510 | // select_drv = (select_rot | FLAG7); //write the selection out to the bus. |
andrewcrussell | 4:d900d90588d0 | 511 | |
andrewcrussell | 4:d900d90588d0 | 512 | printf("\n select_rot = %d \r", select_rot); |
andrewcrussell | 3:f0cd7c22ca94 | 513 | |
andrewcrussell | 0:83d4a20e7bc7 | 514 | } |
andrewcrussell | 3:f0cd7c22ca94 | 515 | |
andrewcrussell | 0:83d4a20e7bc7 | 516 | /************************************ main() ***************************************/ |
andrewcrussell | 0:83d4a20e7bc7 | 517 | int main(void) |
andrewcrussell | 0:83d4a20e7bc7 | 518 | { |
andrewcrussell | 3:f0cd7c22ca94 | 519 | Serial pc(USBTX, USBRX); |
andrewcrussell | 3:f0cd7c22ca94 | 520 | __disable_irq(); // just to make sure we can set up correctly without problems |
andrewcrussell | 3:f0cd7c22ca94 | 521 | stby_pa = LOW; // make sure the power amp is OFF via the trigger output |
andrewcrussell | 3:f0cd7c22ca94 | 522 | muteout = LOW; //make sure the outputis muted from the get go |
andrewcrussell | 4:d900d90588d0 | 523 | // muteind = HIGH; //mute LED must be ON - power up preamble |
andrewcrussell | 4:d900d90588d0 | 524 | select_drv = 0; // no input relays must be on |
andrewcrussell | 4:d900d90588d0 | 525 | // bitstreamsync = LOW; // this is the IR bitsteeam output on pin 14 for debug |
andrewcrussell | 4:d900d90588d0 | 526 | // recloop_out = LOW; // make sure the recloop LED is OFF [its active HIGH] |
andrewcrussell | 4:d900d90588d0 | 527 | // recloop_rly = LOW; // make sure the recloop relay is OFF |
andrewcrussell | 3:f0cd7c22ca94 | 528 | |
andrewcrussell | 4:d900d90588d0 | 529 | // mute_int.mode(PullUp); // set up all the pin states per Pindef1114.h |
andrewcrussell | 3:f0cd7c22ca94 | 530 | rc5dat.mode(PullUp); // pin 17 |
andrewcrussell | 3:f0cd7c22ca94 | 531 | sela.mode(PullUp); // pin 28 |
andrewcrussell | 3:f0cd7c22ca94 | 532 | selb.mode(PullUp); // pin 27 |
andrewcrussell | 3:f0cd7c22ca94 | 533 | stdby.mode(PullUp); // pin 26 |
andrewcrussell | 4:d900d90588d0 | 534 | // recloop_in.mode(PullUp); // pin 14 |
andrewcrussell | 3:f0cd7c22ca94 | 535 | |
andrewcrussell | 3:f0cd7c22ca94 | 536 | wait(.2); |
andrewcrussell | 0:83d4a20e7bc7 | 537 | FLAG1 = FALSE; |
andrewcrussell | 0:83d4a20e7bc7 | 538 | FLAG2 = FALSE; |
andrewcrussell | 4:d900d90588d0 | 539 | // FLAG5 = FALSE; // this is the recloop flag |
andrewcrussell | 3:f0cd7c22ca94 | 540 | FWD1=0; //make sure the volume control motor is OFF |
andrewcrussell | 0:83d4a20e7bc7 | 541 | REV1=0; |
andrewcrussell | 0:83d4a20e7bc7 | 542 | |
andrewcrussell | 3:f0cd7c22ca94 | 543 | // set up the ISR's that will be used |
andrewcrussell | 4:d900d90588d0 | 544 | rc5int.fall(&rc5isr); // trigger int on falling edge - go service it at rc5dat |
andrewcrussell | 0:83d4a20e7bc7 | 545 | select_int.fall(&select_isr); // input from rotary encoder or input select |
andrewcrussell | 4:d900d90588d0 | 546 | // mute_int.fall(&mute_isr); // mute push button interrupt |
andrewcrussell | 4:d900d90588d0 | 547 | // recloop_int.fall(&recloop_isr); // record loop push button interrupt |
andrewcrussell | 4:d900d90588d0 | 548 | stdby_int.fall(&stdby_isr); // the system power/standby switch - on sel rotenc |
andrewcrussell | 0:83d4a20e7bc7 | 549 | |
andrewcrussell | 0:83d4a20e7bc7 | 550 | //now disable them, leaving only the stand by p/button and rc5int interrupts active |
andrewcrussell | 0:83d4a20e7bc7 | 551 | select_int.fall(NULL); |
andrewcrussell | 4:d900d90588d0 | 552 | // mute_int.fall(NULL); |
andrewcrussell | 4:d900d90588d0 | 553 | // recloop_int.fall(NULL); |
andrewcrussell | 0:83d4a20e7bc7 | 554 | |
andrewcrussell | 1:bb881a434906 | 555 | standbyflag = TRUE; // preamp will be set-up first time for OFF |
andrewcrussell | 3:f0cd7c22ca94 | 556 | standby_out(); // set system up |
andrewcrussell | 3:f0cd7c22ca94 | 557 | standbyflag = FALSE; |
andrewcrussell | 4:d900d90588d0 | 558 | select_save = 2; // CD always slected on initital power up |
andrewcrussell | 3:f0cd7c22ca94 | 559 | select_rot = select_save; // CD will be selected when power is first turned on |
andrewcrussell | 3:f0cd7c22ca94 | 560 | wait(3); |
andrewcrussell | 4:d900d90588d0 | 561 | // muteind = LOW; |
andrewcrussell | 0:83d4a20e7bc7 | 562 | __enable_irq(); |
andrewcrussell | 0:83d4a20e7bc7 | 563 | |
andrewcrussell | 3:f0cd7c22ca94 | 564 | // all ready and in standby from this point forward |
andrewcrussell | 1:bb881a434906 | 565 | |
andrewcrussell | 0:83d4a20e7bc7 | 566 | |
andrewcrussell | 0:83d4a20e7bc7 | 567 | LOOP: // this is the main operating loop |
andrewcrussell | 2:674e2dd56e7d | 568 | |
andrewcrussell | 0:83d4a20e7bc7 | 569 | __WFI(); // wait here until interrupt |
andrewcrussell | 0:83d4a20e7bc7 | 570 | |
andrewcrussell | 0:83d4a20e7bc7 | 571 | if (FLAG1 == TRUE) { // FLAG1 indicates remote control was used |
andrewcrussell | 0:83d4a20e7bc7 | 572 | save_stream(); |
andrewcrussell | 3:f0cd7c22ca94 | 573 | process_stream(); |
andrewcrussell | 3:f0cd7c22ca94 | 574 | |
andrewcrussell | 0:83d4a20e7bc7 | 575 | FLAG1 = FALSE; |
andrewcrussell | 0:83d4a20e7bc7 | 576 | } |
andrewcrussell | 0:83d4a20e7bc7 | 577 | |
andrewcrussell | 0:83d4a20e7bc7 | 578 | if (FLAG2 == TRUE) { |
andrewcrussell | 0:83d4a20e7bc7 | 579 | select_process(); //select process |
andrewcrussell | 0:83d4a20e7bc7 | 580 | FLAG2 = FALSE; |
andrewcrussell | 0:83d4a20e7bc7 | 581 | } |
andrewcrussell | 0:83d4a20e7bc7 | 582 | |
andrewcrussell | 0:83d4a20e7bc7 | 583 | if (FLAG3 == TRUE) { |
andrewcrussell | 0:83d4a20e7bc7 | 584 | mute_out(); //mute |
andrewcrussell | 0:83d4a20e7bc7 | 585 | FLAG3 = FALSE; |
andrewcrussell | 0:83d4a20e7bc7 | 586 | } |
andrewcrussell | 3:f0cd7c22ca94 | 587 | |
andrewcrussell | 3:f0cd7c22ca94 | 588 | if (FLAG4 == TRUE) { // standby ON/OFF |
andrewcrussell | 3:f0cd7c22ca94 | 589 | standby_out(); |
andrewcrussell | 3:f0cd7c22ca94 | 590 | FLAG4 = FALSE; |
andrewcrussell | 0:83d4a20e7bc7 | 591 | } |
andrewcrussell | 3:f0cd7c22ca94 | 592 | |
andrewcrussell | 4:d900d90588d0 | 593 | // if (FLAG5 == TRUE) { |
andrewcrussell | 4:d900d90588d0 | 594 | // recloop(); //recloop |
andrewcrussell | 4:d900d90588d0 | 595 | // FLAG5 = FALSE; |
andrewcrussell | 4:d900d90588d0 | 596 | // } |
andrewcrussell | 0:83d4a20e7bc7 | 597 | |
andrewcrussell | 3:f0cd7c22ca94 | 598 | //printf("\r Command = %d Address = %d \n",command, address); |
andrewcrussell | 3:f0cd7c22ca94 | 599 | |
andrewcrussell | 0:83d4a20e7bc7 | 600 | goto LOOP; |
andrewcrussell | 0:83d4a20e7bc7 | 601 | |
andrewcrussell | 0:83d4a20e7bc7 | 602 | } |
andrewcrussell | 0:83d4a20e7bc7 | 603 | |
andrewcrussell | 0:83d4a20e7bc7 | 604 | |
andrewcrussell | 0:83d4a20e7bc7 | 605 | |
andrewcrussell | 2:674e2dd56e7d | 606 |