| 1 | /* Copyright (C) 2007 L. Donnie Smith <cwiidabstrakraft.org> |
|---|
| 2 | * |
|---|
| 3 | * This program is free software; you can redistribute it and/or modify |
|---|
| 4 | * it under the terms of the GNU General Public License as published by |
|---|
| 5 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 6 | * (at your option) any later version. |
|---|
| 7 | * |
|---|
| 8 | * This program is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * GNU General Public License for more details. |
|---|
| 12 | * |
|---|
| 13 | * You should have received a copy of the GNU General Public License |
|---|
| 14 | * along with this program; if not, write to the Free Software |
|---|
| 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 16 | * |
|---|
| 17 | * ChangeLog: |
|---|
| 18 | * 2007-08-26 L. Nick Wilbanks <nickishappy@gmail.com> |
|---|
| 19 | * * Initial Release |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #include "wmplugin.h" |
|---|
| 23 | #include <stdio.h> |
|---|
| 24 | #include <math.h> |
|---|
| 25 | |
|---|
| 26 | static int Enabled = 1.0; |
|---|
| 27 | |
|---|
| 28 | cwiid_wiimote_t *wiimote; |
|---|
| 29 | |
|---|
| 30 | static struct wmplugin_info info; |
|---|
| 31 | static struct wmplugin_data data; |
|---|
| 32 | |
|---|
| 33 | wmplugin_info_t wmplugin_info; |
|---|
| 34 | wmplugin_init_t wmplugin_init; |
|---|
| 35 | wmplugin_exec_t wmplugin_exec; |
|---|
| 36 | |
|---|
| 37 | struct wmplugin_info *wmplugin_info() { |
|---|
| 38 | static unsigned char info_init = 0; |
|---|
| 39 | |
|---|
| 40 | if (!info_init) { |
|---|
| 41 | info.button_count = 0; |
|---|
| 42 | info.axis_count = 0; |
|---|
| 43 | info.param_count = 1; |
|---|
| 44 | info.param_info[0].name = "Enabled"; |
|---|
| 45 | info.param_info[0].type = WMPLUGIN_PARAM_INT; |
|---|
| 46 | info.param_info[0].ptr = &Enabled; |
|---|
| 47 | info_init = 1; |
|---|
| 48 | } |
|---|
| 49 | return &info; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | int wmplugin_init(int id, cwiid_wiimote_t *arg_wiimote) |
|---|
| 53 | { |
|---|
| 54 | wiimote = arg_wiimote; |
|---|
| 55 | |
|---|
| 56 | data.buttons = 0; |
|---|
| 57 | |
|---|
| 58 | if (wmplugin_set_rpt_mode(id, CWIID_RPT_BTN)) { |
|---|
| 59 | return -1; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | return 0; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg mesg[]) |
|---|
| 66 | { |
|---|
| 67 | int i; |
|---|
| 68 | struct cwiid_btn_mesg *btn_mesg; |
|---|
| 69 | struct cwiid_state state; |
|---|
| 70 | |
|---|
| 71 | btn_mesg = NULL; |
|---|
| 72 | for (i=0; i < mesg_count; i++) { |
|---|
| 73 | if (mesg[i].type == CWIID_MESG_BTN) { |
|---|
| 74 | btn_mesg = &mesg[i].btn_mesg; |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | if (!btn_mesg) { |
|---|
| 79 | return NULL; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | if(Enabled) |
|---|
| 83 | { |
|---|
| 84 | cwiid_get_state(wiimote, &state); |
|---|
| 85 | if(state.rumble == 0){ |
|---|
| 86 | cwiid_set_rumble(wiimote, 1); |
|---|
| 87 | } else { |
|---|
| 88 | cwiid_set_rumble(wiimote, 0); |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | return &data; |
|---|
| 93 | } |
|---|