old-www/HOWTO/Coffee-4.html

92 lines
3.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
<TITLE>Coffee Making: Software</TITLE>
<LINK HREF="Coffee-5.html" REL=next>
<LINK HREF="Coffee-3.html" REL=previous>
<LINK HREF="Coffee.html#toc4" REL=contents>
</HEAD>
<BODY>
<A HREF="Coffee-5.html">Next</A>
<A HREF="Coffee-3.html">Previous</A>
<A HREF="Coffee.html#toc4">Contents</A>
<HR>
<H2><A NAME="s4">4. Software</A></H2>
<P>
<P>
<H2><A NAME="ss4.1">4.1 Programming</A>
</H2>
<P>You will have to build an executable that will take the following steps:
<UL>
<LI>Get permission to use I/O address space, by calling kernel, with
the call <B>ioperm</B>: eg <EM>ioperm( BASE, range ,1); </EM></LI>
<LI>Perform an out request instruction, to set the 0-5V voltage to the
parallel port, eg <EM>outb( 1, BASE );</EM></LI>
<LI>Wait enough time so the coffee is made. It would be nice
if that time is read by looking at the command line.</LI>
<LI>Then it will turn off the coffee-machine: outb( 0 , BASE );</LI>
<LI>Before ending it should give back the parallel port
with an <EM>ioperm( BASE, range, 0);</EM></LI>
</UL>
Change BASE = 0x3bc for /dev/lp0, 0x378 for /dev/lp1, and 0x278
for /dev/lp2; range=8.
<P>
<P>It would be useful if you had that program setuid,
so that everybody can drink coffee! You BOFH!
<P>
<H2><A NAME="ss4.2">4.2 Device driver</A>
</H2>
<P>
<P>Just read
<A HREF="http://en.tldp.org/LDP/khg/HyperNews/get/khg.html">kernel hacker's guide</A>,
to implement a device driver; you might also do it in user space.
Please compile it as a module, so that we won't need a
kernel compile in every update.
Then write:
<P>
<PRE>
echo cappuccino >/dev/coffee
</PRE>
<P>And you will have a hot cup of coffee in minutes!
Remember to give the right permissions to /dev/coffee,
depending on whether you want only root making coffee or not.
<P>
<P>The advantage of this method is that it supports feedback
from the coffee-machine by using the ACK of parallel port and such,
so that smart coffee-machines can produce an interrupt when ready.
<P>
<P>Do it yourself, after reading the excellent book
of Alessandro Rubini and Jonathan Corbet
<A HREF="http://www.xml.com/ldd/chapter/book/index.html">Linux Device Drivers</A>
and studying the
<A HREF="http://lxr.linux.no/source/">Cross Reference Linux</A> source code repository.
<P>
<P>
<H2><A NAME="ss4.3">4.3 Connecting with the Internet</A>
</H2>
<P>If you have implemented the controlling program in C (see above),
you just have to write a CGI script to turn ON and OFF
the coffee-machine or pass along more complex instructions.
You should write some nice webpages, explaining how to make coffee,
and put them on an <B>apache</B> web server...
<P>
<P>...LAMP technology (Linux, Apache, MySQL, [Perl|Python|PHP]),
will help you to build a perfect user-customizable coffee system!
<P>At some time in the future when the applications get rather complex,
you might want to extend on the basis of Flow-Based Programming:
<A HREF="http://www.jpaulmorrison.com/fbp/">http://www.jpaulmorrison.com/fbp/</A>.
What a great match for a great Coffee Machine!
<P>
<HR>
<A HREF="Coffee-5.html">Next</A>
<A HREF="Coffee-3.html">Previous</A>
<A HREF="Coffee.html#toc4">Contents</A>
</BODY>
</HTML>