Fix devices not showing as disconnected

This commit is contained in:
Tasos Sahanidis
2021-09-30 12:25:49 +03:00
parent e896ba41b9
commit 16815035a1
5 changed files with 13 additions and 11 deletions
+1 -1
View File
@@ -119,7 +119,7 @@ void _updateconnected(usbdevice* kb){
ckb_info("Locking ckb%d in _updateconnected()", i);
#endif
queued_mutex_lock(devmutex + i);
if((keyboard + i)->status == STATUS_CONNECTED){
if((keyboard + i)->status == DEV_STATUS_CONNECTED){
written = 1;
fprintf(cfile, "%s%d %s %s\n", devpath, i, keyboard[i].serial, keyboard[i].name);
}
+1 -1
View File
@@ -37,7 +37,7 @@ static void quit() {
for(int i = 1; i < DEV_MAX; i++){
// Before closing, set all keyboards back to HID input mode so that the stock driver can still talk to them
queued_mutex_lock(devmutex + i);
if((keyboard + i)->status > STATUS_DISCONNECTED){
if((keyboard + i)->status == DEV_STATUS_CONNECTING || (keyboard + i)->status == DEV_STATUS_CONNECTED){
revertusb(keyboard + i);
closeusb(keyboard + i);
}
+4 -3
View File
@@ -353,9 +353,10 @@ typedef struct usbdevice_ {
} battery_status;
unsigned char battery_level;
enum {
STATUS_DISCONNECTED,
STATUS_CONNECTING,
STATUS_CONNECTED,
DEV_STATUS_DISCONNECTED,
DEV_STATUS_CONNECTING,
DEV_STATUS_CONNECTED,
DEV_STATUS_DISCONNECTING,
} status;
uchar bragi_out_ep;
uchar bragi_in_ep;
+5 -3
View File
@@ -314,7 +314,7 @@ static void* devmain(usbdevice* kb){
int lines = readlines(kbfifo, linectx, &line);
queued_mutex_lock(dmutex(kb));
// End thread when the handle is removed
if(kb->status == STATUS_DISCONNECTED)
if(kb->status == DEV_STATUS_DISCONNECTING || kb->status == DEV_STATUS_DISCONNECTED)
break;
///
/// if nothing is in the line buffer (some magic interrupt?),
@@ -547,7 +547,7 @@ static void* _setupusb(void* context){
// Finished. Enter main loop
int index = INDEX_OF(kb, keyboard);
ckb_info("Setup finished for %s%d", devpath, index);
kb->status = STATUS_CONNECTED;
kb->status = DEV_STATUS_CONNECTED;
queued_mutex_unlock(dmutex(kb));
updateconnected(kb);
queued_mutex_lock(dmutex(kb));
@@ -793,6 +793,7 @@ int _usbrecv(usbdevice* kb, void* out_msg, size_t msg_len, uchar* in_msg, const
/// and closeusb() always returns zero (success).
///
int closeusb(usbdevice* kb){
kb->status = DEV_STATUS_DISCONNECTING;
queued_mutex_lock(imutex(kb));
if(kb->handle){
int index = INDEX_OF(kb, keyboard);
@@ -849,6 +850,7 @@ int closeusb(usbdevice* kb){
return 0;
kb->vtable->freeprofile(kb);
queued_mutex_lock(imutex(kb));
// This implicitly sets the status to STATUS_DISCONNECTED
memset(kb, 0, sizeof(usbdevice));
queued_mutex_unlock(imutex(kb));
return 0;
@@ -883,7 +885,7 @@ void reactivate_devices(){
for(int i = 1; i < DEV_MAX; i++){
usbdevice* kb = keyboard + i;
queued_mutex_lock(dmutex(kb));
if(kb->status == STATUS_CONNECTED && !NEEDS_FW_UPDATE(kb) && kb->active){
if(kb->status == DEV_STATUS_CONNECTED && !NEEDS_FW_UPDATE(kb) && kb->active){
int ret;
// If the device was active, mark it as disabled and re-enable it
kb->active = 0;
+2 -3
View File
@@ -273,7 +273,6 @@ void os_closeusb(usbdevice* kb){
udev_device_unref(kb->udev);
kb->handle = 0;
kb->udev = 0;
kb->status = STATUS_DISCONNECTED;
kbsyspath[INDEX_OF(kb, keyboard)][0] = 0;
}
@@ -470,7 +469,7 @@ int usbadd(struct udev_device* dev, ushort vendor, ushort product) {
// If the mutex is locked then the device is obviously in use, so keep going
continue;
}
if(kb->status == STATUS_DISCONNECTED){
if(kb->status == DEV_STATUS_DISCONNECTED){
// Open the sysfs device
kb->handle = open(path, O_RDWR) + 1;
if(kb->handle <= 0){
@@ -484,7 +483,7 @@ int usbadd(struct udev_device* dev, ushort vendor, ushort product) {
kb->vendor = vendor;
kb->product = product;
strncpy(kbsyspath[index], syspath, FILENAME_MAX);
kb->status = STATUS_CONNECTING;
kb->status = DEV_STATUS_CONNECTING;
// Mutex remains locked
setupusb(kb);
return 0;