button logic finished
Now on par with Python implementation
This commit is contained in:
parent
278de69a16
commit
bde19fd2b7
1 changed files with 21 additions and 12 deletions
|
@ -23,21 +23,29 @@ constexpr uint BUTTON_3_PIN = 15;
|
|||
constexpr char CUSTOM_CHAR_DEG = 0xDF;
|
||||
constexpr char CUSTOM_CHAR_AE = 0xE1;
|
||||
|
||||
// Global variables which have to be accessed by callback function
|
||||
bool isSystemOn = false;
|
||||
float temp_tgt{28.0};
|
||||
absolute_time_t lastPressed = get_absolute_time();
|
||||
|
||||
using std::string;
|
||||
|
||||
void buttonPressedCallback(uint gpio, uint32_t events) {
|
||||
static absolute_time_t lastPressed = get_absolute_time();
|
||||
switch (gpio) {
|
||||
case BUTTON_1_PIN:
|
||||
break;
|
||||
case BUTTON_2_PIN:
|
||||
break;
|
||||
case BUTTON_3_PIN:
|
||||
if (absolute_time_diff_us(lastPressed, get_absolute_time()) > 750000) {
|
||||
std::cout << "Button 3 pressed!" << std::endl;
|
||||
if (absolute_time_diff_us(lastPressed, get_absolute_time()) < 750000) {
|
||||
return;
|
||||
} else {
|
||||
lastPressed = get_absolute_time();
|
||||
}
|
||||
|
||||
switch (gpio) {
|
||||
case BUTTON_1_PIN:
|
||||
temp_tgt -= 0.5;
|
||||
break;
|
||||
case BUTTON_2_PIN:
|
||||
temp_tgt += 0.5;
|
||||
break;
|
||||
case BUTTON_3_PIN:
|
||||
isSystemOn = !isSystemOn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -62,17 +70,17 @@ int main() {
|
|||
// Initialize the Buttons
|
||||
gpio_set_irq_enabled_with_callback(BUTTON_1_PIN, GPIO_IRQ_EDGE_FALL, true,
|
||||
&buttonPressedCallback);
|
||||
gpio_set_irq_enabled(BUTTON_2_PIN, GPIO_IRQ_EDGE_FALL, true);
|
||||
gpio_set_irq_enabled(BUTTON_3_PIN, GPIO_IRQ_EDGE_FALL, true);
|
||||
gpio_set_irq_enabled_with_callback(BUTTON_2_PIN, GPIO_IRQ_EDGE_FALL, true,
|
||||
&buttonPressedCallback);
|
||||
gpio_set_irq_enabled_with_callback(BUTTON_3_PIN, GPIO_IRQ_EDGE_FALL, true,
|
||||
&buttonPressedCallback);
|
||||
|
||||
float temp_act{0};
|
||||
float temp_tgt{28.0};
|
||||
float temp_diff{0.5};
|
||||
std::stringstream lcdText{};
|
||||
bool isHeating = false;
|
||||
bool isSystemOn = false;
|
||||
string heatInfo{" "};
|
||||
string systemInfo{"OFF"};
|
||||
string heatInfo{""};
|
||||
string systemInfo{""};
|
||||
|
||||
lcdText << " G" << CUSTOM_CHAR_AE << "rbox Manager\n (Ver. "
|
||||
<< PROJECT_VERSION << ")";
|
||||
|
@ -92,6 +100,7 @@ int main() {
|
|||
isHeating = false;
|
||||
}
|
||||
isHeating ? heatInfo = ">H<" : heatInfo = " ";
|
||||
isSystemOn ? systemInfo = "ON " : systemInfo = "OFF";
|
||||
|
||||
relais.activate(isHeating);
|
||||
|
||||
|
|
Loading…
Reference in a new issue