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

Add files via upload #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
72 changes: 71 additions & 1 deletion examples/bme68x_demo_sample/label_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,81 @@ void labelProvider::begin()
pinMode(PIN_BUTTON_1, INPUT_PULLUP);
pinMode(PIN_BUTTON_2, INPUT_PULLUP);

#ifdef USE_RING
attachInterrupt(digitalPinToInterrupt(PIN_BUTTON_1), isrButton1_ring, CHANGE);
attachInterrupt(digitalPinToInterrupt(PIN_BUTTON_2), isrButton2_ring, CHANGE);
#else
attachInterrupt(digitalPinToInterrupt(PIN_BUTTON_1), isrButton1, CHANGE);
attachInterrupt(digitalPinToInterrupt(PIN_BUTTON_2), isrButton2, CHANGE);
#endif
}
/*!
* @brief this function is the secondary interrupt function, to handle the bon press of the first Button as a ringbuffer style
*/

void labelProvider::isrButton1_ring()
{
/*check if button is pressed or idle */
if (_but1Pressed == false)
{
/*determine if only this button or both are pressed*/
_but1Pressed = true;
if(_but2Pressed)
{
/* Reset to null label */
_label = BSEC_NO_CLASS;
}
else
{
_label = static_cast<gasLabel>((static_cast<int>(_label) + 1) % BSEC_NUM_CLASSES);
}

}
else
{
/* if both buttons are released, user label according to helper button label */
_but1Pressed = false;
if (!_but2Pressed)
{
xQueueSendFromISR(_queue, (const void*)&_label, 0);
}
}
}

/*!
* @brief this function is the secondary interrupt function, to handle the bon press of the second Button as a ringbuffer style
*/

void labelProvider::isrButton2_ring()
{
/*check if button is pressed or idle */
if (_but2Pressed == false)
{
/*determine if only this button or both are pressed*/
_but2Pressed = true;
if(_but1Pressed)
{
/* Reset to null label */
_label = BSEC_NO_CLASS;
}
else
{
_label = static_cast<gasLabel>((static_cast<int>(_label) + 1) % BSEC_NUM_CLASSES);
}

}
else
{
/* if both buttons are released, user label according to helper button label */
_but2Pressed = false;
if (!_but1Pressed)
{
xQueueSendFromISR(_queue, (const void*)&_label, 0);
}
}
}


/*!
* @brief This function is the interrupt function, that handles the button press of the first button
*/
Expand Down Expand Up @@ -138,4 +209,3 @@ bool labelProvider::getLabel(gasLabel &label)
{
return xQueueReceive(_queue, &label, 0);
}

17 changes: 15 additions & 2 deletions examples/bme68x_demo_sample/label_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@
#define PIN_BUTTON_1 14
#define PIN_BUTTON_2 32

#define USE_RING

enum gasLabel
{
BSEC_NO_CLASS,
BSEC_CLASS_1,
BSEC_CLASS_2,
BSEC_CLASS_3,
BSEC_CLASS_4
BSEC_CLASS_4,
BSEC_NUM_CLASSES
};

/*!
Expand All @@ -83,6 +86,16 @@ class labelProvider
*/
static void isrButton2();

/*!
* @brief : This function is the interrupt handler of the first button (next label ring style)
*/
static void isrButton1_ring();

/*!
* @brief : This function is the interrupt handler of the second button (lowers label ring style)
*/
static void isrButton2_ring();

public:

/*!
Expand All @@ -106,4 +119,4 @@ class labelProvider
bool getLabel(gasLabel &label);
};

#endif
#endif