1 | #ifndef USBRESET_H |
---|
2 | #define USBRESET_H |
---|
3 | |
---|
4 | #define USBRESETPATH "/sys/bus/usb/drivers/usb" |
---|
5 | #define USBRESETUNBIND USBRESETPATH"/unbind" |
---|
6 | #define USBRESETBIND USBRESETPATH"/bind" |
---|
7 | |
---|
8 | int 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 = ostrcat(tmpstr, " (", 1, 0); |
---|
55 | tmpstr = ostrcat(tmpstr, entry->d_name, 1, 0); |
---|
56 | tmpstr = ostrcat(tmpstr, ")", 1, 0); |
---|
57 | struct menulist* m = addmenulist(mlist, tmpstr, NULL, NULL, 0, 0); |
---|
58 | changemenulistparam(m, entry->d_name, NULL, NULL, 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 | } |
---|
75 | |
---|
76 | void screenusbreset() |
---|
77 | { |
---|
78 | struct menulist* mlist = NULL, *mbox = NULL; |
---|
79 | struct skin* load = getscreen("loading"); |
---|
80 | |
---|
81 | addusbreset(USBRESETPATH, &mlist); |
---|
82 | |
---|
83 | mbox = menulistbox(mlist, NULL, "USB Reset", NULL, NULL, 1, 0); |
---|
84 | |
---|
85 | if(mbox != NULL) |
---|
86 | { |
---|
87 | if(mbox->param != NULL) |
---|
88 | { |
---|
89 | drawscreen(load, 0, 0); |
---|
90 | |
---|
91 | writesys(USBRESETUNBIND, mbox->param, 0); //unbind |
---|
92 | sleep(2); |
---|
93 | writesys(USBRESETBIND, mbox->param, 0); //bind |
---|
94 | |
---|
95 | clearscreen(load); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | freemenulist(mlist, 1); mlist = NULL; |
---|
100 | } |
---|
101 | |
---|
102 | #endif |
---|