Changeset 22975 for titan/plugins/usbreset
- Timestamp:
- 08/22/13 15:18:27 (10 years ago)
- Location:
- titan/plugins/usbreset
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
titan/plugins/usbreset/usbreset.h
r22945 r22975 2 2 #define USBRESET_H 3 3 4 #define USBRESETPATH "/sys/bus/usb/drivers/usb /unbind"4 #define USBRESETPATH "/sys/bus/usb/drivers/usb" 5 5 #define USBRESETUNBIND USBRESETPATH"/unbind" 6 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 = 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 } 7 75 8 76 void screenusbreset() … … 12 80 struct skin* load = getscreen("loading"); 13 81 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); 20 83 21 84 mbox = menulistbox(mlist, NULL, "USB Reset", NULL, NULL, 1, 0); … … 23 86 if(mbox != NULL) 24 87 { 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 } 26 99 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; 33 101 } 34 102
Note: See TracChangeset
for help on using the changeset viewer.