/* Function sends signal to specified task */ void do_raise(char *line, uint_t *lpos, char *word, uint_t word_size) { uint_t sig; uint_t pid; char *sigs[2] = { "CHLD", "KILL" }; uint_t was = 0; if ((word = getnextsym(line, lpos, word, word_size)) == NULL) { ph_printf("Bad syntax!, usage: raise <signal> <pid>\n"); return; } for (sig = 0; sig < 2; sig++) if (!ph_strncmp(sigs[sig], word, ph_strlen(word))) { was = 1; break; } /* If can' translate word to number convert it by using ph_atoi() function */ if (!was) sig = ph_atoi(word); if ((word = getnextsym(line, lpos, word, word_size)) == NULL) { ph_printf("Bad syntax!, usage: raise <signal> <pid>\n"); return; } pid = ph_atoi(word); ph_raise(pid, sig); return; }
VALUE ph_phsensor_set_on_ph_change_handler(VALUE self, VALUE handler) { ph_data_t *ph = get_ph_data(self); ph_callback_data_t *callback_data = &ph->dev_callbacks[PH_CHANGE_CALLBACK]; if( TYPE(handler) == T_NIL ) { callback_data->callback = T_NIL; callback_data->exit = true; ph_raise(PhidgetPHSensor_setOnPHChangeHandler((PhidgetPHSensorHandle)ph->handle, NULL, (void *)NULL)); sem_post(&callback_data->callback_called); } else { callback_data->exit = false; callback_data->phidget = self; callback_data->callback = handler; ph_raise(PhidgetPHSensor_setOnPHChangeHandler((PhidgetPHSensorHandle)ph->handle, ph_phsensor_on_ph_change, (void *)callback_data)); ph_callback_thread(callback_data); } return Qnil; }
VALUE ph_voltage_ratio_input_set_on_voltage_ratio_change_handler(VALUE self, VALUE handler) { ph_data_t *ph = get_ph_data(self); ph_callback_data_t *callback_data = &ph->dev_callbacks[VOLTAGE_RATIO_INPUT_VOLTAGE_RATIO_CHANGE_CALLBACK]; if( TYPE(handler) == T_NIL ) { callback_data->callback = T_NIL; callback_data->exit = true; ph_raise(PhidgetVoltageRatioInput_setOnVoltageRatioChangeHandler((PhidgetVoltageRatioInputHandle)ph->handle, NULL, (void *)NULL)); sem_post(&callback_data->callback_called); } else { callback_data->exit = false; callback_data->phidget = self; callback_data->callback = handler; ph_raise(PhidgetVoltageRatioInput_setOnVoltageRatioChangeHandler((PhidgetVoltageRatioInputHandle)ph->handle, ph_voltage_ratio_input_on_voltage_ratio_change, (void *)callback_data)); ph_callback_thread(callback_data); } return Qnil; }
VALUE ph_gyroscope_set_on_angular_rate_update_handler(VALUE self, VALUE handler) { ph_data_t *ph = get_ph_data(self); ph_callback_data_t *callback_data = &ph->dev_callbacks[GYROSCOPE_ANGULAR_RATE_UPDATE_CALLBACK]; if( TYPE(handler) == T_NIL ) { callback_data->callback = T_NIL; callback_data->exit = true; ph_raise(PhidgetGyroscope_setOnAngularRateUpdateHandler((PhidgetGyroscopeHandle)ph->handle, NULL, (void *)NULL)); sem_post(&callback_data->callback_called); } else { callback_data->exit = false; callback_data->phidget = self; callback_data->callback = handler; ph_raise(PhidgetGyroscope_setOnAngularRateUpdateHandler((PhidgetGyroscopeHandle)ph->handle, ph_gyroscope_on_angular_rate_update, (void *)callback_data)); ph_callback_thread(callback_data); } return Qnil; }
VALUE ph_current_input_set_on_current_change_handler(VALUE self, VALUE handler) { ph_data_t *ph = get_ph_data(self); ph_callback_data_t *callback_data = &ph->dev_callbacks[CURRENT_INPUT_CURRENT_CHANGE_CALLBACK]; if( TYPE(handler) == T_NIL ) { callback_data->callback = T_NIL; callback_data->exit = true; ph_raise(PhidgetCurrentInput_setOnCurrentChangeHandler((PhidgetCurrentInputHandle)ph->handle, NULL, (void *)NULL)); sem_post(&callback_data->callback_called); } else { callback_data->exit = false; callback_data->phidget = self; callback_data->callback = handler; ph_raise(PhidgetCurrentInput_setOnCurrentChangeHandler((PhidgetCurrentInputHandle)ph->handle, ph_current_input_on_current_change, (void *)callback_data)); ph_callback_thread(callback_data); } return Qnil; }
VALUE ph_voltage_ratio_input_get_sensor_unit(VALUE self) { VALUE unit_info = rb_hash_new(); Phidget_UnitInfo sensorUnit; ph_raise(PhidgetVoltageRatioInput_getSensorUnit((PhidgetVoltageRatioInputHandle)get_ph_handle(self), &sensorUnit)); rb_hash_aset(unit_info, rb_str_new2("unit"), INT2NUM(sensorUnit.unit)); rb_hash_aset(unit_info, rb_str_new2("name"), rb_str_new2(sensorUnit.name)); rb_hash_aset(unit_info, rb_str_new2("symbol"), rb_str_new2(sensorUnit.symbol)); return unit_info; }
VALUE ph_current_input_set_current_change_trigger(VALUE self, VALUE trigger) { ph_raise(PhidgetCurrentInput_setCurrentChangeTrigger((PhidgetCurrentInputHandle)get_ph_handle(self), NUM2DBL(trigger))); return Qnil; }
VALUE ph_voltage_ratio_input_set_sensor_type(VALUE self, VALUE sensor_type) { ph_raise(PhidgetVoltageRatioInput_setSensorType((PhidgetVoltageRatioInputHandle)get_ph_handle(self), NUM2INT(sensor_type))); return Qnil; }
VALUE ph_phsensor_init(VALUE self) { ph_data_t *ph = get_ph_data(self); ph_raise(PhidgetPHSensor_create((PhidgetPHSensorHandle *)(&(ph->handle)))); return self; }
VALUE ph_phsensor_set_data_interval(VALUE self, VALUE interval) { ph_raise(PhidgetPHSensor_setDataInterval((PhidgetPHSensorHandle)get_ph_handle(self), NUM2UINT(interval))); return Qnil; }
VALUE ph_voltage_ratio_input_set_bridge_gain(VALUE self, VALUE bridge_gain) { ph_raise(PhidgetVoltageRatioInput_setBridgeGain((PhidgetVoltageRatioInputHandle)get_ph_handle(self), NUM2INT(bridge_gain))); return Qnil; }
VALUE ph_current_input_set_power_supply(VALUE self, VALUE power_supply) { ph_raise(PhidgetCurrentInput_setPowerSupply((PhidgetCurrentInputHandle)get_ph_handle(self), NUM2INT(power_supply))); return Qnil; }
VALUE ph_power_guard_set_power_enabled(VALUE self, VALUE enabled) { ph_raise(PhidgetPowerGuard_setPowerEnabled((PhidgetPowerGuardHandle)get_ph_handle(self), TYPE(enabled) == T_TRUE ? PTRUE : PFALSE)); return Qnil; }
VALUE ph_power_guard_set_over_voltage(VALUE self, VALUE over_voltage) { ph_raise(PhidgetPowerGuard_setOverVoltage((PhidgetPowerGuardHandle)get_ph_handle(self), NUM2DBL(over_voltage))); return Qnil; }
VALUE ph_power_guard_set_fan_mode(VALUE self, VALUE mode) { ph_raise(PhidgetPowerGuard_setFanMode((PhidgetPowerGuardHandle)get_ph_handle(self), NUM2INT(mode))); return Qnil; }
VALUE ph_voltage_ratio_input_set_voltage_ratio_change_trigger(VALUE self, VALUE trigger) { ph_raise(PhidgetVoltageRatioInput_setVoltageRatioChangeTrigger((PhidgetVoltageRatioInputHandle)get_ph_handle(self), NUM2DBL(trigger))); return Qnil; }
VALUE ph_voltage_ratio_input_init(VALUE self) { ph_data_t *ph = get_ph_data(self); ph_raise(PhidgetVoltageRatioInput_create((PhidgetVoltageRatioInputHandle *)(&(ph->handle)))); return self; }
VALUE ph_current_input_set_data_interval(VALUE self, VALUE interval) { ph_raise(PhidgetCurrentInput_setDataInterval((PhidgetCurrentInputHandle)get_ph_handle(self), NUM2UINT(interval))); return Qnil; }
VALUE ph_current_input_init(VALUE self) { ph_data_t *ph = get_ph_data(self); ph_raise(PhidgetCurrentInput_create((PhidgetCurrentInputHandle *)(&(ph->handle)))); return self; }
VALUE ph_power_guard_init(VALUE self) { ph_data_t *ph = get_ph_data(self); ph_raise(PhidgetPowerGuard_create((PhidgetPowerGuardHandle *)(&(ph->handle)))); return self; }
VALUE ph_gyroscope_get_max_angular_rate(VALUE self) { double angular_rate[3]; ph_raise(PhidgetGyroscope_getMaxAngularRate((PhidgetGyroscopeHandle)get_ph_handle(self), &angular_rate)); return rb_ary_new3(3, DBL2NUM(angular_rate[0]), DBL2NUM(angular_rate[1]), DBL2NUM(angular_rate[2])); }
VALUE ph_gyroscope_set_data_interval(VALUE self, VALUE interval) { ph_raise(PhidgetGyroscope_setDataInterval((PhidgetGyroscopeHandle)get_ph_handle(self), NUM2UINT(interval))); return Qnil; }
VALUE ph_phsensor_set_correction_temperature(VALUE self, VALUE temperature) { ph_raise(PhidgetPHSensor_setCorrectionTemperature((PhidgetPHSensorHandle)get_ph_handle(self), NUM2DBL(temperature))); return Qnil; }
VALUE ph_voltage_ratio_input_set_bridge_enabled(VALUE self, VALUE enabled) { ph_raise(PhidgetVoltageRatioInput_setBridgeEnabled((PhidgetVoltageRatioInputHandle)get_ph_handle(self), TYPE(enabled) == T_TRUE ? PTRUE : PFALSE)); return Qnil; }
VALUE ph_phsensor_set_ph_change_trigger(VALUE self, VALUE trigger) { ph_raise(PhidgetPHSensor_setPHChangeTrigger((PhidgetPHSensorHandle)get_ph_handle(self), NUM2DBL(trigger))); return Qnil; }
VALUE ph_gyroscope_init(VALUE self) { ph_data_t *ph = get_ph_data(self); ph_raise(PhidgetGyroscope_create((PhidgetGyroscopeHandle *)(&(ph->handle)))); return self; }
VALUE ph_gyroscope_zero(VALUE self) { ph_raise(PhidgetGyroscope_zero((PhidgetGyroscopeHandle)get_ph_handle(self))); return Qnil; }
VALUE ph_voltage_ratio_input_set_data_interval(VALUE self, VALUE interval) { ph_raise(PhidgetVoltageRatioInput_setDataInterval((PhidgetVoltageRatioInputHandle)get_ph_handle(self), NUM2UINT(interval))); return Qnil; }