 
   BMPSetup();
 
+  sleepPeriod = SLEEP_8S;
+
   Serial.println("Initialisation complete.");
   delay(100); //Allow for serial print to complete.
 }


  // Get the baseline pressure:
  
  baseline = getPressure();
}



struct state;
typedef void state_fn(struct state *);

struct state
{
    state_fn * next;
//    int i; // data
    enum period_t sleepPeriod; // how long the processor should sleep for the state
    float baseAltitude; // altitude, in m, above MSL == 0 AGL
};

state_fn foo, bar;

void foo(struct state * state)
{
    Serial.println(__func__);
    state->next = bar;
}

void bar(struct state * state)
{
    Serial.println( __func__);
    state->next = foo;
}

struct state state = { foo, SLEEP_8S };


/***************************************************
 *  Name:        setup

 ***************************************************/
void loop()
{
  double currentPressure, currentAltitude;
  
  /* Toggle the LED */
  digitalWrite(LED_PIN, HIGH);

  currentPressure = getPressure();
  currentAltitude = pressure.altitude(currentPressure, basePressure);

  if (currentAltitude < 2 && currentAltitude > -2) {
    sleepPeriod = SLEEP_8S;
    // consider this noise, set as base
    basePressure = currentPressure;
  } else {
    // we're in the air
    sleepPeriod = SLEEP_1S;

    // human falls at 53 m/s
    // open canopy, full flight 5 m/s
    // refresh rate is 1 s on arduino
    while (previousAltitude - currentAltitude > 35 && // m/s
           currentAltitude < 1370) { // 4500 ft
      // beep and wait for slowing down
      tone(2, 2048);
      LowPower.powerSave(SLEEP_1S, ADC_OFF, BOD_ON, TIMER2_ON);
      noTone(2);
    }
  }
  
  previousPressure = currentPressure;
  previousAltitude = currentAltitude;

  digitalWrite(LED_PIN, LOW);
  
  LowPower.powerDown(sleepPeriod, ADC_OFF, BOD_ON);
}



