-
Notifications
You must be signed in to change notification settings - Fork 3
/
AtmoRemoteControlImplEx.cpp
249 lines (203 loc) · 6.15 KB
/
AtmoRemoteControlImplEx.cpp
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#include "StdAfx.h"
#include "atmoremotecontrolimplex.h"
#include "atmodefs.h"
#include "AtmoTools.h"
#include "atmoconnection.h"
#include "atmoxmlconfig.h"
#include "ObjectModel.h"
#include "AtmoLiveView.h"
CAtmoRemoteControlImplEx::CAtmoRemoteControlImplEx(CAtmoDynData *pAtmoDynData) : m_RefCounter(1)
{
this->m_pAtmoDynData = pAtmoDynData;
m_pLiveViewControl = new CAtmoLiveViewControlImpl(pAtmoDynData);
}
CAtmoRemoteControlImplEx::~CAtmoRemoteControlImplEx(void)
{
m_pLiveViewControl->Release();
}
STDMETHODIMP CAtmoRemoteControlImplEx::QueryInterface(REFIID Id, void** pPointer)
{
if (IsEqualIID(Id, IID_IUnknown))
{
*pPointer = this;
} else if (IsEqualIID(Id, IID_IAtmoRemoteControl))
{
*pPointer = this;
} else if (IsEqualIID(Id, IID_IAtmoRemoteControl2))
{
*pPointer = this;
} else if (IsEqualIID(Id, IID_IAtmoLiveViewControl) && (m_pAtmoDynData->getAtmoConfig()->getEffectMode() == emLivePicture))
{
*pPointer = m_pLiveViewControl;
m_pLiveViewControl->AddRef();
return S_OK;
} else
{
*pPointer = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
STDMETHODIMP_(ULONG) CAtmoRemoteControlImplEx::AddRef()
{
m_RefCounter++;
return m_RefCounter;
}
STDMETHODIMP_(ULONG) CAtmoRemoteControlImplEx::Release()
{
ULONG Temp = --m_RefCounter;
if (!Temp)
delete this;
return Temp;
}
EffectMode CAtmoRemoteControlImplEx::ConvertEffectCom2Atmo(ComEffectMode cem)
{
switch(cem)
{
case cemDisabled: return emDisabled;
case cemStaticColor: return emStaticColor;
case cemLivePicture: return emLivePicture;
case cemColorChange: return emColorChange;
case cemLrColorChange : return emLrColorChange;
//case cemColorMode : return emColorMode;
}
return emUndefined;
}
ComEffectMode CAtmoRemoteControlImplEx::ConvertEffectAtmo2Com(EffectMode em)
{
switch(em)
{
case emDisabled: return cemDisabled;
case emStaticColor: return cemStaticColor;
case emLivePicture: return cemLivePicture;
case emColorChange: return cemColorChange;
case emLrColorChange : return cemLrColorChange;
//case emColorMode : return cemColorMode;
}
return cemUndefined;
}
STDMETHODIMP CAtmoRemoteControlImplEx::setEffect(enum ComEffectMode dwEffect, enum ComEffectMode *dwOldEffect)
{
if (dwEffect==cemColorMode)
{
std::string newprofile;
m_pAtmoDynData->LockCriticalSection();
CAtmoConnection *connection = this->m_pAtmoDynData->getAtmoConnection();
if((connection!=NULL) && (connection->isOpen()))
{
CAtmoConfig *pConfig = m_pAtmoDynData->getAtmoConfig();
CUtils *Utils = new CUtils;
__int64 count = Utils->profiles.GetCount();
//modeswitch...
for (int i=0;i<count;++i)
if ( Utils->profiles[i]==pConfig->lastprofile)
{
if (i==count-1)
newprofile=Utils->profiles[0];
else
newprofile=Utils->profiles[i+1];
}
if ( pConfig->lastprofile=="" && count>0)
newprofile=Utils->profiles[0];
pConfig->lastprofile=newprofile;
pConfig->LoadSettings(pConfig->lastprofile);
EffectMode backupEffectMode = pConfig->getEffectMode();
// destroy current Thread
CAtmoTools::SwitchEffect(this->m_pAtmoDynData, emDisabled);
CAtmoTools::RecreateConnection(this->m_pAtmoDynData);
// reactivate it
CAtmoTools::SwitchEffect(this->m_pAtmoDynData, backupEffectMode);
pConfig->SaveSettings(pConfig->lastprofile);
}
m_pAtmoDynData->UnLockCriticalSection();
return S_OK;
}
else
{
EffectMode oldEm = CAtmoTools::SwitchEffect(this->m_pAtmoDynData, ConvertEffectCom2Atmo(dwEffect));
if(dwOldEffect!=NULL)
*dwOldEffect = ConvertEffectAtmo2Com(oldEm);
if(oldEm == emUndefined)
return S_FALSE;
else
return S_OK;
}
}
STDMETHODIMP CAtmoRemoteControlImplEx::getEffect(enum ComEffectMode *dwEffect)
{
m_pAtmoDynData->LockCriticalSection();
CAtmoConfig *atmoConfig = this->m_pAtmoDynData->getAtmoConfig();
if(atmoConfig!=NULL)
*dwEffect = ConvertEffectAtmo2Com(atmoConfig->getEffectMode());
m_pAtmoDynData->UnLockCriticalSection();
if(atmoConfig == NULL)
return S_FALSE;
else
return S_OK;
}
STDMETHODIMP CAtmoRemoteControlImplEx::setStaticColor(BYTE red, BYTE green, BYTE blue)
{
m_pAtmoDynData->LockCriticalSection();
CAtmoConnection *connection = this->m_pAtmoDynData->getAtmoConnection();
if((connection!=NULL) && (connection->isOpen()))
{
CAtmoConfig *pConfig = m_pAtmoDynData->getAtmoConfig();
pColorPacket newColors;
int zoneCount = pConfig->getZoneCount();
AllocColorPacket(newColors, zoneCount);
for(int i=0;i<zoneCount;i++)
{
newColors->zone[i].r = red;
newColors->zone[i].g = green;
newColors->zone[i].b = blue;
}
newColors = CAtmoTools::ApplyGamma(pConfig, newColors);
if(pConfig->isUseSoftwareWhiteAdj())
newColors = CAtmoTools::WhiteCalibration(pConfig, newColors);
connection->SendData(newColors);
delete (char *)newColors;
}
this->m_pAtmoDynData->UnLockCriticalSection();
return S_OK;
}
STDMETHODIMP CAtmoRemoteControlImplEx::setChannelStaticColor(int channel, BYTE red, BYTE green, BYTE blue)
{
this->m_pAtmoDynData->LockCriticalSection();
tRGBColor newColor;
newColor.r = red;
newColor.g = green;
newColor.b = blue;
CAtmoConnection *connection = this->m_pAtmoDynData->getAtmoConnection();
if((connection!=NULL) && (connection->isOpen()))
{
connection->setChannelColor(channel, newColor);
}
this->m_pAtmoDynData->UnLockCriticalSection();
return S_OK;
}
STDMETHODIMP CAtmoRemoteControlImplEx::setChannelValues(SAFEARRAY *channel_values)
{
if(!channel_values) return S_FALSE;
ATMO_BOOL result = ATMO_FALSE;
unsigned char *pChannel_Values;
SafeArrayAccessData(channel_values,(void **)&pChannel_Values);
int numElements = channel_values->rgsabound[0].cElements;
this->m_pAtmoDynData->LockCriticalSection();
CAtmoConnection *connection = this->m_pAtmoDynData->getAtmoConnection();
if((connection!=NULL) && (connection->isOpen())) {
result = connection->setChannelValues(numElements, pChannel_Values);
}
this->m_pAtmoDynData->UnLockCriticalSection();
SafeArrayUnaccessData(channel_values);
if(result == ATMO_TRUE)
return S_OK;
else
return S_FALSE;
}
STDMETHODIMP CAtmoRemoteControlImplEx::getLiveViewRes(/* [out] */ int *Width, /* [out] */ int *Height)
{
*Width = CAP_WIDTH;
*Height = CAP_HEIGHT;
return S_OK;
}