Contributing to the Sensor Library

This is suggested style guide for submitting sensor interfaces for inclusion in the uLisp Sensor Library.

Please submit sensor interfaces for inclusion to the uLisp forum.

Scope

My belief is that the interface routines should be designed to be as simple as possible, adopting default settings to keep the functions short.

Where there are additional settings, these should be provided by a separate optional function, rather than making the main function try and cater for everything.

Naming

Each function should be named with a short version of the sensor part number, followed by -init for the initialisation function, -temp for the temperature function, and so on.

So the functions for the Si7021 Humidity Sensor would be named:

si7021-init, si7021-temp, and si7021-humidity.

This naming convention is designed so you can have multiple sensors installed at once without conflict, even if more than one provides a temperature reading, for example.

Integer or floating-point?

Where possible the routines should be designed to use integer arithmetic, so they can be run on 8/16-bit platforms. For example, this routine for the ADT7410 returns the temperature in sixteenths of a degree:

(defun adt7410-temp ()
  (with-i2c (str #x48) 
    (write-byte 0 str)
    (restart-i2c str 2)
    (let* ((hi (read-byte str))
           (lo (read-byte str))
           (tmp (logior (ash hi 5) (ash lo -3))))
      (- (logand tmp #x0FFF) (logand tmp #x1000)))))

A user who wants the temperature as a floating-point number, in °C, can do:

(/ (adt7410-temp) 16)

Sample output

An example of sample output from the routine should be shown; for example:

> (adt7410-temp)
338

shows that the temperature is 21.125°C.


Previous: Introduction

Next: I2C Port Scanner