3 * Copyright (C) 2010 Florian Forster <octo at verplant.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "control/haptic_manager.hpp"
20 #include "util/log.hpp"
22 HapticManager::HapticManager () /* {{{ */
27 memset (_effects, 0, sizeof (_effects));
28 for (i = 0; i < ST_HAPTIC_EFFECT_MAX; i++)
30 } /* }}} HapticManager */
33 void HapticManager::addJoystick (SDL_Joystick *j) { /* {{{ */
42 if (SDL_JoystickIsHaptic (j) <= 0)
45 _device = SDL_HapticOpenFromJoystick (j);
49 supported = SDL_HapticQuery (_device);
50 if ((supported & SDL_HAPTIC_SINE) == 0)
52 SDL_HapticClose (_device);
58 _effects[ST_HAPTIC_EFFECT_BUTTJUMP].type = SDL_HAPTIC_SINE;
59 _effects[ST_HAPTIC_EFFECT_BUTTJUMP].periodic.direction.type = SDL_HAPTIC_POLAR;
60 _effects[ST_HAPTIC_EFFECT_BUTTJUMP].periodic.direction.dir[0] = 18000; /* south */
61 _effects[ST_HAPTIC_EFFECT_BUTTJUMP].periodic.period = 50;
62 _effects[ST_HAPTIC_EFFECT_BUTTJUMP].periodic.magnitude = 0x4FFF;
63 _effects[ST_HAPTIC_EFFECT_BUTTJUMP].periodic.length = 250;
64 _effects[ST_HAPTIC_EFFECT_BUTTJUMP].periodic.attack_length = 0;
65 _effects[ST_HAPTIC_EFFECT_BUTTJUMP].periodic.fade_length = 0;
67 _effect_ids[ST_HAPTIC_EFFECT_BUTTJUMP] = SDL_HapticNewEffect (_device,
68 &_effects[ST_HAPTIC_EFFECT_BUTTJUMP]);
69 if (_effect_ids[ST_HAPTIC_EFFECT_BUTTJUMP] < 0)
71 SDL_HapticClose (_device);
76 log_debug << "Haptic manager: Successfully added joystick." << std::endl;
78 } /* }}} void addJoystick */
80 void HapticManager::playEffect (haptic_effect_t idx) { /* {{{ */
81 if ((idx < 0) || (idx >= ST_HAPTIC_EFFECT_MAX))
87 if (_effect_ids[idx] < 0)
90 SDL_HapticRunEffect (_device, _effect_ids[idx],
91 /* iterations = */ 1);
92 } /* }}} void playEffect */
94 /* vim: set sw=2 sts=2 et fdm=marker : */