int unicorn_disconnect_octoprint() { channel_tag fan = NULL; /* If paused, pause thread off */ if (hPause_printing) { Pause_on(hPause_printing); } printf("stepper_idle\n"); stepper_idle(); printf("ok\n"); fan = fan_lookup_by_name("fan_ext"); if (fan) { fan_set_level(fan, 0); fan_disable(fan); } fan = fan_lookup_by_name("fan_ext2"); if (fan) { fan_set_level(fan, 0); fan_disable(fan); } printf("gcode_stop\n"); gcode_stop(); printf("ok\n"); //if (!blocking) { /* Clean up all fifo data */ stepper_clean_up_fifo(); //} printf("plan_stop\n"); plan_stop(); printf("ok\n"); printf("heater_stop\n"); heater_stop(); printf("ok\n"); if (unicorn_get_mode() == FW_MODE_REMOTE) { if (hPause_printing) { Pause_off(hPause_printing); } } printf("unicorn disconnect ok!\n"); return 0; }
static int control_request(usbd_device *usbd_dev, struct usb_setup_data *req, u8 **buf, u16 *len, void (**complete)(usbd_device *usbd_dev, struct usb_setup_data *req)) { (void)complete; (void)buf; (void)usbd_dev; (void)len; PCBUSBLOG("Got request type: bmRequestType: 0x%x bRequest: 0x%x len: 0x%x\n", req->bmRequestType, req->bRequest, *len); if((req->bmRequestType & 0x60) == 0x40) { // Vendor request if(req->bRequest == REQ_SET_SPEED) { if(!IS_HOST_TO_DEVICE(req->bmRequestType) || *len != 2) return USBD_REQ_NOTSUPP; int des_speed = (*buf)[0] + ((*buf)[1] << 8); PCBUSBLOG("Set speed: %d\n", des_speed); set_speed(des_speed); return USBD_REQ_HANDLED; } else if(req->bRequest == REQ_ENABLE_DEBUG_OUT) { if(!IS_HOST_TO_DEVICE(req->bmRequestType) || *len != 1) return USBD_REQ_NOTSUPP; if((*buf)[0]) enable_debug_out(1); else enable_debug_out(0); PCBUSBLOG("Set debug: %d\n", (*buf)[0]); return USBD_REQ_HANDLED; } else if(req->bRequest == REQ_SET_PERSISTENT_FLASH) { if (!IS_HOST_TO_DEVICE(req->bmRequestType) || *len != 0) { return USBD_REQ_NOTSUPP; } if (req->wIndex > 4096) { return USBD_REQ_NOTSUPP; } PCBUSBLOG("Store to flash: 0x%x at index: 0x%x\n", req->wValue, req->wIndex); pcb_flash_store(req->wIndex, req->wValue); return USBD_REQ_HANDLED; } else if(req->bRequest == REQ_GET_PERSISTENT_FLASH) { if (!IS_DEVICE_TO_HOST(req->bmRequestType) || *len <= 0) { return USBD_REQ_NOTSUPP; } int index = req->wIndex; int length = req->wValue; PCBUSBLOG("Get from flash: index: 0x%x len: 0x%x\n", index, length); if (length > DATA_LEN) { return USBD_REQ_NOTSUPP; } for (int i = 0; i < length; i++) { data[i] = pcb_flash_restore(index + i); } *buf = data; *len = length; return USBD_REQ_HANDLED; } else if(req->bRequest == REQ_GET_STEPPER_STATUS) { if(!IS_DEVICE_TO_HOST(req->bmRequestType)) { return USBD_REQ_NOTSUPP; } /* Sanity check */ if(DATA_LEN < 4) return USBD_REQ_NOTSUPP; data[0] = 0; if(!stepper_idle()) data[0] |= 0x01; if(stepper_is_homed) data[0] |= 0x02; data[1] = 0; data[2] = (stepper_current_pos & 0x00FF); data[3] = (stepper_current_pos & 0xFF00) >> 8; *buf = data; *len = 4; return USBD_REQ_HANDLED; } else if(req->bRequest == REQ_HOME_STEPPER) { stepper_home(); return USBD_REQ_HANDLED; } else if(req->bRequest == REQ_MOVE_STEPPER) { int16_t delta_pos = (int16_t) req->wValue; if(req->wIndex) stepper_move(delta_pos); else stepper_move_to(delta_pos); return USBD_REQ_HANDLED; } else if(req->bRequest == REQ_STEPPER_OFF) { stepper_off(); return USBD_REQ_HANDLED; } else if(req->bRequest == REQ_SET_N_SCANS) { max_n_scans = req->wValue; return USBD_REQ_HANDLED; } else if(req->bRequest == REQ_SET_AUTOSTEP) { if(req->wValue) autostep = 1; else autostep = 0; return USBD_REQ_HANDLED; } else if(req->bRequest == REQ_CAN_SEND) { /* Primitive flow control (FIXME) */ if(!IS_DEVICE_TO_HOST(req->bmRequestType)) { return USBD_REQ_NOTSUPP; } data[0] = (dma_write_idx < K_IMAGE_WIDTH); *buf = data; *len = 4; return USBD_REQ_HANDLED; } }