2011-04-24 01:14:00 +00:00
|
|
|
#include "Supermodel.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
ESourceType CMultiInputSource::GetCombinedType(vector<CInputSource*> &sources)
|
|
|
|
{
|
|
|
|
// Check if vector is empty
|
|
|
|
if (sources.size() == 0)
|
|
|
|
return SourceEmpty;
|
|
|
|
// Otherwise, see whether all sources are switches, or if have a full- or half-axis present
|
|
|
|
bool allSwitches = true;
|
|
|
|
bool hasFullAxis = false;
|
|
|
|
bool hasHalfAxis = false;
|
2011-06-05 20:53:39 +00:00
|
|
|
for (vector<CInputSource*>::iterator it = sources.begin(); it != sources.end(); it++)
|
2011-04-24 01:14:00 +00:00
|
|
|
{
|
|
|
|
if ((*it)->type == SourceInvalid)
|
|
|
|
return SourceInvalid; // An invalid source makes the whole lot invalid
|
|
|
|
else if ((*it)->type == SourceSwitch)
|
|
|
|
continue;
|
|
|
|
allSwitches = false;
|
|
|
|
if ((*it)->type == SourceFullAxis)
|
|
|
|
{
|
|
|
|
if (hasHalfAxis)
|
|
|
|
return SourceInvalid; // A half-axis and full-axis combined makes the whole lot invalid
|
|
|
|
hasFullAxis = true;
|
|
|
|
}
|
|
|
|
else if ((*it)->type == SourceHalfAxis)
|
|
|
|
{
|
|
|
|
if (hasFullAxis)
|
|
|
|
return SourceInvalid; // A half-axis and full-axis combined makes the whole lot invalid
|
|
|
|
hasHalfAxis = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Return resulting combined type
|
|
|
|
if (allSwitches) return SourceSwitch;
|
|
|
|
else if (hasFullAxis) return SourceFullAxis;
|
|
|
|
else if (hasHalfAxis) return SourceHalfAxis;
|
|
|
|
else return SourceEmpty;
|
|
|
|
}
|
|
|
|
|
2011-06-22 13:06:52 +00:00
|
|
|
CMultiInputSource::CMultiInputSource() : CInputSource(SourceEmpty), m_isOr(true), m_numSrcs(0), m_srcArray(NULL)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
2011-04-24 01:14:00 +00:00
|
|
|
|
2011-06-22 13:06:52 +00:00
|
|
|
CMultiInputSource::CMultiInputSource(bool isOr, vector<CInputSource*> &sources) :
|
|
|
|
CInputSource(GetCombinedType(sources)), m_isOr(isOr), m_numSrcs(sources.size())
|
2011-04-24 01:14:00 +00:00
|
|
|
{
|
|
|
|
m_srcArray = new CInputSource*[m_numSrcs];
|
|
|
|
copy(sources.begin(), sources.end(), m_srcArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
CMultiInputSource::~CMultiInputSource()
|
|
|
|
{
|
|
|
|
if (m_srcArray != NULL)
|
2011-06-22 13:06:52 +00:00
|
|
|
delete m_srcArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMultiInputSource::Acquire()
|
|
|
|
{
|
|
|
|
CInputSource::Acquire();
|
|
|
|
|
|
|
|
if (m_acquired == 1)
|
2011-06-05 20:53:39 +00:00
|
|
|
{
|
2011-06-22 13:06:52 +00:00
|
|
|
// Acquire all sources
|
2011-06-05 20:53:39 +00:00
|
|
|
for (int i = 0; i < m_numSrcs; i++)
|
2011-06-22 13:06:52 +00:00
|
|
|
m_srcArray[i]->Acquire();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CMultiInputSource::Release()
|
|
|
|
{
|
|
|
|
if (m_acquired == 1)
|
|
|
|
{
|
|
|
|
// Release all sources
|
|
|
|
for (int i = 0; i < m_numSrcs; i++)
|
|
|
|
m_srcArray[i]->Release();
|
2011-06-05 20:53:39 +00:00
|
|
|
}
|
2011-06-22 13:06:52 +00:00
|
|
|
|
|
|
|
CInputSource::Release();
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CMultiInputSource::GetValueAsSwitch(bool &val)
|
|
|
|
{
|
|
|
|
if (m_isOr)
|
|
|
|
{
|
|
|
|
// Return value for first input that is active
|
|
|
|
for (int i = 0; i < m_numSrcs; i++)
|
|
|
|
{
|
|
|
|
if (m_srcArray[i]->GetValueAsSwitch(val))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-05 20:53:39 +00:00
|
|
|
// Check all inputs are active
|
2011-04-24 01:14:00 +00:00
|
|
|
for (int i = 0; i < m_numSrcs; i++)
|
|
|
|
{
|
2011-06-05 20:53:39 +00:00
|
|
|
if (!m_srcArray[i]->GetValueAsSwitch(val))
|
2011-04-24 01:14:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-06-05 20:53:39 +00:00
|
|
|
return m_numSrcs > 0;
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CMultiInputSource::GetValueAsAnalog(int &val, int minVal, int offVal, int maxVal)
|
|
|
|
{
|
|
|
|
if (m_isOr)
|
|
|
|
{
|
|
|
|
// Return value for first input that is active
|
|
|
|
for (int i = 0; i < m_numSrcs; i++)
|
|
|
|
{
|
|
|
|
if (m_srcArray[i]->GetValueAsAnalog(val, minVal, offVal, maxVal))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Check all switch inputs are active
|
|
|
|
for (int i = 0; i < m_numSrcs; i++)
|
|
|
|
{
|
|
|
|
if (m_srcArray[i]->type == SourceSwitch && !m_srcArray[i]->GetValueAsAnalog(val, minVal, offVal, maxVal))
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-05 20:53:39 +00:00
|
|
|
// If so, then return value for first non-switch input that is active
|
2011-04-24 01:14:00 +00:00
|
|
|
for (int i = 0; i < m_numSrcs; i++)
|
|
|
|
{
|
|
|
|
if (m_srcArray[i]->type != SourceSwitch && m_srcArray[i]->GetValueAsAnalog(val, minVal, offVal, maxVal))
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-05 20:53:39 +00:00
|
|
|
// If non found, then value is only valid if not empty and all inputs are switches
|
2011-04-24 01:14:00 +00:00
|
|
|
return m_numSrcs > 0 && type == SourceSwitch;
|
|
|
|
}
|
2011-06-05 20:53:39 +00:00
|
|
|
}
|
|
|
|
|
2011-06-22 13:06:52 +00:00
|
|
|
bool CMultiInputSource::SendForceFeedbackCmd(ForceFeedbackCmd ffCmd)
|
2011-06-05 20:53:39 +00:00
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
for (int i = 0; i < m_numSrcs; i++)
|
|
|
|
result |= m_srcArray[i]->SendForceFeedbackCmd(ffCmd);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-06-22 13:06:52 +00:00
|
|
|
CNegInputSource::CNegInputSource(CInputSource *source) : CInputSource(source->type), m_source(source)
|
|
|
|
{
|
|
|
|
// Acquire source
|
|
|
|
m_source->Acquire();
|
|
|
|
}
|
2011-06-05 20:53:39 +00:00
|
|
|
|
2011-06-22 13:06:52 +00:00
|
|
|
void CNegInputSource::Acquire()
|
2011-06-05 20:53:39 +00:00
|
|
|
{
|
2011-06-22 13:06:52 +00:00
|
|
|
CInputSource::Acquire();
|
|
|
|
|
|
|
|
// Acquire source
|
|
|
|
if (m_acquired == 1)
|
|
|
|
m_source->Acquire();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CNegInputSource::Release()
|
|
|
|
{
|
|
|
|
// Release source
|
|
|
|
if (m_acquired == 1)
|
|
|
|
m_source->Release();
|
|
|
|
|
|
|
|
CInputSource::Release();
|
2011-06-05 20:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CNegInputSource::GetValueAsSwitch(bool &val)
|
|
|
|
{
|
|
|
|
bool oldVal = val;
|
|
|
|
if (m_source->GetValueAsSwitch(val))
|
|
|
|
{
|
|
|
|
val = oldVal;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
val = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CNegInputSource::GetValueAsAnalog(int &val, int minVal, int offVal, int maxVal)
|
|
|
|
{
|
|
|
|
int oldVal = val;
|
|
|
|
if (m_source->GetValueAsAnalog(val, minVal, offVal, maxVal))
|
|
|
|
{
|
|
|
|
val = oldVal;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
val = maxVal;
|
|
|
|
return true;
|
2011-04-24 01:14:00 +00:00
|
|
|
}
|