<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>2718.us blog &#187; gpioctl</title>
	<atom:link href="http://2718.us/blog/tag/gpioctl/feed/" rel="self" type="application/rss+xml" />
	<link>http://2718.us/blog</link>
	<description>Miscellaneous Technological Geekery</description>
	<lastBuildDate>Tue, 18 May 2010 02:42:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Pulsing the Alix LEDs</title>
		<link>http://2718.us/blog/2008/05/25/pulsing-the-alix-leds/</link>
		<comments>http://2718.us/blog/2008/05/25/pulsing-the-alix-leds/#comments</comments>
		<pubDate>Mon, 26 May 2008 01:11:07 +0000</pubDate>
		<dc:creator>2718.us</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[alix]]></category>
		<category><![CDATA[blink]]></category>
		<category><![CDATA[breathing]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[gpio]]></category>
		<category><![CDATA[gpioctl]]></category>
		<category><![CDATA[led]]></category>
		<category><![CDATA[leds]]></category>
		<category><![CDATA[openbsd]]></category>
		<category><![CDATA[pulse]]></category>
		<category><![CDATA[pulsing]]></category>

		<guid isPermaLink="false">http://2718.us/blog/?p=41</guid>
		<description><![CDATA[Now that all my traffic to and from the internet is running happily through my Alix box (and it had no trouble with a few hours of sustained maxing-out of my 6Mbps down/768kbps up DSL line in both directions), and since my first test unslung-NSLU2 &#8220;slug&#8221; seems to be stably doing its job as a [...]]]></description>
			<content:encoded><![CDATA[<p>Now that all my traffic to and from the internet is running happily through my Alix box (and it had no trouble with a few hours of sustained maxing-out of my 6Mbps down/768kbps up DSL line in both directions), and since my first test unslung-NSLU2 &#8220;slug&#8221; seems to be stably doing its job as a backup DNS/DHCP server, it&#8217;s time to do the fun little things, like wonder, &#8220;Hey, the Alix has 3 LEDs on the front.  What could I do with those?&#8221;</p>
<p>Well, first I learned from <a href="http://archives.neohapsis.com/archives/openbsd/2007-12/0330.html">a mailing list archive post</a> that under OpenBSD, the LEDs are easily controlled with <a href="http://www.openbsd.org/cgi-bin/man.cgi?query=gpioctl&amp;apropos=0&amp;sektion=0&amp;manpath=OpenBSD+Current&amp;arch=i386&amp;format=html">gpioctl</a> (using 0 and 1 for off and on):</p>
<div class="geshi no bash">
<div class="head"># one-time setup to get 0 and 1 to mean what we expect</div>
<ol>
<li class="li1">
<div class="de1">gpioctl -q -c <span class="nu0">6</span> out iout</div>
</li>
<li class="li1">
<div class="de1">gpioctl -q -c <span class="nu0">25</span> out iout</div>
</li>
<li class="li1">
<div class="de1">gpioctl -q -c <span class="nu0">27</span> out iout</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">gpioctl -q <span class="nu0">6</span> <span class="br0">&#91;</span><span class="nu0">0</span><span class="sy0">/</span><span class="nu0">1</span><span class="br0">&#93;</span> &nbsp; &nbsp;<span class="co0"># for the left-most LED</span></div>
</li>
<li class="li1">
<div class="de1">gpioctl -q <span class="nu0">25</span> <span class="br0">&#91;</span><span class="nu0">0</span><span class="sy0">/</span><span class="nu0">1</span><span class="br0">&#93;</span> &nbsp; <span class="co0"># for the middle LED</span></div>
</li>
<li class="li1">
<div class="de1">gpioctl -q <span class="nu0">27</span> <span class="br0">&#91;</span><span class="nu0">0</span><span class="sy0">/</span><span class="nu0">1</span><span class="br0">&#93;</span> &nbsp; <span class="co0"># for the right-most LED</span></div>
</li>
</ol>
</div>
<p>That&#8217;s pretty easy, but it&#8217;s just on and off (though it does require privileged access to control the GPIO pins).  Poking around on the web today, though, I found <a href="http://www.semicomplete.com/blog/geekery/soekris-gpio.html">Jordan Sissel&#8217;s blog post on making the Soekris net4501&#8242;s LEDs do the Apple-style pulsing fade-in-out</a>.  <a href="http://www.semicomplete.com/files/blogposts/20080106/glow.c">His C program</a> didn&#8217;t work straight away on my Alix, perhaps because he was working on FreeBSD and I&#8217;m using OpenBSD, but with a little digging in <a href="ftp://ftp.openbsd.org/pub/OpenBSD/src/usr.sbin/gpioctl/gpioctl.c">the OpenBSD source code for gpioctl</a>, I was able to cobble together some C code to replace his &#8220;led&#8221; function that set the state of the LED as well as the device initialization.  With a little tweaking to make the code feel more like my own and to make the LED pulse just once (the original code pulsed indefinitely), I arrived at <a href="http://2718.us/blog/wp-content/uploads/2008/05/pulse_led2_once.c">pulse_led2_once.c</a> (which still must be run as root to work, since it uses the GPIO interface).</p>
<p><span style="font-size: smaller"><strong>NOTE</strong>:  This file is provided &#8220;as is&#8221; and is not guaranteed to do anything at all, including not guaranteed to be safe to run.  It worked for me, YMMV.  I&#8217;ve posted my modifications having asked Jordan Sissel first; I&#8217;d appreciate it if you&#8217;d let me know if you wanted to post modifications to my code.  AFAIK, my inclusion of OpenBSD source was done in compliance with the copyright notice in their source file, reproduced as requested by the code I used.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://2718.us/blog/2008/05/25/pulsing-the-alix-leds/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

