Tini Bookshelf

Java for Small Spaces
Java on a chip
by Chris Carpenter
Listing 2. Tini Bookshelf.


...
protected OneWireMonitor owm;
...
protected BookObserver observer;
public BookListener(
    DSPortAdapter adapter,
    BookObserver observer)
throws OneWireException,
    OneWireIOException,
    TooManyListenersException {
    this.observer = observer;
    ...
    adapter. getNextDeviceContainer();
    }
}
owm = new OneWireMonitor(adapter);
owm.addEventListener(this);
owm.start();
...
public void oneWireArrival(
   OneWireMonitorEvent owme) {
   System.out.println("Arrival Event: " +
        owme.getDeviceContainer().getName());

   try {
    if ( owme.getDeviceContainer().
    getName().
    equalsIgnoreCase("ds1971")) {
        flashLED();
        observer.newBook( readData(
            owme.getDeviceContainer() ) );
   
   System.out.println("Inserted book: " +
        readData(owme.getDeviceContainer()));
    }
   } catch (OneWireException owe) {
    System.out.println("Caught " + owe);
   }
}
...

About the Author

Chris Carpenter is a software engineer and architect at RoleModel Software, Inc. in Holly Springs, NC. He can be contacted at [email protected].