Ignore:
Timestamp:
08/22/13 15:18:27 (10 years ago)
Author:
nit
Message:

[titan] update usb reset

Location:
titan/plugins/usbreset
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • titan/plugins/usbreset/usbreset.h

    r22945 r22975  
    22#define USBRESET_H
    33
    4 #define USBRESETPATH "/sys/bus/usb/drivers/usb/unbind"
     4#define USBRESETPATH "/sys/bus/usb/drivers/usb"
    55#define USBRESETUNBIND USBRESETPATH"/unbind"
    66#define USBRESETBIND USBRESETPATH"/bind"
     7
     8int addusbreset(char* dirname, struct menulist** mlist)
     9{
     10        int ret = 0;
     11        DIR *d;
     12        char* tmpstr = NULL;
     13
     14        //Open the directory specified by dirname
     15        d = opendir(dirname);
     16
     17        //Check it was opened
     18        if(! d)
     19        {
     20                perr("Cannot open directory %s", dirname);
     21                return 1;
     22        }
     23
     24        while(1)
     25        {
     26                struct dirent* entry;
     27                int path_length;
     28                char path[PATH_MAX];
     29
     30                snprintf(path, PATH_MAX, "%s", dirname);
     31                //Readdir gets subsequent entries from d
     32                entry = readdir(d);
     33
     34                if(!entry) //There are no more entries in this directory, so break out of the while loop
     35                        break;
     36
     37                //See if entry is a subdirectory of d
     38                if(entry->d_type == DT_LNK)
     39                {
     40                        //Check that the directory is not d or d's parent
     41                        if(entry->d_name != NULL && ostrcmp(entry->d_name, ".") != 0 && ostrcmp(entry->d_name, "..") != 0)
     42                        {
     43                                path_length = snprintf(path, PATH_MAX, "%s/%s/product", dirname, entry->d_name);
     44                                if(path_length >= PATH_MAX)
     45                                {
     46                                        err("path length has got too long");
     47                                        ret = 1;
     48                                        break;
     49                                }
     50                               
     51                                tmpstr = readsys(path, 1);
     52                                if(tmpstr != NULL && path[1] == '-')
     53                                {
     54                                        tmpstr = ostract(tmpstr, " (", 1, 0);
     55                                        tmpstr = ostract(tmpstr, entry->d_name, 1, 0);
     56                                        tmpstr = ostract(tmpstr, ")", 1, 0);
     57                                        struct menulist* m = addmenulist(mlist, tmpstr, NULL, NULL, 0, 0);
     58                                        changemenulistparam(m, entry->d_name, NULL);
     59                                }
     60                                free(tmpstr); tmpstr = NULL;
     61                               
     62                        }
     63                }
     64        }
     65
     66        //After going through all the entries, close the directory
     67        if(d && closedir(d))
     68        {
     69                perr("Could not close %s", dirname);
     70                ret = 1;
     71        }
     72
     73        return ret;
     74}
    775
    876void screenusbreset()
     
    1280        struct skin* load = getscreen("loading");
    1381       
    14         // /sys/bus/usb/drivers/usb/unbind
    15         // /sys/bus/usb/drivers/usb/1-1/product
    16        
    17         tmpstr = readsys("", 1);
    18         addmenulist(&mlist, tmpstr, NULL, NULL, 0, 0);
    19         free(tmpstr); tmpstr = NULL;
     82        addusbreset(USBRESETPATH, &mlist);
    2083       
    2184        mbox = menulistbox(mlist, NULL, "USB Reset", NULL, NULL, 1, 0);
     
    2386        if(mbox != NULL)
    2487        {
    25                 drawscreen(load, 0, 0);
     88                if(mbox->param != NULL)
     89                {
     90                        drawscreen(load, 0, 0);
     91               
     92                        writesys(USBRESETUNBIND, mbox->param, 0); //unbind
     93                        sleep(2);
     94                        writesys(USBRESETBIND, mbox->param, 0); //bind
     95                       
     96                        clearscreen(load);
     97                }
     98        }
    2699       
    27                 writesys(USBRESETUNBIND, value, 0); //unbind
    28                 sleep(1);
    29                 writesys(USBRESETBIND, value, 0); //bind
    30                
    31                 clearscreen(load);
    32         }
     100        freemenulist(mlist, 1); mlist = NULL;
    33101}
    34102
Note: See TracChangeset for help on using the changeset viewer.