SapFlow Probe
A low-cost HRM probe for measuring a tree's water consumption
sapflow_protothread.ino File Reference
#include "pinout.h"
#include "sleep.h"
#include "measure.h"

Functions

void setup ()
 One-time initialization. More...
 
int schedule (struct pt *pt)
 Controls the schedule of heating and sleeping. More...
 
void loop ()
 Implicit loop. More...
 

Variables

struct measure_stack m1 m2
 Persistent variables for measurement.
 
struct pt schedule_thd measure2_thd baseline2_thd delta2_thd
 < Control structure for schedule() thread More...
 

Function Documentation

◆ loop()

void loop ( )

Implicit loop.

This function is called inside a hidden loop in the Arduino framework. We're using it for protothread scheduling. All the real work happens inside the protothreads.

References m2, measure(), and schedule().

◆ schedule()

int schedule ( struct pt *  pt)

Controls the schedule of heating and sleeping.

It waits on each instance of baseline() and delta(), ensuring they each complete before continuing to the next stage. This function is in the main .ino because you will need to modify it when adding additional probes.

This is the schedule:

  1. Measure temperature of tree (before heat is applied)
  2. Apply heat pulse
  3. Wait for the peak of the heat to reach the upper and lower probes.
  4. Measure the sap flow
  5. Sleep until next measurement cycle
    Parameters
    ptA pointer to the protothread control structure.
    Returns
    the status of the protothread (Waiting, yeilded, exited, or ended)

References baseline(), delta(), delta2_thd, HEATER, m2, rtc_ds, and sleep_cycle().

Referenced by loop().

◆ setup()

void setup ( )

One-time initialization.

This function is called when the microcontroller first starts up or is reset. It's good for things that should only happen once. You do not need to call it yourself. It initializes some hardware, puts the protothreads in a known state, and begins the measurement cycle (which starts with sleep)

References measure_stack::addr, hardware_init(), m2, rtc_ds, and measure_stack::treeID.

Variable Documentation

◆ delta2_thd

struct pt schedule_thd measure2_thd baseline2_thd delta2_thd

< Control structure for schedule() thread

< Control structure for measure() thread < Control structure for baseline() thread Control structure for delta() thread

Referenced by schedule().