Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: net 1-wire lpc1768 crypto clock web fram log
hall-pb.c
00001 #include <stdbool.h> 00002 #include <stdint.h> 00003 00004 #include "gpio.h" 00005 #include "radiator.h" 00006 #include "program.h" 00007 #include "mstimer.h" 00008 #include "rit.h" 00009 00010 #define HALL_PB_PIN FIO0PIN(05) // P0.05 == p29; 00011 00012 #define DEBOUNCE_MS 20 00013 #define LONG_PRESS_MS 3000 00014 #define INACTIVE_REVERT_MS 30000 00015 00016 static int ms = 0; 00017 00018 static void (*ritHook)(); 00019 00020 static void ritHandler() 00021 { 00022 if (ritHook) ritHook(); //Call the RIT function chain before this 00023 00024 if (HALL_PB_PIN) { if (ms < DEBOUNCE_MS) ms++; } 00025 else { if (ms > 0 ) ms--; } 00026 } 00027 00028 static bool getHallPbPressed() 00029 { 00030 static bool pressed = false; 00031 if (ms >= DEBOUNCE_MS) pressed = false; 00032 if (ms <= 0) pressed = true; 00033 return pressed; 00034 } 00035 00036 bool HallPbOverrideMode = true; 00037 00038 void HallPbInit() 00039 { 00040 ritHook = RitHook; 00041 RitHook = ritHandler; 00042 } 00043 void HallPbMain() 00044 { 00045 static uint32_t hallButtonPushedMsTimer = 0; 00046 static uint32_t hallButtonNotPushedMsTimer = 0; 00047 00048 static bool buttonWasPressed = false; 00049 static bool buttonWasLongPressed = false; 00050 00051 bool buttonIsPressed = getHallPbPressed(); 00052 bool buttonIsLongPressed; 00053 if (buttonIsPressed) 00054 { 00055 buttonIsLongPressed = MsTimerRelative(hallButtonPushedMsTimer, LONG_PRESS_MS); 00056 hallButtonNotPushedMsTimer = MsTimerCount; 00057 } 00058 else 00059 { 00060 buttonIsLongPressed = false; 00061 hallButtonPushedMsTimer = MsTimerCount; 00062 } 00063 00064 if (buttonIsLongPressed && !buttonWasLongPressed) HallPbOverrideMode = !HallPbOverrideMode; 00065 if (MsTimerRelative(hallButtonNotPushedMsTimer, INACTIVE_REVERT_MS)) HallPbOverrideMode = true; 00066 00067 if (!buttonIsPressed && buttonWasPressed && !buttonWasLongPressed) 00068 { 00069 if (HallPbOverrideMode) RadiatorChgOverride(); 00070 else RadiatorChgWinter(); 00071 } 00072 buttonWasPressed = buttonIsPressed; 00073 buttonWasLongPressed = buttonIsLongPressed; 00074 }
Generated on Tue Jul 12 2022 18:50:15 by
