mirror of
https://github.com/Fledge68/WiiFlow_Lite.git
synced 2024-11-01 00:55:06 +01:00
d7e5460f31
usb hdd every second if the hdd is more than 20 seconds idle to keep it alive, it gets resetted as soon as wiiflow does some action with it
74 lines
1.8 KiB
C
74 lines
1.8 KiB
C
/****************************************************************************
|
|
* Copyright (C) 2012 FIX94
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program 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 General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
****************************************************************************/
|
|
#include <ogc/cache.h>
|
|
#include <ogc/lwp.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
|
|
#include "usbthread.h"
|
|
#include "usbstorage.h"
|
|
#include "gecko/gecko.h"
|
|
|
|
lwp_t USB_Thread = LWP_THREAD_NULL;
|
|
volatile bool CheckUSB = false;
|
|
volatile bool idle = false;
|
|
volatile time_t start = 0;
|
|
u8 sector[4096];
|
|
|
|
void *KeepUSBAlive(void *nothing)
|
|
{
|
|
int NumberSectors = USBStorage2_GetCapacity(0, NULL);
|
|
start = time(NULL);
|
|
srand(start);
|
|
while(CheckUSB)
|
|
{
|
|
if(idle || (time(NULL) - start) > 19)
|
|
{
|
|
USBStorage2_ReadSectors(0, rand() % NumberSectors, 1, sector);
|
|
idle = true;
|
|
}
|
|
sleep(1);
|
|
}
|
|
return nothing;
|
|
}
|
|
|
|
void CreateUSBKeepAliveThread()
|
|
{
|
|
CheckUSB = true;
|
|
LWP_CreateThread(&USB_Thread, KeepUSBAlive, NULL, NULL, 0, 40);
|
|
}
|
|
|
|
void KillUSBKeepAliveThread()
|
|
{
|
|
CheckUSB = false;
|
|
USBKeepAliveThreadReset();
|
|
if(USB_Thread != LWP_THREAD_NULL)
|
|
{
|
|
LWP_JoinThread(USB_Thread, NULL);
|
|
USB_Thread = LWP_THREAD_NULL;
|
|
}
|
|
}
|
|
|
|
void USBKeepAliveThreadReset()
|
|
{
|
|
while(reading)
|
|
usleep(100);
|
|
start = time(NULL);
|
|
idle = false;
|
|
}
|