Ticket #43: led_with_battery.patch

File led_with_battery.patch, 7.5 kB (added by nickishappy, 4 years ago)

led plugin with battery meter option

  • configure

    diff -urpN ./trunk/configure ./led_edit/configure
    old new  
    47844784 
    47854785 
    47864786 
    4787 ac_config_files="$ac_config_files Makefile defs.mak common/include/lib.mak doc/Makefile man/Makefile libcwiid/Makefile libcwiid/cwiid.pc wmdemo/Makefile wmgui/Makefile wminput/Makefile wminput/plugins/Makefile wminput/plugins/ir_ptr/Makefile wminput/plugins/acc/Makefile wminput/plugins/nunchuk_acc/Makefile lswm/Makefile python/Makefile" 
     4787ac_config_files="$ac_config_files Makefile defs.mak common/include/lib.mak doc/Makefile man/Makefile libcwiid/Makefile libcwiid/cwiid.pc wmdemo/Makefile wmgui/Makefile wminput/Makefile wminput/plugins/Makefile wminput/plugins/ir_ptr/Makefile wminput/plugins/acc/Makefile wminput/plugins/nunchuk_acc/Makefile wminput/plugins/led/Makefile lswm/Makefile python/Makefile" 
    47884788 
    47894789cat >confcache <<\_ACEOF 
    47904790# This file is a shell script that caches the results of configure 
     
    53535353    "wminput/plugins/ir_ptr/Makefile") CONFIG_FILES="$CONFIG_FILES wminput/plugins/ir_ptr/Makefile" ;; 
    53545354    "wminput/plugins/acc/Makefile") CONFIG_FILES="$CONFIG_FILES wminput/plugins/acc/Makefile" ;; 
    53555355    "wminput/plugins/nunchuk_acc/Makefile") CONFIG_FILES="$CONFIG_FILES wminput/plugins/nunchuk_acc/Makefile" ;; 
     5356    "wminput/plugins/led/Makefile") CONFIG_FILES="$CONFIG_FILES wminput/plugins/led/Makefile" ;; 
    53565357    "lswm/Makefile") CONFIG_FILES="$CONFIG_FILES lswm/Makefile" ;; 
    53575358    "python/Makefile") CONFIG_FILES="$CONFIG_FILES python/Makefile" ;; 
    53585359 
  • wminput/configs/acc_led

    diff -urpN ./trunk/wminput/configs/acc_led ./led_edit/wminput/configs/acc_led
    old new  
     1#acc_led 
     2 
     3include buttons 
     4 
     5Plugin.acc.X    = REL_X 
     6Plugin.acc.Y    = REL_Y 
     7 
     8# You can set Plugin.led.Led[1->4) to 1 
     9# to have that led be active all the time 
     10Plugin.led.Led4 = 1 
     11 
     12# Setting battery to 1 enables the battery check function 
     13# By default the keypress is A + B 
     14# You can change this by setting Plugin.led.Button to any 
     15# wiimote or attachment button 
     16Plugin.led.Battery = 1 
  • wminput/Makefile.in

    diff -urpN ./trunk/wminput/Makefile.in ./led_edit/wminput/Makefile.in
    old new  
    4343install_configs: 
    4444        install -d $(WMINPUT_CONFIG_DIR) 
    4545        install configs/* $(WMINPUT_CONFIG_DIR) 
    46         ln -sf acc_ptr $(WMINPUT_CONFIG_DIR)/default 
     46        ln -sf acc_led $(WMINPUT_CONFIG_DIR)/default 
    4747 
    4848#uninstall_configs: 
    4949#       rm -f $(WMINPUT_CONFIG_DIR)/default 
  • wminput/plugins/ir_ptr/ir_ptr.c

    diff -urpN ./trunk/wminput/plugins/ir_ptr/ir_ptr.c ./led_edit/wminput/plugins/ir_ptr/ir_ptr.c
    old new  
    147147        } 
    148148 
    149149        /* LEDs */ 
     150        /* Commented out so it doesn't overide led plugin. 
     151         * It shouldn't matter, since only one IR source 
     152         * is used now anyways. If the pointer is moving, 
     153         * it sees a source. 
    150154        switch (src_index) { 
    151155        case 0: 
    152156                flag = CWIID_LED1_ON; 
     
    164168                flag = 0; 
    165169                break; 
    166170        } 
     171 
    167172        if (flag != old_flag) { 
    168173                cwiid_set_led(wiimote, flag); 
    169174                old_flag = flag; 
    170175        } 
     176        */ 
    171177 
    172178        if ((src_index == -1) || !ir_mesg->src[src_index].valid) { 
    173179                data.axes[0].valid = data.axes[1].valid = 0; 
  • wminput/plugins/led/led.c

    diff -urpN ./trunk/wminput/plugins/led/led.c ./led_edit/wminput/plugins/led/led.c
    old new  
    11#include "wmplugin.h" 
     2#include <math.h> 
     3 
    24 
    35cwiid_wiimote_t *wiimote; 
    46 
     
    1012wmplugin_init_t wmplugin_init; 
    1113wmplugin_exec_t wmplugin_exec; 
    1214 
    13 static int led1 = 0; 
    14 static int led2 = 0; 
    15 static int led3 = 0; 
    16 static int led4 = 0; 
     15static int Led1 = 0; 
     16static int Led2 = 0; 
     17static int Led3 = 0; 
     18static int Led4 = 0; 
     19static int Battery = 0; 
     20static uint8_t Button = CWIID_BTN_A + CWIID_BTN_B; 
     21 
     22static void show_battery(); 
    1723 
    1824struct wmplugin_info *wmplugin_info() 
    1925{ 
    2026        if (!info_init) { 
    2127                info.button_count = 0; 
    2228                info.axis_count = 0; 
    23                 info.param_count = 4; 
    24                 info.param_info[0].name = "led1"; 
     29                info.param_count = 6; 
     30                info.param_info[0].name = "Led1"; 
    2531                info.param_info[0].type = WMPLUGIN_PARAM_INT; 
    26                 info.param_info[0].ptr = &led1; 
    27                 info.param_info[1].name = "led2"; 
     32                info.param_info[0].ptr = &Led1; 
     33                info.param_info[1].name = "Led2"; 
    2834                info.param_info[1].type = WMPLUGIN_PARAM_INT; 
    29                 info.param_info[1].ptr = &led2; 
    30                 info.param_info[2].name = "led3"; 
     35                info.param_info[1].ptr = &Led2; 
     36                info.param_info[2].name = "Led3"; 
    3137                info.param_info[2].type = WMPLUGIN_PARAM_INT; 
    32                 info.param_info[2].ptr = &led3; 
    33                 info.param_info[3].name = "led4"; 
     38                info.param_info[2].ptr = &Led3; 
     39                info.param_info[3].name = "Led4"; 
    3440                info.param_info[3].type = WMPLUGIN_PARAM_INT; 
    35                 info.param_info[3].ptr = &led4; 
     41                info.param_info[3].ptr = &Led4; 
     42                info.param_info[4].name = "Battery"; 
     43                info.param_info[4].type = WMPLUGIN_PARAM_INT; 
     44                info.param_info[4].ptr = &Battery; 
     45                info.param_info[5].name = "Button"; 
     46                info.param_info[5].type = WMPLUGIN_PARAM_INT; 
     47                info.param_info[5].ptr = &Button;                
    3648                info_init = 1; 
    3749        } 
    3850        return &info; 
     
    4254{ 
    4355        wiimote = arg_wiimote; 
    4456 
    45         uint8_t led_state = (led1 ? CWIID_LED1_ON : 0) 
    46                           | (led2 ? CWIID_LED2_ON : 0) 
    47                           | (led3 ? CWIID_LED3_ON : 0) 
    48                           | (led4 ? CWIID_LED4_ON : 0); 
     57        uint8_t led_state = (Led1 ? CWIID_LED1_ON : 0) 
     58                          | (Led2 ? CWIID_LED2_ON : 0) 
     59                          | (Led3 ? CWIID_LED3_ON : 0) 
     60                          | (Led4 ? CWIID_LED4_ON : 0); 
    4961 
    5062        cwiid_command(wiimote, CWIID_CMD_LED, led_state); 
     63         
     64        if (wmplugin_set_rpt_mode(id, CWIID_RPT_BTN)) { 
     65                return -1; 
     66        }        
    5167 
    5268        return 0; 
    5369} 
    5470 
    5571struct wmplugin_data *wmplugin_exec(int mesg_count, union cwiid_mesg mesg[]) 
    5672{ 
     73        int i; 
     74        uint8_t button; 
     75        struct cwiid_btn_message *btn_mesg; 
     76 
     77        uint8_t led_state = (Led1 ? CWIID_LED1_ON : 0) 
     78                          | (Led2 ? CWIID_LED2_ON : 0) 
     79                          | (Led3 ? CWIID_LED3_ON : 0) 
     80                          | (Led4 ? CWIID_LED4_ON : 0); 
     81 
     82        if(Battery != 0) {               
     83                btn_mesg = NULL; 
     84                for (i=0; i < mesg_count; i++) { 
     85                        if (mesg[i].type == CWIID_MESG_BTN) { 
     86                                btn_mesg = &mesg[i].btn_mesg; 
     87                                button = mesg[i].btn_mesg.buttons; 
     88                        } 
     89                } 
     90 
     91                if (!btn_mesg) { 
     92                        return NULL; 
     93                } 
     94 
     95                if(button == Button) { 
     96                        show_battery(); 
     97                }  
     98                else { 
     99                        cwiid_command(wiimote, CWIID_CMD_LED, led_state); 
     100                } 
     101        } 
     102         
    57103        return &data; 
    58104} 
     105 
     106static void show_battery() 
     107{ 
     108        struct cwiid_state state; 
     109        float battery_percent; 
     110        int battery_led; 
     111 
     112        cwiid_get_state(wiimote, &state); 
     113         
     114        // calculate battery as a percent, then decide how many leds to light up         
     115        battery_percent = (100*state.battery / CWIID_BATTERY_MAX); 
     116        battery_led = ceil(battery_percent / 25); 
     117 
     118        switch(battery_led) { 
     119        case 1: 
     120                cwiid_set_led(wiimote, CWIID_LED1_ON); 
     121                break; 
     122        case 2: 
     123                cwiid_set_led(wiimote, CWIID_LED1_ON | CWIID_LED2_ON ); 
     124                break; 
     125        case 3: 
     126                cwiid_set_led(wiimote, CWIID_LED1_ON | CWIID_LED2_ON | CWIID_LED3_ON ); 
     127                break; 
     128        case 4: 
     129                cwiid_set_led(wiimote, CWIID_LED1_ON | CWIID_LED2_ON | CWIID_LED3_ON | CWIID_LED4_ON ); 
     130                break; 
     131        default: 
     132                break; 
     133        } 
     134}