Mercurial > ~darius > hgwebdir.cgi > stm32temp
annotate tempctrl.c @ 42:56b32b0c9a40
Store port & pin as char & number and map.
Allow them to be inverted for active low setups.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 01 Apr 2013 21:12:57 +1030 |
parents | d3b7d4964807 |
children | b4440f9f6d47 |
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" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
40 #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
|
41 #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
|
42 |
03592ca4d37e
Port tempctrl.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 /* 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 /* 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
|
51 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
|
52 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
|
53 |
03592ca4d37e
Port tempctrl.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 /* 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
|
55 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
|
56 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
|
57 |
03592ca4d37e
Port tempctrl.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 /* 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
|
59 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
|
60 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
|
61 |
03592ca4d37e
Port tempctrl.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 #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
|
63 #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
|
64 #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
|
65 #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
|
66 #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
|
67 char 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
|
68 |
03592ca4d37e
Port tempctrl.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 /* 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
|
70 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
|
71 uint16_t coolpin; |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
72 uint8_t coolinv; |
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
|
73 |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
74 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
|
75 uint16_t heatpin; |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
76 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
|
77 |
03592ca4d37e
Port tempctrl.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 /* 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
|
79 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
|
80 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
|
81 |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
82 uint8_t pad[1]; /* Pad to multiple of 4 bytes */ |
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
|
83 } settings_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
|
84 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
85 /* Current settings in RAM */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
86 static settings_t 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
|
87 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
88 /* Defaults that are shoved into SPI flash if it isn't inited */ |
03592ca4d37e
Port tempctrl.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 const settings_t 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
|
90 .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
|
91 .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
|
92 .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
|
93 .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
|
94 .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
|
95 .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
|
96 .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
|
97 .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
|
98 .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
|
99 .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
|
100 .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
|
101 .mode = TC_MODE_AUTO, |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
102 .coolport = 'E', |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
103 .coolpin = 4, |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
104 .coolinv = 1, |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
105 .heatport = 'E', |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
106 .heatpin = 5, |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
107 .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
|
108 .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
|
109 .stale_factor = 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
|
110 }; |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
111 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
112 /* 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
|
113 |
03592ca4d37e
Port tempctrl.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 /* 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
|
115 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
|
116 static void tempctrl_default_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
|
117 static void tempctrl_write_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
|
118 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
|
119 static const char * 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
|
120 static void printtemp(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
|
121 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
|
122 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
123 /* |
03592ca4d37e
Port tempctrl.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 * 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
|
125 * |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
126 */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 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
|
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 /* |
03592ca4d37e
Port tempctrl.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_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
|
135 * |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
136 * 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
|
137 * (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
|
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 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
|
141 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
|
142 /* 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
|
143 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
|
144 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
|
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 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 /* 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
|
155 * 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
|
156 |
03592ca4d37e
Port tempctrl.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 /* 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 struct tm tm; |
03592ca4d37e
Port tempctrl.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 char buf[23]; |
03592ca4d37e
Port tempctrl.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 |
03592ca4d37e
Port tempctrl.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 t = time(NULL); |
03592ca4d37e
Port tempctrl.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 |
03592ca4d37e
Port tempctrl.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 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
|
170 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
|
171 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
|
172 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
173 checktime = t + settings.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
|
174 |
03592ca4d37e
Port tempctrl.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 /* Don't do any logging, just force idle and leave */ |
03592ca4d37e
Port tempctrl.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 if (settings.mode == TC_MODE_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
|
177 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
|
178 goto setstate; |
03592ca4d37e
Port tempctrl.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 |
03592ca4d37e
Port tempctrl.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 /* 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
|
182 * 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
|
183 */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
184 tempt = OWGetTemp(settings.fermenter_ROM); |
03592ca4d37e
Port tempctrl.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 fridge_temp = OWGetTemp(settings.fridge_ROM); |
03592ca4d37e
Port tempctrl.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 ambient_temp = OWGetTemp(settings.ambient_ROM); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
187 |
03592ca4d37e
Port tempctrl.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 /* 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
|
189 * 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
|
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 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
|
192 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
|
193 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
|
194 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
195 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
196 /* Check for 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
|
197 if (lastdata + (settings.check_interval * settings.stale_factor) < 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
|
198 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
|
199 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
|
200 stale = 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
|
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 /* 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
|
203 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
|
204 |
03592ca4d37e
Port tempctrl.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 /* Temperature diff, -ve => too cold, +ve => too warm */ |
03592ca4d37e
Port tempctrl.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 diff = fermenter_temp - settings.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
|
207 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
208 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
|
209 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
|
210 /* If we're idle then only heat or cool if the temperate difference is out of 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
|
211 * hysteresis band |
03592ca4d37e
Port tempctrl.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 */ |
03592ca4d37e
Port tempctrl.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 if (abs(diff) > settings.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
|
214 if (diff < 0 && settings.minheatofftime + 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
|
215 nextstate = '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
|
216 else if (diff > 0 && settings.mincoolofftime + 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
|
217 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
|
218 } |
03592ca4d37e
Port tempctrl.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 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
|
220 |
03592ca4d37e
Port tempctrl.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 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
|
222 /* Work out if we should go idle (based on min on time & overshoot) */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
223 if (diff + settings.mincoolovershoot < 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
|
224 settings.mincoolontime + 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
|
225 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
|
226 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
|
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 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
|
229 if (diff - settings.minheatovershoot > 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
|
230 settings.minheatontime + 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
|
231 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
|
232 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
|
233 |
03592ca4d37e
Port tempctrl.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 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
|
235 printf("\r\nUnknown state %c, going to idle\n", 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
|
236 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
|
237 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
|
238 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
239 |
03592ca4d37e
Port tempctrl.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 /* 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
|
241 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
|
242 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
|
243 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
244 /* Handle state forcing */ |
03592ca4d37e
Port tempctrl.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 if (settings.mode != 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
|
246 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
|
247 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
|
248 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
|
249 |
03592ca4d37e
Port tempctrl.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 (settings.mode == 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
|
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 else if (settings.mode == 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
|
253 nextstate = '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
|
254 else if (settings.mode == 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
|
255 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
|
256 |
03592ca4d37e
Port tempctrl.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 // Keep track of when we last turned things on or 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 |
03592ca4d37e
Port tempctrl.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 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
|
266 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
|
267 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
|
268 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
|
269 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
|
270 |
03592ca4d37e
Port tempctrl.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 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 } |
03592ca4d37e
Port tempctrl.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 |
03592ca4d37e
Port tempctrl.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 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
|
279 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
|
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 |
33
d3b7d4964807
Create a TZ info structure for ACST and use it when printing times.
Daniel O'Connor <darius@dons.net.au>
parents:
31
diff
changeset
|
282 localtime_r(&t, &tm); |
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
|
283 assert(strftime(buf, sizeof(buf) - 1, "%Y/%m/%d %H:%M:%S: ", &tm) != 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
|
284 fputs(buf, stdout); |
03592ca4d37e
Port tempctrl.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 printtemp("Tr", settings.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
|
286 printtemp("Fm", tempt, ", "); // Use actual value from sensor |
03592ca4d37e
Port tempctrl.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 printtemp("Fr", fridge_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
|
288 printtemp("Am", ambient_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
|
289 printf("St: %s, Fl: %s%s\r\n", state2long(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
|
290 forced ? "F" : "", |
03592ca4d37e
Port tempctrl.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 stale ? "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
|
292 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
293 setstate: |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
294 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
|
295 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
296 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
297 /* |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
298 * Print out temperature (or short error code) with specified trailer |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
299 */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
300 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
|
301 printtemp(const char *name, int tmp, const char *trailer) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
302 if (tmp > 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
|
303 printf("%s: %d.%02d%s", name, GETWHOLE(tmp), GETFRAC(tmp), trailer); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
304 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
|
305 printf("%s: %s%s", name, OWTempStatusStr(tmp, 1), trailer); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
306 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
307 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
308 /* 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
|
309 * 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
|
310 */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
311 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
|
312 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
|
313 /* XXX: todo */ |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
314 if (!flashreadblock(0, sizeof(settings), &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
|
315 fputs("CRC fails, loading defaults\r\n", stdout); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
316 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
|
317 tempctrl_write_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
|
318 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
319 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
320 |
03592ca4d37e
Port tempctrl.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 /* 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
|
322 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
|
323 tempctrl_default_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
|
324 memcpy(&settings, &default_settings, sizeof(settings_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
|
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 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
327 /* Write the current settings out to 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
|
328 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
|
329 tempctrl_write_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
|
330 flashwriteblock(0, sizeof(settings), &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
|
331 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
332 |
03592ca4d37e
Port tempctrl.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 /* 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
|
334 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
|
335 setstate(char state) { |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
336 uint8_t cool, heat; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
337 |
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
|
338 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
|
339 case 'c': |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
340 cool = 1; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
341 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
|
342 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
|
343 |
03592ca4d37e
Port tempctrl.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 case 'h': |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
345 cool = 0; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
346 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
|
347 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
|
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 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
|
350 printf("Unknown state %c, setting idle\r\n", 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
|
351 /* 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
|
352 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
353 case 'i': |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
354 cool = 0; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
355 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
|
356 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
|
357 } |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
358 |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
359 if (cool ^ settings.coolinv) |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
360 GPIO_SetBits(char2port(settings.coolport), 1 << settings.coolpin); |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
361 else |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
362 GPIO_ResetBits(char2port(settings.coolport), 1 << settings.coolpin); |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
363 |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
364 if (heat ^ settings.heatinv) |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
365 GPIO_SetBits(char2port(settings.heatport), 1 << settings.heatpin); |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
366 else |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
367 GPIO_ResetBits(char2port(settings.heatport), 1 << 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
|
368 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
369 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
370 /* 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
|
371 * |
03592ca4d37e
Port tempctrl.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 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
|
374 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
|
375 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
|
376 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
|
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 if (argc < 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
|
379 printf("Unable to parse tc subcommand\r\n"); |
03592ca4d37e
Port tempctrl.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 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
|
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 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
383 if (!strcasecmp(argv[0], "help")) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
384 printf("tc help This help\r\n" |
03592ca4d37e
Port tempctrl.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 "tc save Save settings to EEPROM\r\n" |
03592ca4d37e
Port tempctrl.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 "tc load Load or default settings from EEPROM\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
387 "tc dflt Load defaults from flash\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
388 "tc list List current settings\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
389 "tc mode [achin] Change control mode, must be one of\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
390 " a Auto\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
391 " c Always cool\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
392 " h Always heat\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
393 " i Always idle\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
394 " n Like idle but don't log anything\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
395 "tc X Y Set X to Y where X is one of\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
396 " targ Target temperature\r\n" |
03592ca4d37e
Port tempctrl.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 " hys Hysteresis range\r\n" |
03592ca4d37e
Port tempctrl.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 " mhov Minimum heat overshoot\r\n" |
03592ca4d37e
Port tempctrl.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 " mcov Minimum cool overshoot\r\n" |
03592ca4d37e
Port tempctrl.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 " mcon Minimum cool on time\r\n" |
03592ca4d37e
Port tempctrl.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 " mcoff Minimum cool off time\r\n" |
03592ca4d37e
Port tempctrl.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 " mhin Minimum heat on time\r\n" |
03592ca4d37e
Port tempctrl.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 " mhoff Minimum heat off time\r\n" |
03592ca4d37e
Port tempctrl.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 "tc A B Set temperature sensor ID\r\n" |
03592ca4d37e
Port tempctrl.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 " Where A is ferm, frg or amb\r\n" |
03592ca4d37e
Port tempctrl.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 " and B is of the form xx:xx:xx:xx:xx:xx:xx:xx\r\n" |
03592ca4d37e
Port tempctrl.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 "\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
408 " Times are in seconds\r\n" |
03592ca4d37e
Port tempctrl.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 " Temperatures are in hundredths of degrees Celcius\r\n" |
03592ca4d37e
Port tempctrl.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 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
|
412 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
413 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
414 if (!strcasecmp(argv[0], "save")) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
415 tempctrl_write_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
|
416 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
|
417 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
422 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
|
423 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
|
424 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
|
425 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
426 if (!strcasecmp(argv[0], "list")) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
427 printf("Fermenter ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
428 "Fridge ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
429 "Ambient ROM ID %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
430 "Mode - %c, Target - %d, Hystersis - %d\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
431 "Min heat overshoot - %d, Min cool overshoot - %d\r\n" |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
432 "Min cool on time - %d, Min cool off time - %d\r\n" |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
433 "Min heat on time - %d, Min heat off time - %d\r\n" |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
434 "Cool: Port %c Pin %d Inv %d, Heat: Port %c Pin %d Inv %d\r\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
|
435 settings.fermenter_ROM[0], settings.fermenter_ROM[1], settings.fermenter_ROM[2], settings.fermenter_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
|
436 settings.fermenter_ROM[4], settings.fermenter_ROM[5], settings.fermenter_ROM[6], settings.fermenter_ROM[7], |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
437 settings.fridge_ROM[0], settings.fridge_ROM[1], settings.fridge_ROM[2], settings.fridge_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
|
438 settings.fridge_ROM[4], settings.fridge_ROM[5], settings.fridge_ROM[6], settings.fridge_ROM[7], |
03592ca4d37e
Port tempctrl.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 settings.ambient_ROM[0], settings.ambient_ROM[1], settings.ambient_ROM[2], settings.ambient_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
|
440 settings.ambient_ROM[4], settings.ambient_ROM[5], settings.ambient_ROM[6], settings.ambient_ROM[7], |
03592ca4d37e
Port tempctrl.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 settings.mode, settings.target_temp, settings.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
|
442 settings.minheatovershoot, settings.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
|
443 settings.mincoolontime, settings.minheatontime, |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
444 settings.minheatontime, settings.minheatofftime, |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
445 settings.coolport, settings.coolpin, settings.coolinv, |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
446 settings.heatport, settings.heatpin, settings.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
|
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 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
|
449 } |
03592ca4d37e
Port tempctrl.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 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
|
451 if (argc < 2) { |
03592ca4d37e
Port tempctrl.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 fputs("Incorrect number of arguments\r\n", stdout); |
03592ca4d37e
Port tempctrl.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 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
|
454 } |
03592ca4d37e
Port tempctrl.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 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
|
457 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
|
458 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
|
459 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
|
460 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
|
461 case TC_MODE_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
|
462 settings.mode = 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
|
463 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
|
464 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
465 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
|
466 printf("Unknown mode character '%c'\r\n", 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
|
467 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
|
468 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
469 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
|
470 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
471 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
|
472 !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
|
473 !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
|
474 if (argc < 2) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
475 fputs("Incorrect number of arguments\r\n", stdout); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
476 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
|
477 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
478 |
03592ca4d37e
Port tempctrl.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 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
|
480 &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
|
481 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 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
|
482 printf("Unable to parse ROM ID\r\n"); |
03592ca4d37e
Port tempctrl.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 } 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
|
484 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
|
485 memcpy(&settings.fermenter_ROM, ROM, sizeof(ROM)); |
03592ca4d37e
Port tempctrl.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 if (!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
|
487 memcpy(&settings.fridge_ROM, ROM, sizeof(ROM)); |
03592ca4d37e
Port tempctrl.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 if (!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
|
489 memcpy(&settings.ambient_ROM, ROM, sizeof(ROM)); |
03592ca4d37e
Port tempctrl.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 } |
03592ca4d37e
Port tempctrl.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 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
|
492 } |
03592ca4d37e
Port tempctrl.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 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
494 /* 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
|
495 * 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
|
496 if (argc < 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
|
497 fputs("Incorrect number of arguments for variable/value\r\n", stdout); |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
498 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
|
499 } |
03592ca4d37e
Port tempctrl.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 if (sscanf(argv[2], "%hd", &data) != 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
|
502 printf("Unable to parse value for variable\r\n"); |
03592ca4d37e
Port tempctrl.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 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
|
504 } |
03592ca4d37e
Port tempctrl.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 |
03592ca4d37e
Port tempctrl.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 (!strcasecmp(argv[1], "targ")) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
507 settings.target_temp = 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
|
508 } else if (!strcasecmp(argv[1], "hys")) { |
03592ca4d37e
Port tempctrl.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 settings.hysteresis = 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
|
510 } else if (!strcasecmp(argv[1], "mhov")) { |
03592ca4d37e
Port tempctrl.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 settings.minheatovershoot = 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
|
512 } else if (!strcasecmp(argv[1], "mcov")) { |
03592ca4d37e
Port tempctrl.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 settings.mincoolovershoot = 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
|
514 } else if (!strcasecmp(argv[1], "mcon")) { |
03592ca4d37e
Port tempctrl.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 settings.mincoolontime = 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
|
516 } else if (!strcasecmp(argv[1], "mcoff")) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
517 settings.mincoolofftime = 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
|
518 } else if (!strcasecmp(argv[1], "mhon")) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
519 settings.minheatontime = 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
|
520 } else if (!strcasecmp(argv[1], "mhoff")) { |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
521 settings.minheatofftime = 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
|
522 } 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
|
523 printf("Unknown setting\r\n"); |
03592ca4d37e
Port tempctrl.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 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
525 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
526 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
534 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
|
535 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
|
536 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
|
537 |
03592ca4d37e
Port tempctrl.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 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
|
539 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
|
540 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
|
541 |
03592ca4d37e
Port tempctrl.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 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
|
543 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
|
544 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
|
545 |
03592ca4d37e
Port tempctrl.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 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
|
547 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
|
548 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
|
549 } |
03592ca4d37e
Port tempctrl.c from AVR. I removed the beep code as I don't have a
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
550 } |
42
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
551 |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
552 /* 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
|
553 static GPIO_TypeDef * |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
554 char2port(char port) { |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
555 char p; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
556 |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
557 p = toupper(port); |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
558 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
|
559 |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
560 switch (p) { |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
561 case 'A': |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
562 return GPIOA; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
563 case 'B': |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
564 return GPIOB; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
565 case 'C': |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
566 return GPIOC; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
567 case 'D': |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
568 return GPIOD; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
569 case 'E': |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
570 return GPIOE; |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
571 } |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
572 } |
56b32b0c9a40
Store port & pin as char & number and map.
Daniel O'Connor <darius@dons.net.au>
parents:
33
diff
changeset
|
573 |