~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/anduril/tempcheck-mode.c

  • Committer: Selene ToyKeeper
  • Date: 2023-11-02 17:05:02 UTC
  • mfrom: (483.12.159 multi-channel)
  • mto: This revision was merged to the branch mainline in revision 491.
  • Revision ID: bzr@toykeeper.net-20231102170502-sinkm18qjxlorsxa
merged multi-channel branch with a major refactor and half a year of updates

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * tempcheck-mode.c: Temperature check mode for Anduril.
3
 
 *
4
 
 * Copyright (C) 2017 Selene Scriven
5
 
 *
6
 
 * This program is free software: you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation, either version 3 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
 
1
// tempcheck-mode.c: Temperature check mode for Anduril.
 
2
// Copyright (C) 2017-2023 Selene ToyKeeper
 
3
// SPDX-License-Identifier: GPL-3.0-or-later
19
4
 
20
 
#ifndef TEMPCHECK_MODE_C
21
 
#define TEMPCHECK_MODE_C
 
5
#pragma once
22
6
 
23
7
#include "tempcheck-mode.h"
24
8
 
26
10
    // 1 click: off
27
11
    if (event == EV_1click) {
28
12
        set_state(off_state, 0);
29
 
        return MISCHIEF_MANAGED;
 
13
        return EVENT_HANDLED;
30
14
    }
31
15
    // 2 clicks: next blinky mode
32
16
    else if (event == EV_2clicks) {
37
21
        #elif defined(USE_BATTCHECK)
38
22
        set_state(battcheck_state, 0);
39
23
        #endif
40
 
        return MISCHIEF_MANAGED;
 
24
        return EVENT_HANDLED;
41
25
    }
42
26
    // 7H: thermal config mode
43
27
    else if (event == EV_click7_hold) {
44
28
        push_state(thermal_config_state, 0);
45
 
        return MISCHIEF_MANAGED;
 
29
        return EVENT_HANDLED;
46
30
    }
47
31
    return EVENT_NOT_HANDLED;
48
32
}
51
35
    if (value) {
52
36
        // item 1: calibrate room temperature
53
37
        if (step == 1) {
54
 
            int8_t rawtemp = temperature - therm_cal_offset;
55
 
            therm_cal_offset = value - rawtemp;
 
38
            int8_t rawtemp = temperature - cfg.therm_cal_offset;
 
39
            cfg.therm_cal_offset = value - rawtemp;
56
40
            adc_reset = 2;  // invalidate all recent temperature data
57
41
        }
58
42
 
59
43
        // item 2: set maximum heat limit
60
44
        else {
61
 
            therm_ceil = 30 + value - 1;
 
45
            cfg.therm_ceil = 30 + value - 1;
62
46
        }
63
47
    }
64
48
 
65
 
    if (therm_ceil > MAX_THERM_CEIL) therm_ceil = MAX_THERM_CEIL;
 
49
    if (cfg.therm_ceil > MAX_THERM_CEIL) cfg.therm_ceil = MAX_THERM_CEIL;
66
50
}
67
51
 
68
52
uint8_t thermal_config_state(Event event, uint16_t arg) {
70
54
                             2, thermal_config_save);
71
55
}
72
56
 
73
 
 
74
 
#endif
75