Central Heating controller using the real time clock, PHY module for internet, 1-wire interface for temperature sensors, a system log and a configuration file

Dependencies:   net 1-wire lpc1768 crypto clock web fram log

/media/uploads/andrewboyson/heating.sch

/media/uploads/andrewboyson/heating.brd

/media/uploads/andrewboyson/eagle.epf

Committer:
andrewboyson
Date:
Fri Apr 23 08:36:42 2021 +0000
Revision:
106:41ed3ea0bbba
Parent:
58:d968191f46f2
Not working, crashes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 58:d968191f46f2 1 #include <stdbool.h>
andrewboyson 58:d968191f46f2 2 #include <stdint.h>
andrewboyson 58:d968191f46f2 3
andrewboyson 58:d968191f46f2 4 #include "gpio.h"
andrewboyson 58:d968191f46f2 5 #include "radiator.h"
andrewboyson 58:d968191f46f2 6 #include "program.h"
andrewboyson 58:d968191f46f2 7 #include "mstimer.h"
andrewboyson 58:d968191f46f2 8 #include "rit.h"
andrewboyson 58:d968191f46f2 9
andrewboyson 58:d968191f46f2 10 #define HALL_PB_PIN FIO0PIN(05) // P0.05 == p29;
andrewboyson 58:d968191f46f2 11
andrewboyson 58:d968191f46f2 12 #define DEBOUNCE_MS 20
andrewboyson 58:d968191f46f2 13 #define LONG_PRESS_MS 3000
andrewboyson 58:d968191f46f2 14 #define INACTIVE_REVERT_MS 30000
andrewboyson 58:d968191f46f2 15
andrewboyson 58:d968191f46f2 16 static int ms = 0;
andrewboyson 58:d968191f46f2 17
andrewboyson 58:d968191f46f2 18 static void (*ritHook)();
andrewboyson 58:d968191f46f2 19
andrewboyson 58:d968191f46f2 20 static void ritHandler()
andrewboyson 58:d968191f46f2 21 {
andrewboyson 58:d968191f46f2 22 if (ritHook) ritHook(); //Call the RIT function chain before this
andrewboyson 58:d968191f46f2 23
andrewboyson 58:d968191f46f2 24 if (HALL_PB_PIN) { if (ms < DEBOUNCE_MS) ms++; }
andrewboyson 58:d968191f46f2 25 else { if (ms > 0 ) ms--; }
andrewboyson 58:d968191f46f2 26 }
andrewboyson 58:d968191f46f2 27
andrewboyson 58:d968191f46f2 28 static bool getHallPbPressed()
andrewboyson 58:d968191f46f2 29 {
andrewboyson 58:d968191f46f2 30 static bool pressed = false;
andrewboyson 58:d968191f46f2 31 if (ms >= DEBOUNCE_MS) pressed = false;
andrewboyson 58:d968191f46f2 32 if (ms <= 0) pressed = true;
andrewboyson 58:d968191f46f2 33 return pressed;
andrewboyson 58:d968191f46f2 34 }
andrewboyson 58:d968191f46f2 35
andrewboyson 58:d968191f46f2 36 bool HallPbOverrideMode = true;
andrewboyson 58:d968191f46f2 37
andrewboyson 58:d968191f46f2 38 void HallPbInit()
andrewboyson 58:d968191f46f2 39 {
andrewboyson 58:d968191f46f2 40 ritHook = RitHook;
andrewboyson 58:d968191f46f2 41 RitHook = ritHandler;
andrewboyson 58:d968191f46f2 42 }
andrewboyson 58:d968191f46f2 43 void HallPbMain()
andrewboyson 58:d968191f46f2 44 {
andrewboyson 58:d968191f46f2 45 static uint32_t hallButtonPushedMsTimer = 0;
andrewboyson 58:d968191f46f2 46 static uint32_t hallButtonNotPushedMsTimer = 0;
andrewboyson 58:d968191f46f2 47
andrewboyson 58:d968191f46f2 48 static bool buttonWasPressed = false;
andrewboyson 58:d968191f46f2 49 static bool buttonWasLongPressed = false;
andrewboyson 58:d968191f46f2 50
andrewboyson 58:d968191f46f2 51 bool buttonIsPressed = getHallPbPressed();
andrewboyson 58:d968191f46f2 52 bool buttonIsLongPressed;
andrewboyson 58:d968191f46f2 53 if (buttonIsPressed)
andrewboyson 58:d968191f46f2 54 {
andrewboyson 58:d968191f46f2 55 buttonIsLongPressed = MsTimerRelative(hallButtonPushedMsTimer, LONG_PRESS_MS);
andrewboyson 58:d968191f46f2 56 hallButtonNotPushedMsTimer = MsTimerCount;
andrewboyson 58:d968191f46f2 57 }
andrewboyson 58:d968191f46f2 58 else
andrewboyson 58:d968191f46f2 59 {
andrewboyson 58:d968191f46f2 60 buttonIsLongPressed = false;
andrewboyson 58:d968191f46f2 61 hallButtonPushedMsTimer = MsTimerCount;
andrewboyson 58:d968191f46f2 62 }
andrewboyson 58:d968191f46f2 63
andrewboyson 58:d968191f46f2 64 if (buttonIsLongPressed && !buttonWasLongPressed) HallPbOverrideMode = !HallPbOverrideMode;
andrewboyson 58:d968191f46f2 65 if (MsTimerRelative(hallButtonNotPushedMsTimer, INACTIVE_REVERT_MS)) HallPbOverrideMode = true;
andrewboyson 58:d968191f46f2 66
andrewboyson 58:d968191f46f2 67 if (!buttonIsPressed && buttonWasPressed && !buttonWasLongPressed)
andrewboyson 58:d968191f46f2 68 {
andrewboyson 58:d968191f46f2 69 if (HallPbOverrideMode) RadiatorChgOverride();
andrewboyson 58:d968191f46f2 70 else RadiatorChgWinter();
andrewboyson 58:d968191f46f2 71 }
andrewboyson 58:d968191f46f2 72 buttonWasPressed = buttonIsPressed;
andrewboyson 58:d968191f46f2 73 buttonWasLongPressed = buttonIsLongPressed;
andrewboyson 58:d968191f46f2 74 }