void firmware_init(){ // Initialize firmware dxl_initialize(0,1); //initialize dynamixel communication serial_initialize(57600); //initialize serial communication //initialize sensors sensor_init(SENSOR_FRONT,SENSOR_DISTANCE); sensor_init(SENSOR_FRONTLEFT,SENSOR_IR); sensor_init(SENSOR_FRONTRIGHT,SENSOR_IR); sensor_init(SENSOR_BACKLEFT,SENSOR_IR); sensor_init(SENSOR_BACKRIGHT,SENSOR_IR); //initialize I/O io_init(); io_set_interrupt(BTN_START, &reset_state); //assign callback function when start button is pressed // Activate general interrupts sei(); // Set motors to wheel mode motor_set_mode(254, MOTOR_WHEEL_MODE); // Set serial communication through ZigBee serial_set_zigbee(); }
int main(void) { halInit(); chSysInit(); get_device_id(); /* start stdout port */ sdStart(SD_STDIO, NULL); xflash_init(); cmdline_init(); rngStart(&RNGD); app_cfg_init(); check_for_faults(); gfx_init(); touch_init(); sensor_init(SENSOR_1, SD_OW1); sensor_init(SENSOR_2, SD_OW2); temp_control_init(CONTROLLER_1); temp_control_init(CONTROLLER_2); ota_update_init(); net_init(); web_api_init(); sntp_init(); gui_init(); thread_watchdog_init(); create_home_screen(); recovery_screen_create(); screen_saver_create(); if (palReadPad(PORT_SELF_TEST_EN, PAD_SELF_TEST_EN) == 0) { widget_t* self_test_screen = self_test_screen_create(); gui_push_screen(self_test_screen); } recovery_img_init(); while (TRUE) { cmdline_restart(); toggle_LED1(); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds; // Initialize. app_trace_init(); timers_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); device_manager_init(erase_bonds); gap_params_init(); advertising_init(); services_init(); sensor_simulator_init(); conn_params_init(); #if defined(__RING_SUPPORT__) btn_init(); spi_flash_init(); sensor_init(); lcd_init(); #endif // Start execution. application_timers_start(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); // Enter main loop. for (;;) { power_manage(); } }
PROCESS_THREAD(node_timeout_process, ev, data) { PROCESS_BEGIN(); while (1) { static struct etimer timeout; int16_t sensor_value = 0; static char message[3]; etimer_set(&timeout, CLOCK_SECOND * SLEEP_TIMEOUT); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timeout)); etimer_set(&timeout, CLOCK_SECOND/16); leds_on(LEDS_ALL); sensor_init(); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timeout)); sensor_value = sensor_read() - my_noise; sensor_uinit(); itoa(sensor_value, message, 10); strcat(message, "!\0"); transmit_runicast(message, SINK_NODE); leds_off(LEDS_ALL); } PROCESS_END(); }
PROCESS_THREAD(node_read_process, ev, data) { PROCESS_BEGIN(); static struct etimer etimer; static int16_t sensor_value = 0; static char message[3]; etimer_set(&etimer, CLOCK_SECOND * sleep_time); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer)); etimer_set(&etimer, CLOCK_SECOND/16); leds_on(LEDS_ALL); sensor_init(); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer)); sensor_value = sensor_read() - my_noise; sensor_uinit(); itoa(sensor_value, message, 10); strcat(message, "!\0"); transmit_runicast(message, SINK_NODE); leds_off(LEDS_ALL); // process_start(&node_timeout_process, NULL); PROCESS_END(); }
//The setup function is called once at startup of the sketch void setup() { // Add your initialization code here // Note : This will initialize Serial port on Arduino at 115200 bauds OC_LOG_INIT(); OC_LOG(DEBUG, TAG, ("Demoserver is starting...")); // Connect to Ethernet or WiFi network if (ConnectToNetwork() != 0) { OC_LOG(ERROR, TAG, ("Unable to connect to network")); return; } // Initialize the OC Stack in Server mode if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK) { OC_LOG(ERROR, TAG, ("OCStack init error")); return; } // Initialize Grove related Devices sensor_init(); led_init(); lcd_init(); buzzer_init(); button_init(); // Declare and create the resource: grove createDemoResource(); }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_change_detect_process, ev, data) { static struct etimer etimer; PROCESS_BEGIN(); leds_init(); while(1) { sensor_init(); etimer_set(&etimer, CLOCK_SECOND / 4); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); sample = sensor_read(); sensor_uinit(); printf("sample = %d\n",sample); if(abs_sub(sample, sample_mean) > (sample_std_dev * NUM_DEVS)) { // Change detected, turn on LED(s)? leds_on(LEDS_RED); } else { // Turn off LED(s). leds_off(LEDS_RED); } } PROCESS_END(); }
/** * Expects to be called back through os_dev_create(). * * @param The device object associated with this accelerometer * @param Argument passed to OS device init, unused * * @return 0 on success, non-zero error on failure. */ int sim_accel_init(struct os_dev *dev, void *arg) { struct sim_accel *sa; struct sensor *sensor; int rc; sa = (struct sim_accel *) dev; sensor = &sa->sa_sensor; rc = sensor_init(sensor, dev); if (rc != 0) { goto err; } rc = sensor_set_driver(sensor, SENSOR_TYPE_ACCELEROMETER, (struct sensor_driver *) &g_sim_accel_sensor_driver); if (rc != 0) { goto err; } rc = sensor_mgr_register(sensor); if (rc != 0) { goto err; } return (0); err: return (rc); }
static int gsensor_load_driver(struct sensors_poll_context_t *dev) { int ret = -1; char buffer[20]; int bytes = 0; int values = 0; load_driver_value = 0; if(detect_value[0] < ( SENSORS_NUMBER + 1)) { ALOGD("start to isnmod %s.ko\n",sensors[detect_value[0]-1].name); if (insmod(driver_path[detect_value[0]-1].name, "") < 0) { ALOGD("insmod %s.ko failed!",sensors[detect_value[0]-1].name); rmmod(sensors[detect_value[0]-1].name);//it may be load driver already,try remove it. return 0; } if(!(ret = sensor_init(dev))){ ALOGD("sensor_init error !\n"); return 0; } }else{ ALOGD("detect_value isn't valid!\n"); return 0; } return 1; }
/** * Expects to be called back through os_dev_create(). * * @param The device object associated with this color sensor * @param Argument passed to OS device init, unused * * @return 0 on success, non-zero error on failure. */ int tcs34725_init(struct os_dev *dev, void *arg) { struct tcs34725 *tcs34725; struct sensor *sensor; int rc; if (!arg || !dev) { rc = SYS_ENODEV; goto err; } tcs34725 = (struct tcs34725 *) dev; tcs34725->cfg.mask = SENSOR_TYPE_ALL; sensor = &tcs34725->sensor; /* Initialise the stats entry */ rc = stats_init( STATS_HDR(g_tcs34725stats), STATS_SIZE_INIT_PARMS(g_tcs34725stats, STATS_SIZE_32), STATS_NAME_INIT_PARMS(tcs34725_stat_section)); SYSINIT_PANIC_ASSERT(rc == 0); /* Register the entry with the stats registry */ rc = stats_register("tcs34725", STATS_HDR(g_tcs34725stats)); SYSINIT_PANIC_ASSERT(rc == 0); rc = sensor_init(sensor, dev); if (rc != 0) { goto err; } /* Add the color sensor driver */ rc = sensor_set_driver(sensor, SENSOR_TYPE_COLOR, (struct sensor_driver *) &g_tcs34725_sensor_driver); if (rc != 0) { goto err; } /* Set the interface */ rc = sensor_set_interface(sensor, arg); if (rc) { goto err; } rc = sensor_mgr_register(sensor); if (rc != 0) { goto err; } rc = sensor_set_type_mask(sensor, tcs34725->cfg.mask); if (rc) { goto err; } return (0); err: return (rc); }
/** * \brief Configuration function for the HDC1000 sensor. * * \param type Activate, enable or disable the sensor. See below * \param enable * * When type == SENSORS_HW_INIT we turn on the hardware * When type == SENSORS_ACTIVE and enable==1 we enable the sensor * When type == SENSORS_ACTIVE and enable==0 we disable the sensor */ static int configure(int type, int enable) { switch(type) { case SENSORS_HW_INIT: raw_temp = 0; raw_hum = 0; memset(&data, 0, sizeof(data)); sensor_init(); enabled = HDC_1000_SENSOR_STATUS_INITIALISED; break; case SENSORS_ACTIVE: /* Must be initialised first */ if(enabled == HDC_1000_SENSOR_STATUS_DISABLED) { return HDC_1000_SENSOR_STATUS_DISABLED; } if(enable) { start(); ctimer_set(&startup_timer, SENSOR_STARTUP_DELAY, notify_ready, NULL); enabled = HDC_1000_SENSOR_STATUS_TAKING_READINGS; } else { ctimer_stop(&startup_timer); enabled = HDC_1000_SENSOR_STATUS_INITIALISED; } break; default: break; } return enabled; }
void init() { m_clockdivide(0); m_disableJTAG(); movement_init(); sensor_init(); }
int aos_kernel_init(kinit_t *kinit) { #ifdef AOS_VFS vfs_init(); vfs_device_init(); #endif #ifdef CONFIG_AOS_CLI if (kinit->cli_enable) aos_cli_init(); #endif #ifdef AOS_KV aos_kv_init(); #endif #ifdef WITH_SAL sal_device_init(); #endif #ifdef AOS_LOOP aos_loop_init(); #endif #ifdef VCALL_RHINO trace_start(); #endif #ifdef AOS_FOTA ota_service_init(); #endif #ifdef AOS_SENSOR sensor_init(); #endif // auto_component generated by the compiler system, now gcc support #if defined (__GNUC__) aos_components_init(); #endif #ifdef AOS_BINS app_pre_init(); framework_pre_init(); if (framework_info->framework_entry) { framework_info->framework_entry((void *)syscall_ktbl, kinit->argc, kinit->argv); } #else #ifdef AOS_FRAMEWORK_COMMON aos_framework_init(); #endif application_start(kinit->argc, kinit->argv); #endif return 0; }
/** * Expects to be called back through os_dev_create(). * * @param The device object associated with this accellerometer * @param Argument passed to OS device init, unused * * @return 0 on success, non-zero error on failure. */ int bno055_init(struct os_dev *dev, void *arg) { struct bno055 *bno055; struct sensor *sensor; int rc; bno055 = (struct bno055 *) dev; rc = bno055_default_cfg(&bno055->cfg); if (rc) { goto err; } #if MYNEWT_VAL(BNO055_LOG) log_register("bno055", &_log, &log_console_handler, NULL, LOG_SYSLEVEL); #endif sensor = &bno055->sensor; #if MYNEWT_VAL(BNO055_STATS) /* Initialise the stats entry */ rc = stats_init( STATS_HDR(g_bno055stats), STATS_SIZE_INIT_PARMS(g_bno055stats, STATS_SIZE_32), STATS_NAME_INIT_PARMS(bno055_stat_section)); SYSINIT_PANIC_ASSERT(rc == 0); /* Register the entry with the stats registry */ rc = stats_register("bno055", STATS_HDR(g_bno055stats)); SYSINIT_PANIC_ASSERT(rc == 0); #endif rc = sensor_init(sensor, dev); if (rc != 0) { goto err; } /* Add the accelerometer/magnetometer driver */ rc = sensor_set_driver(sensor, SENSOR_TYPE_ACCELEROMETER | SENSOR_TYPE_MAGNETIC_FIELD | SENSOR_TYPE_GYROSCOPE | SENSOR_TYPE_TEMPERATURE | SENSOR_TYPE_ROTATION_VECTOR | SENSOR_TYPE_GRAVITY | SENSOR_TYPE_LINEAR_ACCEL | SENSOR_TYPE_EULER, (struct sensor_driver *) &g_bno055_sensor_driver); if (rc != 0) { goto err; } rc = sensor_mgr_register(sensor); if (rc != 0) { goto err; } return (0); err: return (rc); }
/* * init_lmSensors(): * Initialization routine. This is called when the agent starts up. * At a minimum, registration of your variables should take place here. */ void init_lmSensors(void) { sensor_init(); /* * register ourselves with the agent to handle our mib tree */ REGISTER_MIB("lmSensors", lmSensors_variables, variable4, lmSensors_variables_oid); }
static int sensor_command(struct i2c_client *client, unsigned int cmd, void *arg) { switch (cmd) { case SENSOR_INIT: sensor_init(client); printk(KERN_INFO "External Camera initialized\n"); break; case USER_ADD: break; case USER_EXIT: break; case SENSOR_QSVGA: change_sensor_size(client, SENSOR_QSVGA); break; case SENSOR_VGA: change_sensor_size(client, SENSOR_VGA); break; case SENSOR_SVGA: change_sensor_size(client, SENSOR_SVGA); break; case SENSOR_SXGA: change_sensor_size(client, SENSOR_SXGA); break; case SENSOR_UXGA: change_sensor_size(client, SENSOR_UXGA); break; /* Todo case SENSOR_BRIGHTNESS: change_sensor_setting(); break; */ case SENSOR_WB: printk("[ *** 4XA Sensor White Balance , No mode ***]\n"); change_sensor_wb(client, (int) arg); break; default: panic("4xa_sensor.c : Unexpect Sensor Command \n"); break; } return 0; }
void __init msm8974_init(void) { struct of_dev_auxdata *adata = msm8974_auxdata_lookup; #ifdef CONFIG_SEC_DEBUG sec_debug_init(); #endif #ifdef CONFIG_PROC_AVC sec_avc_log_init(); #endif if (socinfo_init() < 0) pr_err("%s: socinfo_init() failed\n", __func__); samsung_sys_class_init(); msm_8974_init_gpiomux(); regulator_has_full_constraints(); board_dt_populate(adata); msm8974_add_drivers(); platform_add_devices(common_devices, ARRAY_SIZE(common_devices)); #if defined (CONFIG_MOTOR_DRV_ISA1400) vienna_motor_init(); #endif #ifdef CONFIG_REGULATOR_MAX77826 i2c_register_board_info(MAX77826_I2C_BUS_ID, max77826_pmic_info, ARRAY_SIZE(max77826_pmic_info)); #endif #ifdef CONFIG_SEC_S_PROJECT sensor_init(); #endif #ifdef CONFIG_SENSORS_SSP sensor_hub_init(); #endif #ifdef CONFIG_SEC_PATEK_PROJECT platform_device_register(&folder_keypad_device); #endif #ifdef CONFIG_SEC_PM_DEBUG msm_show_resume_irq_mask = 1; #endif #if defined(CONFIG_BT_BCM4335) || defined(CONFIG_BT_BCM4339) msm8974_bt_init(); #endif }
Object initPlayer(Map room) { Object playerObj = object_init(object_new(), "@", (mapVec){3, 1, 0}, (mapVec){1, 1, 0}, room ); Sensor leftEye = sensor_init(sensor_new(), "left_eye", frustum_init(frustum_new(), mapvec_zero, (mapVec){1, -1, 0}, 1, 2, 0, 10 ) ); Sensor rightEye = sensor_init(sensor_new(), "right_eye", frustum_init(frustum_new(), mapvec_zero, (mapVec){1, 1, 0}, 1, 2, 0, 10 ) ); Sensor basicSense = sensor_init(sensor_new(), "basic_sense", sphere_init(sphere_new(), mapvec_zero, 2 ) ); object_add_sensor(playerObj, leftEye); object_add_sensor(playerObj, rightEye); object_add_sensor(playerObj, basicSense); map_add_object(room, playerObj); return playerObj; }
/** * Expects to be called back through os_dev_create(). * * @param The device object associated with this accellerometer * @param Argument passed to OS device init, unused * * @return 0 on success, non-zero error on failure. */ int mpu6050_init(struct os_dev *dev, void *arg) { struct mpu6050 *mpu; struct sensor *sensor; int rc; if (!arg || !dev) { return SYS_ENODEV; } mpu = (struct mpu6050 *) dev; mpu->cfg.mask = SENSOR_TYPE_ALL; log_register(dev->od_name, &_log, &log_console_handler, NULL, LOG_SYSLEVEL); sensor = &mpu->sensor; /* Initialise the stats entry */ rc = stats_init( STATS_HDR(g_mpu6050stats), STATS_SIZE_INIT_PARMS(g_mpu6050stats, STATS_SIZE_32), STATS_NAME_INIT_PARMS(mpu6050_stat_section)); SYSINIT_PANIC_ASSERT(rc == 0); /* Register the entry with the stats registry */ rc = stats_register(dev->od_name, STATS_HDR(g_mpu6050stats)); SYSINIT_PANIC_ASSERT(rc == 0); rc = sensor_init(sensor, dev); if (rc) { return rc; } /* Add the accelerometer/gyroscope driver */ rc = sensor_set_driver(sensor, SENSOR_TYPE_GYROSCOPE | SENSOR_TYPE_ACCELEROMETER, (struct sensor_driver *) &g_mpu6050_sensor_driver); if (rc) { return rc; } rc = sensor_set_interface(sensor, arg); if (rc) { return rc; } return sensor_mgr_register(sensor); }
void init_all() { sensor_init(); stepper_init(); dc_mot_init(); servo_init(); pinMode(13,OUTPUT); Serial.begin(115200); pinMode(12,OUTPUT); digitalWrite(12,HIGH); pinMode(13,OUTPUT); digitalWrite(13,LOW); }
void sensor_list_append(Sensor_list_t *sensor_list, char* name, Sensor_t new_sensor) { int i; // make sure there's room to expand into sensor_list_double_capacity_if_full(sensor_list); // append the value and increment sensor_list->size sensor_list->data[sensor_list->size].name = (char*)malloc(sizeof(char)*NAME_SIZE); strncpy(sensor_list->data[sensor_list->size].name, name, NAME_SIZE); sensor_init(&sensor_list->data[sensor_list->size]); for (i = 0 ; i < new_sensor.number_of_values ; i++) sensor_append(&sensor_list->data[sensor_list->size], new_sensor.data[i]); sensor_list->size++; }
/** * \brief Initialize the leJOS driver and all required submodules * * Initialization contains: AINTC, systick, sensor ports, motor ports, SPI controller, ADC, hardware buttons, LEDs * * \return none **/ void leJOS_init(void) { if (!is_AINTC_initialized) { // This should be done only once per application - if we use OSEK, leJOS_init will be called at least 2 times interrupt_init(); systick_init(); is_AINTC_initialized = 1; } sensor_init(); spi_init(); adc_init(); motor_init(); led_init(); button_init(); // Confirm that the initialization was successful by setting the LEDs to green led_set(LED_BOTH, LED_GREEN); }
/**@brief Function for application main entry. */ int main(void) { system_HFCLK_init(); // uart init simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, 0); xprintf("APP start up..\r\n"); mcu_bootloader_check(); // Initialize. app_trace_init(); leds_init(); buttons_init(); ble_stack_init(); device_manager_init(); timers_init(); gap_params_init(); advertising_init(); services_init(); sensor_sim_init(); conn_params_init(); //I2C and sensor initial system_I2C_init(); OLED_Init(); sensor_init(); enter_pedo_mode(); GPIO_HiToLo_INT_config(BUTTON_2); // Test battery if(!battery_self_detect()) { system_low_battery(); } // Start execution. application_timers_start(); advertising_start(); // Enter main loop. for (;;) { power_manage(); } }
// MAIN TASK INITIALIZATIOON result_t Task_SmartPHTApp_Init(void) { result_t result; adc_init(); rtc_initialize(); rtc_set(&statusBarData.time); RESULT_CHECK( ioexp_initialize(), result); RESULT_CHECK( touch_initialize(), result); battery_init(); battery_enable_usb_charger(bTrue); battery_enable_ac_charger(bTrue); install_event_handlers(); gui_set_current_view(&view_dashboard); // Initialize USB initCDC(); // setup the CDC state machine usb_init(cdc_device_descriptor, cdc_config_descriptor, cdc_str_descs, USB_NUM_STRINGS); // initialize USB. TODO: Remove magic with macro usb_start(); //start the USB peripheral EnableUsbPerifInterrupts(USB_TRN + USB_SOF + USB_UERR + USB_URST); EnableUsbGlobalInterrupt(); // Only enables global USB interrupt. Chip interrupts must be enabled by the user (PIC18) sensor_init(); reset_minmax(); reset_alarms(); // Reset waveforms wfrm_clear(&wfrmPressure); wfrm_clear(&wfrmHumidity); wfrm_clear(&wfrmTemperature); // Set plot scale lineplot_set_sample_per(&lineplot, &supportedSamplingPeriods[sliderSampPeriodData.value]); // Default sensor checkable_set_checked(&btnSelInterface0, bTrue); return RV_OK; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(shell_sample_stats_process, ev, data) { static uint16_t data_sam[NUM_SAM]; uint16_t sum = 0; uint16_t sqsum = 0; static struct etimer etimer; PROCESS_BEGIN(); // Gather NUM_SAM samples over 1 second of time sensor_init(); printf("Gathering data... "); for(counter = 0;counter < NUM_SAM;counter++) { // Get data for no change analysis. etimer_set(&etimer, CLOCK_SECOND / NUM_SAM); PROCESS_WAIT_UNTIL(etimer_expired(&etimer)); data_sam[counter] = sensor_read(); } printf("done!\n"); sensor_uinit(); // Sum the no change data sum = 0; for(counter = 0;counter < NUM_SAM;counter++) { sum = sum + data_sam[counter]; } sample_mean = 0; printf("sum = %d\n",sum); sample_mean = sum/NUM_SAM; printf("sample_mean = %d\n",sample_mean); // Caclulate sample_std_dev sqsum = 0; for(counter = 0;counter < NUM_SAM;counter++) { sqsum = sqsum + mypow2(abs_sub(data_sam[counter], sample_mean)); } sample_std_dev = 0; sample_std_dev = sqsum/NUM_SAM; sample_std_dev = mysqrt(sample_std_dev); printf("std_dev = %d\n",sample_std_dev); PROCESS_END(); }
void InitSensor(int LeftLine, int TopLine, int Width, int Height, int FPReaderOpt) { ImageWidth=Width; ImageHeight=Height; cim_init(Width,Height); if( sensor_init(LeftLine, TopLine, Width, Height, FPReaderOpt)!=0 ) { GPIO_HY7131_Power(FALSE); fd_sensor = 0; printf("Initialize sensor failed !!!\n"); } else { fd_sensor = 1; abs(-1); printf("%d\n",abs(-1)); printf("Finished sensor init.\n"); } }
const mp_obj_module_t *py_sensor_init() { /* Init sensor */ if (sensor_init() != 0) { return NULL; } /* Reset sensor and registers */ sensor_reset(); /* Use some default settings */ sensor_set_pixformat(PIXFORMAT_RGB565); sensor_set_framesize(FRAMESIZE_QQVGA); sensor_set_framerate(FRAMERATE_30FPS); sensor_set_gainceiling(GAINCEILING_8X); sensor_set_contrast(0); sensor_set_brightness(0); return &sensor_module; }
/****************************************************************************** * funciton : Sensor init * note : different sensor corresponding different lib. So, you can change SENSOR_TYPE in Makefile.para, instead of modify program code. ******************************************************************************/ HI_S32 SAMPLE_COMM_ISP_SensorInit(void) { HI_S32 s32Ret; #ifdef ISP_V1 /* 1. sensor init */ sensor_init(); /* 0: linear mode, 1: WDR mode */ sensor_mode_set(0); #endif /* 2. sensor register callback */ s32Ret = sensor_register_callback(); if (s32Ret != HI_SUCCESS) { printf("%s: sensor_register_callback failed with %#x!\n", \ __FUNCTION__, s32Ret); return s32Ret; } return HI_SUCCESS; }
PROCESS_THREAD(shell_sleepy_trilat_start_process, ev, data) { PROCESS_BEGIN(); open_runicast(); my_node = rimeaddr_node_addr.u8[0]; if (my_node != SINK_NODE) { static struct etimer etimer0; static char message[4]; static int i = 0; etimer_set(&etimer0, CLOCK_SECOND/16); sensor_init(); // leds_on(LEDS_ALL); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer0)); for (i = 1; i <= 100; i++) { etimer_set(&etimer0, CLOCK_SECOND/50); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer0)); my_noise = sensor_read() + my_noise; } sensor_uinit(); my_noise = my_noise / 100; etimer_set(&etimer0, CLOCK_SECOND * (my_node - FIRST_NODE + 1)); leds_on(LEDS_ALL); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&etimer0)); leds_off(LEDS_ALL); itoa(my_noise, message, 10); strcat(message, "!\0"); transmit_runicast(message, SINK_NODE); // process_start(&node_timeout_process, NULL); } PROCESS_END(); }
//Main. int main (int argc, char *argv[]) { //Initialize sensors and structures... if (argc>2) { fprintf(stderr, "Usage: %s {raw, cooked}\n", argv[0]); exit(EXIT_FAILURE); } else { sensor_init((argc==2 && strcmp(argv[1], "raw")==0) ? raw : cooked); } //Create X connection. display_init(); int x_fd=XConnectionNumber(_D); //To be perfectly formal, I have to check POSIX compatibility. fprintf(log_stream, "X Connection descriptor opened on fd %3d.\n", x_fd); /**/ while (service_select_request(x_fd)!=loop_end) ; /**/ sleep(2); //Terminate X connection. display_destr(); //Close files and structures... sensor_destr(); return 0; }