Skip to content

Software Overview

Thomas edited this page Nov 4, 2017 · 1 revision

A scripting language for a thermostat

This project builds a scripting language for W1209 thermostats. The scripting language is Forth based, but that doesn't mean that you need to know much Forth to get something done (the goal is that you don't need to know it's Forth).

To do achieve this, a simple "processing" pattern is applied: linear data flow.

\ background task with temperature control
: task ( -- )
  measure            \ measure temperature
  control            \ temperature control
  logger             \ data logging
  menu               \ menu and display code
;

Like in jQuery, one can chain "filters" if the data type of "output" matches the "input". In the case of a thermostat that's easy: it's all about temperature.

The other part is that "chainable" filters are self-contained units, a basic modular programming techniques.

The chained init function uses a feature of eForth: when redefined a word, the old word can still be called in the new definition:

\ chained init - starting point
: init ( -- )
;
#include measure.fs
#include control.fs
#include logger.fs
#include menu.fs

In a module, e.g. measure, the initialization looks like this:

\ chained init
: init ( -- ) init
  \ init LPF state with max. value
  dig2temp2 DUP @ 1- 2* 1+ + @ LPFDIG !
;

The word init first calls the init word of the previous module, and the complicated part, e.g. filter initialization, is nicely hidden.

An important feature of e4thcom is the file search order. The file search path is: "cwd:cwd/mcu:cwd/target:cwd/lib" (cwd = current working directory). The standard filter words of the thermostat application are in the main folder. In an application. If required, library words can be transparently replaced with a modified version without the need to change the library.