Mercurial > ~darius > hgwebdir.cgi > stm32temp
annotate tempctrl.c @ 87:e30fe4bb8011
Add missing prototype
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Fri, 13 Mar 2015 11:36:26 +1030 |
parents | 345a42f6151b |
children |
rev | line source |
---|---|
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 /* |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
2 * Temperature control logic, copied from AVR version |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 * |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 * Copyright (c) 2012 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
6 * |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
7 * Redistribution and use in source and binary forms, with or without |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
8 * modification, are permitted provided that the following conditions |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
9 * are met: |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
10 * 1. Redistributions of source code must retain the above copyright |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
11 * notice, this list of conditions and the following disclaimer. |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
13 * notice, this list of conditions and the following disclaimer in the |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
14 * documentation and/or other materials provided with the distribution. |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
15 * |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
26 * SUCH DAMAGE. |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
27 */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
29 #include <assert.h> |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
30 #include <ctype.h> |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
31 #include <stdio.h> |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 #include <stdint.h> |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
33 #include <stdlib.h> |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
34 #include <string.h> |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
35 #include <sys/time.h> |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
36 #include <time.h> |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
37 #include "stm32f10x.h" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
38 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
39 #include "1wire.h" |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
40 #include "ff.h" |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
41 #include "flash.h" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
42 #include "tempctrl.h" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
43 |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
44 #define TEMPCTRL_FLASH_ADDRESS 0 /* First sector */ |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
45 |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 /* Holds all the settings needed */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
47 typedef struct { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
48 uint8_t fermenter_ROM[8]; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
49 uint8_t fridge_ROM[8]; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
50 uint8_t ambient_ROM[8]; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
51 int16_t target_temp; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
52 uint16_t hysteresis; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
53 /* How much to under/overshoot on heating/cooling */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 int16_t minheatovershoot; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
55 int16_t mincoolovershoot; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
56 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
57 /* Minimum time the cooler can be on/off */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
58 int16_t mincoolontime; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
59 int16_t mincoolofftime; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
60 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
61 /* Minimum time the heater can be on/off */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
62 int16_t minheatontime; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
63 int16_t minheatofftime; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
64 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
65 #define TC_MODE_AUTO 'a' /* Automatic control */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
66 #define TC_MODE_HEAT 'h' /* Force heating */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
67 #define TC_MODE_COOL 'c' /* Force cooling */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
68 #define TC_MODE_IDLE 'i' /* Force idle */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
69 #define TC_MODE_NOTHING 'n' /* Do nothing (like idle but log nothing) */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
70 char mode; |
86
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
83
diff
changeset
|
71 |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
72 /* GPIO port the heater & cooler are on */ |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
73 char coolport; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
74 uint16_t coolpin; |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
75 uint8_t coolinv; |
86
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
83
diff
changeset
|
76 |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
77 char heatport; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
78 uint16_t heatpin; |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
79 uint8_t heatinv; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
80 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
81 /* Check/stale times */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
82 int16_t check_interval; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
83 int16_t stale_factor; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
84 |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
85 char logfilefmt[64]; |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
86 |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
87 uint8_t pad[1]; /* Pad to multiple of 4 bytes */ |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
88 } tc_settings_t; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
89 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
90 /* Current settings in RAM */ |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
91 static tc_settings_t tc_settings; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
92 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
93 /* Defaults that are shoved into SPI flash if it isn't inited */ |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
94 const tc_settings_t default_tc_settings = { |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
95 .fermenter_ROM = { 0x10, 0x4c, 0x7d, 0x53, 0x01, 0x08, 0x00, 0xff }, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
96 .fridge_ROM = { 0x10, 0x6d, 0x40, 0x53, 0x01, 0x08, 0x00, 0x16 }, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
97 .ambient_ROM = { 0x10, 0x76, 0x05, 0x53, 0x01, 0x08, 0x00, 0x8e }, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
98 .target_temp = 1000, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
99 .hysteresis = 100, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
100 .minheatovershoot = 50, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
101 .mincoolovershoot = -50, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
102 .mincoolontime = 300, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
103 .mincoolofftime = 600, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
104 .minheatontime = 60, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
105 .minheatofftime = 60, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
106 .mode = TC_MODE_AUTO, |
86
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
83
diff
changeset
|
107 .coolport = 'A', |
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
83
diff
changeset
|
108 .coolpin = 11, |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
109 .coolinv = 1, |
86
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
83
diff
changeset
|
110 .heatport = 'A', |
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
83
diff
changeset
|
111 .heatpin = 12, |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
112 .heatinv = 1, |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
113 .check_interval = 10, |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
114 .stale_factor = 3, |
86
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
83
diff
changeset
|
115 .logfilefmt = "\0" |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
116 }; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
117 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
118 /* Local variable declarations */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
119 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
120 /* Local function prototypes */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
121 static void tempctrl_load_or_init_settings(void); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
122 static void tempctrl_default_settings(void); |
70
aaf0603d7f88
Add routine to CRC a block of flash. Use it to verify a flash block write.
Daniel O'Connor <darius@dons.net.au>
parents:
66
diff
changeset
|
123 static int tempctrl_write_settings(void); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
124 static void setstate(char state); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
125 static const char * state2long(char s); |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
126 static int fmttemp(char *buf, const char *name, int tmp, const char *trailer); |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
127 static GPIO_TypeDef *char2port(char port); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
128 |
86
345a42f6151b
Catch up with change to new board
Daniel O'Connor <darius@dons.net.au>
parents:
83
diff
changeset
|
129 /* |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
130 * tempctrl_init |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
131 * |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
132 */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
133 void |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
134 tempctrl_init(void) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
135 tempctrl_load_or_init_settings(); |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
136 setstate('i'); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
137 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
138 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
139 /* |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
140 * tempctrl_update |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
141 * |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
142 * Should be called in a normal context, could run things that take a long time. |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
143 * (ie 1wire bus stuff) |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
144 * |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
145 */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
146 void |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
147 tempctrl_update(void) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
148 /* State variables */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
149 static int32_t checktime = 0; // Time of next check |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
150 static int32_t lastdata = INT32_MIN; // Last time we got data |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
151 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
152 static int16_t fermenter_temp = 0; // Fermenter temperature |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
153 static int16_t fridge_temp = 0; // Fridge temperature |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
154 static int16_t ambient_temp = 0; // Ambient temperature |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
155 static int32_t lastheaton = INT32_MIN; // Last time the heater was on |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
156 static int32_t lastheatoff = INT32_MIN;// Last time the heater was off |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
157 static int32_t lastcoolon = INT32_MIN; // Last time the cooler was on |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
158 static int32_t lastcooloff = INT32_MIN;// Last time the cooler was off |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
159 static char currstate = 'i'; // Current state |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
160 /* We init to times to INT32_MIN so that things function properly when |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
161 * now < settings.minheat/cool/on/offtime */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
162 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
163 /* Temporary variables */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
164 int32_t tempt; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
165 int16_t diff; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
166 char nextstate; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
167 int forced; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
168 int stale; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
169 time_t t; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
170 struct tm tm; |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
171 char linebuf[90], *p; |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
172 FRESULT fserr; |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
173 FIL f; |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
174 char fbuf[20]; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
175 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
176 t = time(NULL); |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
177 stale = 0; |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
178 tempt = 0; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
179 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
180 /* Time to check temperatures? */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
181 if (t < checktime) |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
182 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
183 |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
184 checktime = t + tc_settings.check_interval; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
185 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
186 /* Don't do any logging, just force idle and leave */ |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
187 if (tc_settings.mode == TC_MODE_NOTHING) { |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
188 nextstate = 'i'; |
43 | 189 goto skip; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
190 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
191 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
192 /* Update our temperatures |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
193 * Can take a while (800ms each!) |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
194 */ |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
195 tempt = OWGetTemp(tc_settings.fermenter_ROM); |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
196 fridge_temp = OWGetTemp(tc_settings.fridge_ROM); |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
197 ambient_temp = OWGetTemp(tc_settings.ambient_ROM); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
198 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
199 /* We only care about this one, only update the value we decide on |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
200 * only if it is valid |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
201 */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
202 if (tempt > OW_TEMP_BADVAL) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
203 fermenter_temp = tempt; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
204 lastdata = t; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
205 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
206 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
207 /* Check for stale data */ |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
208 if (lastdata + (tc_settings.check_interval * tc_settings.stale_factor) < t) |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
209 stale = 1; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
210 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
211 /* Default to remaining as we are */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
212 nextstate = '-'; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
213 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
214 /* Temperature diff, -ve => too cold, +ve => too warm */ |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
215 diff = fermenter_temp - tc_settings.target_temp; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
216 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
217 switch (currstate) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
218 case 'i': |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
219 /* If we're idle then only heat or cool if the temperate difference is out of the |
43 | 220 * hysteresis band and the heater/cooler have been off long enough |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
221 */ |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
222 if (abs(diff) > tc_settings.hysteresis) { |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
223 if (diff < 0 && tc_settings.minheatofftime + lastheatoff < t) |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
224 nextstate = 'h'; |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
225 else if (diff > 0 && tc_settings.mincoolofftime + lastcooloff < t) |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
226 nextstate = 'c'; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
227 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
228 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
229 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
230 case 'c': |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
231 /* Work out if we should go idle (based on min on time & overshoot) */ |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
232 if (diff + tc_settings.mincoolovershoot < 0 && |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
233 tc_settings.mincoolontime + lastcoolon < t) |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
234 nextstate = 'i'; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
235 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
236 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
237 case 'h': |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
238 if (diff - tc_settings.minheatovershoot > 0 && |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
239 tc_settings.minheatontime + lastheaton < t) |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
240 nextstate = 'i'; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
241 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
242 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
243 default: |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
244 printf("\nUnknown state %c, going to idle\n", currstate); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
245 nextstate = 'i'; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
246 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
247 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
248 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
249 /* Override if we have stale data */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
250 if (stale) |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
251 nextstate = 'i'; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
252 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
253 /* Handle state forcing */ |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
254 if (tc_settings.mode != TC_MODE_AUTO) |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
255 forced = 1; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
256 else |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
257 forced = 0; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
258 |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
259 if (tc_settings.mode == TC_MODE_IDLE) |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
260 nextstate = 'i'; |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
261 else if (tc_settings.mode == TC_MODE_HEAT) |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
262 nextstate = 'h'; |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
263 else if (tc_settings.mode == TC_MODE_COOL) |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
264 nextstate = 'c'; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
265 |
43 | 266 /* Keep track of when we last turned things on or off */ |
267 skip: | |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
268 switch (nextstate) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
269 case 'c': |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
270 if (currstate == 'h') |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
271 lastheatoff = t; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
272 lastcoolon = t; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
273 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
274 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
275 case 'h': |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
276 if (currstate == 'c') |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
277 lastcooloff = t; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
278 lastheaton = t; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
279 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
280 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
281 default: |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
282 if (currstate == 'c') |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
283 lastcooloff = t; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
284 if (currstate == 'h') |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
285 lastheatoff = t; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
286 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
287 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
288 if (nextstate != '-') |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
289 currstate = nextstate; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
290 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
291 |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
292 if (tc_settings.mode != TC_MODE_NOTHING) { |
43 | 293 localtime_r(&t, &tm); |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
294 p = linebuf; |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
295 p += strftime(p, sizeof(linebuf) - 1, "%Y/%m/%d %H:%M:%S: ", &tm); |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
296 p += fmttemp(p, "Tr", tc_settings.target_temp, ", "); |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
297 p += fmttemp(p, "Fm", tempt, ", "); |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
298 p += fmttemp(p, "Fr", fridge_temp, ", "); |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
299 p += fmttemp(p, "Am", ambient_temp, ", "); |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
300 sprintf(p, "St: %s, Fl: %s%s\n", state2long(currstate), |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
301 forced ? "F" : "", |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
302 stale ? "S" : ""); |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
303 fputs(linebuf, stdout); |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
304 if (tc_settings.logfilefmt[0] != '\0') { |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
305 strftime(fbuf, sizeof(fbuf) - 1, tc_settings.logfilefmt, &tm); |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
306 |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
307 if ((fserr = f_open(&f, fbuf, FA_WRITE | FA_OPEN_ALWAYS)) != FR_OK) { |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
308 printf("Failed to open file: %d\n", fserr); |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
309 goto openerr; |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
310 } |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
311 |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
312 if ((fserr = f_lseek(&f, f_size(&f))) != FR_OK) { |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
313 printf("Failed to seek to end of file: %d\n", fserr); |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
314 goto openerr; |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
315 } |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
316 |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
317 f_puts(linebuf, &f); |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
318 f_close(&f); |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
319 } |
43 | 320 } |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
321 |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
322 openerr: |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
323 setstate(currstate); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
324 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
325 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
326 /* |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
327 * Format a temperature (or short error code) with specified trailer |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
328 */ |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
329 static int |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
330 fmttemp(char *buf, const char *name, int tmp, const char *trailer) { |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
331 if (tmp > OW_TEMP_BADVAL) |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
332 return sprintf(buf, "%s: %d.%02d%s", name, GETWHOLE(tmp), GETFRAC(tmp), trailer); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
333 else |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
334 return sprintf(buf, "%s: %s%s", name, OWTempStatusStr(tmp, 1), trailer); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
335 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
336 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
337 /* Read the settings from SPI flash |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
338 * If the CRC fails then reload from onboard flash |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
339 */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
340 static void |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
341 tempctrl_load_or_init_settings(void) { |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
342 if (!flashreadblock(TEMPCTRL_FLASH_ADDRESS, sizeof(tc_settings), &tc_settings)) { |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
343 fputs("CRC fails, loading defaults\n", stdout); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
344 tempctrl_default_settings(); |
70
aaf0603d7f88
Add routine to CRC a block of flash. Use it to verify a flash block write.
Daniel O'Connor <darius@dons.net.au>
parents:
66
diff
changeset
|
345 if (tempctrl_write_settings()) |
aaf0603d7f88
Add routine to CRC a block of flash. Use it to verify a flash block write.
Daniel O'Connor <darius@dons.net.au>
parents:
66
diff
changeset
|
346 fputs("Failed to write settings\n", stdout); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
347 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
348 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
349 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
350 /* Load in the defaults from flash */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
351 static void |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
352 tempctrl_default_settings(void) { |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
353 memcpy(&tc_settings, &default_tc_settings, sizeof(tc_settings_t)); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
354 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
355 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
356 /* Write the current settings out to SPI flash */ |
70
aaf0603d7f88
Add routine to CRC a block of flash. Use it to verify a flash block write.
Daniel O'Connor <darius@dons.net.au>
parents:
66
diff
changeset
|
357 static int |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
358 tempctrl_write_settings(void) { |
70
aaf0603d7f88
Add routine to CRC a block of flash. Use it to verify a flash block write.
Daniel O'Connor <darius@dons.net.au>
parents:
66
diff
changeset
|
359 return flashwriteblock(TEMPCTRL_FLASH_ADDRESS, sizeof(tc_settings), &tc_settings); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
360 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
361 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
362 /* Set the relays to match the desired state */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
363 static void |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
364 setstate(char state) { |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
365 uint8_t cool, heat; |
83
05ba84c7da97
Add a flash layer for compatibility (in future).
Daniel O'Connor <darius@dons.net.au>
parents:
70
diff
changeset
|
366 |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
367 switch (state) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
368 case 'c': |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
369 cool = 1; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
370 heat = 0; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
371 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
372 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
373 case 'h': |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
374 cool = 0; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
375 heat = 1; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
376 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
377 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
378 default: |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
379 printf("Unknown state %c, setting idle\n", state); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
380 /* fallthrough */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
381 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
382 case 'i': |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
383 cool = 0; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
384 heat = 0; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
385 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
386 } |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
387 |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
388 if (cool ^ tc_settings.coolinv) |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
389 GPIO_SetBits(char2port(tc_settings.coolport), 1 << tc_settings.coolpin); |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
390 else |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
391 GPIO_ResetBits(char2port(tc_settings.coolport), 1 << tc_settings.coolpin); |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
392 |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
393 if (heat ^ tc_settings.heatinv) |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
394 GPIO_SetBits(char2port(tc_settings.heatport), 1 << tc_settings.heatpin); |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
395 else |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
396 GPIO_ResetBits(char2port(tc_settings.heatport), 1 << tc_settings.heatpin); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
397 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
398 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
399 /* Handle user command |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
400 * |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
401 */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
402 void |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
403 tempctrl_cmd(int argc, char **argv) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
404 int16_t data; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
405 uint8_t ROM[8]; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
406 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
407 if (argc < 1) { |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
408 printf("Unable to parse tc subcommand\n"); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
409 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
410 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
411 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
412 if (!strcasecmp(argv[0], "help")) { |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
413 printf("tc help This help\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
414 "tc save Save settings to EEPROM\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
415 "tc load Load or default settings from EEPROM\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
416 "tc dflt Load defaults from flash\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
417 "tc list List current settings\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
418 "tc mode [achin] Change control mode, must be one of\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
419 " a Auto\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
420 " c Always cool\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
421 " h Always heat\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
422 " i Always idle\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
423 " n Like idle but don't log anything\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
424 "tc X Y Set X to Y where X is one of\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
425 " targ Target temperature\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
426 " hys Hysteresis range\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
427 " mhov Minimum heat overshoot\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
428 " mcov Minimum cool overshoot\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
429 " mcon Minimum cool on time\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
430 " mcoff Minimum cool off time\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
431 " mhin Minimum heat on time\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
432 " mhoff Minimum heat off time\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
433 "tc A B Set temperature sensor ID\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
434 " Where A is ferm, frg or amb\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
435 " and B is of the form xx:xx:xx:xx:xx:xx:xx:xx\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
436 "\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
437 " Times are in seconds\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
438 " Temperatures are in hundredths of degrees Celcius\n" |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
439 ); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
440 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
441 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
442 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
443 if (!strcasecmp(argv[0], "save")) { |
70
aaf0603d7f88
Add routine to CRC a block of flash. Use it to verify a flash block write.
Daniel O'Connor <darius@dons.net.au>
parents:
66
diff
changeset
|
444 if (tempctrl_write_settings()) |
aaf0603d7f88
Add routine to CRC a block of flash. Use it to verify a flash block write.
Daniel O'Connor <darius@dons.net.au>
parents:
66
diff
changeset
|
445 fputs("Failed to write settings\n", stdout); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
446 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
447 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
448 if (!strcasecmp(argv[0], "load")) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
449 tempctrl_load_or_init_settings(); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
450 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
451 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
452 if (!strcasecmp(argv[0], "dflt")) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
453 tempctrl_default_settings(); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
454 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
455 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
456 if (!strcasecmp(argv[0], "list")) { |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
457 printf("Fermenter ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
458 "Fridge ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
459 "Ambient ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
460 "Mode - %c, Target - %d, Hystersis - %d\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
461 "Min heat overshoot - %d, Min cool overshoot - %d\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
462 "Min cool on time - %d, Min cool off time - %d\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
463 "Min heat on time - %d, Min heat off time - %d\n" |
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
464 "Cool: Port %c Pin %d Inv %d, Heat: Port %c Pin %d Inv %d\n" |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
465 "Log format: %s\n", |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
466 tc_settings.fermenter_ROM[0], tc_settings.fermenter_ROM[1], tc_settings.fermenter_ROM[2], tc_settings.fermenter_ROM[3], |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
467 tc_settings.fermenter_ROM[4], tc_settings.fermenter_ROM[5], tc_settings.fermenter_ROM[6], tc_settings.fermenter_ROM[7], |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
468 tc_settings.fridge_ROM[0], tc_settings.fridge_ROM[1], tc_settings.fridge_ROM[2], tc_settings.fridge_ROM[3], |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
469 tc_settings.fridge_ROM[4], tc_settings.fridge_ROM[5], tc_settings.fridge_ROM[6], tc_settings.fridge_ROM[7], |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
470 tc_settings.ambient_ROM[0], tc_settings.ambient_ROM[1], tc_settings.ambient_ROM[2], tc_settings.ambient_ROM[3], |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
471 tc_settings.ambient_ROM[4], tc_settings.ambient_ROM[5], tc_settings.ambient_ROM[6], tc_settings.ambient_ROM[7], |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
472 tc_settings.mode, tc_settings.target_temp, tc_settings.hysteresis, |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
473 tc_settings.minheatovershoot, tc_settings.mincoolovershoot, |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
474 tc_settings.mincoolontime, tc_settings.minheatontime, |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
475 tc_settings.minheatontime, tc_settings.minheatofftime, |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
476 tc_settings.coolport, tc_settings.coolpin, tc_settings.coolinv, |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
477 tc_settings.heatport, tc_settings.heatpin, tc_settings.heatinv, |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
478 tc_settings.logfilefmt[0] == '\0' ? "none" : tc_settings.logfilefmt |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
479 ); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
480 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
481 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
482 if (!strcasecmp(argv[0], "mode")) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
483 if (argc < 2) { |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
484 fputs("Incorrect number of arguments\n", stdout); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
485 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
486 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
487 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
488 switch (argv[1][0]) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
489 case TC_MODE_AUTO: |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
490 case TC_MODE_HEAT: |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
491 case TC_MODE_COOL: |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
492 case TC_MODE_IDLE: |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
493 case TC_MODE_NOTHING: |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
494 tc_settings.mode = argv[1][0]; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
495 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
496 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
497 default: |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
498 printf("Unknown mode character '%c'\n", argv[1][0]); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
499 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
500 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
501 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
502 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
503 if (!strcasecmp(argv[0], "ferm") || |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
504 !strcasecmp(argv[0], "frg") || |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
505 !strcasecmp(argv[0], "amb")) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
506 if (argc < 2) { |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
507 fputs("Incorrect number of arguments\n", stdout); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
508 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
509 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
510 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
511 if (sscanf(argv[1], "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
512 &ROM[0], &ROM[1], &ROM[2], &ROM[3], |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
513 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) { |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
514 printf("Unable to parse ROM ID\n"); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
515 } else { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
516 if (!strcasecmp(argv[0], "ferm")) |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
517 memcpy(&tc_settings.fermenter_ROM, ROM, sizeof(ROM)); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
518 if (!strcasecmp(argv[0], "frg")) |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
519 memcpy(&tc_settings.fridge_ROM, ROM, sizeof(ROM)); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
520 if (!strcasecmp(argv[0], "amb")) |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
521 memcpy(&tc_settings.ambient_ROM, ROM, sizeof(ROM)); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
522 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
523 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
524 } |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
525 if (!strcasecmp(argv[0], "log")) { |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
526 if (argc == 1) |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
527 bzero(tc_settings.logfilefmt, sizeof(tc_settings.logfilefmt)); |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
528 else { |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
529 if (strlen(argv[1]) > sizeof(tc_settings.logfilefmt) - 1) |
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
530 printf("New path too log (%d > %d)\n", strlen(argv[1]), sizeof(tc_settings.logfilefmt)); |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
531 else |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
532 strcpy(tc_settings.logfilefmt, argv[1]); |
61
9c5db7fee912
Make 'td log' work without printing an error.
Daniel O'Connor <darius@dons.net.au>
parents:
60
diff
changeset
|
533 } |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
534 return; |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
535 } |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
536 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
537 /* Handle setting the multitude of variables |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
538 * It's last to simplify things */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
539 if (argc < 3) { |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
540 fputs("Incorrect number of arguments for variable/value\n", stdout); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
541 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
542 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
543 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
544 if (sscanf(argv[2], "%hd", &data) != 1) { |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
545 printf("Unable to parse value for variable\n"); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
546 return; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
547 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
548 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
549 if (!strcasecmp(argv[1], "targ")) { |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
550 tc_settings.target_temp = data; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
551 } else if (!strcasecmp(argv[1], "hys")) { |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
552 tc_settings.hysteresis = data; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
553 } else if (!strcasecmp(argv[1], "mhov")) { |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
554 tc_settings.minheatovershoot = data; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
555 } else if (!strcasecmp(argv[1], "mcov")) { |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
556 tc_settings.mincoolovershoot = data; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
557 } else if (!strcasecmp(argv[1], "mcon")) { |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
558 tc_settings.mincoolontime = data; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
559 } else if (!strcasecmp(argv[1], "mcoff")) { |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
560 tc_settings.mincoolofftime = data; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
561 } else if (!strcasecmp(argv[1], "mhon")) { |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
562 tc_settings.minheatontime = data; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
563 } else if (!strcasecmp(argv[1], "mhoff")) { |
66
0916bfe3f418
Rename settings to tc_settings as it's global.
Daniel O'Connor <darius@dons.net.au>
parents:
61
diff
changeset
|
564 tc_settings.minheatofftime = data; |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
565 } else { |
60
bbdf5642a7b7
Convert \r\n -> \n now _write() DTRT.
Daniel O'Connor <darius@dons.net.au>
parents:
57
diff
changeset
|
566 printf("Unknown setting\n"); |
31
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
567 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
568 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
569 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
570 static const char* |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
571 state2long(char s) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
572 switch (s) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
573 case 'i': |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
574 return "idle"; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
575 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
576 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
577 case 'c': |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
578 return "cool"; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
579 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
580 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
581 case 'h': |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
582 return "heat"; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
583 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
584 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
585 case '-': |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
586 return "-"; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
587 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
588 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
589 default: |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
590 return "unknown"; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
591 break; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
592 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
593 } |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
594 |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
595 /* Convert a port name into a number */ |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
596 static GPIO_TypeDef * |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
597 char2port(char port) { |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
598 char p; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
599 |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
600 p = toupper(port); |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
601 assert(p >= 'A' && p <= 'E'); |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
602 |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
603 switch (p) { |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
604 case 'A': |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
605 return GPIOA; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
606 case 'B': |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
607 return GPIOB; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
608 case 'C': |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
609 return GPIOC; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
610 case 'D': |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
611 return GPIOD; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
612 case 'E': |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
613 return GPIOE; |
57
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
614 default: |
adc9b1555f9d
Add the ability to log temperatures to SD card.
Daniel O'Connor <darius@dons.net.au>
parents:
43
diff
changeset
|
615 assert(1 == 0); /* Silence GCC warning */ |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
616 } |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
617 } |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
618 |