/
ApHSC.ino
140 lines (131 loc) · 5.96 KB
/
ApHSC.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* ApHSC (Arduino powered Heated Seat Controller)
* After-market Heated Seat Switching (powered by Arduino)
* Copyright (C) 2015 Luis E Alvarado
* Contact: admin@avnet.ws or alvaradorocks@gmail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* Software: https://github.com/avluis/ApHSC
* Hardware: https://github.com/avluis/ApHSC-Hardware
*
* Purpose:
* To control a ComfortHeat "Automotive Carbon Fiber Seat Heaters" by Rostra
* with the stock control panel of a vehicle, in my case, a 2011 Suzuki Kizashi.
* [Rostra Kit: 250-1872 (Universal Kit. Double thumb-dial Switch)
* Install Instructions: http://www.rostra.com/manuals/250-1870_Form5261.pdf]
*
* This program handles the logic required to control a 4-Stage Heated Seat Module.
* The stages are HIGH, MEDIUM, LOW and OFF. OFF is the default-start state.
* Indication of stages is done via LEDs for HIGH, MEDIUM and LOW.
* Vehicle wiring is ground based and built-in LEDs turn on when grounded.
* Rostra Control module is positive (+12v) signal switching.
*
* Grounding of LEDs is handled by a ULN2003A/TPL7407L (U3).
* Heat level switching is handled by a M54564P/A2982/TD62783APG (U4).
* U3 & U4 input pins are driven by the Arduino's Digital Output Pins.
*
* INPUT:
* Pin 2 & 3 for the Driver and Passenger Heat Buttons.
*
* OUTPUT:
* Pin 4, 5 and 6 for Driver side LEDs/Heat Level.
* Pin 7, 8 and 9 for Passenger side LEDs/Heat Level.
* Pin 10 is the ON signal for the Rostra Controller.
*
* Guide for the non-programmer:
*
* Auto Startup and Timer -
* If activated, the heat controller will start up when it receives power (think remote start)
* at a previously saved heat level. Additionally, a timer will run for a preset amount of time
* (adjustable) from the current heat level and power off once the preset time has passed.
* If Auto Startup is enabled, the timer can be turned off manually (until next power on)
* if any (either side) of the heated seat buttons is pressed.
* The timer will run only once (per startup) - only if Auto Start has been enabled and only
* for the seat(s) not set to OFF whenever Auto Start is enabled.
*
* To enable Auto Start, first set the desired heat level for both seats, then press and hold
* the driver side button for a few seconds to save the current heat level and enable Auto Start.
* Note that the timer will only run on the side where a heat level has been selected.
* So if you want the timer for both sides, set both seats to the desired heat level.
* If you want the timer on only one side, set that side only (leave the other side OFF).
* Pressing and holding the driver side button again while both seats are OFF will clear the saved
* heat levels and disable Auto Start.
*
* To set how long the timer will run (for both seats), press and hold the passenger side button for
* a few seconds with the following in mind:
* High Heat = 15 minutes, Medium Heat = 10 minutes and Low Heat = 5 minutes.
* Please note that disabling Auto Start will reset the timer to 1 minute (as a means prevent accidents).
* If you want to set the timer to 1 minute (manually), set the passenger heat level to OFF and then
* press and hold the passenger button (just like when saving) to reset the timer back to 1 minute.
*
* Additional features:
*
* While enabling/disabling Auto Start or saving/clearing heat levels - the current heat level will blink
* to indicate ON (long blink on, short blink off), OFF (short blink on, long blink off), and toggle
* (medium blinks of equal duration). An error blink is available, but not yet implemented.
*
* If populated, Arduino pin 13 (pin 17 in wiring) is used as a HeartBeat indicator per loop cycle.
* This is helpful if you wish to measure (in Hz) how long the program is taking to complete a loop.
* The LED is set to blink at a rate of 1000ms (1 second) by default.
*
* There are two ways (previous mentioned above) to monitor program activity via Serial -
* simply set kMonitorEnabled to 1 and open a Serial Monitor at a Baud Rate of 9600.
* If you wish, kDebugEnabled can be set as well, but be warned that it will flood your Serial Monitor.
*/
#include "Const.h"
#include "ApHSCZ.h"
#include <Arduino.h>
#include <HardwareSerial.h>
#include <stdint.h>
#include <WString.h>
void setup(void);
void loop(void);
// Setup
void setup() {
// Initializing On-Board LED as an output
pinMode(kOnBoardLedPin, OUTPUT);
// Initializing On Signal Pin as output
pinMode(kOnSignalPin, OUTPUT);
// Initializing Buttons as inputs
for (byte x = 0; x < ArrayLength(kBtnPins); x++) {
pinMode(kBtnPins[x], INPUT);
}
// Initializing Status Pins as outputs
for (byte x = 0; x < ArrayLength(kStatusPins); x++) {
pinMode(kStatusPins[x], OUTPUT);
}
// Serial || Debug
if (kMonitorEnabled || kDebugEnabled) {
Serial.begin(SERIALBAUD);
Serial.println(F("Heat Controller Up & Running."));
}
// Serial AND Debug!
if (kMonitorEnabled && kDebugEnabled) {
Serial.println(F("Don't blame me if you have to scroll~"));
} else if (kDebugEnabled) { // Debug Time!
Serial.println(F("Debug is enabled - don't get flooded!"));
} else { // Just Serial please.
Serial.println(F("Welcome, enjoy your stay."));
}
// ApHSC
ApHSC::init();
}
// Program loop
void loop() {
// Read the state of each button
ApHSC::queryBtnState();
// Reset counters when btn_push_count is OOR
ApHSC::resetBtnPushCount();
// Toggle power when btn_push_count != 0
ApHSC::togglePower();
// Still alive?
ApHSC::heartBeat();
}