AppleRemote receive library.

Committer:
tosihisa
Date:
Sat Oct 09 09:39:45 2010 +0000
Revision:
1:6d06459fb6db
Parent:
0:a5f26ed3f510
Release for library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tosihisa 0:a5f26ed3f510 1 /**
tosihisa 0:a5f26ed3f510 2 * @section LICENSE
tosihisa 0:a5f26ed3f510 3 *
tosihisa 0:a5f26ed3f510 4 * This source code is "zlib" license.
tosihisa 0:a5f26ed3f510 5 * Of course, this is not a part of the zlib software.
tosihisa 0:a5f26ed3f510 6 * The license is zlib license.
tosihisa 0:a5f26ed3f510 7 *
tosihisa 0:a5f26ed3f510 8 * Copyright (C) 2010 tosihisa
tosihisa 0:a5f26ed3f510 9 *
tosihisa 0:a5f26ed3f510 10 * This software is provided 'as-is', without any express or implied
tosihisa 0:a5f26ed3f510 11 * warranty. In no event will the authors be held liable for any damages
tosihisa 0:a5f26ed3f510 12 * arising from the use of this software.
tosihisa 0:a5f26ed3f510 13 *
tosihisa 0:a5f26ed3f510 14 * Permission is granted to anyone to use this software for any purpose,
tosihisa 0:a5f26ed3f510 15 * including commercial applications, and to alter it and redistribute it
tosihisa 0:a5f26ed3f510 16 * freely, subject to the following restrictions:
tosihisa 0:a5f26ed3f510 17 *
tosihisa 0:a5f26ed3f510 18 * 1. The origin of this software must not be misrepresented; you must not
tosihisa 0:a5f26ed3f510 19 * claim that you wrote the original software. If you use this software
tosihisa 0:a5f26ed3f510 20 * in a product, an acknowledgment in the product documentation would be
tosihisa 0:a5f26ed3f510 21 * appreciated but is not required.
tosihisa 0:a5f26ed3f510 22 * 2. Altered source versions must be plainly marked as such, and must not be
tosihisa 0:a5f26ed3f510 23 * misrepresented as being the original software.
tosihisa 0:a5f26ed3f510 24 * 3. This notice may not be removed or altered from any source distribution.
tosihisa 0:a5f26ed3f510 25 *
tosihisa 0:a5f26ed3f510 26 * @section DESCRIPTION
tosihisa 0:a5f26ed3f510 27 *
tosihisa 0:a5f26ed3f510 28 * Apple Remote Decoder
tosihisa 0:a5f26ed3f510 29 * http://en.wikipedia.org/wiki/Apple_Remote
tosihisa 0:a5f26ed3f510 30 *
tosihisa 0:a5f26ed3f510 31 */
tosihisa 0:a5f26ed3f510 32 #ifndef APPLEREMOTE_H
tosihisa 0:a5f26ed3f510 33 #define APPLEREMOTE_H
tosihisa 0:a5f26ed3f510 34
tosihisa 0:a5f26ed3f510 35 class AppleRemote {
tosihisa 0:a5f26ed3f510 36 public:
tosihisa 0:a5f26ed3f510 37 /**
tosihisa 0:a5f26ed3f510 38 * Constructor.
tosihisa 0:a5f26ed3f510 39 *
tosihisa 0:a5f26ed3f510 40 * Because "_ir mbed pin" is processed by the interruption(use InterruptIn class),
tosihisa 0:a5f26ed3f510 41 * the thing set excluding p19 and p20 .
tosihisa 0:a5f26ed3f510 42 *
tosihisa 0:a5f26ed3f510 43 * @param _ir mbed pin to use for Apple Remote.
tosihisa 0:a5f26ed3f510 44 */
tosihisa 0:a5f26ed3f510 45 AppleRemote( PinName _ir );
tosihisa 0:a5f26ed3f510 46
tosihisa 0:a5f26ed3f510 47 /**
tosihisa 0:a5f26ed3f510 48 * Reading is started.
tosihisa 0:a5f26ed3f510 49 *
tosihisa 0:a5f26ed3f510 50 * The interruption of "_ir mbed pin" is effectively done.
tosihisa 0:a5f26ed3f510 51 */
tosihisa 0:a5f26ed3f510 52 void start();
tosihisa 0:a5f26ed3f510 53
tosihisa 0:a5f26ed3f510 54 /**
tosihisa 0:a5f26ed3f510 55 * Reading is stopped.
tosihisa 0:a5f26ed3f510 56 *
tosihisa 0:a5f26ed3f510 57 * The interrupt of "_ir mbed pin" is stopped.
tosihisa 0:a5f26ed3f510 58 */
tosihisa 0:a5f26ed3f510 59 void stop();
tosihisa 0:a5f26ed3f510 60
tosihisa 0:a5f26ed3f510 61 /**
tosihisa 0:a5f26ed3f510 62 * Reading is reset.
tosihisa 0:a5f26ed3f510 63 *
tosihisa 0:a5f26ed3f510 64 * This resets reading processing it now.
tosihisa 0:a5f26ed3f510 65 */
tosihisa 0:a5f26ed3f510 66 void reset();
tosihisa 0:a5f26ed3f510 67
tosihisa 0:a5f26ed3f510 68 /**
tosihisa 0:a5f26ed3f510 69 * Determine if there is a key-code available to read
tosihisa 0:a5f26ed3f510 70 *
tosihisa 0:a5f26ed3f510 71 * @return 1 if there is a key-code available to read, else 0
tosihisa 0:a5f26ed3f510 72 */
tosihisa 0:a5f26ed3f510 73 int readable();
tosihisa 0:a5f26ed3f510 74
tosihisa 0:a5f26ed3f510 75 /**
tosihisa 0:a5f26ed3f510 76 * Read a key-code
tosihisa 0:a5f26ed3f510 77 *
tosihisa 0:a5f26ed3f510 78 * key-code does buffering. The size of the buffer is 15.
tosihisa 0:a5f26ed3f510 79 * The 16 bits of key-code consist of a one byte remote ID , a one byte command.
tosihisa 0:a5f26ed3f510 80 *
tosihisa 0:a5f26ed3f510 81 * @return The key-code read from the Apple Remote.
tosihisa 0:a5f26ed3f510 82 */
tosihisa 0:a5f26ed3f510 83 int getc();
tosihisa 0:a5f26ed3f510 84
tosihisa 0:a5f26ed3f510 85 /**
tosihisa 0:a5f26ed3f510 86 * Setting of repeat
tosihisa 0:a5f26ed3f510 87 *
tosihisa 0:a5f26ed3f510 88 * The repeat code of Apple Remote is not used by default.
tosihisa 0:a5f26ed3f510 89 * Please call this function when you use the repeat code.
tosihisa 0:a5f26ed3f510 90 * (The same key code returns while the key is being pushed.)
tosihisa 0:a5f26ed3f510 91 *
tosihisa 0:a5f26ed3f510 92 * @param enable 1 if use the repeat code. else 0
tosihisa 0:a5f26ed3f510 93 */
tosihisa 0:a5f26ed3f510 94 void repeat(int enable);
tosihisa 0:a5f26ed3f510 95
tosihisa 0:a5f26ed3f510 96 enum KEY_CODE {
tosihisa 0:a5f26ed3f510 97 MENU_1ST = 0x02,
tosihisa 0:a5f26ed3f510 98 PLAY_1ST = 0x04,
tosihisa 0:a5f26ed3f510 99 RIGHT_1ST = 0x07,
tosihisa 0:a5f26ed3f510 100 LEFT_1ST = 0x08,
tosihisa 0:a5f26ed3f510 101 UP_1ST = 0x0B,
tosihisa 0:a5f26ed3f510 102 DOWN_1ST = 0x0D,
tosihisa 0:a5f26ed3f510 103 /* --- */
tosihisa 0:a5f26ed3f510 104 CENTER_2ND = 0x5C,
tosihisa 0:a5f26ed3f510 105 MENU_2ND = 0x03,
tosihisa 0:a5f26ed3f510 106 PLAY_2ND = 0x5F,
tosihisa 0:a5f26ed3f510 107 RIGHT_2ND = 0x06,
tosihisa 0:a5f26ed3f510 108 LEFT_2ND = 0x09,
tosihisa 0:a5f26ed3f510 109 UP_2ND = 0x0A,
tosihisa 0:a5f26ed3f510 110 DOWN_2ND = 0x0C,
tosihisa 0:a5f26ed3f510 111 };
tosihisa 0:a5f26ed3f510 112
tosihisa 0:a5f26ed3f510 113 private:
tosihisa 0:a5f26ed3f510 114 static const int ID = 0x87EE;
tosihisa 0:a5f26ed3f510 115 static const int bufsize = 0x10;
tosihisa 0:a5f26ed3f510 116
tosihisa 0:a5f26ed3f510 117 enum IR_SCAN_STAT {
tosihisa 0:a5f26ed3f510 118 WAIT_READER,
tosihisa 0:a5f26ed3f510 119 CHK_READER_1ST,
tosihisa 0:a5f26ed3f510 120 CHK_READER_2ND,
tosihisa 0:a5f26ed3f510 121 CHK_CODE_1ST,
tosihisa 0:a5f26ed3f510 122 CHK_CODE_2ND,
tosihisa 0:a5f26ed3f510 123 CHK_STOP_1ST,
tosihisa 0:a5f26ed3f510 124 CHK_STOP_2ND,
tosihisa 0:a5f26ed3f510 125 };
tosihisa 0:a5f26ed3f510 126 InterruptIn IR;
tosihisa 0:a5f26ed3f510 127 int nowStart;
tosihisa 0:a5f26ed3f510 128 Timer IR_Timer;
tosihisa 0:a5f26ed3f510 129 volatile enum IR_SCAN_STAT cjobst;
tosihisa 0:a5f26ed3f510 130 volatile int bit_index;
tosihisa 0:a5f26ed3f510 131 volatile unsigned long IR_code;
tosihisa 0:a5f26ed3f510 132 unsigned long pre_IR_code;
tosihisa 0:a5f26ed3f510 133 volatile int pre_timer;
tosihisa 0:a5f26ed3f510 134 volatile unsigned short buf[bufsize];
tosihisa 0:a5f26ed3f510 135 volatile unsigned char widx;
tosihisa 0:a5f26ed3f510 136 volatile unsigned char ridx;
tosihisa 0:a5f26ed3f510 137 int _repeatEnable;
tosihisa 0:a5f26ed3f510 138 void IR_fall();
tosihisa 0:a5f26ed3f510 139 void IR_rise();
tosihisa 0:a5f26ed3f510 140 };
tosihisa 0:a5f26ed3f510 141
tosihisa 0:a5f26ed3f510 142 #endif /* APPLEREMOTE_H */