Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format fix for the selected clang-format #29

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions examples/SwitchCallbackExample/SwitchCallbackExample.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,35 @@ const byte multiresponseButtonpin = 9;
Switch toggleSwitch = Switch(toggleSwitchpin);
Switch multiresponseButton = Switch(multiresponseButtonpin);

void buttonCallbackFunction(void *s) {
Serial.print("Button: ");
Serial.println((char *)s);
void buttonCallbackFunction(void* s)
{
Serial.print("Button: ");
Serial.println((char*)s);
}

void toggleCallbackFunction(void *s) {
Serial.print("Toggle: ");
Serial.println((char *)s);
void toggleCallbackFunction(void* s)
{
Serial.print("Toggle: ");
Serial.println((char*)s);
}

void setup() {
Serial.begin(9600);
toggleSwitch.setPushedCallback(&toggleCallbackFunction, (void *)"turned on");
toggleSwitch.setReleasedCallback(&toggleCallbackFunction,
(void *)"turned off");
void setup()
{
Serial.begin(9600);
toggleSwitch.setPushedCallback(&toggleCallbackFunction, (void*)"turned on");
toggleSwitch.setReleasedCallback(&toggleCallbackFunction,
(void*)"turned off");

multiresponseButton.setLongPressCallback(&buttonCallbackFunction,
(void *)"long press");
multiresponseButton.setDoubleClickCallback(&buttonCallbackFunction,
(void *)"double click");
multiresponseButton.setSingleClickCallback(&buttonCallbackFunction,
(void *)"single click");
multiresponseButton.setLongPressCallback(&buttonCallbackFunction,
(void*)"long press");
multiresponseButton.setDoubleClickCallback(&buttonCallbackFunction,
(void*)"double click");
multiresponseButton.setSingleClickCallback(&buttonCallbackFunction,
(void*)"single click");
}

void loop() {
toggleSwitch.poll();
multiresponseButton.poll();
void loop()
{
toggleSwitch.poll();
multiresponseButton.poll();
}
119 changes: 60 additions & 59 deletions examples/SwitchExample/SwitchExample.ino
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include "avdweb_Switch.h"

const byte pushButtonpin = 10; // downButton
const byte toggleSwitchpin = 9; // upButton
const byte pushButtonpin = 10; // downButton
const byte toggleSwitchpin = 9; // upButton
const byte multiresponseButtonpin = 4; // selectButton
const byte alleventsButtonpin = 7; // weldButton
const byte buzzerPin = 3; // for beep when a switch is pressed
const byte alleventsButtonpin = 7; // weldButton
const byte buzzerPin = 3; // for beep when a switch is pressed

int i;
Switch pushButton =
Switch(pushButtonpin); // button to GND, use internal 20K pullup resistor
Switch pushButton = Switch(pushButtonpin); // button to GND, use internal 20K pullup resistor
Switch toggleSwitch = Switch(toggleSwitchpin);
Switch multiresponseButton = Switch(multiresponseButtonpin);
Switch alleventsButton = Switch(alleventsButtonpin);
Expand All @@ -18,65 +17,67 @@ Switch alleventsButton = Switch(alleventsButtonpin);
// pushButton1ms = Switch(pushButtonpin, INPUT_PULLUP, LOW, 1); // debounceTime
// 1ms

void beepCallbackFunction(void *s) // optional
void beepCallbackFunction(void* s) // optional
{
tone(3, 2400, 5); // is non-blocking
// Serial.print("BeepCallback: "); Serial.println((char*)s);
(void)s; // Fix Unused warning
tone(3, 2400, 5); // is non-blocking
// Serial.print("BeepCallback: "); Serial.println((char*)s);
(void)s; // Fix Unused warning
}

void setup() {
Serial.begin(115200);
toggleSwitch.setBeepAllCallback(
&beepCallbackFunction /*, "Beep done"*/); // needed only for one switch
// because of static
// multiresponseButton.doubleClickPeriod=0; disable doubleClick()
void setup()
{
Serial.begin(115200);
toggleSwitch.setBeepAllCallback(
&beepCallbackFunction /*, "Beep done"*/); // needed only for one switch
// because of static
// multiresponseButton.doubleClickPeriod=0; disable doubleClick()
}

void loop() { // pushButton simple events
pushButton.poll();
if (pushButton.switched())
Serial.print("pushButton switched ");
if (pushButton.pushed()) {
Serial.print("pushButton pushed ");
Serial.print(++i);
Serial.println(" times");
}
if (pushButton.released())
Serial.println("pushButton released");
void loop()
{ // pushButton simple events
pushButton.poll();
if (pushButton.switched())
Serial.print("pushButton switched ");
if (pushButton.pushed()) {
Serial.print("pushButton pushed ");
Serial.print(++i);
Serial.println(" times");
}
if (pushButton.released())
Serial.println("pushButton released");

// toggleSwitch report status only when changed
if (toggleSwitch.poll()) {
Serial.print("toggleSwitch status changed to ");
Serial.println(toggleSwitch.on());
}
// toggleSwitch report status only when changed
if (toggleSwitch.poll()) {
Serial.print("toggleSwitch status changed to ");
Serial.println(toggleSwitch.on());
}

// multiresponseButton complex events
multiresponseButton.poll();
if (multiresponseButton.longPress())
Serial.println("multiresponseButton longPress");
if (multiresponseButton.doubleClick())
Serial.println("multiresponseButton doubleClick");
if (multiresponseButton.singleClick())
Serial.println("multiresponseButton singleClick");
// multiresponseButton complex events
multiresponseButton.poll();
if (multiresponseButton.longPress())
Serial.println("multiresponseButton longPress");
if (multiresponseButton.doubleClick())
Serial.println("multiresponseButton doubleClick");
if (multiresponseButton.singleClick())
Serial.println("multiresponseButton singleClick");

// alleventsButton complex events
alleventsButton.poll();
if (alleventsButton.switched()) {
Serial.println("all_e_B switched.");
Serial.print(" all_e_B status to ");
Serial.print(alleventsButton.on());
Serial.println(".");
}
if (alleventsButton.pushed()) {
Serial.println(" all_e_B pushed.");
}
if (alleventsButton.released())
Serial.println(" all_e_B released.");
if (alleventsButton.longPress())
Serial.println(" ==> all_e_B longPress.");
if (alleventsButton.doubleClick())
Serial.println(" ==> all_e_B doubleClick.");
if (alleventsButton.singleClick())
Serial.println(" ==> all_e_B singleClick.");
// alleventsButton complex events
alleventsButton.poll();
if (alleventsButton.switched()) {
Serial.println("all_e_B switched.");
Serial.print(" all_e_B status to ");
Serial.print(alleventsButton.on());
Serial.println(".");
}
if (alleventsButton.pushed()) {
Serial.println(" all_e_B pushed.");
}
if (alleventsButton.released())
Serial.println(" all_e_B released.");
if (alleventsButton.longPress())
Serial.println(" ==> all_e_B longPress.");
if (alleventsButton.doubleClick())
Serial.println(" ==> all_e_B doubleClick.");
if (alleventsButton.singleClick())
Serial.println(" ==> all_e_B singleClick.");
}
Loading
Loading