/** * Initialisation des differents capteurs et du bluetooth */ void init(void) { nx_display_clear(); nx_display_cursor_set_pos(0, 0); nx_display_string("Lo52 project\n"); nx_display_cursor_set_pos(0, 2); //on affiche le niveau de la batterie nx_display_uint(nx_avr_get_battery_voltage()); nx_display_cursor_set_pos(4, 2); nx_display_string("/4000\n"); nx_systick_install_scheduler(watchdog); // initialise le radar ultrason nx_radar_init(RADAR_SENSOR); //initialise le bluetooth bt_init(); nx_display_string("bluetooth...OK"); //initialise le son nx__sound_init(); // initialise le capteur de contact nx_sensors_analog_enable(TOUCH_SENSOR); //initialise le capteur de luminosité nx_sensors_analog_enable(LIGHT_SENSOR); nx_sensors_analog_digi_set(LIGHT_SENSOR, DIGI0); }
void nx_assert_error(const char *file, const int line, const char *expr, const char *msg) { const char *basename = strrchr(file, '/'); basename = basename ? basename+1 : file; /* Try to halt as many moving parts of the system as possible. */ nx_systick_install_scheduler(NULL); nx__avr_set_motor(0, 0, TRUE); nx__avr_set_motor(1, 0, TRUE); nx__avr_set_motor(2, 0, TRUE); nx_display_clear(); nx_sound_freq_async(440, 1000); nx_display_string("** Assertion **\n"); nx_display_string(basename); nx_display_string(":"); nx_display_uint(line); nx_display_end_line(); nx_display_string(expr); nx_display_end_line(); nx_display_string(msg); nx_display_end_line(); while (nx_avr_get_button() != BUTTON_CANCEL); nx_core_halt(); }
void main (void) { nx_systick_install_scheduler(security_hook); nx_rs485_init(); while (1) { lock = 1; nx_rs485_send(out_buffer, sizeof(out_buffer), send_callback); while (lock) { nx_systick_wait_ms(1000); } } }
void main(void) { nx_systick_install_scheduler(security_hook); //tests_all(); // tests_fantom(); //tests_gdbdebug(); //tests_usb(); //tests_bt(); //tests_usb_hardcore(); tests_legocolor(); //tests_radar(); //tests_util(); //tests_defrag(); //tests_ht_compass(); //tests_ht_accel(); //ht_color_calibrate(); //tests_ht_color(); //tests_ht_gyro(); //tests_ht_irlink(); //tests_digitemp(); //tests_sysinfo(); }
void main(void) { nx_systick_install_scheduler(security_hook); bool moving = FALSE; S32 total_rotation = 0; S8 speed = 60; S8 start_angle = 0; //tests_all(); //tests_usb(); //tests_bt(); //tests_usb_hardcore(); //tests_radar(); //tests_util(); //tests_defrag(); nx_radar_init(RADAR_SENSOR); nx_lightsensor_init(LIGHT_SENSOR); //nx_lightsensor_fire_spamlight(LIGHT_SENSOR); /* for (fuffa_rot = 0; (nx_motors_get_tach_count(0) % 360) < 90; fuffa_rot++) { nx_systick_wait_ms(1000); nx_motors_rotate_angle(0, 100, 1, TRUE); } */ for(;;) { nx_systick_wait_ms(500); //nx_display_cursor_set_pos(9, 3); nx_display_clear(); total_rotation = nx_motors_get_tach_count(RADAR_MOTOR); display_rotation_data(speed, total_rotation, start_angle); switch (nx_avr_get_button()) { case BUTTON_LEFT: /* if (speed >= -95) { speed -= 5; } else { speed = -100; }*/ nx_motors_rotate (0, -60); nx_systick_wait_ms(100); start_angle = nx_motors_get_tach_count(0); nx_motors_rotate_angle(RADAR_MOTOR, -35, 45, FALSE); /*nx_systick_wait_ms(1000); *nx_motors_rotate_angle(0, 100, 45, TRUE); */ break; case BUTTON_RIGHT: /*if (speed <= 95) { speed += 5; } else { speed = 100; } nx_motors_rotate (0, speed);*/ nx_motors_rotate (0, 60); nx_systick_wait_ms(100); start_angle = nx_motors_get_tach_count(0); nx_motors_rotate_angle(RADAR_MOTOR, 35, 45, FALSE); break; case BUTTON_OK: if (moving) { nx_motors_stop(RADAR_MOTOR, TRUE); //nx_motors_stop(1, TRUE); //nx_motors_stop(2, TRUE); moving = !moving; } else { nx_motors_rotate(RADAR_MOTOR, speed); //nx_motors_rotate(1, 20); //nx_motors_rotate(2, 20); moving = !moving; } break; default: break; } }; }
void mv__scheduler_run(void) { sched_state.last_context_switch = nx_systick_get_ms(); nx_interrupts_disable(); nx_systick_install_scheduler(scheduler_cb); mv__task_run_first(task_idle, sched_state.task_idle->stack_current); }
void main() { /* We'll use this buffer to read data from the RS485 bus. This needs * to be volatile because it gets modified outside of the main code * path (in interrupt handlers). */ U8 buffer_hello[12] = "Hello world"; U8 buffer_empty[12] = {0}; /* Install our emergency shutdown hook. See above for details. */ nx_systick_install_scheduler(shutdown_hook); /* Initialize the RS485 driver for communication at 9600 bits per * second with no timeout. If you need special communication modes * (number of start/stop bits, parity checks...), you can specify an * explicit mode register value. */ nx_rs485_init(RS485_BR_9600, 0, 0, FALSE); for (int i = 0; i < 10; ++i) { /* This is just to alternate between sending two different * messages. One time we send "hello world", the other an empty * string. */ U8 *buffer = (i % 2 == 0) ? buffer_hello : buffer_empty; /* Display what we are transmitting, for the record */ nx_display_clear(); nx_display_string("Iteration "); nx_display_uint(i+1); nx_display_string("\n"); nx_display_string((char*)buffer); /* Wait a bit before actually sending, to get a nice obvious * delayed transmission effect. */ nx_systick_wait_ms(1000); /* Try to write 12 bytes to the RS485 bus. This call merely * instructs the RS485 driver to start writing data, and returns * immediately. * * Once the read of all 12 bytes is complete, the given callback * function will be called, with a status value, indicating * whether or not there was an error. */ nx_rs485_send(buffer, sizeof(buffer), send_callback); /* Since the above function returns immediately, we need a way to * wait for the receive to complete. How you do this depends on * how you want your application kernel to work, but in this case, * we'll just block on our spinlock, until the callback unlocks it * after the write completes. */ nx_spinlock_acquire(&lock); /* Wait before transmitting the next round, again purely for * effect. */ nx_systick_wait_ms(1000); } }