Status::Status(){ setSolenoid(0); setReedSwitch(0); setVibration(0); setMic(1023); setHumidity(0.0); setTemperature(0.0); }
void Joystick::getVibration(float &left, float &right) { if (vibration.endtime != SDL_HAPTIC_INFINITY) { // With some drivers, the effect physically stops at the right time, but // SDL_HapticGetEffectStatus still thinks it's playing. So we explicitly // stop it once it's done, just to be sure. if (SDL_TICKS_PASSED(SDL_GetTicks(), vibration.endtime)) { setVibration(); vibration.endtime = SDL_HAPTIC_INFINITY; } } // Check if the haptic effect has stopped playing. int id = vibration.id; if (!haptic || id == -1 || SDL_HapticGetEffectStatus(haptic, id) != 1) vibration.left = vibration.right = 0.0f; left = vibration.left; right = vibration.right; }
bool Joystick::setVibration(float left, float right, float duration) { left = std::min(std::max(left, 0.0f), 1.0f); right = std::min(std::max(right, 0.0f), 1.0f); if (left == 0.0f && right == 0.0f) return setVibration(); if (!checkCreateHaptic()) return false; Uint32 length = SDL_HAPTIC_INFINITY; if (duration >= 0.0f) { float maxduration = std::numeric_limits<Uint32>::max() / 1000.0f; length = Uint32(std::min(duration, maxduration) * 1000); } bool success = false; unsigned int features = SDL_HapticQuery(haptic); int axes = SDL_HapticNumAxes(haptic); if ((features & SDL_HAPTIC_LEFTRIGHT) != 0) { memset(&vibration.effect, 0, sizeof(SDL_HapticEffect)); vibration.effect.type = SDL_HAPTIC_LEFTRIGHT; vibration.effect.leftright.length = length; vibration.effect.leftright.large_magnitude = Uint16(left * LOVE_UINT16_MAX); vibration.effect.leftright.small_magnitude = Uint16(right * LOVE_UINT16_MAX); success = runVibrationEffect(); } // Some gamepad drivers only give support for controlling individual motors // through a custom FF effect. if (!success && isGamepad() && (features & SDL_HAPTIC_CUSTOM) && axes == 2) { // NOTE: this may cause issues with drivers which support custom effects // but aren't similar to https://github.com/d235j/360Controller . // Custom effect data is clamped to 0x7FFF in SDL. vibration.data[0] = vibration.data[2] = Uint16(left * 0x7FFF); vibration.data[1] = vibration.data[3] = Uint16(right * 0x7FFF); memset(&vibration.effect, 0, sizeof(SDL_HapticEffect)); vibration.effect.type = SDL_HAPTIC_CUSTOM; vibration.effect.custom.length = length; vibration.effect.custom.channels = 2; vibration.effect.custom.period = 10; vibration.effect.custom.samples = 2; vibration.effect.custom.data = vibration.data; success = runVibrationEffect(); } // Fall back to a simple sine wave if all else fails. This only supports a // single strength value. if (!success && (features & SDL_HAPTIC_SINE) != 0) { memset(&vibration.effect, 0, sizeof(SDL_HapticEffect)); vibration.effect.type = SDL_HAPTIC_SINE; vibration.effect.periodic.length = length; vibration.effect.periodic.period = 10; float strength = std::max(left, right); vibration.effect.periodic.magnitude = Sint16(strength * 0x7FFF); success = runVibrationEffect(); } if (success) { vibration.left = left; vibration.right = right; if (length == SDL_HAPTIC_INFINITY) vibration.endtime = SDL_HAPTIC_INFINITY; else vibration.endtime = SDL_GetTicks() + length; } else { vibration.left = vibration.right = 0.0f; vibration.endtime = SDL_HAPTIC_INFINITY; } return success; }
/* Name: XIO::closeInterface Purpose: Resets hardware. Input: None Output: None */ void XIO::closeInterface() { initLamp(); setVibration(3, 1); resetPedal(); }
SimpleXbox360Controller::~SimpleXbox360Controller(){ setVibration(0,0); pollingTimer->stop(); delete pollingTimer; }