/* * Start printing */ int unicorn_start(int fd_rd, int fd_wr, int fd_rd_emerg) { /* Turn on fans */ printf("unicorn_start\n"); channel_tag fan = NULL; fan = fan_lookup_by_name("fan_3"); if (fan) { fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); fan_enable(fan); } fan = fan_lookup_by_name("fan_4"); if (fan) { fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); fan_enable(fan); } heater_start(); plan_start(); stepper_start(); gcode_start(fd_rd, fd_wr, fd_rd_emerg); if (hPause_printing) { Pause_off(hPause_printing); } printf("unicorn_start ok!!!\n"); return 0; }
int main () { int ret; ret = fan_is_supported (); printf ("fan_is_supported: %d\n", ret); assert (ret); /* you're not running as root! */ /* system calls, yes, I suck :( */ system ("cat /proc/acpi/ibm/fan"); printf ("-\n"); fan_set_level (2); system ("cat /proc/acpi/ibm/fan"); printf ("-\n"); sleep (10); system ("cat /proc/acpi/ibm/fan"); printf ("-\n"); fan_set_level (0); sleep (10); system ("cat /proc/acpi/ibm/fan"); printf ("-\n"); fan_set_level (FAN_SPEED_AUTO); sleep (10); system ("cat /proc/acpi/ibm/fan"); printf ("-\n"); }
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; }
int unicorn_init(void) { channel_tag fan = NULL; int ret = 0; board_info_t board_info; printf("unicorn_init...\n"); ret = eeprom_read_board_info(EEPROM_DEV, &board_info); if (ret < 0) { printf("Read eeprom board info failed\n"); return -1; } if (!strncasecmp("bbp1s", board_info.name, 5)) { bbp_board_type = BOARD_BBP1S; } else if(!strncasecmp("bbp1", board_info.name, 4)){ bbp_board_type = BOARD_BBP1; } printf("board name:%s, version:%s, get board type:%d \n", board_info.name, board_info.version, bbp_board_type); /* * Create fifo * fifo_plan2st, fifo_st2plan * fifo_plan2gc, fifo_gc2plan */ Fifo_Attrs fAttrs = Fifo_Attrs_DEFAULT; hFifo_plan2st = Fifo_create(&fAttrs); hFifo_st2plan = Fifo_create(&fAttrs); if ((hFifo_st2plan == NULL) || (hFifo_plan2st == NULL)) { printf("Create Fifo failed\n"); return -1; } Pause_Attrs pAttrs = Pause_Attrs_DEFAULT; hPause_printing = Pause_create(&pAttrs); if (hPause_printing == NULL) { printf("Create pause err\n"); return -1; } else { Pause_on(hPause_printing); } /* set up unicorn system */ ret = unicorn_setup(); if (ret < 0) { return ret; } /* init sub systems of unicorn */ ret = parameter_init(EEPROM_DEV); if (ret < 0) { printf("parameter_init failed\n"); return ret; } ret = analog_init(); if (ret < 0) { printf("analog_init failed\n"); return ret; } ret = temp_init(); if (ret < 0) { printf("temp_init failed\n"); return ret; } ret = pwm_init(); if (ret < 0) { printf("pwm_init failed\n"); return ret; } ret = fan_init(); if (ret < 0) { printf("fan_init failed\n"); return ret; } ret = heater_init(); if (ret < 0) { printf("heater_init failed\n"); return ret; } #ifdef SERVO if (bbp_board_type == BOARD_BBP1S) { ret = servo_init(); if (ret < 0) { printf("servo_init failed\n"); return ret; } } #endif ret = lmsw_init(); if (ret < 0) { printf("lmsw_init failed\n"); return ret; } ret = plan_init(); if (ret < 0) { printf("plan_init failed\n"); return ret; } ret = stepper_init(); if (ret < 0) { printf("stepper_init failed\n"); return ret; } ret = gcode_init(); if (ret < 0) { printf("gcode_init failed\n"); return ret; } fan = fan_lookup_by_name("fan_3"); if (fan) { fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); fan_enable(fan); } fan = fan_lookup_by_name("fan_4"); if (fan) { fan_enable(fan); fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); } fan = fan_lookup_by_name("fan_5"); if (fan) { fan_enable(fan); fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); } fan = fan_lookup_by_name("fan_6"); if (fan) { fan_enable(fan); fan_set_level(fan, DEFAULT_FAN_MAX_LEVEL); } printf("unicorn_init ok!!!\n"); return ret; }
int unicorn_test(void) { int i = 0; int idx = 0; int num_fans = 0; double celsius = 0.0; channel_tag heater, fan, pwm; if (bbp_board_type == BOARD_BBP1S) { num_fans = 6; } else if (bbp_board_type == BOARD_BBP1) { num_fans = 5; } #if 0 start_test_thread(); int count = 10; while (1) { printf("wait evtout count=%d\n", count); prussdrv_pru_wait_event(PRU_EVTOUT_1); prussdrv_pru_clear_event(PRU_EVTOUT_1, PRU1_ARM_INTERRUPT); if(count-- == 0){ return; } } #endif printf("Test 1: Fan testing...\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 1: Fan testing...\n"); printf(" Please watch the led lights and leds on board\n"); printf(" 1.1 close all fans\n"); for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { fan_disable(fan); } } printf(" 1.2 open each fan for 1s then close one by one\n"); for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { printf(" Open %s\n", tag_name(fan)); fan_enable(fan); fan_set_level(fan, 80); sleep(1); printf(" Close %s\n", tag_name(fan)); fan_set_level(fan, 0); fan_disable(fan); } } printf(" 1.3 turn on all fans for 1s, then turn off, repeat 3 times\n"); for (i = 0; i < 2; i++) { for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { fan_enable(fan); fan_set_level(fan, 80); } } sleep(1); for (idx = 0; idx < num_fans; idx++) { fan = fan_lookup_by_index(idx); if (fan) { fan_disable(fan); } } sleep(1); } printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 2: LMSW testing...\n"); printf(" 2.1 Please press min x: \n"); wait_lmsw_min_test(X_AXIS); printf(" min_x ok\n"); printf(" 2.2 Please press min y: \n"); wait_lmsw_min_test(Y_AXIS); printf(" min_y ok\n"); printf(" 2.3 Please press min z: \n"); wait_lmsw_min_test(Z_AXIS); printf(" min_z ok\n"); printf(" 2.4 Please press max x: \n"); wait_lmsw_max(X_AXIS); printf(" max_x ok\n"); printf(" 2.5 Please press max y: \n"); wait_lmsw_max(Y_AXIS); printf(" max_y ok\n"); printf(" 2.6 Please press max z: \n"); wait_lmsw_max(Z_AXIS); printf(" max_z ok\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 3: Heater testing...\n"); printf(" open each heater for 1s then close\n"); printf(" Please watch the led beside the heater interface!\n"); if (bbp_board_type == BOARD_BBP1S) { pwm = pwm_lookup_by_name("pwm_ext"); if (pwm) { pwm_set_output(pwm, 80); } sleep(1); pwm_set_output(pwm, 0); sleep(1); pwm = pwm_lookup_by_name("pwm_ext2"); if (pwm) { pwm_set_output(pwm, 80); } sleep(1); pwm_set_output(pwm, 0); sleep(1); pwm = pwm_lookup_by_name("pwm_bed"); if (pwm) { pwm_set_output(pwm, 80); } sleep(1); pwm_set_output(pwm, 0); sleep(1); for (i = 0; i < 2; i++) { pwm = pwm_lookup_by_name("pwm_ext"); if (pwm) { pwm_set_output(pwm, 80); } pwm = pwm_lookup_by_name("pwm_ext2"); if (pwm) { pwm_set_output(pwm, 80); } pwm = pwm_lookup_by_name("pwm_bed"); if (pwm) { pwm_set_output(pwm, 80); } sleep(4); pwm = pwm_lookup_by_name("pwm_ext"); if (pwm) { pwm_set_output(pwm, 0); } pwm = pwm_lookup_by_name("pwm_ext2"); if (pwm) { pwm_set_output(pwm, 0); } pwm = pwm_lookup_by_name("pwm_bed"); if (pwm) { pwm_set_output(pwm, 0); } sleep(2); } } if (bbp_board_type == BOARD_BBP1) { for (idx = 0; idx < NUM_HEATERS; idx++) { heater = heater_lookup_by_index(idx); if (heater) { printf(" Open %s\n", tag_name(heater)); heater_enable(heater); heater_set_raw_pwm(heater, 40); sleep(5); printf(" Close %s\n", tag_name(heater)); heater_set_raw_pwm(heater, 0); heater_disable(heater); } } } printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 4: Stepper testing...\n"); printf(" 4.1 Turn on all stepper\n"); stepper_test(); printf(" 4.2 Stop Stepper\n"); printf(" Please press min x to stop stepper\n"); wait_lmsw_min(X_AXIS); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 5: USB Host testing...\n"); printf(" 5.1 please insert U mass storage\n"); if(unicorn_test_usb_storage() == -1){ halt_test("Usb mass storage is BAD!!!!!!!!!!!!!!!\n"); } printf("Usb mass storage is OK\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 6: Internal emmc testing...\n"); if(unicorn_test_emmc() == -1){ halt_test("Internal emmc is BAD!!!!!!!!!!!!!!\n"); } printf("Internal emmc is OK\n"); printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 7: eeprom testing...\n"); if(unicorn_test_eeprom() == -1){ halt_test("eeprom is BAD!!!!!!!!!!!!\n"); } printf("eeprom is OK\n"); printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 8: rtc testing...\n"); if(unicorn_test_rtc() == -1) { halt_test("rtc is BAD!!!!!!!!!!!!\n"); } printf("rtc is OK\n"); printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("\n-------------------------------------------------------------\n"); printf("Test 9: Network testing...\n"); printf(" Start to ping the router..\n"); if(unicorn_test_network() == -1) { halt_test("network is BAD!!!!!!!!!!!!\n"); } printf("done.\n"); printf("-------------------------------------------------------------\n"); printf("Test 10: USB OTG testing...\n"); printf(" 11.1 Please connect usb otg line to PC\n"); printf(" 11.2 Could you see the boot partion? If yes, Please press min_x..\n"); wait_lmsw_min_test(X_AXIS); printf("done.\n"); printf("-------------------------------------------------------------\n"); if (bbp_board_type == BOARD_BBP1S) { printf("Test 11: Test max6675 temperature...\n"); printf("long press min y key to exit\n"); if(unicorn_test_max6675() == -1) { halt_test("max6675 is BAD!!!!!!!!!!!!\n"); } printf("\n-------------------------------------------------------------\n"); } #if 0 if (bbp_board_type == BOARD_BBP1S) { #ifdef SERVO printf("Test 12: Test servo...\n"); if (unicorn_test_servo()) { halt_test("servo is BAD!!!!!!!!!!!!\n"); } printf("\n-------------------------------------------------------------\n"); #endif } #endif printf("\n-------------------------------------------------------------\n"); printf("Test 12: Temp adc testing...\n"); heater_start(); if (bbp_board_type == BOARD_BBP1S) { char *heater_array_bbp1s[] = {"heater_ext", "heater_ext2", "heater_bed"}; for (idx = 0; idx < sizeof(heater_array_bbp1s)/sizeof(heater_array_bbp1s[0]); idx++) { heater = heater_lookup_by_name(heater_array_bbp1s[idx]); if (heater) { heater_enable(heater); heater_set_setpoint(heater, TARGET_TEMP); } } for (i = 0; i < 80 && stepper_check_lmsw(X_AXIS) == 0; i++) { for (idx = 0; idx < sizeof(heater_array_bbp1s)/sizeof(heater_array_bbp1s[0]); idx++) { heater = heater_lookup_by_name(heater_array_bbp1s[idx]); if (heater) { celsius = 0.0; heater_get_celsius(heater, &celsius); printf("%s -> %f\n", tag_name(heater), celsius); sleep(1); } } } } else if (bbp_board_type == BOARD_BBP1) { for (idx = 0; idx < NUM_HEATERS; idx++) { heater = heater_lookup_by_index(idx); if (heater) { heater_enable(heater); heater_set_setpoint(heater, TARGET_TEMP); } } printf("long press min x key to exit\n"); heater = heater_lookup_by_name("heater_bed"); for (i = 0; i < 80 && stepper_check_lmsw(X_AXIS) == 0; i++) { if (heater_temp_reached(heater)) { printf("ok\n"); break; } else { sleep(1); } for (idx = 0; idx < NUM_HEATERS; idx++) { heater = heater_lookup_by_index(idx); if (heater) { celsius = 0.0; heater_get_celsius(heater, &celsius); printf("%s -> %f\n", tag_name(heater), celsius); } } printf("\n"); } } heater_stop(); printf("done.\n"); printf("-------------------------------------------------------------\n"); halt_test("All is Good!\n"); return 0; }