Skip to content

Commit

Permalink
update - see revision.md
Browse files Browse the repository at this point in the history
  • Loading branch information
duff2013 committed Apr 15, 2020
1 parent 2931bf3 commit c81b9e9
Show file tree
Hide file tree
Showing 39 changed files with 3,391 additions and 435 deletions.
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016
Copyright (c) 2020

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
19 changes: 13 additions & 6 deletions README.md
@@ -1,12 +1,12 @@
# Snooze v6.3.6
# Snooze v6.3.7

---
Low power library for the Teensy LC/3.2/3.5/3.6/4.0 class microcontrollers.
---
***
This is a maintenance update because of a change in the new class structure which the main Snooze Class is now decoupled from the Drivers and HAL. Now sleep*, deepSleepand hibernate work with T_LC and 3.x. Now the T_LC/36 Driver "Touch" works in "sleep" mode.
Teensy 4.0 v1 update!

Work on the Teensy 4.0 is continuing.
This is a maintenance update because of a change in the new class structure which the main Snooze Class is now decoupled from the Drivers and HAL. Now sleep*, deepSleepand hibernate work with T_LC and 3.x. Now the T_LC/36 Driver "Touch" works in "sleep" mode.

* not all drivers work in "sleep" yet.
***
Expand All @@ -25,6 +25,9 @@ pinMode(LED_BUILTIN, OUTPUT);
Define digital pins for waking the teensy up. This
combines pinMode and attachInterrupt in one function.
Teensy 4.0
Digtal pins: all pins
Teensy 3.x
Digital pins: 2,4,6,7,9,10,11,13,16,21,22,26,30,33
Expand All @@ -48,9 +51,9 @@ digitalWrite(LED_BUILTIN, LOW);
```

Current Divers:
1. touch - Using the Kinetis touch module to wake your Teensy. (Teensy 3.5 does not have Touch)
1. touch - Using the Kinetis touch module to wake your Teensy. (Teensy 3.5/4.0 does not have Touch)
2. digital - Wake your Teensy with a RISING or FALLING event on a certain pin.
3. timer - Use the Low Power timer in milliseconds to wake your Teensy,
3. timer - Use the Low Power timer in milliseconds T3.x/LC, seconds T4.x to wake your Teensy,
4. alarm - Use the RTC clock to wake your Teensy.
5. compare - Setup a voltage crossing to wake your Teensy.
6. usbSerial - Does not wake the teensy it makes USB Serial play nice while using Snooze.
Expand All @@ -71,12 +74,16 @@ SnoozeBlock config(timer, digital);
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
/********************************************************
* Set Low Power Timer wake up in milliseconds.
* Set Low Power Timer wake up in milliseconds T3.x/LC,
* seconds T4.x.
********************************************************/
timer.setTimer(5000);// milliseconds
/********************************************************
* Define digital pins for waking the teensy up. This
* combines pinMode and attachInterrupt in one function.
*
* Teensy 4.0
* Digtal pins: all pins
*
* Teensy 3.x
* Digital pins: 2,4,6,7,9,10,11,13,16,21,22,26,30,33
Expand Down
6 changes: 3 additions & 3 deletions examples/SkeletonDriverClass/SnoozeSkeletonDriverClass.cpp
Expand Up @@ -2,7 +2,7 @@
/*
*/
void SnoozeSkeletonDriverClass::enableDriver( void ) {
void SnoozeSkeletonDriverClass::enableDriver( uint8_t mode ) {
// This function gets called before any sleep or
// low power operation from the Snooze Class.

Expand All @@ -25,7 +25,7 @@ void SnoozeSkeletonDriverClass::enableDriver( void ) {
/*
*/
void SnoozeSkeletonDriverClass::disableDriver( void ) {
void SnoozeSkeletonDriverClass::disableDriver( uint8_t mode ) {
// This function gets called after any sleep or
// low power operation from the Snooze Class.

Expand All @@ -50,7 +50,7 @@ void SnoozeSkeletonDriverClass::disableDriver( void ) {
/*
*/
void SnoozeSkeletonDriverClass::clearIsrFlags( void ) {
void SnoozeSkeletonDriverClass::clearIsrFlags( uint8_t mode ) {
// This function gets called from wakeup Isr, you clear
// any module flags that need to cleared here.

Expand Down
6 changes: 3 additions & 3 deletions examples/SkeletonDriverClass/SnoozeSkeletonDriverClass.h
Expand Up @@ -6,9 +6,9 @@

class SnoozeSkeletonDriverClass : public SnoozeBlock {
private:
virtual void disableDriver( void );
virtual void enableDriver( void );
virtual void clearIsrFlags( void );
virtual void disableDriver( uint8_t mode );
virtual void enableDriver( uint8_t mode );
virtual void clearIsrFlags( uint8_t mode );
volatile uint32_t save_pin_config;
int digital_pin;

Expand Down
Expand Up @@ -5,9 +5,10 @@
(pin 21) which will wake the Teensy and start logging data until
the button is released in which the Teensy will go back into
deepSleep.
The SPI Driver configures the SDIO or SPI pins to minimize leakage
current during deepSleep and reconfigure the pins back after waking.
The SPI Driver configures the SDIO or SPI pins to minimize
leakage current during deepSleep and reconfigure the pins
back after wake up.
*/

/***********************************************************
Expand Down Expand Up @@ -56,7 +57,7 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT);
// Configure pin 21 for bounce library
pinMode(21, INPUT_PULLUP);

/******************Snooze Driver Config******************/
// Configure pin 21 for Snooze wakeup, also used by bounce
// but no need to reconfigure the pin after waking Snooze
Expand All @@ -65,16 +66,17 @@ void setup() {
// Configure SD Card for Low Power operation
sdCard.setClockPin( BUILTIN_SDCARD );
/****************End Snooze Driver Config****************/

//UNCOMMENT THESE TWO LINES FOR TEENSY AUDIO BOARD:
//SPI.setMOSI(7); // Audio shield has MOSI on pin 7
//SPI.setSCK(14); // Audio shield has SCK on pin 14

// wait for port to open:
while (!Serial);
delay(100);

Serial.print("Snooze SD Card Push Button Hold Data-Logger Example");

Serial.println("Snooze SD Card Push Button Hold Data-Logger Example");
Serial.println("---------------------------------------------------");
// see if the card is present and can be initialized:
SD.begin(chipSelect);
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Expand Down Expand Up @@ -120,7 +122,7 @@ inline void sleepDataLogger() {
while (!Serial || time < 100) {
// print out a bunch of NULLS to serial monitor
Serial.write(0x00);
delay(5);
//delay(5);
}
// normal delay for Arduino Serial Monitor to connect to pc
delay(100);
Expand All @@ -147,7 +149,7 @@ void handleButtonHold() {
}
// ----------------------------------------------------------------------------------------------
void logData(uint32_t count) {

// make a string for assembling the data to log:
String dataString;// = st;//"Time\tAna1\tAna2\tAna3\r\n";
// read three sensors and append to the string:
Expand All @@ -163,7 +165,7 @@ void logData(uint32_t count) {
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("datalog.txt", FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
dataFile.print(dataString);
Expand Down Expand Up @@ -193,13 +195,13 @@ void sdCardInfo() {
default:
Serial.println("Unknown");
}

// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
return;
}

// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Expand All @@ -220,10 +222,10 @@ void sdCardInfo() {
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;
Serial.println(volumesize);

Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);

// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
delay(100);
Expand All @@ -244,27 +246,27 @@ time_t getTeensy3Time() {
}

String digitalClockDisplay(elapsedMillis millis_t) {

String time;

if (hour() < 10) time += 0;
//< 10 ? '0' + hour() : hour();
time += hour() ;
time += ":";

if (minute() < 10) time += 0;
//< 10 ? '0' + minute() : minute();
time += minute() ;
time += ":";

if (second() < 10) time += 0;
time += second();
time += ".";

if (millis_t < 100) time += 0;
if (millis_t < 10) time += 0;
time += (int)millis_t;

return time;
}
// ----------------------------------------------------------------------------------------------
Expand Down
38 changes: 19 additions & 19 deletions examples/deepsleep/button_hold_wakeup/button_hold_wakeup.ino
@@ -1,8 +1,8 @@
/*************************************************
This example is used when you want to simulate a
button being held for certian amount of time
button being held for a certian amount of time
before waking your Teensy from deepSleep sleep.
This example uses the Bounce library to make sure
the button is still pressed for 3 seconds after
waking up from low power mode. If it released
Expand All @@ -22,8 +22,8 @@ Snoozelc5vBuffer lc5vBuffer;
Bounce button = Bounce(21, 5);

// install driver into SnoozeBlock
#if defined(__MK66FX1M0__) || defined(__MK64FX512__) || defined(__MK20DX256__)
SnoozeBlock config_teensy3x(digital);
#if defined(__IMXRT1062__) || defined(__MK66FX1M0__) || defined(__MK64FX512__) || defined(__MK20DX256__)
SnoozeBlock config_teensy(digital);
#elif defined(__MKL26Z64__)
SnoozeBlock config_teensyLC(digital, lc5vBuffer);
#endif
Expand All @@ -46,45 +46,45 @@ void loop() {
SLEEP:
// you need to update before sleeping.
button.update();

// returns module that woke processor after waking from low power mode.
#if defined(__MK66FX1M0__) || defined(__MK64FX512__) || defined(__MK20DX256__)
Snooze.deepSleep( config_teensy3x );
#if defined(__IMXRT1062__) || defined(__MK66FX1M0__) || defined(__MK64FX512__) || defined(__MK20DX256__)
Snooze.deepSleep( config_teensy );
#elif defined(__MKL26Z64__)
Snooze.deepSleep( config_teensyLC );
#endif

// indicate the button woke it up, hold led high for as long as the button
// is held down.
digitalWrite(LED_BUILTIN, HIGH);

elapsedMillis timeout = 0;
// bounce needs to call update longer than the debounce time = 5ms,
// which is set in constructor.
while (timeout < 6) button.update();

// now check for 3 second button hold
bool awake = threeSecondHold();

// if not held for 3 seconds go back to sleep
if (!awake) goto SLEEP;

// the button was held for at least 3 seconds if
// you get here do some stuff for 7 seconds then
// go to sleep.
elapsedMillis time = 0;

while (1) {
unsigned int t = time;
Serial.printf("doin stuff for: %i milliseconds\n", t);

// back to sleep after 7 seconds
if (time > 7000) {
Serial.println("sleeping now :)");

// little delay so serial can finish sending
delay(5);

goto SLEEP;
}
digitalWrite(LED_BUILTIN, HIGH);
Expand All @@ -97,10 +97,10 @@ SLEEP:
bool threeSecondHold() {
// this is the 3 sec button press check
while (button.duration() < 3000) {

// get the current pin state, must have this!
button.update();

// check the pin 2 state, if button not
// pressed before 3 seconds go back to
// sleep. We read 0 since pin 2 is
Expand All @@ -112,7 +112,7 @@ bool threeSecondHold() {
}
}
digitalWrite(LED_BUILTIN, LOW);

// button was held for 3 seconds so now we are awake
return true;
}

0 comments on commit c81b9e9

Please sign in to comment.