I have been working on stuff in latex recently and wanted something to trigger
regeneration of pdfs without manual intervention. At first I thought about
doing so in a loop every so often, but it didn't seem like the best approach.
Knowing about the cool
kqueue
framework I looked to see if there was a
utility to watch files for me. I found the
wait_on
command via a FreeBSD
forums post.
The wait
on command will wait until the watched file has been changed and then
exit. It is meant to be used within a loop. I through this together in zsh. Now
when I :wq in vim wait
on exists and my document rebuilds, evinces picks up on
this and refreshes the display.
$ while true; do wait_on pres.tex; xelatex pres.tex; sleep 5; done
I have the sleep at the end to stop the document being built too often.
I have just finished reading
Cryptonomicon
, without any spoilers I can say
that at a certain point a character controls the led's on his keyboard. This
morning I found the
kbdled
utility via a forum post. It looks like a nice
simple way to make the keyboard do something useful.
As I write this there are not any packages available for FreeBSD arm. That
means on the Raspberry Pi I have to build the things I need from ports. Ports
gives a lot of control about how the software is built, but right now I just
want the tools I need installed.
It is hard to set up ports to install a collection of tools in a oner, but we
can use portmaster to do this for us. The Pi is quite slow and will take a long
time to build a small number of tools and their dependencies.
Normally portmaster will prompt for configuration for each package as it
builds, it will then build a list of packages and prompt again to install these.
The following line will install the listed tools without any prompting.
$ portmaster -mBATCH=yes --no-confirm -y sysutils/tmux editors/vim
-
The -m flag will pass options to make
-
--no-confirm will disable the 'install' prompt
-
-y will answer yes to any prompts
I finally got all the components to use the bag of electret microphones I got
last year. Using a LM36 audio amp I set up a
simple circuit
to read values
from the microphone and set LED's corresponding to the value read.
I had trouble finding a solid example of doing analog reads in a loop for the
msp430. This program, sets up LED's(On P1.1 and P1.6), sets up the ADC, then
sits in a loop. If the value on the ADC is grater than 512 the LED will go red.
I tested this by shouting at the micro controller, something I have done many
times before, but never with such satisfying results.
#include <msp430g2553.h>
unsigned int adcvalue = 0;
void configureADC(void);
int
main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Stop the Watch dog
P1DIR |= 0x41; //Enabled P1.0 and P1.6
P1OUT = 0x41;
BCSCTL1 = CALBC1_1MHZ; //Set range
BCSCTL2 &= CALBC1_1MHZ; //SMCLK = DCO = 1MHz
P1SEL |= BIT3;
configureADC();
__enable_interrupt();
while(1) {
__delay_cycles(20000);
ADC10CTL0 |= ENC + ADC10SC; //Sampling and conversion start
adcvalue = ADC10MEM; //Read from the ADC
if(adcvalue > 512)
P1OUT = 0x40;
else
P1OUT = 0x01;
}
return 0;
}
void
configureADC(void)
{
ADC10CTL1 = INCH_3 + ADC10DIV_3;
ADC10CTL0 = SREF_0 + ADC10SHT_3 + ADC10ON + ADC10IE;
ADC10AE0 |= BIT3;
}
The cool thing we get with the msp430 and the Launchpad is on chip debugging.
This goes a long way to pave over the warts of writing straight C for the 430.
We will load up the blink program from
last time
, run it with the debugger
and pause execution.
Start up mspdebug as before, this time we pass a command for mspdebug to run
directly. The "gdb" command will cause mspdebug to listen on port 2000, gdb can
then connect and control the debugger.
$ mspdebug rf2500 "gdb"
Next we are going to start up msp430-gdb, load the program from before and
start it running.
$ msp430-gdb
(gdb) target remote localhost:2000
(gdb) file led.elf
(gdb) load led.elf
(gdb) continue
^C
(gdb) break main.c:14
(gdb) c #We can shorthand commands
Now between each continue we will see the LED's toggle, red then green.
(gdb) continue
From gdb we can send mspdebug directly with the monitor command.