static void resetRainRecordYear (WVIEWD_WORK *work) { // initialize the store sensorInit (&work->sensors.sensor[STF_YEAR][SENSOR_RAIN]); sensorInit (&work->sensors.sensor[STF_YEAR][SENSOR_RAINRATE]); sensorInit (&work->sensors.sensor[STF_YEAR][SENSOR_ET]); sensorAddSample (&work->sensors.sensor[STF_YEAR][SENSOR_RAIN], &work->sensors.sensor[STF_INTERVAL][SENSOR_RAIN]); sensorAddSample (&work->sensors.sensor[STF_YEAR][SENSOR_RAINRATE], &work->sensors.sensor[STF_INTERVAL][SENSOR_RAINRATE]); sensorAddSample (&work->sensors.sensor[STF_YEAR][SENSOR_ET], &work->sensors.sensor[STF_INTERVAL][SENSOR_ET]); return; }
void init() { //initialise colour sensor sensorInit(); //iniitalise interface InterfaceInit(); //initialise servos for seperator and sorter servoInit(); // Configure button S1 interrupt GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN3, GPIO_LOW_TO_HIGH_TRANSITION); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN3); GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN3); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN3); // Configure button S2 interrupt GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN4, GPIO_LOW_TO_HIGH_TRANSITION); GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN4); GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN4); GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN4); }
void sensorClearSet (WV_SENSOR *set) { int type; for (type = 0; type < SENSOR_MAX; type ++) { sensorInit (&set[type]); } return; }
int doorbell_init() { //sensor init if ((devFD = sensorInit(sensor_dev, ARRAY_SIZE(sensor_dev))) == -1) { printf("Fail to init sensor sound\n"); return -1; } //LED init if ((exportGPIOPin(LEDpin)) == -1) { printf("exportGPIOPin(%d) failed\n", LEDpin); return -1; } if ((setGPIODirection(LEDpin, GPIO_OUT)) == -1) { printf("setGPIODirection(%d) failed\n", LEDpin); return -1; } return 0; }
void trainTaskInit(void) { clockInitTask(); mioInit(); tioInit(); logInit(); Create(31, idlerTask); Delay(50); vtInit(); turnoutInit(); sensorInit(); parserInit(); clockDrawerInit(); controllerInit(); freightInit(); initTrackA(nodes, hashtbl); }
int PMW3901::init() { int ret = PX4_ERROR; // get yaw rotation from sensor frame to body frame param_t rot = param_find("SENS_FLOW_ROT"); if (rot != PARAM_INVALID) { int32_t val = 0; param_get(rot, &val); _yaw_rotation = (enum Rotation)val; } /* For devices competing with NuttX SPI drivers on a bus (Crazyflie SD Card expansion board) */ SPI::set_lockmode(LOCK_THREADS); /* do SPI init (and probe) first */ if (SPI::init() != OK) { goto out; } sensorInit(); /* allocate basic report buffers */ _reports = new ringbuffer::RingBuffer(2, sizeof(optical_flow_s)); if (_reports == nullptr) { goto out; } ret = OK; _sensor_ok = true; _previous_collect_timestamp = hrt_absolute_time(); out: return ret; }
int main(){ //wiringPi check showError(); // ctl + c ...exiting (void)signal(SIGINT,control_event); (void)signal(SIGQUIT,control_event); //gnuplot file gnuPlotOpenfile(); //sensor initial sensorInit(); printf("....start loop....\n"); while(1) { //accel getAccelValue(); accelCalculate(); //gyro getGyroValue(); gyroCalculate(); //mag getMagValue(); //baro getBaroValue(); //filter sensorFilter( pitchRatio, rollRatio, yawRatio, altitudeRatio ); //put data to file gnuPlotPutToFile(dataNum); printResult(); delay(10);//+40(in getTempValue)....sampling time dataNum++; } }
int main(void) { int i; int retSize = -1; char value[ARRAY_SIZE(lean)]; int devFD = -1; if ((devFD =sensorInit(lean, ARRAY_SIZE(lean))) == -1) { printf("Fail to init sensor\n"); return -1; } if (( retSize = sensorRead(devFD, value, ARRAY_SIZE(lean)) ) == -1) { printf("Fail to read sensors\n"); } if (retSize > 0) { i = 0; for(i=0; i<retSize; i++) { printf("lean:%d\n", value[i]); } } sensorDeinit(devFD); return 0; }
int main(void){ int log = 0; //Start Switch // DDRA = 0x00; // PORTA = 0x12; //Start PORT A for switch and IR sensors DDRA = 0xFC; PORTA = 0xFE; //LED Initial DDRC = 0x7F; PORTC = 0x7E; DDRD = 0x70; PORTD = 0x11; MotorInit(); initSerial(); char * readData = NULL; int isFinish = 0; sensorInit(); if (isCaptureMode ==1) dxl_write_byte( BROADCAST_ID, P_TORQUE_ENABLE, 0 ); while(1){ sensorTest(0); sensorTest(1); sensorTest(2); setMode(); if( checkSerialRead() > 0 ){ readData = getReadBuffer(); if( readData != NULL ){ // printf( "readData=%s\n", &readData[0] ); split( &readData[0] ); switch( serCmd[0] ){ case EVT_ACTION: ServoControl( serCmd[1] ); // setSpeedTest( serCmd[1] ); sendAck(1); break; case EVT_START_MOTION: startMotion( serCmd[1], serCmd[2] ); PORTC = ~(1 << (LED_MAX - 2)); sendAck(1); break; case EVT_STOP_MOTION: stopMotion(); sendAck(1); break; case EVT_FORCE_MOTION: forceMotion( serCmd[1], serCmd[2] ); break; case EVT_GET_NOW_ANGLE: getAngle(); break; case EVT_SET_ANGLE: setAngle(); case EVT_GET_ACT_ANGLE: if( serCmd[1] >= ACT_MAX ){ sendAck(0); }else{ sendActAngle(serCmd[1]); } break; case EVT_GET_LOAD: getLoad(); // printf( "%d\n", movingTime ); break; case EVT_GET_VOLTAGE: getVoltage(); break; case EVT_TORQUE_DISABLE: dxl_write_byte( BROADCAST_ID, P_TORQUE_ENABLE, 0 ); break; case EVT_WATCH_DOG: watchDogCnt = 0; break; case EVT_MOTION_EDIT: break; case 999: // printf( "finish\n"); sendAck(999); isFinish = 1; break; default: sendAck(0); } if( isFinish > 0 ){ MotorControl( 0, 0 ); break; } memset( readData, 0x00, SERIAL_BUFFER_SIZE ); } } memset( &serCmd[0], 0x00, sizeof(int) * SERIAL_BUFFER_SIZE ); if (~PINA & SW_START ) { if (log == 1) printf( "main() 0\n"); if( iStart > 0 ){ iStart = 0; PORTC = LED_BAT|LED_TxD|LED_RxD|LED_AUX|LED_MANAGE|LED_PROGRAM|LED_PLAY; if (isCaptureMode != 1) ServoControl( 0 ); } }else{ if( iStart == 0 ){ PORTC &= ~LED_PLAY; iStart = 1; } if( modeWait <= 0 ){ if (log == 1) printf( "main() 1\n"); setModeAction(); if (isMovetest == 1) { moveTest(); } else { move(); } }else{ if (log == 1) printf( "main() 2\n"); modeWait -= MAIN_DELAY; } } if (sensorValue[0] == 0 && sensorValueOld[0] != sensorValue[0]) { if (log == 1) printf( "### main() sensorValue[0] == 0\n"); PORTC |= LED_PROGRAM; //edit }else if (sensorValueOld[0] != sensorValue[0]){ if (log == 1) printf( "### main() sensorValue[0] == 1\n"); PORTC &= ~LED_PROGRAM; //edit } if (sensorValue[1] == 0 && sensorValueOld[1] != sensorValue[1]) { if (log == 1) printf( "### main() sensorValue[1] == 0\n"); PORTC |= LED_MANAGE; //mon }else if (sensorValueOld[1] != sensorValue[1]){ if (log == 1) printf( "### main() sensorValue[1] == 1\n"); PORTC &= ~LED_MANAGE; //mon } if (sensorValue[2] == 0 && sensorValueOld[2] != sensorValue[2]) { if (log == 1) printf( "### main() sensorValue[2] == 0\n"); PORTC |= LED_AUX; //AUX }else if (sensorValueOld[2] != sensorValue[2]){ if (log == 1) printf( "### main() sensorValue[2] == 1\n"); PORTC &= ~LED_AUX; //AUX } sensorValueOld[0] = sensorValue[0]; sensorValueOld[1] = sensorValue[1]; sensorValueOld[2] = sensorValue[2]; // walk pattern LED // brinkLED(); _delay_ms(MAIN_DELAY); watchDogCnt++; caputureCount1++; if (caputureCount1 == 25){ if (isCaptureMode == 1) getAngle(); caputureCount1 = 0; } } }
static UINT32 sysInit( void ) { /* board dependent modules */ rtcInit(); wdtInit(); inputInit(); audioInit(); fmInit(); lineBufferInit(); graphicInit(); scalarInit(); if (strcmp(SYSCONFIG_PRODUCT, "gplus.microwindowsUI__gplus.evm32900b") != 0) { aesInit(); } sdmaInit(); #ifdef SYSCONFIG_ARCH_SPMP8050 rotatorInit(); #endif #ifdef SYSCONFIG_ARCH_SPMP8050 cevaInit(); #endif if( gp_ver.major == MACH_GPL32900 ) { cevaInit(); } storageInit(); if (strcmp(SYSCONFIG_MAINSTORAGE, "gp_usb_disk")) { usbInit(); } usbWifiInit(); touchpanelInit(); #ifdef SYSCONFIG_SDIO system("modprobe cfg80211"); system("modprobe mac80211"); system("modprobe sunrpc"); #endif sensorInit(); ppuInit(); //tvInit(); powerInit(); batteryInit(); gsensorInit(); asensorInit(); #ifdef SYSCONFIG_GP_FAST_BOOT gpFastBootInit(); #endif /* SYSCONFIG_GP_FAST_BOOT */ if( gp_ver.major == MACH_GPL32900B ) { On2Init(); LBPInit(); } return SP_OK; }
// compute HILOW values for the current year static int computeDataYear (WVIEWD_WORK *work, time_t lastTime) { SENSOR_STORE *store = &work->sensors; int i, retVal, numrecs = 0; int nowmonth, rainmonth, nowyear, rainyear; time_t startTime, timenow = time(NULL); struct tm startMonth, bkntimenow; // do this so we pick up the proper hour/day when mins < archiveInterval timenow -= (work->archiveInterval * 60); localtime_r (&timenow, &bkntimenow); nowmonth = bkntimenow.tm_mon + 1; nowyear = bkntimenow.tm_year + 1900; bkntimenow.tm_mon = 0; bkntimenow.tm_mday = 1; bkntimenow.tm_hour = 0; bkntimenow.tm_min = 0; bkntimenow.tm_sec = 0; bkntimenow.tm_isdst = -1; startTime = mktime(&bkntimenow); if (lastTime > startTime) { // Only add new records: startTime = lastTime + 1; } localtime_r(&startTime, &startMonth); // loop through each month this year (so far) for (i = startMonth.tm_mon+1; i <= nowmonth; i ++) { // process the month retVal = computeDataForMonth (work, i, nowyear, STF_YEAR, FALSE, startTime); if (retVal == ERROR || retVal == 0) { // just continue here continue; } radMsgLog(PRI_STATUS, "computeDataYear: %4.4d%2.2d", nowyear, i); // Clear this so it is only used the first time through: startTime = 0; numrecs += retVal; } // If we didn't have save data: if (lastTime == 0) { // Clear rain/ET sensors: sensorInit(&store->sensor[STF_YEAR][SENSOR_RAIN]); sensorInit(&store->sensor[STF_YEAR][SENSOR_RAINRATE]); sensorInit(&store->sensor[STF_YEAR][SENSOR_ET]); // Do the Year rain totals to account for rain season start: rainmonth = work->stationRainSeasonStart; rainyear = nowyear; if (rainmonth > nowmonth) { // we need to go back a year... rainyear --; } localtime_r (&timenow, &bkntimenow); bkntimenow.tm_year = rainyear - 1900; bkntimenow.tm_mon = rainmonth - 1; bkntimenow.tm_mday = 1; bkntimenow.tm_hour = 0; bkntimenow.tm_min = 0; bkntimenow.tm_sec = 0; bkntimenow.tm_isdst = -1; startTime = mktime(&bkntimenow); // now loop till we get to this month: while ((rainyear < nowyear) || ((rainmonth <= nowmonth) && (rainyear == nowyear))) { // process the month for yearly rain computeDataForMonth (work, rainmonth, rainyear, STF_YEAR, TRUE, startTime); if (++rainmonth > 12) { rainmonth = 1; rainyear ++; } // Only use this the first time through: startTime = 0; } } return OK; }