diff --git a/examples/bme68x_demo_sample/label_provider.cpp b/examples/bme68x_demo_sample/label_provider.cpp index e942582..63f126c 100644 --- a/examples/bme68x_demo_sample/label_provider.cpp +++ b/examples/bme68x_demo_sample/label_provider.cpp @@ -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((static_cast(_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((static_cast(_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 */ @@ -138,4 +209,3 @@ bool labelProvider::getLabel(gasLabel &label) { return xQueueReceive(_queue, &label, 0); } - diff --git a/examples/bme68x_demo_sample/label_provider.h b/examples/bme68x_demo_sample/label_provider.h index bdf5ae0..c69d5e4 100644 --- a/examples/bme68x_demo_sample/label_provider.h +++ b/examples/bme68x_demo_sample/label_provider.h @@ -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 }; /*! @@ -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: /*! @@ -106,4 +119,4 @@ class labelProvider bool getLabel(gasLabel &label); }; -#endif \ No newline at end of file +#endif