-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhiluxLightModule.ino
More file actions
144 lines (129 loc) · 5.41 KB
/
hiluxLightModule.ino
File metadata and controls
144 lines (129 loc) · 5.41 KB
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
141
142
143
144
/************************************
* hiluxLightModule v2.0.1
* Date: 05.01.2025 | 23:14
* <Hilux Light Module>
* Copyright (C) 2025 Marina Egner <hello@sheepcs.de>
*
* 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, either version 3 of the License, or (at your option) any later version.
*
* 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, see <https://www.gnu.org/licenses/>.
************************************/
/************************************
* Configuration Programm
************************************/
#include "config.h" // Configuration File
#include "ioMapping.h" // IO Mapping File
/************************************
* Include Module and Library Files
************************************/
#include "readPPMdata.h" // read Data from Buffer
#include "lightFunctions.h"
//Setup Serial and check if Board is UNO with one Serial or Leonardo/Micro with to Serials
#ifdef HAVE_HWSERIAL1 //if serial ports 1 exist then the arduino has more than one serial port
#ifndef SerialUSB //if not allready defined
#define SerialUSB SERIAL_PORT_MONITOR //then define monitor port
#endif
#else
#if (DEBUGLEVEL >1) //if serial ports are the same debuging is not possible (for example on UNO)
#define DEBUGLEVEL 1 //do not change!!!
#endif
#endif
boolean lastChannel1DownState = false;
boolean hazardState = false;
boolean leftFlasherState = false;
boolean rightFlasherState = false;
boolean auxLightState = false;
boolean previousHighBeamState = false;
boolean parkingLightState = false;
boolean lowBeamState = false;
boolean highBeamState = false;
void setup() {
// put your setup code here, to run once:
/************************************
* Setup Inputs
************************************/
pinMode(inChannel1PPM, INPUT_PULLUP);
pinMode(inChannel2PPM, INPUT_PULLUP);
/************************************
* Setup Outputs
************************************/
initLightOutput();
setupLightOutput(outParkingLight, LIGHT_FADE_ON_TIME, LIGHT_FADE_OFF_TIME);
setupLightOutput(outLightFront, LIGHT_FADE_ON_TIME, LIGHT_FADE_OFF_TIME);
setupLightOutput(outPositionLightFront, LIGHT_FADE_ON_TIME, LIGHT_FADE_OFF_TIME);
setupLightOutput(outAuxLight, LIGHT_FADE_ON_TIME, LIGHT_FADE_OFF_TIME);
setupLightOutput(outFlasherLeft, LIGHT_FADE_ON_TIME, LIGHT_FADE_OFF_TIME);
setupLightOutput(outFlasherRight, LIGHT_FADE_ON_TIME, LIGHT_FADE_OFF_TIME);
setupLightOutput(outAuxLight, LIGHT_FADE_ON_TIME, LIGHT_FADE_OFF_TIME);
/************************************
* Setup Functions
************************************/
initInterrupts(inChannel1PPM, inChannel2PPM);
#if DEBUGLEVEL >= 2
SerialUSB.begin(9600);
#endif
}
#define LAYER1 1
#define LAYER2 2
uint8_t channelValue[3] { 0 };
boolean channel1StateDown = false;
void loop() { // put your main code here, to run repeatedly:
channelValue[LAYER1] = getChannel1Switch(DIRECTION_MID);
channelValue[LAYER2] = getChannel2Switch(DIRECTION_MID);
#if DEBUGLEVEL == 2
SerialUSB.print("Channel 1: ");
SerialUSB.println(channelValue[LAYER1]);
SerialUSB.print("Channel 2: ");
SerialUSB.println(channelValue[LAYER2]);
#endif
mapSwitchToState(LAYER1, channelValue[LAYER1], &highBeamState, &channel1StateDown);
mapSwitchToState(LAYER2, channelValue[LAYER2], &auxLightState, &hazardState);
#if DEBUGLEVEL == 2
SerialUSB.print("highBeamState: ");
SerialUSB.println(highBeamState);
SerialUSB.print("auxLightState: ");
SerialUSB.println(auxLightState);
#endif
// Edge shifts through modes
if((channel1StateDown == 1) && (lastChannel1DownState == 0)){
if((parkingLightState == true) && (lowBeamState == true)) {
parkingLightState = !parkingLightState;
lowBeamState = !lowBeamState;
setBooleanLight(outParkingLight, LOW, NORMAL_LIGHT_DIMMING);
setBooleanLight(outPositionLightFront, LOW, NORMAL_LIGHT_DIMMING);
} else if((parkingLightState == true) && (lowBeamState == false)) {
lowBeamState = !lowBeamState;
} else if((parkingLightState == false) && (lowBeamState == false)) {
parkingLightState = !parkingLightState;
setBooleanLight(outParkingLight, HIGH, PARKING_DIMM);
setBooleanLight(outPositionLightFront, HIGH, PARKING_DIMM);
}
lastChannel1DownState = channel1StateDown;
} else {
lastChannel1DownState = channel1StateDown;
}
// Set Light on front depending on different states
if(highBeamState == false) {
if(lowBeamState == true) {
setBooleanLight(outLightFront, HIGH, HEADLIGHT_LOWBEAM_VALUE);
} else {
setBooleanLight(outLightFront, LOW, HEADLIGHT_LOWBEAM_VALUE);
}
} else if(highBeamState == true) {
setBooleanLight(outLightFront, HIGH, HEADLIGHT_HIGHBEAM_VALUE);
}
bool leftFlasherOut = false;
bool rightFlasherOut = false;
setFlasherLight(leftFlasherState, rightFlasherState, hazardState, &leftFlasherOut, &rightFlasherOut, BLINKER_FREQUENCY);
setBooleanLight(outFlasherLeft, leftFlasherOut, NORMAL_LIGHT_DIMMING);
setBooleanLight(outFlasherRight, rightFlasherOut, NORMAL_LIGHT_DIMMING);
// Aux Light
setBooleanLight(outAuxLight, auxLightState, NORMAL_LIGHT_DIMMING);
}