Skip to content

Commit

Permalink
update versione 1.0.4
Browse files Browse the repository at this point in the history
Update including a doList fix, new macro, pin settings and new examples.
  • Loading branch information
filoconnesso committed Aug 29, 2022
1 parent 0520812 commit 5713534
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 41 deletions.
57 changes: 57 additions & 0 deletions examples/13.Pads/Adjust_Timer/Adjust_Timer.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
*
* ADJUST TIMER TO PAD EXAMPLE FOR TWEAKLY
* Created By Mirko Pacioni
*
* Functionality to straighten the timing of the pads,
* if you need to customize and optimize the response times of events on the pads, you can use the padSettings object.
*
*/
#include "Tweakly.h"

//Create button Pad
Pad button(8, INPUT);

padSettings myButtonSettings;

void setup() {

//Start serial
Serial.begin(115200);

//Set the debouncing time to 25 milliseconds.
myButtonSettings.debounceTimer = 25;

//Set the double click event timeout to 400 millisecons.
myButtonSettings.doubleClickTimer = 400;

//Set the long press time to 2000 milliseconds.
//Tweakly automatically corrects the relationship between the double click timer from the moment
//it recognizes that a long double click is being performed. (long click timer - double click timeout)
myButtonSettings.longPressTimer = 2000;

//Applies the settings contained in myButtonSettings to the button.
button.adjust(myButtonSettings);

//Attach click event to button Pad
button.onEvent(CLICK, [] {
Serial.println("click!");
});

//Attach double click event to button Pad
button.onEvent(DOUBLE_CLICK, [] {
Serial.println("double click!");
});

//Attach long press event to button Pad
button.onEvent(LONG_PRESS, [] {
Serial.println("long press!");
});

}

void loop() {
//Call Tweakly for ever
TweaklyRun();
//Put your code here :-)
}
60 changes: 60 additions & 0 deletions examples/13.Pads/Pad_Events/Pad_Events.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
*
* PAD EVENTS EXAMPLE FOR TWEAKLY
* Created By Mirko Pacioni
*
* Tweakly monitors events on pins,
* this is a modern feature that allows you to perform an operation when a pin's state changes.
*
*/
#include "Tweakly.h"

//Create button Pad
Pad button(12, INPUT_PULLUP);

//Create led Pad
Pad led(13);

void setup() {

//Start serial
Serial.begin(115200);

//Attach click event to button Pad
button.onEvent(CLICK, [] {
Serial.println("click!");
led.toggle();
});

//Attach double click event to button Pad
button.onEvent(DOUBLE_CLICK, [] {
Serial.println("double click!");
});

//Attach long press event to button Pad
button.onEvent(LONG_PRESS, [] {
Serial.println("long press!");
});

//Attach release event to button Pad
button.onEvent(RELEASE, [] {
Serial.println("release!");
});

//Attach To On Event to led Pad
led.onEvent(TO_ON, [] {
Serial.println("led on!");
});

//Attach To Off Event to led Pad
led.onEvent(TO_OFF, [] {
Serial.println("led off!");
});

}

void loop() {
//Call Tweakly for ever
TweaklyRun();
//Put your code here :-)
}
48 changes: 48 additions & 0 deletions examples/14.Macros/rollup/rollup.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
*
* ROLLUP EXAMPLE (BLINK) FOR TWEAKLY
* Created By Mirko Pacioni
*
* The rollup macro allows you to turn off a portion of code within the loop for a certain period of time.
* Tweakly Rollup is a non-blocking alternative to classic delay.
* to rewind the desired portion of code, the time to be controlled must be indicated with the sleep_for(milliseconds) macro.
*
*/
#include "Tweakly.h"

//Create led Pad
Pad led(6);

void setup() {

//Start serial
Serial.begin(115200);

}

void loop() {
//Call Tweakly for ever
TweaklyRun();

//Start rollup
//The first rollup interrupts part of the code for 1000 milliseconds,
//when the time is exceeded the current state of the LED is switched.
TWEAKLY_ROLLUP
sleep_for(1000);
led.toggle();
END_ROLLUP
//Finish rollup

//Start rollup
//The second rollup prints the current status of the LED every 3000 milliseconds.
TWEAKLY_ROLLUP
sleep_for(3000);
Serial.print("led status = ");
Serial.print(led.read());
Serial.print("\n");
END_ROLLUP
//Finish rollup

//Your code continues without interruption
//Put your code here :-)
}
15 changes: 15 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Echo KEYWORD1
Player KEYWORD1
Clock KEYWORD1
Pong KEYWORD1
Async KEYWORD1
padSettings KEYWORD1

#######################################
# Methods and Functions
Expand Down Expand Up @@ -77,6 +79,12 @@ value KEYWORD2
startWatch KEYWORD2
stopWatch KEYWORD2
getWatchTime KEYWORD2
sleep_for KEYWORD2
longPressTimer KEYWORD2
doubleClickTimer KEYWORD2
debounceTimer KEYWORD2
adjust KEYWORD2
back KEYWORD2

#######################################
# ESP32 Methods and Functions
Expand Down Expand Up @@ -223,3 +231,10 @@ NOTE_CS8 LITERAL1
NOTE_D8 LITERAL1
NOTE_DS8 LITERAL1
NOTE_END LITERAL1

#######################################
# Macros
#######################################

TWEAKLY_ROLLUP KEYWORD3 RESERVED_WORD
END_ROLLUP KEYWORD3 RESERVED_WORD
6 changes: 6 additions & 0 deletions src/Tweakly.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ using namespace std;
#include "core/clock.h"
#include "core/string.h"
#include "core/numbers.h"
#include "core/macros.h"

using namespace tweaklypads;
using namespace tweaklyticktimers;
using namespace tweaklypolyphonic;
using namespace tweaklyclock;
using namespace tweaklystring;
using namespace tweaklynumbers;
using namespace asyncer;

//Include peripherals libs
#include "peripherals/sonar.h"
Expand All @@ -90,6 +92,8 @@ void TweaklyRun(){
//peripherals
sonar::Setup();
encoder::Setup();
//Tweakly statements
asyncer::Setup();
_tweakly_ready = true;
} else {
//core
Expand All @@ -100,6 +104,8 @@ void TweaklyRun(){
//peripherals
sonar::Loop();
encoder::Loop();
//Tweakly statements
asyncer::Loop();
}
}

Expand Down
59 changes: 43 additions & 16 deletions src/apps/TweaklyApps/doList/doList.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#ifndef DOLIST_H
#define DOLIST_H

#include "Arduino.h"

namespace dolist {

//Variables
Expand All @@ -42,34 +44,42 @@ namespace dolist {

//Enablers
volatile bool _list_exists { false };

// Struct required for lists
struct _lists{
uint16_t _list_index;
uint16_t _functions_counter;
_list_callback _function_callback;
_lists * _next_function = NULL;
uint16_t _list_index;
int _functions_counter;
_list_callback _function_callback;
_lists * _next_function = NULL;
};

_lists *_first_function = NULL, *_last_function = NULL;

_lists *_first_function = NULL;
_lists *_last_function = NULL;

//Class for doList
class doList {
private :
uint16_t _list_position = _lists_counter++;
uint16_t _list_function_position_counter = 0;
uint16_t _functions_counter = 0;
uint16_t _list_position;
int _list_function_position_counter;
int _functions_counter;
public :
doList() {

_list_position = _lists_counter++;
_list_function_position_counter = 0;
_functions_counter = 0;
}
void addTask(_list_callback _function);
void next();
void back();
//operator "++"
doList operator++(int) {
this->next();
return *this;
}
doList operator--(int) {
this->back();
return *this;
}
};

// addTask Function : add tasks to the list
Expand All @@ -89,7 +99,7 @@ namespace dolist {
}
}

// next Function : go to the task in the next list
// next Function : go to the next task
void doList::next(){
if (_list_exists){
for (_lists *_this_function = _first_function; _this_function != NULL; _this_function = _this_function->_next_function){
Expand All @@ -99,10 +109,27 @@ namespace dolist {
}
}
}
this->_list_function_position_counter++;
if(this->_list_function_position_counter >= this->_functions_counter) {
this->_list_function_position_counter = 0;
}
this->_list_function_position_counter++;
if(this->_list_function_position_counter > this->_functions_counter - 1) {
this->_list_function_position_counter = 0;
}
}
}

// back Functions : go to the previous task
void doList::back(){
if (_list_exists){
for (_lists *_this_function = _first_function; _this_function != NULL; _this_function = _this_function->_next_function){
if (this->_list_position == _this_function->_list_index){
if(_this_function->_functions_counter == this->_list_function_position_counter) {
_this_function->_function_callback();
}
}
}
this->_list_function_position_counter--;
if(this->_list_function_position_counter < 0) {
this->_list_function_position_counter = this->_functions_counter - 1;
}
}
}

Expand Down
Loading

0 comments on commit 5713534

Please sign in to comment.