-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlsrandomeffect.c
162 lines (152 loc) · 4.12 KB
/
lsrandomeffect.c
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
//*****************************************************************************
//
// Application Name - LightServer
// File Name - lsrandomeffect.c
// Application Version - 2.5.0
// Application Modify Date - 26th of December 2014
// Application Developer - Glenn Vassallo
// Application Contact - [email protected]
// Application Repository - https://github.com/remixed123/LightServer
//
// Application Overview - LightServer is a Wifi enabled embedded device which
// controls RGB Intelligent lighting in various ways.
// You can control the lights via iOS Apps or via a
// webpages that are on the device.This example project
// provides a starting
//
// File Overview - lsrandomeffect.c contains functions to randomly
// select effects.
//
// Application Details - https://github.com/remixed123/LightServer/readme.txt
//
//*****************************************************************************
#include "lightserver.h"
#include "lsrandomeffect.h"
#include <stdlib.h>
//*****************************************************************************
//! randomEffectSelector
//!
//! The function selects the random effect
//!
//! \param randEffect
//!
//! \return 0 on success
//*****************************************************************************
lsresult_t randomEffectSelector(int randEffect)
{
if (randEffect == 1)
{
memcpy(effectControl.fx, "Fixed", 5);
effectControl.fx[5] = '\0';
}
else if (randEffect == 2)
{
memcpy(effectControl.fx, "Candle", 6);
effectControl.fx[6] = '\0';
}
else if (randEffect == 3)
{
memcpy(effectControl.fx, "Chase", 5);
effectControl.fx[5] = '\0';
}
else if (randEffect == 4)
{
memcpy(effectControl.fx, "Strobe", 6);
effectControl.fx[6] = '\0';
}
else if (randEffect == 5)
{
memcpy(effectControl.fx, "Waves", 5);
effectControl.fx[5] = '\0';
}
else if (randEffect == 6)
{
memcpy(effectControl.fx, "Comets", 6);
effectControl.fx[6] = '\0';
}
else if (randEffect == 7)
{
memcpy(effectControl.fx, "Snakes", 6);
effectControl.fx[6] = '\0';
}
else if (randEffect == 8)
{
memcpy(effectControl.fx, "Twinkle", 7);
effectControl.fx[7] = '\0';
}
else if (randEffect == 9)
{
memcpy(effectControl.fx, "Rainbow", 7);
effectControl.fx[7] = '\0';
}
else if (randEffect == 10)
{
memcpy(effectControl.fx, "Color Wheel", 11);
effectControl.fx[11] = '\0';
}
else if (randEffect == 11)
{
memcpy(effectControl.fx, "Glow", 4);
effectControl.fx[4] = '\0';
}
else if (randEffect == 12)
{
memcpy(effectControl.fx, "Pulse", 5);
effectControl.fx[5] = '\0';
}
else if (randEffect == 13)
{
memcpy(effectControl.fx, "Glow Mix", 8);
effectControl.fx[8] = '\0';
}
else if (randEffect == 14)
{
memcpy(effectControl.fx, "Glow Wave", 9);
effectControl.fx[9] = '\0';
}
else if (randEffect == 15)
{
memcpy(effectControl.fx, "Ants", 4);
effectControl.fx[4] = '\0';
}
else if (randEffect == 16)
{
memcpy(effectControl.fx, "Paint", 5);
effectControl.fx[5] = '\0';
}
else if (randEffect == 17)
{
memcpy(effectControl.fx, "Blend", 5);
effectControl.fx[5] = '\0';
}
else if (randEffect == 18)
{
memcpy(effectControl.fx, "Blend Mix", 9);
effectControl.fx[9] = '\0';
}
else
{
memcpy(effectControl.fx, "Fixed", 5);
effectControl.fx[5] = '\0';
}
return LS_SUCCESS;
}
//*****************************************************************************
//! selectRandomEffect()
//!
//! Selects a random effect to use
//!
//!
//****************************************************************************
lsresult_t selectRandomEffect()
{
effectControl.randEffect = rand() % 19;
randomEffectSelector(effectControl.randEffect);
effectControl.speed = (rand() % 100) + 1;
effectControl.direction = (rand() % 100) % 2;
effectControl.colorCount = (rand() % 5) + 1;
effectControl.actualColorCount = effectControl.colorCount;
effectControl.storedColorCount = effectControl.actualColorCount;
beginEffectClock();
return LS_SUCCESS;
}