-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStatusLeds.c
More file actions
183 lines (154 loc) · 5.09 KB
/
StatusLeds.c
File metadata and controls
183 lines (154 loc) · 5.09 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
Copyright (C) Pete Brownlow 2014-2017 software@upsys.co.uk
CBUS Status LEDs - I/O routines for the SLiM and FLiM status LEDs
This code is for a standard CBUS module that has a yellow and green LED
This work is licensed under the:
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
To view a copy of this license, visit:
http://creativecommons.org/licenses/by-nc-sa/4.0/
or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
License summary:
You are free to:
Share, copy and redistribute the material in any medium or format
Adapt, remix, transform, and build upon the material
The licensor cannot revoke these freedoms as long as you follow the license terms.
Attribution : You must give appropriate credit, provide a link to the license,
and indicate if changes were made. You may do so in any reasonable manner,
but not in any way that suggests the licensor endorses you or your use.
NonCommercial : You may not use the material for commercial purposes. **(see note below)
ShareAlike : If you remix, transform, or build upon the material, you must distribute
your contributions under the same license as the original.
No additional restrictions : You may not apply legal terms or technological measures that
legally restrict others from doing anything the license permits.
** For commercial use, please contact the original copyright holder(s) to agree licensing terms
This software 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
**************************************************************************************************************
Note: This source code has been written using a tab stop and indentation setting
of 4 characters. To see everything lined up correctly, please set your
IDE or text editor to the same settings.
******************************************************************************************************
For library version number and revision history see CBUSLib.h
Modifications to initStatusLeds() by Ian Hogg 23/5/2017
*/
#include "module.h"
#include "StatusLeds.h"
TickValue flashTime;
enum FlashStates flashState;
TickValue flickerTime;
enum FlickerStates flickerState;
//******* Routines to set the Green and Yellow SLiM and FLiM LEDs *************************
/**
* Initialise with both LEDs off.
*/
void initStatusLeds(void)
{
TRIS_LED1Y = 0;
TRIS_LED2G = 0;
LED1Y = LED_OFF;
LED2G = LED_OFF;
flashState = flNone;
flickerTime.Val = 0;
}
/**
* Set the Green LED and turn of the Yellow LED.
*/
void setSLiMLed(void)
{
LED1Y = 0;
LED2G = 1;
flashState = flNone;
}
/**
* Set the yellow LED and turn off the green LED.
*/
void setFLiMLed(void)
{
LED1Y = 1;
LED2G = 0;
flashState = flNone;
}
/**
* Sets either the FLiM or the SLiM LED.
* @param FLiMLED if true turns on the FLiM LED otherwise turn on the SLiM LED.
*/
void setStatusLed( BOOL FLiMLED )
{
if (FLiMLED)
setFLiMLed();
else
setSLiMLed();
}
/**
* Flash the FLiM LED.
*/
void doFLiMFlash(void)
{
LED1Y = !LED1Y;
flashTime.Val = tickGet();
}
/**
* Start the FLiM LED flashing at the specified rate.
* @param fast if true flash the LED quickly
*/
void startFLiMFlash( BOOL fast )
{
flashState = (fast? flFLiMFast : flFLiMSlow);
doFLiMFlash();
}
/**
* Process the FLiM LED flashing. Call regularly.
*/
void checkFlashing(void)
{
switch (flashState)
{
case flFLiMSlow:
if (tickTimeSince(flashTime) > SLOW_FLASH_TIME)
doFLiMFlash();
break;
case flFLiMFast:
if (tickTimeSince(flashTime) > FAST_FLASH_TIME)
doFLiMFlash();
break;
}
switch(flickerState) {
case flickWaitingOn:
// turn on the LED - FLiM this would be the green SLiM led
if (flimState == fsSLiM) {
LED1Y = 1;
} else {
LED2G = 1;
}
flickerState = flickOn;
break;
case flickOn:
// time to turn off yet?
if (tickGet() >= flickerTime.Val) {
// turn off the LED - in FLiM this would be the green SLiM led
if (flimState == fsSLiM) {
LED1Y = 0;
} else {
LED2G = 0;
}
flickerState = flickOff;
}
break;
}
}
/**
* Flicker the other LED on for a short time
*/
void shortFlicker() {
if (flickerTime.Val < tickGet() + SHORT_FLICKER_TIME) {
flickerTime.Val = tickGet() + SHORT_FLICKER_TIME;
flickerState = flickWaitingOn;
}
}
/**
* Flicker the other LED on for a longer time
*/
void longFlicker() {
flickerTime.Val = tickGet() + LONG_FLICKER_TIME;
flickerState = flickWaitingOn;
}