Modprobe scripts now working! Plus JVC keyset.
[pierogi] / doc / documentation.html
1 <html>
2 <head>
3 </head>
4 <body>
5
6 <h1>Pierogi Documentation</h1>
7
8 <p>
9 The Pierogi universal infrared remote controller is a single self-contained
10 app capable of sending IR commands to a wide variety of devices.
11 At the moment, it is oriented towards television, VCR, DVD, and Blu-ray
12 devices, but a few other types of device have had their command sets entered.
13 </p>
14
15 <p>
16 In this app, each family of related infrared commands is collected into a
17 "keyset".  As manufacturers commonly reuse a given set of commands rather
18 than re-invent the wheel each time they come out with a new product, many
19 devices can share the same keyset.
20 </p>
21
22 <p>
23 Pierogi also follows the classic concept of a universal remote, by having
24 a common set of buttons that are reused for each device.  So, for example,
25 the "power" button has the same name and is located in the same position,
26 no matter what keyset is currently in use -- even if that keyset has a
27 different name for "power", or has no "power" command at all.  (Check out
28 the <a href="http://en.wikipedia.org/wiki/Universal_remote">Universal
29 Remote wiki</a> for a description of universal remote controls, which
30 includes a special mention of the N900!)
31 </p>
32
33 <p>
34 So in short, to use Pierogi, you first select an appropriate keyset, then
35 press the appropriate buttons to control the target device.  More detail on
36 the features of Pierogi is provided below.
37 </p>
38
39 <h2>Using Pierogi</h2>
40
41 <p>
42 The current Pierogi design is built around a tabbed window, each tab containing
43 a group of related buttons.  Depending on the keyset that has been selected,
44 some of these buttons will be active, others inactive.  Active buttons are ones
45 which have been associated with a command in the current keyset.  Pressing an
46 active button will begin repeating the associated command; letting up on the
47 button will stop the command.
48 </p>
49
50 <p>
51 Keysets can be chosen using the "Select Keyset" option in the drop-down menu.
52 If you have a particular keyset you use often, it can be stored in the
53 "favorites" tab for quick access.
54 </p>
55
56 <h3>Main Tab</h3>
57
58 <p>The Main tab contains just the power, volume, and channel buttons.  It is
59 intended to be a quick way to get to the most important, commonly used
60 controls.  The name of the current keyset is also provided in this tab.</p>
61
62 <h3>Utility Tab</h3>
63
64 <p>The Utility tab contains a selection of commonly useful controls, such as
65 "Mute", "Sleep", "Input", "Closed Captions / Subtitles", and the color buttons.
66 The exact selection of buttons on this tab will probably change to reflect
67 which commands turn out to be the most popular.</p>
68
69 <h3>Keypad Tab</h3>
70
71 <p>This tab provides a numeric keypad and a handful of associated commands,
72 intended mainly for use with televisions.  The "Prev Channel" button should
73 take you to the previously selected channel, if any.  The "Dash" button
74 should allow you to specify a digital subchannel, as in "16-4".  The "+100"
75 button is used for television sets which normally expect only two digits
76 per channel; using this button allows you to enter a third digit.  The "-/--
77 Double Digit" button is used on very old televisions that normally expect
78 channels to be represented by just a single digit; pressing this should
79 allow you to enter a second digit.</p>
80
81 <h3>Menu Tab</h3>
82
83 <p>This tab contains buttons used to enter and exit a menu, navigate within
84 a menu, and select menu entries.  The "Menu" button is meant to enter the
85 main system menu of a given device; the "Info" and "Guide" buttons are
86 targeted towards entering other useful menus when available.</p>
87
88 <h3>Media Tab</h3>
89
90 <p>Many of the most important playback commands are represented on this tab.
91 Play, pause, and stop are the most common ones, along with "Reverse" (often
92 called "Rewind") and Fast Forward.  A variety of other less common navigation
93 controls are included, along with the "eject" command.</p>
94
95 <h3>Misc Tab</h3>
96
97 <p>This tab contains a selection of buttons that did not fit into any of the
98 previous tabs.  The content of this tab is subject to change.</p>
99
100 <h3>Favorites Tab</h3>
101
102 <p>As there are numerous keysets available in Pierogi, a "favorites" tab has
103 been implemented.  To add a favorite keyset to the tab, first select that
104 keyset from the "Select Keyset" window.  Then, navigate to the Favorites tab
105 and press "Add Current Keyset".</p>
106
107 <p>Once you have added some keysets to the favorites list, you can tell
108 Pierogi to use one by simply selecting that keyset from the list.</p>
109
110 <p>A keyset can be removed from the list by selecting it and pressing
111 "Remove Selected Keyset".</p>
112
113 <h3>Select Keyset Window</h3>
114
115 <p>The Select Keyset window presents a list of all the keysets currently
116 available in Pierogi.  As this list is fairly long, a button has been added
117 at the top of the window that allows you to choose the make (or brand) of
118 the device you are trying to control; once a make has been selected, all
119 keysets not associated with that make will be hidden.  To use a keyset,
120 simply select it from the list, and close the window (by pressing the
121 return arrow at the top right of the screen).</p>
122
123 <h2>Design Rationale</h2>
124
125 <p>Here I collect my thoughts on the how and why of creating Pierogi.</p>
126
127 <h3>Hasn't this been done before?</h3>
128
129 <p>Yes, remote control software has already been written for the N900.  In
130 particular, the
131 <a href="http://irreco.garage.maemo.org/">Irreco / QtIrreco</a> project
132 creates beautiful virtual remote controls.  I've also used the
133 <a href="http://thp.io/2010/raemote/">Raemote</a> widget to control my Apple
134 computers.  But these programs have their shortcomings; in particular, they
135 are not universal.  Each simulated remote control in QtIrreco is a completely
136 separate animal.  I would like to have a standard set of buttons that I can
137 use on all sorts of different hardware.</p>
138
139 <h3>What's up with LIRC?</h3>
140
141 <p>Just as QtIrreco and Raemote do, I want to leverage the work of the 
142 <a href="http://www.lirc.org/">Linux Infrared Remote Control</a> project.
143 The LIRC project is by far the most influential open-source effort working
144 with consumer IR.  And the N900 comes with a device driver made
145 specifically for their server!  But, you see, I have a problem.  I
146 don't want to do things the way LIRC wants to do things.</p>
147
148 <p>The N900 is different from other Linux systems using IR -- rather than
149 being the machine at which you point a remote control, this machine <i>is</i>
150 the remote control.  This is not what LIRC was designed for; the heart of the
151 LIRC project is a server that will sit and wait for messages to arrive from
152 the IR system.  Although it can also broadcast IR data back out (when using
153 hardware that supports 2-way IR communication), that is not its primary
154 purpose.</p>
155
156 <p>I believe there are three disadvantages to using the LIRC server as it
157 currently exists.  First, there isn't much point to running a daemon on
158 the N900 to manage the IR device; no messages are ever going to come in from
159 the output-only hardware on the N900, so why sit and listen for them?</p>
160
161 <p>The second problem is somewhat larger.  LIRC uses configuration files to
162 describe the command set for each remote control.  And there are a lot of them.
163 A whole lot.  We're talking thousands of files here, and each file can describe
164 many remote controls.  This is not a problem for Raemote or Irreco, as they
165 only need to deal with one config file at a time.  But if you're aiming to
166 manage the whole lot of them, you need to find a way to deal with the
167 multitudes.</p>
168
169 <p>The third problem is more subtle, but really tough to crack.  You see, the
170 whole point of LIRC is to take the commands it receives from the IR port and
171 translate them into something recognizable.  As such, each config file provides
172 a mapping from numeric commands to human-readable strings.  This is a
173 serious problem, if your interest is in finding similar commands in
174 different config files!  Take, for example, the "power"
175 button found on most remote controls.  In some config files, the string for
176 this is "power".  Others have "Power", or "POWER".  You can also find "pwr",
177 "PWR", "ON/OFF", "ON-OFF", "ONOFF", "POWER_ON_OFF", "KEY_POWER", "Operate",
178 "Standby", and who knows what else.  And, you've gotta be careful not to get
179 confused by strings like "SUBTITLE_ON/OFF" or "TV_ON_TIMER".  How is an app to
180 know which key to map all these strings to?</p>
181
182 <h3>So how is Pierogi different?</h3>
183
184 <p>
185 Pierogi attempts to answer these problems.  First, it talks directly to the
186 /dev/lirc0 device, no server middleman needed.  Yes, you can use Pierogi
187 without the LIRC daemon running; in fact, there's no need to ever install it.
188 Second, Pierogi is built
189 around the concept of the "keyset"; all IR codes that can share the same
190 protocol without interfering with one another are combined into a single
191 family of related commands.  In short, this reduces the quantity of data
192 available from LIRC config files to something much more manageable.</p>
193  
194 <p>The third problem mentioned above is a bit harder to solve; I'm currently
195 mapping each LIRC string to a corresponding Pierogi key by hand.  Naturally,
196 this process will be fraught with errors; I intend to keep updating Pierogi
197 as these errors are found and fixed.
198 </p>
199
200 <h2>Internal Design Notes</h2>
201
202 <p>If you're interested in the ugly details of the code, read on!</p>
203
204 <h3>What's up with the name of this app?</h3>
205
206 <p>Lately I've been naming my projects after tasty foods.  In particular,
207 I've been working my way through the pasta-oriented dishes.  (My previous
208 project, "Linguine", has gotten bogged down, so I moved on to this one...)</p>
209
210 <h3>Why use Qt?</h3>
211
212 <p>I'm a C++ kind of guy, it just makes sense to me to use a C++ kind of
213 interface.  The Qt classes have everything you need to set up a decent UI,
214 and Qt Creator makes coding up a project for the N900 relatively
215 painless.  Check it out for yourself at
216 <a href="http://qt.nokia.com/">the Qt webpage</a>.
217 </p>
218
219 <h3>The simplest device ever!</h3>
220
221 <p>If you ever wanted to learn how to work with device drivers on Linux, the
222 N900's infrared port is the device you want to start with.  It's not 
223 much more than a flashlight: You turn it on.  You turn it off.  You turn it on
224 again.  You turn it off again.  You really can't get much simpler than that.
225 Interaction with the "/dev/lirc0" device involves no more than handing
226 it an array of integers: the first integer being an amount of time to keep the
227 light lit (in microseconds), the second being an amount of time to leave it
228 switched off, the third on, the fourth off, and so on.</p>
229
230 <p>Well, ok, so it involves just a little bit more than that.  You don't want
231 to leave the light stuck in the "on" state when you are finished, so the driver
232 demands that the last item in every array be an "on" amount -- after finishing
233 that timer, the IR will stay off until the next command arrives.
234 </p>
235
236 <p>
237 Also, in an attempt to weed out any confusing signals from natural IR sources
238 in the environment, consumer IR devices are "pulsed" at a particular
239 frequency.  So you're really turning a strobelight on and off, not just a
240 flashlight.  When the receiver sees that the light is coming from a strobelight
241 pulsing at the desired frequency, it can be assured that that signal came from
242 an actual remote control.  The N900's device driver allows you to set the
243 frequency anywhere between 20000 Hz and 500000 Hz.  38000 Hz seems to the most
244 popular frequency used by modern remote controls, at least from what you find
245 in LIRC config files.  Also, you can set how long each pulse needs to be held,
246 in terms of a percentage: 25% means turning the light on for just one quarter
247 of the pulse, 33% means leaving it on for one third, etc.  This is called the
248 "duty cycle", and can be anywhere between 0 and 100 percent.  LIRC's default
249 duty cycle is 50 percent.
250 </p>
251
252 <p>And that's about it.  I've been using a 
253 <a href="http://svn.jacekowski.org/host_mode/trunk/drivers/input/lirc/lirc_rx51.c">web page</a>
254 that lists the source code for the IR device driver.  I'm not sure if there's
255 a better location out there for N900 source code, but this seems accurate
256 so far.</p>
257
258 <h3>You did <i>what</i> to the LIRC daemon?</h3>
259
260 <p>
261 Well, ok, yeah, I've cannibalized the transmission code out of the LIRC
262 server and dumped it into my app.  Sort of.  I can't really keep my hands off
263 of code once I've seen it, so I've rewritten it in C++, reorganizing it in
264 an object-oriented manner along the way.</p>
265
266 <p>
267 Here's one way in which I disagree with the authors of LIRC: they've managed
268 to cram support for practically every protocol used by every remote control
269 ever made into a single codepath.  So, there's a single "transmit" function,
270 sorting through a massive pile of flags, conditional statements, and some
271 really funky delayed-action buffering to make everything work.  The simple act
272 of splitting the code into one routine for the RC5 (biphase) protocol and
273 another for the NEC (space-encoded) protocol makes it much easier to read, at
274 least to my eyes.  (I haven't yet implemented the RC6 or other protocols.)
275 </p>
276
277 <p>
278 In any case, I owe the LIRC authors a deep debt of gratitude for their
279 efforts.  If you are one such author, thank you.  As Pierogi is more-or-less
280 derived directly from their work, it is also licensed under the same terms,
281 the GNU General Public License (GPL) version 2 or later.
282 </p>
283
284 <h2>Attribution</h2>
285
286 <p>I've fallen in love with the Gentleface Mono Icon Set.  Of the creative
287 commons icon sets available, theirs stands head and shoulders above the rest.
288 Find their work at <a href="http://www.gentleface.com">www.gentleface.com</a>.
289
290 <h2>References</h2>
291
292 <p>A set of links to some resources I've used while writing the code.</p>
293
294 <ul>
295 <li>The center of the Linux infrared world, the
296 <a href="http://www.lirc.org/">Linux Infrared Remote Control</a> project.
297
298 <li>A <a href="http://en.wikipedia.org/wiki/Consumer_IR">Wiki page</a> with
299 general info on consumer IR
300
301 <li>A <a href="http://www.sbprojects.com/knowledge/ir/index.php">good introduction</a>
302 to the theory and practice behind consumer IR devices
303
304 <li>A <a href="http://en.wikipedia.org/wiki/RC-5">Wiki for the RC-5 protocol</a>
305
306 <li>Some <a href="http://www.sbprojects.com/knowledge/ir/nec.php">Info on the NEC protocol</a>
307
308 <li>Some <a href="http://www2.renesas.com/faq/en/mi_com/f_com_remo.html">More info on the NEC protocol</a>
309
310 <li>Link to (what appears to be) source code for the N900's
311 <a href="http://svn.jacekowski.org/host_mode/trunk/drivers/input/lirc/lirc_rx51.c">/dev/lirc0 device driver</a>.
312 <ul>
313
314 </body>
315 </html>