From 4c300161e1b198a6a77ce2aac4f9dc5a6e066332 Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Sun, 13 May 2012 18:56:34 +0000 Subject: [PATCH] -replaced wiilight by something better from libprojectM because its open source and we can modify it as we want, that should fix the problem that the wii light sometimes did not disable properly ;) --- Makefile | 2 +- portlibs/include/wiilight.h | 21 -------- portlibs/lib/libwiilight.a | Bin 8420 -> 0 bytes source/gui/Gekko.c | 100 ++++++++++++++++++++++++++++++++++++ source/gui/Gekko.h | 38 ++++++++++++++ source/gui/video.cpp | 16 +++--- source/main.cpp | 2 - source/menu/menu.cpp | 8 +-- 8 files changed, 152 insertions(+), 35 deletions(-) delete mode 100644 portlibs/include/wiilight.h delete mode 100644 portlibs/lib/libwiilight.a create mode 100644 source/gui/Gekko.c create mode 100644 source/gui/Gekko.h diff --git a/Makefile b/Makefile index d7151952..b3f93e0c 100644 --- a/Makefile +++ b/Makefile @@ -78,7 +78,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80A00 #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- -LIBS := -lcustomfat -lcustomntfs -lcustomext2fs -lpng -lm -lz -lwiiuse -lbte -lasnd -logc -lfreetype -lvorbisidec -lmad -ljpeg -lwiilight -lmodplay +LIBS := -lcustomfat -lcustomntfs -lcustomext2fs -lpng -lm -lz -lwiiuse -lbte -lasnd -logc -lfreetype -lvorbisidec -lmad -ljpeg -lmodplay #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing diff --git a/portlibs/include/wiilight.h b/portlibs/include/wiilight.h deleted file mode 100644 index d24d0bd2..00000000 --- a/portlibs/include/wiilight.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _WIILIGHT_H_ -#define _WIILIGHT_H_ - - -#ifdef __cplusplus -extern "C" { -#endif - -void WIILIGHT_Init(); -void WIILIGHT_TurnOn(); -int WIILIGHT_GetLevel(); -int WIILIGHT_SetLevel(int level); - -void WIILIGHT_Toggle(); -void WIILIGHT_TurnOff(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/portlibs/lib/libwiilight.a b/portlibs/lib/libwiilight.a deleted file mode 100644 index 358db7e0c0451c2615a9c8c0fb115a9b895a3f43..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8420 zcmcIpeQZqrZ`o|93_kQQ&o_p@OpU(+(CUVKqtqUW;Qd-}-{?_&l8{6A927@h9Wj}+#*0y$4 zA-<4^Du_hqrz!jU`l5Y1dj|%0x`n8F#7&ct%whLwgTbSzR5~>>S{N*(#@sy_nj<)L zsOY0FlPXwTzSMdmmnkX-!0oZ?NLGs$n7FM^DyOsN7y^OljXs-t{!d0!3D{2Jk_DlcbNfDKd{T|35cfnOAL3!9;9 zs3aU=lDT8%fjd^2X3O7$I&c@A6*evb;W4d&kaSEJHO&4+249j zD|fu1sNPn=_8=!m4!`|8e8=$+e@F4Lh{^HK2fNSbpYI5a2fgSx5IEg_zaw}QH#$xk z3~np)m!&cVasuG!c_+X|uH$FjJJJWeA{~f0Y6;gFgV{kC(T)HjAo>oRi$|S2VBT3n z+*HIV;CawlFQt6~Kh zrY5m>3H!QL^ze%bBA84ebP*Lj5cG+CwMPM%r15;fIeh?}NDIzB zxH#Pa_PoFvbgHLMOuaja&Nxf!If1`yz+(@OF+Cv44{-Cf;iyciVW_uBgu%?1Am;}+HRBF%fhj7 zHyb)l7OR)_lF!Ebr^18jGdI{hn&u7)Q3 z>zZg>68{!VYH7W{tCw}OB~El|0r?r9-bMaXMSs+Fe)cC@y67By zQsR!Mr`w5W*X-FTW9AE$4{a zz&LR{;`m>#dOEZ(*~e6hqg z7K>cz*msXW`L?-9n!6>WSB=zMC^1BxMk;TNknFZ@m3&X+u{B2et_b1RONG+#nW9Wx z5y`2y{CU?_gt=~x5Z6ygx0&jFd|`!TuaS6{Vu+GfRqtL3L#CLQgyL9uV)@iV%F~2N z52=3hbYO~lFXCZmn(#(|+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O&M`+#Zog~g4KeBb@L5%d^(hJOI={l3&_|Xt-+_Kh6Gzmg7!h z{Gi@SuFJF#m~EJ-mH}q}zgj{)3?;_%|^u zgN=>>{;M@ce@$%dM2)&FdC5}Rfb6;Z2eLk}#MxJ<{=y^_! z3I`y^I+b$9>l9``SpTN2ZiUeff5%BVW7tVN101vL;|g;OSa;Iq3E;yDUj)WHnWxro n39iQ4)^dAXf>wW(~DP(g|%A diff --git a/source/gui/Gekko.c b/source/gui/Gekko.c new file mode 100644 index 00000000..6a355e83 --- /dev/null +++ b/source/gui/Gekko.c @@ -0,0 +1,100 @@ +/** + * Gekko.h - Additional rendering routines for the Gekko platform. + * + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE' included within this release + */ + +#include +#include +#include +#include + +#include "Gekko.h" + +#define HW_GPIO 0xCD0000C0; +#define DISC_SLOT_LED 0x20 + +lwp_t light_thread = LWP_THREAD_NULL; + +void *light_loop(); +vu32 *light_reg = (u32*) HW_GPIO; +bool light_on = false; +u8 light_level = 0; + +struct timespec light_timeon; +struct timespec light_timeoff; + +void wiiLightOn() +{ + light_on = true; + + if(light_thread == LWP_THREAD_NULL) + LWP_CreateThread(&light_thread, light_loop, NULL, NULL, 0, LWP_PRIO_HIGHEST); +} + +void wiiLightOff() +{ + light_on = false; + + LWP_JoinThread(light_thread, NULL); + light_thread = LWP_THREAD_NULL; + *light_reg &= ~DISC_SLOT_LED; +} + +void wiiLightSetLevel(int level) +{ + light_level = MIN(MAX(level, 0), 100); + + // Calculate the new on/off times for this light intensity + u32 level_on; + u32 level_off; + level_on = (light_level * 2.55) * 40000; + level_off = 10200000 - level_on; + light_timeon.tv_nsec = level_on; + light_timeoff.tv_nsec = level_off; +} + +/** + * Since you can only turn the disc slot light either completely on + * or completely off, this thread simulates different light intensity + * levels by turning the light on and off very quickly at a specific + * interval defined by the current light intensity level. + * + * Its all an eye trick ;) + * + */ +void *light_loop() +{ + struct timespec timeon; + struct timespec timeoff; + + // Loop whilst the light is still 'on' + while(light_on) + { + timeon = light_timeon; + timeoff = light_timeoff; + // Turn on the light and sleep for a bit + *light_reg |= DISC_SLOT_LED; + nanosleep(&timeon); + // Turn off the light (if required) and sleep for a bit + if (timeoff.tv_nsec > 0) + *light_reg &= ~DISC_SLOT_LED; + nanosleep(&timeoff); + } + return NULL; +} diff --git a/source/gui/Gekko.h b/source/gui/Gekko.h new file mode 100644 index 00000000..50a03542 --- /dev/null +++ b/source/gui/Gekko.h @@ -0,0 +1,38 @@ +/** + * Gekko.h - Additional rendering routines for the Gekko platform. + * + * Copyright (c) 2009 Rhys "Shareese" Koedijk + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * See 'LICENSE' included within this release + */ + +#ifndef _GEKKO_H_ +#define _GEKKO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// Wii disc slot light routines +void wiiLightOn(); +void wiiLightOff(); +void wiiLightSetLevel(int level); + +#ifdef __cplusplus +} +#endif + +#endif /* _GEKKO_H_ */ diff --git a/source/gui/video.cpp b/source/gui/video.cpp index 11356ccc..7e83a288 100644 --- a/source/gui/video.cpp +++ b/source/gui/video.cpp @@ -1,7 +1,7 @@ #include "pngu.h" #include "video.hpp" #include -#include +#include "gekko.h" #include "gecko.h" #define DEFAULT_FIFO_SIZE (256 * 1024) @@ -457,8 +457,8 @@ void CVideo::_showWaitMessages(CVideo *m) if (m->m_useWiiLight) { - WIILIGHT_SetLevel(0); - WIILIGHT_TurnOn(); + wiiLightSetLevel(0); + wiiLightOn(); } while (m->m_showWaitMessage) @@ -476,7 +476,7 @@ void CVideo::_showWaitMessages(CVideo *m) currentLightLevel = 0; fadeDirection = 1; } - WIILIGHT_SetLevel(currentLightLevel); + wiiLightSetLevel(currentLightLevel); } if (waitFrames == 0) @@ -494,8 +494,8 @@ void CVideo::_showWaitMessages(CVideo *m) } if (m->m_useWiiLight) { - WIILIGHT_SetLevel(0); - WIILIGHT_TurnOff(); + wiiLightSetLevel(0); + wiiLightOff(); } m->m_waitMessages.clear(); m->m_showingWaitMessages = false; @@ -508,8 +508,8 @@ void CVideo::hideWaitMessage() m_showWaitMessage = false; CheckWaitThread(); - WIILIGHT_SetLevel(0); - WIILIGHT_TurnOff(); + wiiLightSetLevel(0); + wiiLightOff(); } void CVideo::CheckWaitThread() diff --git a/source/main.cpp b/source/main.cpp index 29f1ac64..6227c5f1 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -8,7 +8,6 @@ #include "text.hpp" #include #include -#include #include "DeviceHandler.hpp" #include "homebrew.h" #include "gecko.h" @@ -46,7 +45,6 @@ int main(int argc, char **argv) // Init video CVideo vid; vid.init(); - WIILIGHT_Init(); vid.waitMessage(0.2f); char *gameid = NULL; diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index bca444a4..367f3b92 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include "gecko.h" #include "defines.h" @@ -24,6 +23,7 @@ #include "cios.hpp" #include "loader/playlog.h" #include "gc/fileOps.h" +#include "Gekko.h" // Sounds extern const u8 click_wav[]; @@ -495,8 +495,10 @@ void CMenu::cleanup(bool ios_reload) if (!ios_reload || (!m_use_wifi_gecko && ios_reload)) _deinitNetwork(); - WIILIGHT_SetLevel(0); - WIILIGHT_TurnOff(); + wiiLightSetLevel(0); + wiiLightOff(); + + gprintf(" \nMemory cleaned up\n"); } void CMenu::_reload_wifi_gecko(void)