add mcu_sleep routines
This commit is contained in:
parent
743245e230
commit
9a3c6adf8d
|
@ -54,6 +54,34 @@
|
|||
#include "adc.h"
|
||||
#include "hw-arduino.h"
|
||||
|
||||
extern volatile uint8_t mcusleepcycle;
|
||||
volatile uint8_t mcusleepcycleval;
|
||||
|
||||
/*-------------- enabled sleep mode ----------------------------------------*/
|
||||
void
|
||||
mcu_sleep_init(void)
|
||||
{
|
||||
mcusleepcycleval=mcusleepcycle;
|
||||
}
|
||||
void
|
||||
mcu_sleep_on(void)
|
||||
{
|
||||
mcusleepcycle= mcusleepcycleval;
|
||||
}
|
||||
/*--------------- disable sleep mode ---------------------------------------*/
|
||||
void
|
||||
mcu_sleep_off(void)
|
||||
{
|
||||
mcusleepcycle=0;
|
||||
}
|
||||
/*---------------- set duty cycle value ------------------------------------*/
|
||||
void
|
||||
mcu_sleep_set(uint8_t value)
|
||||
{
|
||||
mcusleepcycleval= value;
|
||||
mcusleepcycle = mcusleepcycleval;
|
||||
}
|
||||
|
||||
PROCESS(arduino_sketch, "Arduino Sketch Wrapper");
|
||||
|
||||
#ifndef LOOP_INTERVAL
|
||||
|
@ -65,8 +93,8 @@ PROCESS_THREAD(arduino_sketch, ev, data)
|
|||
static struct etimer loop_periodic_timer;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
adc_init ();
|
||||
mcu_sleep_init ();
|
||||
setup ();
|
||||
/* Define application-specific events here. */
|
||||
etimer_set(&loop_periodic_timer, LOOP_INTERVAL);
|
||||
|
|
|
@ -51,6 +51,13 @@
|
|||
|
||||
#include "contiki.h"
|
||||
|
||||
/*--------------- enable sleep mode ---------------------------------------*/
|
||||
void mcu_sleep_on(void);
|
||||
/*--------------- disable sleep mode ---------------------------------------*/
|
||||
void mcu_sleep_off(void);
|
||||
/*---------------- set sleep value ------------------------------------*/
|
||||
void mcu_sleep_set(uint8_t value);
|
||||
|
||||
extern void loop (void);
|
||||
extern void setup (void);
|
||||
extern void arduino_init (void);
|
||||
|
|
|
@ -17,12 +17,10 @@
|
|||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#include "arduino-process.h"
|
||||
#include "rest-engine.h"
|
||||
#include "sketch.h"
|
||||
|
||||
extern volatile uint8_t mcusleepcycle; // default 16
|
||||
|
||||
// Data wire is plugged into port 2 on the Arduino
|
||||
#define ONE_WIRE_BUS 3
|
||||
#define TEMPERATURE_PRECISION 9
|
||||
|
@ -130,7 +128,7 @@ void setup (void)
|
|||
// LOOP_INTERVAL (20 * CLOCK_SECOND)
|
||||
void loop (void)
|
||||
{
|
||||
mcusleepcycle=0; // dont sleep
|
||||
mcu_sleep_off();
|
||||
// call sensors.requestTemperatures() to issue a global temperature
|
||||
// request to all devices on the bus
|
||||
// printf("Requesting temperatures...");
|
||||
|
@ -156,5 +154,5 @@ void loop (void)
|
|||
printf("Temp: %s",htu21d_temp_s);
|
||||
printf("\t\tHum: %s\n",htu21d_hum_s);
|
||||
|
||||
mcusleepcycle=32; // sleep, wakeup every 32 cycles
|
||||
mcu_sleep_on();
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#include "arduino-process.h"
|
||||
#include "rest-engine.h"
|
||||
#include "sketch.h"
|
||||
|
||||
|
@ -161,7 +161,7 @@ void setup (void)
|
|||
// LOOP_INTERVAL (10 * CLOCK_SECOND)
|
||||
void loop (void)
|
||||
{
|
||||
mcusleepcycle=0; // dont sleep
|
||||
mcu_sleep_off();
|
||||
// call sensors.requestTemperatures() to issue a global temperature
|
||||
// request to all devices on the bus
|
||||
printf("Requesting temperatures...");
|
||||
|
@ -171,7 +171,7 @@ void loop (void)
|
|||
// print the device information
|
||||
printData(insideThermometer,0);
|
||||
printData(outsideThermometer,1);
|
||||
mcusleepcycle=32; // sleep, wakeup every 32 cycles
|
||||
mcu_sleep_on();
|
||||
|
||||
// debug only
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "arduino-process.h"
|
||||
#include "sketch.h"
|
||||
#include "rest-engine.h"
|
||||
#include "net/netstack.h"
|
||||
|
||||
extern volatile uint8_t mcusleepcycle; // default 16
|
||||
extern resource_t res_battery, res_distance;
|
||||
#define LED_PIN 4 /* LED Pin */
|
||||
|
||||
|
@ -39,8 +39,8 @@ void setup (void)
|
|||
|
||||
void loop (void)
|
||||
{
|
||||
mcusleepcycle=0; // dont sleep
|
||||
mcu_sleep_off();
|
||||
|
||||
mcusleepcycle=16; // sleep, wakeup every 32 cycles
|
||||
mcu_sleep_on();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "arduino-process.h"
|
||||
#include "rest-engine.h"
|
||||
|
||||
extern resource_t res_door, res_battery;
|
||||
|
@ -29,9 +30,12 @@ void setup (void)
|
|||
rest_init_engine ();
|
||||
rest_activate_resource (&res_door, "s/door");
|
||||
rest_activate_resource (&res_battery, "s/battery");
|
||||
// NETSTACK_MAC.off(1);
|
||||
}
|
||||
|
||||
void loop (void)
|
||||
{
|
||||
mcu_sleep_off();
|
||||
|
||||
mcu_sleep_on();
|
||||
}
|
||||
|
|
|
@ -14,12 +14,9 @@
|
|||
#include "Adafruit_HTU21DF.h"
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
#include "arduino-process.h"
|
||||
#include "rest-engine.h"
|
||||
|
||||
extern volatile uint8_t mcusleepcycle; // default 16
|
||||
|
||||
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
|
||||
|
||||
extern resource_t res_htu21dtemp, res_htu21dhum, res_battery;
|
||||
|
@ -51,12 +48,12 @@ void setup (void)
|
|||
// LOOP_INTERVAL (10 * CLOCK_SECOND)
|
||||
void loop (void)
|
||||
{
|
||||
mcusleepcycle=0; // dont sleep
|
||||
mcu_sleep_off();
|
||||
htu21d_temp = htu.readTemperature();
|
||||
htu21d_hum = htu.readHumidity();
|
||||
mcusleepcycle=32; // sleep, wakeup every 32 cycles
|
||||
mcu_sleep_on();
|
||||
dtostrf(htu21d_temp , 6, 2, htu21d_temp_s );
|
||||
dtostrf(htu21d_hum , 6, 2, htu21d_hum_s );
|
||||
tostrf(htu21d_hum , 6, 2, htu21d_hum_s );
|
||||
// remove space
|
||||
if(htu21d_temp_s[0]==' '){
|
||||
memcpy (htu21d_temp_s,htu21d_temp_s+1,strlen(htu21d_temp_s)+1);
|
||||
|
|
|
@ -11,11 +11,10 @@
|
|||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "arduino-process.h"
|
||||
#include "rest-engine.h"
|
||||
#include "net/netstack.h"
|
||||
|
||||
extern volatile uint8_t mcusleepcycle; // default 16
|
||||
|
||||
extern resource_t res_leds, res_battery, res_cputemp;
|
||||
uint8_t door_pin = 3;
|
||||
uint8_t door_status = 0;
|
||||
|
@ -39,7 +38,7 @@ void setup (void)
|
|||
|
||||
void loop (void)
|
||||
{
|
||||
mcusleepcycle=0;
|
||||
mcu_sleep_off();
|
||||
|
||||
mcusleepcycle=16;
|
||||
mcu_sleep_on();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "arduino-process.h"
|
||||
#include "rest-engine.h"
|
||||
|
||||
extern volatile uint8_t mcusleepcycle; // default 16
|
||||
|
@ -37,12 +38,12 @@ void setup (void)
|
|||
|
||||
void loop (void)
|
||||
{
|
||||
mcusleepcycle=0; // dont sleep
|
||||
mcu_sleep_off();
|
||||
moisture_voltage = analogRead(moisture_pin);
|
||||
if(moisture_voltage < 800){
|
||||
digitalWrite(BUZZER_PIN, LOW);
|
||||
}else{
|
||||
digitalWrite(BUZZER_PIN, HIGH);
|
||||
}
|
||||
mcusleepcycle=32; // sleep, wakeup every 32 cycles
|
||||
mcu_sleep_on();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue