12 CPhidget_getDeviceName(IFK, &name);
13 CPhidget_getSerialNumber(IFK, &serialNo);
22 sprintf_s(msg, 99,
"InterfaceKit::AttachHandler %s (%s) reattached!", name, interfaceKit->
config->
friendlyName.c_str());
27 sprintf_s(msg, 99,
"InterfaceKit::AttachHandler %s (%s) attached!", name, interfaceKit->
config->
friendlyName.c_str());
43 CPhidget_getDeviceName(IFK, &name);
44 CPhidget_getSerialNumber(IFK, &serialNo);
47 sprintf_s(msg, 99,
"InterfaceKit::DetachHandler %s (%s) detached!", name, interfaceKit->
config->
friendlyName.c_str());
51 for (UINT i = 0; i < interfaceKit->
config->
sensors.size(); i++)
55 for (UINT i = 0; i < interfaceKit->
config->
inputs.size(); i++)
70 sprintf_s(msg, 99,
"InterfaceKit::ErrorHandler Error handled. %s", unknown);
90 if (input.
name ==
"Component")
93 sprintf_s(msg, 99,
"InterfaceKit::InputChangeHandler Index %i: %i", input.
name.c_str(), Index, State);
102 if (State != 0 && State != 1)
109 *input.
ptrFloat =
static_cast<float>(State);
116 sprintf_s(msg, 99,
"InterfaceKit::InputChangeHandler %s (%i): %i", input.
name.c_str(), Index, State);
127 sprintf_s(msg, 99,
"InterfaceKit::InputChangeHandler: Added command: %s", command.
name.c_str());
167 #pragma region // phidgets precision temperature sensor 169 if (sensor.
type ==
"1124_0")
176 sprintf_s(msg, 99,
"InterfaceKit::SensorChangeHandler %s (%d): NO SIGNAL", sensor.
guid.c_str(), Index);
181 float celciusTemp = (
static_cast<float>(Value) * 0.2222f) - 61.111f;
182 if (sensor.
inverse) celciusTemp = -celciusTemp;
183 celciusTemp += sensor.
bias;
186 float farenheitTemp = celciusTemp * 9.0f / 5.0f + 32.0f;
188 sprintf_s(msg, 99,
"InterfaceKit::SensorChangeHandler %s (%d): %.1f°C %.1f°F", sensor.
guid.c_str(), Index, celciusTemp, farenheitTemp);
193 #pragma region // 20 Amp Current Sensor DC Current (DC Amps) 194 else if (sensor.
type ==
"1119_0" && sensor.
subtype ==
"DC")
201 sprintf_s(msg, 99,
"InterfaceKit::SensorChangeHandler %s (%d): NO SIGNAL", sensor.
guid.c_str(), Index);
206 float dcAmps =
static_cast<float>(Value) / 20.0f - 25.0f;
207 if (sensor.
inverse) dcAmps = -dcAmps;
208 dcAmps += sensor.
bias;
212 sprintf_s(msg, 99,
"InterfaceKit::SensorChangeHandler %s (%d): %.1f A (%.1f A)", sensor.
guid.c_str(), Index, dcAmps,
static_cast<float>(Value) / 20.0f - 25.0f);
218 #pragma region // 200 PSI pressure sensor Custom0 219 else if (sensor.
type ==
"Custom0")
226 sprintf_s(msg, 99,
"InterfaceKit::SensorChangeHandler %s (%d): NO SIGNAL", sensor.
guid.c_str(), Index);
235 float psi = (
static_cast<float>(Value) - 100.0f) / 800.0f * 200.0f;
236 if (sensor.
inverse) psi = -psi;
246 #pragma region // Vibration sensor 247 else if (sensor.
type ==
"1104_0")
254 sprintf_s(msg, 99,
"InterfaceKit::SensorChangeHandler %s (%d): NO SIGNAL", sensor.
guid.c_str(), Index);
259 float mils = (
static_cast<float>(Value)-500.0f) / 10.0f;
260 if (sensor.
inverse) mils = -mils;
265 sprintf_s(msg, 99,
"InterfaceKit::SensorChangeHandler %s (%d): %.1f", sensor.
guid.c_str(), Index, mils);
274 sprintf_s(msg, 99,
"InterfaceKit::SensorChangeHandler Unknown sensor type \"%s\" at index: %d (%d)", sensor.
type, Index, Value);
287 int serialNo, version, numInputs, numOutputs, numSensors, triggerVal, ratiometric = 0, i;
290 CPhidget_getDeviceType(reinterpret_cast<CPhidgetHandle>(phid), &ptr);
291 CPhidget_getSerialNumber(reinterpret_cast<CPhidgetHandle>(phid), &serialNo);
292 CPhidget_getDeviceVersion(reinterpret_cast<CPhidgetHandle>(phid), &version);
294 CPhidgetInterfaceKit_getInputCount(phid, &numInputs);
295 CPhidgetInterfaceKit_getOutputCount(phid, &numOutputs);
296 CPhidgetInterfaceKit_getSensorCount(phid, &numSensors);
298 CPhidgetInterfaceKit_getRatiometric(phid, &ratiometric);
301 sprintf_s(msg, 99,
"InterfaceKit::display_properties Type: %s", ptr);
303 sprintf_s(msg, 99,
"InterfaceKit::display_properties Serial Number: %i", serialNo);
305 sprintf_s(msg, 99,
"InterfaceKit::display_properties Version: %i", version);
307 sprintf_s(msg, 99,
"InterfaceKit::display_properties Digital Inputs: %d", numInputs);
309 sprintf_s(msg, 99,
"InterfaceKit::display_properties Digital Outputs: %d", numOutputs);
311 sprintf_s(msg, 99,
"InterfaceKit::display_properties Sensors: %d", numSensors);
314 for (i = 0; i < numSensors; i++)
316 CPhidgetInterfaceKit_getSensorChangeTrigger(phid, i, &triggerVal);
318 sprintf_s(msg, 99,
"InterfaceKit::display_properties Sensor#: %d > Sensitivity Trigger: %d", i, triggerVal);
324 sprintf_s(msg, 99,
"InterfaceKit::display_properties Ratiometric: %d", ratiometric);
344 CPhidgetInterfaceKit_create(&
ifKit);
347 CPhidget_set_OnAttach_Handler(reinterpret_cast<CPhidgetHandle>(
ifKit),
AttachHandler,
this);
348 CPhidget_set_OnDetach_Handler(reinterpret_cast<CPhidgetHandle>(
ifKit),
DetachHandler,
this);
349 CPhidget_set_OnError_Handler(reinterpret_cast<CPhidgetHandle>(
ifKit),
ErrorHandler,
this);
368 sprintf_s(msg, 99,
"InterfaceKit::ctor Waiting for interface kit %i to be attached...",
config->
serialno);
370 result = CPhidget_waitForAttachment(reinterpret_cast<CPhidgetHandle>(
ifKit), 5000);
373 CPhidget_getErrorDescription(result, &err);
374 sprintf_s(msg, 99,
"InterfaceKit::ctor Problem waiting for attachment of %i: %s",
config->
serialno, err);
385 CPhidgetInterfaceKit_setSensorChangeTrigger(
ifKit, i,
config->
sensors.at(i).sensitivity);
404 CPhidget_close(reinterpret_cast<CPhidgetHandle>(
ifKit));
405 CPhidget_delete(reinterpret_cast<CPhidgetHandle>(
ifKit));
413 #pragma region Command Stream 417 if (command.
delay != 0.0f)
continue;
427 sprintf_s(msg, 199,
"InterfaceKit::FrameMove Sending digital output signal %i to index %i!", command.
ivalue, j);
431 int result = CPhidgetInterfaceKit_setOutputState(
ifKit, j, command.
ivalue);
435 CPhidget_getErrorDescription(result, &err);
436 sprintf_s(msg, 199,
"InterfaceKit::FrameMove Problem sending digital output signal: %s (%i)", err,
config->
serialno);
452 #pragma region Components 458 bool currentState = *
config->
outputs.at(j).busCurrentState > 0.5f;
462 int ivalue = currentState ? 1 : 0;
464 sprintf_s(msg, 199,
"InterfaceKit::FrameMove Sending digital output signal %i to index %i!", ivalue, j);
468 int result = CPhidgetInterfaceKit_setOutputState(
ifKit, j, ivalue);
472 CPhidget_getErrorDescription(result, &err);
473 sprintf_s(msg, 199,
"InterfaceKit::FrameMove Problem sending digital output signal: %s (%i)", err,
config->
serialno);
CPhidgetInterfaceKitHandle ifKit
static int CCONV ErrorHandler(CPhidgetHandle IFK, void *userptr, int ErrorCode, const char *unknown)
std::vector< Command > commandStream
Systems::Fault * GetComponentFaultStatePtr(std::string guidStr)
static int CCONV InputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int State)
InterfaceKitConfig * config
static int CCONV SensorChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int Value)
std::vector< Output > outputs
okay, the portable keyboard numbers don't work like the outside keypad because the outside keypad is ...
std::string name
command name
Systems::Fault * ptrFault
std::vector< Input > inputs
static int CCONV DetachHandler(CPhidgetHandle IFK, void *userptr)
static int CCONV AttachHandler(CPhidgetHandle IFK, void *userptr)
int display_properties(CPhidgetInterfaceKitHandle phid) const
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.
void Initialize(Logger *logger, InterfaceKitConfig *config, Bus *prmBus)
float * GetComponentSetStatePtr(std::string guidStr)
float delay
wait number of seconds before executing command
std::vector< Sensor > sensors