void CC1200::reset() { SendStrobe(SRES); delay(5); SendStrobe(SRES); //is twice necessary? Probably not. Does it cause problems? You tell me... }
pulsesequence() { double gstab = getval("gstab"), gt1 = getval("gt1"), gzlvl1 = getval("gzlvl1"), gt2 = getval("gt2"), gzlvl2 = getval("gzlvl2"), satpwr = getval("satpwr"), satdly = getval("satdly"), del = getval("del"), del2 = getval("del2"), dosyfrq = getval("sfrq"), gzlvlhs = getval("gzlvlhs"), hsgt = getval("hsgt"), Ddelta,dosytimecubed; char convcomp[MAXSTR],satmode[MAXSTR],alt_grd[MAXSTR],lkgate_flg[MAXSTR], sspul[MAXSTR]; getstr("convcomp",convcomp); getstr("satmode",satmode); getstr("alt_grd",alt_grd); getstr("lkgate_flg",lkgate_flg); getstr("sspul",sspul); //synchronize gradients to srate for probetype='nano' // Preserve gradient "area" gt1 = syncGradTime("gt1","gzlvl1",1.0); gzlvl1 = syncGradLvl("gt1","gzlvl1",1.0); gt2 = syncGradTime("gt2","gzlvl2",1.0); gzlvl2 = syncGradLvl("gt2","gzlvl2",1.0); /* CHECK CONDITIONS */ if (p1 == 0.0) p1 = 2*pw; /* STEADY-STATE PHASECYCLING This section determines if the phase calculations trigger off of (SS - SSCTR) or off of CT */ ifzero(ssctr); dbl(ct, v1); hlv(ct, v3); elsenz(ssctr); sub(ssval, ssctr, v7); /* v7 = 0,...,ss-1 */ dbl(v7, v1); hlv(v7, v3); endif(ssctr); /* PHASECYCLE CALCULATION */ hlv(v3, v2); mod2(v3, v3); add(v3, v1, v1); assign(v1, oph); dbl(v2, v4); add(v4, oph, oph); add(v2, v3, v2); Ddelta=gt1; /*the diffusion-encoding pulse width is gt1*/ if (convcomp[A]=='y') dosytimecubed=Ddelta*Ddelta*(del - (4.0*Ddelta/3.0)); else dosytimecubed=Ddelta*Ddelta*(del - (Ddelta/3.0)); putCmd("makedosyparams(%e,%e)\n",dosytimecubed,dosyfrq); mod2(ct,v10); /* gradients change sign at odd transients */ /* BEGIN ACTUAL SEQUENCE */ status(A); if (sspul[0]=='y') { zgradpulse(gzlvlhs,hsgt); rgpulse(pw,zero,rof1,rof1); zgradpulse(gzlvlhs,hsgt); } if (satmode[0] == 'y') { if (d1 - satdly > 0) delay(d1 - satdly); obspower(satpwr); rgpulse(satdly,zero,rof1,rof1); obspower(tpwr); } else delay(d1); if (getflag("wet")) wet4(zero,one); status(B); if (del>0.0) { if (convcomp[A]=='y') { if (lkgate_flg[0] == 'y') lk_hold(); /* turn lock sampling off */ if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(-gzlvl2,2.0*gt2); elsenz(v10); zgradpulse(gzlvl2,2.0*gt2); endif(v10); } else zgradpulse(-gzlvl2,2.0*gt2); delay(gstab); rgpulse(pw, v1, rof1, rof1); delay(d2/2.0); delay(gstab); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(gzlvl1,gt1); elsenz(v10); zgradpulse(-1.0*gzlvl1,gt1); endif(v10); } else zgradpulse(gzlvl1,gt1); if (satmode[1] == 'y') { obspower(satpwr); rgpulse(((del+del2)/4)-gt1-2.0*rof1,zero,rof1,rof1); obspower(tpwr); } else delay(((del+del2)/4)-gt1); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(-1.0*gzlvl1,gt1); elsenz(v10); zgradpulse(gzlvl1,gt1); endif(v10); } else zgradpulse(-1.0*gzlvl1,gt1); delay(gstab); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(-1.0*gzlvl1,gt1); elsenz(v10); zgradpulse(gzlvl1,gt1); endif(v10); } else zgradpulse(-1.0*gzlvl1,gt1); if (satmode[1] == 'y') { obspower(satpwr); rgpulse(((del-del2)/4)-gt1-2.0*rof1,zero,rof1,rof1); obspower(tpwr); } else delay(((del-del2)/4)-gt1); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(gzlvl1,gt1); elsenz(v10); zgradpulse(-1.0*gzlvl1,gt1); endif(v10); } else zgradpulse(gzlvl1,gt1); delay(gstab); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(gzlvl2,gt2); elsenz(v10); zgradpulse(-1.0*gzlvl2,gt2); endif(v10); } else zgradpulse(gzlvl2,gt2); delay(gstab); rgpulse(p1, v2, rof1, rof1); delay(gstab); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(gzlvl2,gt2); elsenz(v10); zgradpulse(-1.0*gzlvl2,gt2); endif(v10); } else zgradpulse(gzlvl2,gt2); delay(gstab); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(gzlvl1,gt1); elsenz(v10); zgradpulse(-1.0*gzlvl1,gt1); endif(v10); } else zgradpulse(gzlvl1,gt1); if (satmode[1] == 'y') { obspower(satpwr); rgpulse(((del-del2)/4)-gt1-2.0*rof1,zero,rof1,rof1); obspower(tpwr); } else delay(((del-del2)/4)-gt1); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(-1.0*gzlvl1,gt1); elsenz(v10); zgradpulse(gzlvl1,gt1); endif(v10); } else zgradpulse(-1.0*gzlvl1,gt1); delay(gstab); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(-1.0*gzlvl1,gt1); elsenz(v10); zgradpulse(gzlvl1,gt1); endif(v10); } else zgradpulse(-1.0*gzlvl1,gt1); if (satmode[1] == 'y') { obspower(satpwr); rgpulse(((del+del2)/4)-gt1-2.0*rof1,zero,rof1,rof1); obspower(tpwr); } else delay(((del+del2)/4)-gt1); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(gzlvl1,gt1); elsenz(v10); zgradpulse(-1.0*gzlvl1,gt1); endif(v10); } else zgradpulse(gzlvl1,gt1); delay(gstab); delay(d2/2.0); if (lkgate_flg[0] == 'y') lk_sample(); /* turn lock sampling on */ } else { rgpulse(pw, v1, rof1, rof1); if (lkgate_flg[0] == 'y') lk_hold(); /* turn lock sampling off */ delay(d2/2.0); delay(gstab); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(gzlvl1,gt1); elsenz(v10); zgradpulse(-1.0*gzlvl1,gt1); endif(v10); } else zgradpulse(gzlvl1,gt1); if (satmode[1] == 'y') { obspower(satpwr); rgpulse((del-p1-2.0*rof1-gt1)/2.0-2.0*rof1,zero,rof1,rof1); obspower(tpwr); } else delay((del-p1-2.0*rof1-gt1)/2.0); rgpulse(p1, v2, rof1, rof1); if (satmode[1] == 'y') { obspower(satpwr); rgpulse((del-p1-2.0*rof1-gt1)/2.0-2.0*rof1,zero,rof1,rof1); obspower(tpwr); } else delay((del-p1-2.0*rof1-gt1)/2.0); if (alt_grd[0] == 'y') { ifzero(v10); zgradpulse(gzlvl1,gt1); elsenz(v10); zgradpulse(-1.0*gzlvl1,gt1); endif(v10); } else zgradpulse(gzlvl1,gt1); delay(gstab); delay(d2/2.0); if (lkgate_flg[0] == 'y') lk_sample(); /* turn lock sampling on */ } } else rgpulse(pw,oph,rof1,rof2); status(C); }
boolean WiFlyDevice::enterCommandMode(boolean isAfterBoot) { /* */ DEBUG_LOG(1, "Entered enterCommandMode"); // Note: We used to first try to exit command mode in case we were // already in it. Doing this actually seems to be less // reliable so instead we now just ignore the errors from // sending the "$$$" in command mode. for (int retryCount = 0; retryCount < COMMAND_MODE_ENTER_RETRY_ATTEMPTS; retryCount++) { // At first I tried automatically performing the // wait-send-wait-send-send process twice before checking if it // succeeded. But I removed the automatic retransmission even // though it makes things marginally less reliable because it speeds // up the (hopefully) more common case of it working after one // transmission. We also now have automatic-retries for the whole // process now so it's less important anyway. if (isAfterBoot) { delay(1000); // This delay is so characters aren't missed after a reboot. } delay(COMMAND_MODE_GUARD_TIME); uart.print("$$$"); delay(COMMAND_MODE_GUARD_TIME); // We could already be in command mode or not. // We could also have a half entered command. // If we have a half entered command the "$$$" we've just added // could succeed or it could trigger an error--there's a small // chance it could also screw something up (by being a valid // argument) but hopefully it's not a general issue. Sending // these two newlines is intended to clear any partial commands if // we're in command mode and in either case trigger the display of // the version prompt (not that we actually check for it at the moment // (anymore)). // TODO: Determine if we need less boilerplate here. uart.println(); uart.println(); // TODO: Add flush with timeout here? // This is used to determine whether command mode has been entered // successfully. // TODO: Find alternate approach or only use this method after a (re)boot? uart.println("ver"); //Why check for line break? from "\r\nWiFly Ver" - > "WiFly Ver" if (findInResponse("WiFly Ver", 1000)) { // TODO: Flush or leave remainder of output? return true; } } return false; }
// play an MF tone: void mf(int digit) { // Store the digit IFF recording: if(rec && ((digit>=0&&digit<=9)||digit==-13||digit==-6)) { for(int i=0; i<=23; i++) { // ONLY record KP,ST,0-9 if(store[i]==-1) { store[i]=digit; break; } } } int duration = bbdur[0]; // OKAY for DTMF too if(mode==1) { if(digit==49) { // international mode A digit=13; } if(digit==50) { // international mode B digit=14; } if(digit==51) { sf(2600,1000); return; } } else if(mode==4) { // DTMF Serial.println(digit); if((digit>=1&&digit<=3)) { // 1,2,3 digit-=1; } else if(digit>=7&&digit<=9) { digit+=1; } else if(digit==49) { digit = 3; // A } else if(digit==50) { digit = 7; // B } else if(digit==51) { digit = 11; // C } else if(digit==52) { digit = 15; // D } else if(digit==-13) { digit = 12; // * } else if(digit==-6) { digit = 14; // # } else if(digit==0) { digit = 13; // 0 } else if(digit==13) { duration=150; } Serial.println("and: "); Serial.println(digit); freq[0].play(dtmfFreq[dtmf[digit][0]],duration); freq[1].play(dtmfFreq[dtmf[digit][1]],duration); return; } if(digit<0) { duration = bbdur[1]; if(digit==-13) { digit=10; } if(digit==-6) { digit=11; } } if(digit==-1) { return; // -1 in storage? } if(digit==12) { // 85ms for international trunk seizing duration = 200; } if (mode==3) duration = 150; // SS4 Supervisory MF (150ms) freq[0].play(bb[digit][0],duration); freq[1].play(bb[digit][1],duration); (autoDial) ? delay(duration + 60) : delay(duration); // ? expression? statement? if(rec) { delay(25); sf(2600,33); }// chirp to signify recording return; // Now we can leave. }
void GLCD_Init (void) { unsigned short driverCode; /* Configure the LCD Control pins --------------------------------------------*/ RCC->AHB1ENR |=((1UL << 0) | /* Enable GPIOA clock */ #ifndef __STM_EVAL /* MCBSTM32F200 and MCBSTMF400 board */ (1UL << 2) | /* Enable GPIOC clock */ #endif (1UL << 3) | /* Enable GPIOD clock */ (1UL << 4) | /* Enable GPIOE clock */ (1UL << 5) | /* Enable GPIOF clock */ (1UL << 6)); /* Enable GPIOG clock */ /* PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE) */ /* PD.08(D13), PD.09(D14), PD.10(D15), PD.14(D0), PD.15(D1) */ GPIOD->MODER &= ~0xF03F0F0F; /* Clear Bits */ GPIOD->MODER |= 0xA02A0A0A; /* Alternate Function mode */ GPIOD->OSPEEDR &= ~0xF03F0F0F; /* Clear Bits */ GPIOD->OSPEEDR |= 0xA02A0A0A; /* 50 MHz Fast speed */ GPIOD->AFR[0] &= ~0x00FF00FF; /* Clear Bits */ GPIOD->AFR[0] |= 0x00CC00CC; /* Alternate Function mode AF12 */ GPIOD->AFR[1] &= ~0xFF000FFF; /* Clear Bits */ GPIOD->AFR[1] |= 0xCC000CCC; /* Alternate Function mode AF12 */ /* PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8) */ /* PE.12(D9), PE.13(D10), PE.14(D11), PE.15(D12) */ GPIOE->MODER &= ~0xFFFFC000; /* Clear Bits */ GPIOE->MODER |= 0xAAAA8000; /* Alternate Function mode */ GPIOE->OSPEEDR &= ~0xFFFFC000; /* Clear Bits */ GPIOE->OSPEEDR |= 0xAAAA8000; /* 50 MHz Fast speed */ GPIOE->AFR[0] &= ~0xF0000000; /* Clear Bits */ GPIOE->AFR[0] |= 0xC0000000; /* Alternate Function mode AF12 */ GPIOE->AFR[1] &= ~0xFFFFFFFF; /* Clear Bits */ GPIOE->AFR[1] |= 0xCCCCCCCC; /* Alternate Function mode AF12 */ /* PF.00(A0 (RS)) */ GPIOF->MODER &= ~0x00000003; /* Clear Bits */ GPIOF->MODER |= 0x00000002; /* Alternate Function mode */ GPIOF->OSPEEDR &= ~0x00000003; /* Clear Bits */ GPIOF->OSPEEDR |= 0x00000002; /* 50 MHz Fast speed */ GPIOF->AFR[0] &= ~0x0000000F; /* Clear Bits */ GPIOF->AFR[0] |= 0x0000000C; /* Alternate Function mode AF12 */ #ifdef __STM_EVAL /* STM3220G-EVAL and STM3240G-EVAL */ /* PG.10(NE4 (LCD/CS)) - CE1(LCD /CS) */ GPIOG->MODER &= ~0x00300000; /* Clear Bits */ GPIOG->MODER |= 0x00200000; /* Alternate Function mode */ GPIOG->OSPEEDR &= ~0x00300000; /* Clear Bits */ GPIOG->OSPEEDR |= 0x00200000; /* 50 MHz Fast speed */ GPIOG->AFR[1] &= ~0x00000F00; /* Clear Bits */ GPIOG->AFR[1] |= 0x00000C00; /* Alternate Function mode AF12 */ /* PA.08(LCD Backlight */ GPIOA->BSRRH |= (1UL << 8); /* Backlight off */ GPIOA->MODER &= ~(3UL << 2*8); /* Clear Bits */ GPIOA->MODER |= (1UL << 2*8); /* PA.9 is output */ GPIOA->OTYPER &= ~(1UL << 8); /* PA.9 is output Push-Pull */ GPIOA->OSPEEDR &= ~(3UL << 2*8); /* Clear Bits */ GPIOA->OSPEEDR |= (2UL << 2*8); /* PA.9 is 50MHz Fast Speed */ #else /* MCBSTM32F200 and MCBSTMF400 board */ /* PG.12(NE4 (LCD/CS)) - CE1(LCD /CS) */ GPIOG->MODER &= ~0x03000000; /* Clear Bits */ GPIOG->MODER |= 0x02000000; /* Alternate Function mode */ GPIOG->OSPEEDR &= ~0x03000000; /* Clear Bits */ GPIOG->OSPEEDR |= 0x02000000; /* 50 MHz Fast speed */ GPIOG->AFR[1] &= ~0x000F0000; /* Clear Bits */ GPIOG->AFR[1] |= 0x000C0000; /* Alternate Function mode AF12 */ /* PC.07(LCD Backlight */ GPIOC->BSRRH |= (1UL << 7); /* Backlight off */ GPIOC->MODER &= ~(3UL << 2*7); /* Clear Bits */ GPIOC->MODER |= (1UL << 2*7); /* PC.7 is output */ GPIOC->OTYPER &= ~(1UL << 7); /* PC.7 is output Push-Pull */ GPIOC->OSPEEDR &= ~(3UL << 2*7); /* Clear Bits */ GPIOC->OSPEEDR |= (2UL << 2*7); /* PC.7 is 50MHz Fast Speed */ #endif /*-- FSMC Configuration ------------------------------------------------------*/ RCC->AHB3ENR |= (1UL << 0); /* Enable FSMC clock */ #ifdef __STM_EVAL /* STM3220G-EVAL and STM3240G-EVAL */ FSMC_Bank1->BTCR[(3-1)*2 + 1] = /* Bank3 NOR/SRAM timing register */ /* configuration */ #else /* MCBSTM32F200 and MCBSTMF400 board */ FSMC_Bank1->BTCR[(4-1)*2 + 1] = /* Bank4 NOR/SRAM timing register */ /* configuration */ #endif (0 << 28) | /* FSMC AccessMode A */ (0 << 24) | /* Data Latency */ (0 << 20) | /* CLK Division */ (0 << 16) | /* Bus Turnaround Duration */ (9 << 8) | /* Data SetUp Time */ (0 << 4) | /* Address Hold Time */ (1 << 0); /* Address SetUp Time */ #ifdef __STM_EVAL /* STM3220G-EVAL and STM3240G-EVAL */ FSMC_Bank1->BTCR[(3-1)*2 + 0] = #else /* MCBSTM32F200 and MCBSTMF400 board */ FSMC_Bank1->BTCR[(4-1)*2 + 0] = /* Control register */ #endif (0 << 19) | /* Write burst disabled */ (0 << 15) | /* Async wait disabled */ (0 << 14) | /* Extended mode disabled */ (0 << 13) | /* NWAIT signal is disabled */ (1 << 12) | /* Write operation enabled */ (0 << 11) | /* NWAIT signal is active one data */ /* cycle before wait state */ (0 << 10) | /* Wrapped burst mode disabled */ (0 << 9) | /* Wait signal polarity active low */ (0 << 8) | /* Burst access mode disabled */ (1 << 4) | /* Memory data bus width is 16 bits */ (0 << 2) | /* Memory type is SRAM */ (0 << 1) | /* Address/Data Multiplexing disable */ (1 << 0); /* Memory Bank enable */ delay(5); /* Delay 50 ms */ driverCode = rd_reg(0x00); if (driverCode == 0x47) { /* LCD with HX8347-D LCD Controller */ Himax = 1; /* Set Himax LCD controller flag */ /* Driving ability settings ----------------------------------------------*/ wr_reg(0xEA, 0x00); /* Power control internal used (1) */ wr_reg(0xEB, 0x20); /* Power control internal used (2) */ wr_reg(0xEC, 0x0C); /* Source control internal used (1) */ wr_reg(0xED, 0xC7); /* Source control internal used (2) */ wr_reg(0xE8, 0x38); /* Source output period Normal mode */ wr_reg(0xE9, 0x10); /* Source output period Idle mode */ wr_reg(0xF1, 0x01); /* RGB 18-bit interface ;0x0110 */ wr_reg(0xF2, 0x10); /* Adjust the Gamma Curve ------------------------------------------------*/ wr_reg(0x40, 0x01); wr_reg(0x41, 0x00); wr_reg(0x42, 0x00); wr_reg(0x43, 0x10); wr_reg(0x44, 0x0E); wr_reg(0x45, 0x24); wr_reg(0x46, 0x04); wr_reg(0x47, 0x50); wr_reg(0x48, 0x02); wr_reg(0x49, 0x13); wr_reg(0x4A, 0x19); wr_reg(0x4B, 0x19); wr_reg(0x4C, 0x16); wr_reg(0x50, 0x1B); wr_reg(0x51, 0x31); wr_reg(0x52, 0x2F); wr_reg(0x53, 0x3F); wr_reg(0x54, 0x3F); wr_reg(0x55, 0x3E); wr_reg(0x56, 0x2F); wr_reg(0x57, 0x7B); wr_reg(0x58, 0x09); wr_reg(0x59, 0x06); wr_reg(0x5A, 0x06); wr_reg(0x5B, 0x0C); wr_reg(0x5C, 0x1D); wr_reg(0x5D, 0xCC); /* Power voltage setting -------------------------------------------------*/ wr_reg(0x1B, 0x1B); wr_reg(0x1A, 0x01); wr_reg(0x24, 0x2F); wr_reg(0x25, 0x57); wr_reg(0x23, 0x88); /* Power on setting ------------------------------------------------------*/ wr_reg(0x18, 0x36); /* Internal oscillator frequency adj */ wr_reg(0x19, 0x01); /* Enable internal oscillator */ wr_reg(0x01, 0x00); /* Normal mode, no scrool */ wr_reg(0x1F, 0x88); /* Power control 6 - DDVDH Off */ delay(20); wr_reg(0x1F, 0x82); /* Power control 6 - Step-up: 3 x VCI */ delay(5); wr_reg(0x1F, 0x92); /* Power control 6 - Step-up: On */ delay(5); wr_reg(0x1F, 0xD2); /* Power control 6 - VCOML active */ delay(5); /* Color selection -------------------------------------------------------*/ wr_reg(0x17, 0x55); /* RGB, System interface: 16 Bit/Pixel*/ wr_reg(0x00, 0x00); /* Scrolling off, no standby */ /* Interface config ------------------------------------------------------*/ wr_reg(0x2F, 0x11); /* LCD Drive: 1-line inversion */ wr_reg(0x31, 0x00); wr_reg(0x32, 0x00); /* DPL=0, HSPL=0, VSPL=0, EPL=0 */ /* Display on setting ----------------------------------------------------*/ wr_reg(0x28, 0x38); /* PT(0,0) active, VGL/VGL */ delay(20); wr_reg(0x28, 0x3C); /* Display active, VGL/VGL */ #if (LANDSCAPE == 1) #if (ROTATE180 == 0) wr_reg (0x16, 0xA8); #else wr_reg (0x16, 0x68); #endif #else #if (ROTATE180 == 0) wr_reg (0x16, 0x08); #else wr_reg (0x16, 0xC8); #endif #endif /* Display scrolling settings --------------------------------------------*/ wr_reg(0x0E, 0x00); /* TFA MSB */ wr_reg(0x0F, 0x00); /* TFA LSB */ wr_reg(0x10, 320 >> 8); /* VSA MSB */ wr_reg(0x11, 320 & 0xFF); /* VSA LSB */ wr_reg(0x12, 0x00); /* BFA MSB */ wr_reg(0x13, 0x00); /* BFA LSB */ }
AP_Autopilot::AP_Autopilot(AP_Navigator * navigator, AP_Guide * guide, AP_Controller * controller, AP_Board * board, float loopRate, float loop0Rate, float loop1Rate, float loop2Rate, float loop3Rate) : Loop(loopRate, callback, this), _navigator(navigator), _guide(guide), _controller(controller), _board(board), callbackCalls(0) { board->debug->printf_P(PSTR("initializing autopilot\n")); board->debug->printf_P(PSTR("free ram: %d bytes\n"),freeMemory()); /* * Comm links */ board->gcs = new MavlinkComm(board->gcsPort, navigator, guide, controller, board, 3); if (board->getMode() != AP_Board::MODE_LIVE) { board->hil = new MavlinkComm(board->hilPort, navigator, guide, controller, board, 3); } board->gcsPort->printf_P(PSTR("gcs hello\n")); board->gcs->sendMessage(MAVLINK_MSG_ID_HEARTBEAT); board->gcs->sendMessage(MAVLINK_MSG_ID_SYS_STATUS); /* * Calibration */ controller->setState(MAV_STATE_CALIBRATING); board->gcs->sendMessage(MAVLINK_MSG_ID_HEARTBEAT); board->gcs->sendMessage(MAVLINK_MSG_ID_SYS_STATUS); if (navigator) navigator->calibrate(); /* * Look for valid initial state */ while (_navigator) { // letc gcs known we are alive board->gcs->sendMessage(MAVLINK_MSG_ID_HEARTBEAT); board->gcs->sendMessage(MAVLINK_MSG_ID_SYS_STATUS); if (board->getMode() == AP_Board::MODE_LIVE) { _navigator->updateSlow(0); if (board->gps) { if (board->gps->fix) { break; } else { board->gps->update(); board->gcs->sendText(SEVERITY_LOW, PSTR("waiting for gps lock\n")); board->debug->printf_P(PSTR("waiting for gps lock\n")); } } else { // no gps, can skip break; } } else if (board->getMode() == AP_Board::MODE_HIL_CNTL) { // hil board->hil->sendMessage(MAVLINK_MSG_ID_HEARTBEAT); board->hil->receive(); if (_navigator->getTimeStamp() != 0) { // give hil a chance to send some packets for (int i = 0; i < 5; i++) { board->debug->println_P(PSTR("reading initial hil packets")); board->gcs->sendText(SEVERITY_LOW, PSTR("reading initial hil packets")); delay(1000); } break; } board->debug->println_P(PSTR("waiting for hil packet")); board->gcs->sendText(SEVERITY_LOW, PSTR("waiting for hil packets")); } delay(500); } AP_MavlinkCommand::home.setAlt(_navigator->getAlt()); AP_MavlinkCommand::home.setLat(_navigator->getLat()); AP_MavlinkCommand::home.setLon(_navigator->getLon()); AP_MavlinkCommand::home.setCommand(MAV_CMD_NAV_WAYPOINT); AP_MavlinkCommand::home.save(); _board->debug->printf_P(PSTR("\nhome before load lat: %f deg, lon: %f deg, cmd: %d\n"), AP_MavlinkCommand::home.getLat()*rad2Deg, AP_MavlinkCommand::home.getLon()*rad2Deg, AP_MavlinkCommand::home.getCommand()); AP_MavlinkCommand::home.load(); _board->debug->printf_P(PSTR("\nhome after load lat: %f deg, lon: %f deg, cmd: %d\n"), AP_MavlinkCommand::home.getLat()*rad2Deg, AP_MavlinkCommand::home.getLon()*rad2Deg, AP_MavlinkCommand::home.getCommand()); guide->setCurrentIndex(0); controller->setMode(MAV_MODE_LOCKED); controller->setState(MAV_STATE_STANDBY); /* * Attach loops, stacking for priority */ board->debug->println_P(PSTR("attaching loops")); subLoops().push_back(new Loop(loop0Rate, callback0, this)); subLoops().push_back(new Loop(loop1Rate, callback1, this)); subLoops().push_back(new Loop(loop2Rate, callback2, this)); subLoops().push_back(new Loop(loop3Rate, callback3, this)); board->debug->println_P(PSTR("running")); board->gcs->sendText(SEVERITY_LOW, PSTR("running")); }
void main() { x=0; counter = 0; fw=0; ew=0; bz=0; TMOD=0x20; //Enable Timer 1 TH1=0XFD; SCON=0x50; TR1=1; // Triggering Timer 1 lcd_init(); lcd_cmd(0x81); //Place cursor to second position of first line lcd_cmd(0x01); //clear screen lcd_string("SoS App"); delay(200); //recieve(); //SBUF=" "; lcd_init(); lcd_cmd(0x81); //Place cursor to second position of first line //lcd_cmd(0x01); //clear screen lcd_cmd(0xC1); //Place cursor to second position of second line //lcd_string("UNIQUE ID:"); //recieve(); while(1) { int l; if (fw == 1 && counter == 0) { counter = 1; bz = 1; for(l=0;l<12;l++) { lcd_data(flood[l]); } // Mobile communication start serial_init(); //serial initialization // LED = 0x00; printf("AT+CMGF=1%c",13); delay2(20); //Text Mode | hex value of 13 is 0x0D (CR ) printf("AT+CMGS=\"8939965828\"%c",13); delay2(20); //Type your mobile number Eg : "9884467058" // led_left(); //scroll left delay1(20); printf("Sos-Warning:"); delay2(20); //Type text as u want printf(flood); delay2(20); //Type text as u want printf("%c",0x1A); delay2(20); //line feed command // Mobile Communication end } if (ew == 1 && counter == 0) { counter = 1; bz =1; for(l=0;l<17;l++) { lcd_data(earthquake[l]); } // Mobile communication start serial_init(); //serial initialization // LED = 0x00; printf("AT+CMGF=1%c",13); delay2(20); //Text Mode | hex value of 13 is 0x0D (CR ) printf("AT+CMGS=\"8939965828\"%c",13); delay2(20); //Type your mobile number Eg : "9884467058" // led_left(); //scroll left delay1(20); printf("Sos-Warning:"); delay2(20); //Type text as u want printf(earthquake); delay2(20); //Type text as u want printf("%c",0x1A); delay2(20); //line feed command // Mobile Communication end } } }
//this one is slow and unsave.... long readMultiValueContinuousAVG(int amount, int delayMilis){ long value = 0; char bufDataRead[] = { 0x5C }; //select Data reg for continous read transfer(bufDataRead, sizeof(bufDataRead)); int valuesRead=0; int emptyCount=0; long fullData=0; int rdy=1; while (emptyCount<20 && valuesRead<amount) { /* char buf[] = { 0x00 }; transfer(buf, 1); if (buf[0] == 0xFF){ delay(100); //Data not yet available, wait 100ms ++emptyCount; } else { fullData = buf[0]; char buf[] = { 0x00, 0x00 }; transfer(buf, 2); fullData = (fullData << 8) | buf[0]; fullData = (fullData << 8) | buf[1]; if (fullData != 0){ //it's not possible to be value 0 value += fullData; valuesRead++; } else { ++emptyCount; } } */ /* char buf[] = { 0x00, 0x00, 0x00 }; transfer(buf, 3); fullData = buf[0]; fullData = (fullData << 8) | buf[1]; fullData = (fullData << 8) | buf[2]; if (fullData != 0 && fullData != 0xFFFFFF){ value += fullData; valuesRead++; } */ /* //This is not the correct way for check rdy-pin is fall low rdy=1; int rdyTimes=0; while(rdy==1 && rdyTimes<10000){ delayMicroseconds(100); rdy = bcm2835_gpio_lev(RDY_PIN); ++rdyTimes; } printf("%d times check if ready\n",rdyTimes); char buf[] = { 0x00, 0x00, 0x00 }; transfer(buf, 3); fullData = buf[0]; fullData = (fullData << 8) | buf[1]; fullData = (fullData << 8) | buf[2]; value += fullData; valuesRead++; */ /* //logic error, this wouldn't use value if a byte of it have realy the value 0xFF if (buf[0] == 0xFF){ nanosleep(100000); //Data not yet available, wait 100ms emptyCount++; if (valIndex != 0){ printf("uncomplete data"); valIndex=0; } } else { value[valIndex] = buf[0]; if (valIndex<2) { valIndex++; } else { long fullData = value[0]; fullData = (fullData << 8) | value[1]; fullData = (fullData << 8) | value[2]; valIndex=0; value += fullData; valuesRead++; } } */ /*if (valuesRead>0){ printf("Value at input %d: %d / %06X sum %d avg %d\n", currentInput, fullData, fullData, value, value / valuesRead); } else { printf("Value at input %d: %d / %06X sum %d\n", currentInput, fullData, fullData, value); }*/ if (delayMilis>0){ delay(delayMilis); } } char bufDataEndRead[] = { 0x58, 0x00, 0x00, 0x00 }; //stop continous read -> select Data reg for read and read 3 bytes(to be sure it's back in command promt mode.) transfer(bufDataEndRead, sizeof(bufDataEndRead)); if (valuesRead == 0){ return -1; } else { return value / valuesRead; } }
long readSingleValueFromInput(int input){ changeInput(input); delay(120); return readSingleValue(); }
pulsesequence() { int i, relay; /* GET NEW PARAMETERS */ relay = (int) (getval("relay") + 0.5); /* CHECK CONDITIONS */ if (p1 == 0.0) p1 = pw; /* CALCULATE PHASES */ sub(ct, ssctr, v11); /* v11 = ct-ss */ initval(256.0, v12); add(v11, v12, v11); /* v11 = ct-ss+256 */ hlv(v11, v1); /* v1 = cyclops = 00112233 */ for (i = 0; i < relay + 1; i++) hlv(v1, v1); /* cyclops = 2**(relay+2) 0's, 1's, 2's, 3's */ mod4(v11, v2); /* v2 = 0123 0123... */ dbl(v2, oph); /* oph = 0202 0202 */ add(v2, v1, v2); /* v2 = 0123 0123 + cyclops */ add(oph, v1, oph); /* oph = 0202 0202 + cyclops */ hlv(v11, v3); /* v3 = 0011 2233 4455 ... */ /* PULSE SEQUENCE */ status(A); if (rof1 == 0.0) { rof1 = 1.0e-6; /* phase switching time */ rcvroff(); } hsdelay(d1); /* preparation period */ status(B); rgpulse(pw, v1, rof1, rof1); delay(d2); /* evolution period */ status(A); if (relay == 0) delay(tau); /* for delayed cosy */ rgpulse(p1, v2, rof1, rof1); /* start of mixing period */ if (relay == 0) delay(tau); /* for delayed cosy */ for (i = 0; i < relay; i++) /* relay coherence */ { hlv(v3, v3); /* v3=2**(relay+1) 0's, 1's, 2's, 3's */ dbl(v3, v4); /* v4=2**(relay+1) 0's, 2's, 0's, 2's */ add(v2, v4, v5); /* v5=v4+v2 (including cyclops) */ delay(tau/2); rgpulse(2.0*pw, v2, rof1, rof1); delay(tau/2); rgpulse(pw, v5, rof1, rof1); } status(C); delay(rof2); rcvron(); }
/* * Given the file system, inode OR id, and type (UDQUOT/GDQUOT), return a * a locked dquot, doing an allocation (if requested) as needed. * When both an inode and an id are given, the inode's id takes precedence. * That is, if the id changes while we don't hold the ilock inside this * function, the new dquot is returned, not necessarily the one requested * in the id argument. */ int xfs_qm_dqget( xfs_mount_t *mp, xfs_inode_t *ip, /* locked inode (optional) */ xfs_dqid_t id, /* uid/projid/gid depending on type */ uint type, /* XFS_DQ_USER/XFS_DQ_PROJ/XFS_DQ_GROUP */ uint flags, /* DQALLOC, DQSUSER, DQREPAIR, DOWARN */ xfs_dquot_t **O_dqpp) /* OUT : locked incore dquot */ { struct xfs_quotainfo *qi = mp->m_quotainfo; struct radix_tree_root *tree = XFS_DQUOT_TREE(qi, type); struct xfs_dquot *dqp; int error; ASSERT(XFS_IS_QUOTA_RUNNING(mp)); if ((! XFS_IS_UQUOTA_ON(mp) && type == XFS_DQ_USER) || (! XFS_IS_PQUOTA_ON(mp) && type == XFS_DQ_PROJ) || (! XFS_IS_GQUOTA_ON(mp) && type == XFS_DQ_GROUP)) { return (ESRCH); } #ifdef DEBUG if (xfs_do_dqerror) { if ((xfs_dqerror_target == mp->m_ddev_targp) && (xfs_dqreq_num++ % xfs_dqerror_mod) == 0) { xfs_debug(mp, "Returning error in dqget"); return (EIO); } } ASSERT(type == XFS_DQ_USER || type == XFS_DQ_PROJ || type == XFS_DQ_GROUP); if (ip) { ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); ASSERT(xfs_inode_dquot(ip, type) == NULL); } #endif restart: mutex_lock(&qi->qi_tree_lock); dqp = radix_tree_lookup(tree, id); if (dqp) { xfs_dqlock(dqp); if (dqp->dq_flags & XFS_DQ_FREEING) { xfs_dqunlock(dqp); mutex_unlock(&qi->qi_tree_lock); trace_xfs_dqget_freeing(dqp); delay(1); goto restart; } dqp->q_nrefs++; mutex_unlock(&qi->qi_tree_lock); trace_xfs_dqget_hit(dqp); XFS_STATS_INC(xs_qm_dqcachehits); *O_dqpp = dqp; return 0; } mutex_unlock(&qi->qi_tree_lock); XFS_STATS_INC(xs_qm_dqcachemisses); /* * Dquot cache miss. We don't want to keep the inode lock across * a (potential) disk read. Also we don't want to deal with the lock * ordering between quotainode and this inode. OTOH, dropping the inode * lock here means dealing with a chown that can happen before * we re-acquire the lock. */ if (ip) xfs_iunlock(ip, XFS_ILOCK_EXCL); error = xfs_qm_dqread(mp, id, type, flags, &dqp); if (ip) xfs_ilock(ip, XFS_ILOCK_EXCL); if (error) return error; if (ip) { /* * A dquot could be attached to this inode by now, since * we had dropped the ilock. */ if (xfs_this_quota_on(mp, type)) { struct xfs_dquot *dqp1; dqp1 = xfs_inode_dquot(ip, type); if (dqp1) { xfs_qm_dqdestroy(dqp); dqp = dqp1; xfs_dqlock(dqp); goto dqret; } } else { /* inode stays locked on return */ xfs_qm_dqdestroy(dqp); return XFS_ERROR(ESRCH); } } mutex_lock(&qi->qi_tree_lock); error = -radix_tree_insert(tree, id, dqp); if (unlikely(error)) { WARN_ON(error != EEXIST); /* * Duplicate found. Just throw away the new dquot and start * over. */ mutex_unlock(&qi->qi_tree_lock); trace_xfs_dqget_dup(dqp); xfs_qm_dqdestroy(dqp); XFS_STATS_INC(xs_qm_dquot_dups); goto restart; } /* * We return a locked dquot to the caller, with a reference taken */ xfs_dqlock(dqp); dqp->q_nrefs = 1; qi->qi_dquots++; mutex_unlock(&qi->qi_tree_lock); dqret: ASSERT((ip == NULL) || xfs_isilocked(ip, XFS_ILOCK_EXCL)); trace_xfs_dqget_miss(dqp); *O_dqpp = dqp; return (0); }
static bool hmc5883lInit(void) { int16_t magADC[3]; int32_t xyz_total[3] = { 0, 0, 0 }; // 32 bit totals so they won't overflow. bool bret = true; // Error indicator delay(50); i2cWrite(MAG_I2C_INSTANCE, MAG_ADDRESS, HMC58X3_R_CONFA, 0x010 + HMC_POS_BIAS); // Reg A DOR = 0x010 + MS1, MS0 set to pos bias // Note that the very first measurement after a gain change maintains the same gain as the previous setting. // The new gain setting is effective from the second measurement and on. i2cWrite(MAG_I2C_INSTANCE, MAG_ADDRESS, HMC58X3_R_CONFB, 0x60); // Set the Gain to 2.5Ga (7:5->011) delay(100); hmc5883lRead(magADC); int validSamples1 = 0; int failedSamples1 = 0; int saturatedSamples1 = 0; while (validSamples1 < 10 && failedSamples1 < INITIALISATION_MAX_READ_FAILURES) { // Collect 10 samples i2cWrite(MAG_I2C_INSTANCE, MAG_ADDRESS, HMC58X3_R_MODE, 1); delay(70); if (hmc5883lRead(magADC)) { // Get the raw values in case the scales have already been changed. // Detect saturation. if (-4096 >= MIN(magADC[X], MIN(magADC[Y], magADC[Z]))) { ++saturatedSamples1; ++failedSamples1; } else { ++validSamples1; // Since the measurements are noisy, they should be averaged rather than taking the max. xyz_total[X] += magADC[X]; xyz_total[Y] += magADC[Y]; xyz_total[Z] += magADC[Z]; } } else { ++failedSamples1; } LED1_TOGGLE; } // Apply the negative bias. (Same gain) i2cWrite(MAG_I2C_INSTANCE, MAG_ADDRESS, HMC58X3_R_CONFA, 0x010 + HMC_NEG_BIAS); // Reg A DOR = 0x010 + MS1, MS0 set to negative bias. int validSamples2 = 0; int failedSamples2 = 0; int saturatedSamples2 = 0; while (validSamples2 < 10 && failedSamples2 < INITIALISATION_MAX_READ_FAILURES) { // Collect 10 samples i2cWrite(MAG_I2C_INSTANCE, MAG_ADDRESS, HMC58X3_R_MODE, 1); delay(70); if (hmc5883lRead(magADC)) { // Get the raw values in case the scales have already been changed. // Detect saturation. if (-4096 >= MIN(magADC[X], MIN(magADC[Y], magADC[Z]))) { ++saturatedSamples2; ++failedSamples2; } else { ++validSamples2; // Since the measurements are noisy, they should be averaged. xyz_total[X] -= magADC[X]; xyz_total[Y] -= magADC[Y]; xyz_total[Z] -= magADC[Z]; } } else { ++failedSamples2; } LED1_TOGGLE; } if (failedSamples1 >= INITIALISATION_MAX_READ_FAILURES || failedSamples2 >= INITIALISATION_MAX_READ_FAILURES) { addBootlogEvent4(BOOT_EVENT_HMC5883L_READ_OK_COUNT, BOOT_EVENT_FLAGS_NONE, validSamples1, validSamples2); addBootlogEvent4(BOOT_EVENT_HMC5883L_READ_FAILED, BOOT_EVENT_FLAGS_WARNING, failedSamples1, failedSamples2); bret = false; } if (saturatedSamples1 > 0 || saturatedSamples2 > 0) { addBootlogEvent4(BOOT_EVENT_HMC5883L_SATURATION, BOOT_EVENT_FLAGS_WARNING, saturatedSamples1, saturatedSamples2); } if (bret) { magGain[X] = fabsf(660.0f * HMC58X3_X_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[X]); magGain[Y] = fabsf(660.0f * HMC58X3_Y_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[Y]); magGain[Z] = fabsf(660.0f * HMC58X3_Z_SELF_TEST_GAUSS * 2.0f * 10.0f / xyz_total[Z]); } else { // Something went wrong so get a best guess magGain[X] = 1.0f; magGain[Y] = 1.0f; magGain[Z] = 1.0f; } // leave test mode i2cWrite(MAG_I2C_INSTANCE, MAG_ADDRESS, HMC58X3_R_CONFA, 0x70); // Configuration Register A -- 0 11 100 00 num samples: 8 ; output rate: 15Hz ; normal measurement mode i2cWrite(MAG_I2C_INSTANCE, MAG_ADDRESS, HMC58X3_R_CONFB, 0x20); // Configuration Register B -- 001 00000 configuration gain 1.3Ga i2cWrite(MAG_I2C_INSTANCE, MAG_ADDRESS, HMC58X3_R_MODE, 0x00); // Mode register -- 000000 00 continuous Conversion Mode delay(100); hmc5883lConfigureDataReadyInterruptHandling(); return bret; }
void main5() { int gd=DETECT,gm=0,col=0,dol=600; initgraph(&gd,&gm,"c:/tc/bgi"); settextstyle(10,HORIZ_DIR,1); outtextxy(30,30,""); settextstyle(11,HORIZ_DIR,1); settextstyle(10,HORIZ_DIR,1); outtextxy(30,200,"Hit ENTER to Start the Magic..."); settextstyle(12,HORIZ_DIR,1); getch(); cleardevice(); while(!kbhit()) { for(int j=0;j<=50;j++) { { setcolor(2); circle(col,100,50+j); setfillstyle(4,2); floodfill(col,100,2); delay(3); col++; if(col>=600) col=0; } { setcolor(4); circle(dol,330,50+j); setfillstyle(5,4); floodfill(dol,330,4); delay(3); dol--; if(dol<=0) dol=600; } for(int i=1;i<=15;i++) { if(col==200) { setbkcolor(random(i)); } if(col==400) { setbkcolor(random(i)); } }//for inner close }//for outer loop for(int k=1;k<=120;k++) { setcolor(random(15)); circle(300,250,1+k); delay(1); } cleardevice(); } closegraph(); getch(); }
boolean ALB_DHT11::read(bool force) { // Check if sensor was read less than two seconds ago and return early // to use last reading. uint32_t currenttime = millis(); if (!force && ((currenttime - _lastreadtime) < 2000)) { return _lastresult; // return last correct measurement } _lastreadtime = currenttime; // Reset 40 bits of received data to zero. data[0] = data[1] = data[2] = data[3] = data[4] = 0; // Send start signal. See DHT datasheet for full signal diagram: // http://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf // Go into high impedence state to let pull-up raise data line level and // start the reading process. digitalWrite(_pin, HIGH); delay(250); // First set data line low for 20 milliseconds. pinMode(_pin, OUTPUT); digitalWrite(_pin, LOW); delay(20); uint32_t cycles[80]; { // Turn off interrupts temporarily because the next sections are timing critical // and we don't want any interruptions. InterruptLock lock; // End the start signal by setting data line high for 40 microseconds. digitalWrite(_pin, HIGH); delayMicroseconds(40); // Now start reading the data line to get the value from the DHT sensor. pinMode(_pin, INPUT_PULLUP); delayMicroseconds(10); // Delay a bit to let sensor pull data line low. // First expect a low signal for ~80 microseconds followed by a high signal // for ~80 microseconds again. if (expectPulse(LOW) == 0) { _lastresult = false; return _lastresult; } if (expectPulse(HIGH) == 0) { _lastresult = false; return _lastresult; } // Now read the 40 bits sent by the sensor. Each bit is sent as a 50 // microsecond low pulse followed by a variable length high pulse. If the // high pulse is ~28 microseconds then it's a 0 and if it's ~70 microseconds // then it's a 1. We measure the cycle count of the initial 50us low pulse // and use that to compare to the cycle count of the high pulse to determine // if the bit is a 0 (high state cycle count < low state cycle count), or a // 1 (high state cycle count > low state cycle count). Note that for speed all // the pulses are read into a array and then examined in a later step. for (int i = 0; i < 80; i += 2) { cycles[i] = expectPulse(LOW); cycles[i + 1] = expectPulse(HIGH); } } // Timing critical code is now complete. // Inspect pulses and determine which ones are 0 (high state cycle count < low // state cycle count), or 1 (high state cycle count > low state cycle count). for (int i = 0; i < 40; ++i) { uint32_t lowCycles = cycles[2 * i]; uint32_t highCycles = cycles[2 * i + 1]; if ((lowCycles == 0) || (highCycles == 0)) { _lastresult = false; return _lastresult; } data[i / 8] <<= 1; // Now compare the low and high cycle times to see if the bit is a 0 or 1. if (highCycles > lowCycles) { // High cycles are greater than 50us low cycle count, must be a 1. data[i / 8] |= 1; } // Else high cycles are less than (or equal to, a weird case) the 50us low // cycle count so this must be a zero. Nothing needs to be changed in the // stored data. } // Check we read 40 bits and that the checksum matches. if (data[4] == ((data[0] + data[1] + data[2] + data[3]) & 0xFF)) { _lastresult = true; return _lastresult; } else { _lastresult = false; return _lastresult; } }
//use only 4 char titles (should be changed soon) void generic_dual_display (char title1[ ], long high1, long cur_value1, long peak1, long hiWarn1, long loWarn1, boolean hilo1, char title2[ ], long high2, long cur_value2, long peak2, long hiWarn2, long loWarn2, boolean hilo2){ int ndigits = 0; Serial.print(0xFE, BYTE); Serial.print(128, BYTE); Serial.print(title1); Serial.print(" "); if ( (hilo1 == true) && (cur_value1 == 0) ){ Serial.print("LOW "); } else if ( (hilo1 == true) && (cur_value1 == 9999) ){ Serial.print("HIGH "); } else { Serial.print(cur_value1/10); Serial.print("."); Serial.print(cur_value1%10); ndigits = numberofdigits(cur_value1) + 1; if (ndigits <= 2){ ndigits = ndigits + 1;} for (int i = 0; i < 5 - ndigits; i++) { Serial.print(" "); } } Serial.print("/"); ndigits = numberofdigits(peak1) + 1; if (ndigits <= 2){ ndigits = ndigits + 1;} for (int i = 0; i < 6 - ndigits; i++){ Serial.print(" "); } Serial.print(peak1/10); Serial.print("."); Serial.print(peak1%10); if ( (cur_value1 > hiWarn1) || (cur_value1 < loWarn1) ){ //blink if warning threshold is met warn_flash(); } Serial.print(0xFE, BYTE); //select the second line Serial.print(192, BYTE); Serial.print(title2); Serial.print(" "); if ( (hilo2 == true) && (cur_value2 == 0) ){ Serial.print("LOW "); } else if ( (hilo2 == true) && (cur_value2 == 9999) ){ Serial.print("HIGH "); } else { Serial.print(cur_value2/10); Serial.print("."); Serial.print(cur_value2%10); ndigits = numberofdigits(cur_value2) + 1; if (ndigits <= 2){ ndigits = ndigits + 1;} for (int i = 0; i < 5 - ndigits; i++) { Serial.print(" "); } } Serial.print("/"); ndigits = numberofdigits(peak2) + 1; if (ndigits <= 2){ ndigits = ndigits + 1;} for (int i = 0; i < 6 - ndigits; i++){ Serial.print(" "); } Serial.print(peak2/10); Serial.print("."); Serial.print(peak2%10); if ( (cur_value2 > hiWarn2) || (cur_value2 < loWarn2) ){ //blink if warning threshold is met warn_flash(); } delay(100); }
long readAvgValueFromInput(int input, int avgOver, int delayMilis){ changeInput(input); delay(120); return readMultiValueAVG(avgOver, delayMilis); }
int GSM::begin(long baud_rate){ int response=-1; int cont=0; boolean norep=false; boolean turnedON=false; SetCommLineStatus(CLS_ATCMD); _cell.begin(baud_rate); setStatus(IDLE); for (cont=0; cont<3; cont++){ if (AT_RESP_ERR_NO_RESP == SendATCmdWaitResp("AT", 500, 100, "OK", 5)&&!turnedON) { //check power // there is no response => turn on the module #ifdef DEBUG_ON Serial.println("DB:NO RESP"); #endif // generate turn on pulse digitalWrite(GSM_ON, HIGH); delay(1200); digitalWrite(GSM_ON, LOW); delay(10000); norep=true; } else{ #ifdef DEBUG_ON Serial.println("DB:ELSE"); #endif norep=false; } } if (AT_RESP_OK == SendATCmdWaitResp("AT", 500, 100, "OK", 5)){ #ifdef DEBUG_ON Serial.println("DB:CORRECT BR"); #endif turnedON=true; } if(cont==3&&norep){ Serial.println("Trying to force the baud-rate to 9600\n"); for (int i=0;i<8;i++){ switch (i) { case 0: _cell.begin(1200); _cell.print(F("AT+IPR=9600\r")); break; case 1: _cell.begin(2400); _cell.print(F("AT+IPR=9600\r")); break; case 2: _cell.begin(4800); _cell.print(F("AT+IPR=9600\r")); break; case 3: _cell.begin(9600); _cell.print(F("AT+IPR=9600\r")); break; case 4: _cell.begin(19200); _cell.print(F("AT+IPR=9600\r")); break; case 5: _cell.begin(38400); _cell.print(F("AT+IPR=9600\r")); break; case 6: _cell.begin(57600); _cell.print(F("AT+IPR=9600\r")); break; case 7: _cell.begin(115200); _cell.print(F("AT+IPR=9600\r")); break; } } Serial.println("ERROR: SIM900 doesn't answer. Check power and serial pins in GSM.cpp"); return 0; } if (AT_RESP_ERR_DIF_RESP == SendATCmdWaitResp("AT", 500, 100, "OK", 5)&&!turnedON){ //check OK #ifdef DEBUG_ON Serial.println("DB:DIFF RESP"); #endif for (int i=0;i<8;i++){ switch (i) { case 0: _cell.begin(1200); break; case 1: _cell.begin(2400); break; case 2: _cell.begin(4800); break; case 3: _cell.begin(9600); break; case 4: _cell.begin(19200); break; case 5: _cell.begin(38400); break; case 6: _cell.begin(57600); break; case 7: _cell.begin(115200); _cell.print(F("AT+IPR=9600\r")); _cell.begin(9600); delay(500); break; // if nothing else matches, do the default // default is optional } delay(100); #ifdef DEBUG_PRINT // parameter 0 - because module is off so it is not necessary // to send finish AT<CR> here DebugPrint("DEBUG: Stringa ", 0); DebugPrint(buff, 0); #endif if (AT_RESP_OK == SendATCmdWaitResp("AT", 500, 100, "OK", 5)){ #ifdef DEBUG_ON Serial.println("DB:FOUND PREV BR"); #endif _cell.print(F("AT+IPR=")); _cell.print(baud_rate); _cell.print("\r"); // send <CR> delay(500); _cell.begin(baud_rate); delay(100); if (AT_RESP_OK == SendATCmdWaitResp("AT", 500, 100, "OK", 5)){ #ifdef DEBUG_ON Serial.println("DB:OK BR"); #endif } turnedON=true; break; } #ifdef DEBUG_ON Serial.println("DB:NO BR"); #endif } // communication line is not used yet = free SetCommLineStatus(CLS_FREE); // pointer is initialized to the first item of comm. buffer p_comm_buf = &comm_buf[0]; } SetCommLineStatus(CLS_FREE); if(turnedON){ WaitResp(50, 50); InitParam(PARAM_SET_0); InitParam(PARAM_SET_1);//configure the module Echo(0); //enable AT echo setStatus(READY); return(1); } else{ //just to try to fix some problems with 115200 baudrate _cell.begin(115200); delay(1000); _cell.print(F("AT+IPR=")); _cell.print(baud_rate); _cell.print("\r"); // send <CR> return(0); } }
void sbscn_attach_channel(struct sbscn_softc *sc, int chan, int intr) { struct sbscn_channel *ch = &sc->sc_channels[chan]; u_long chan_addr; struct tty *tp; ch->ch_sc = sc; ch->ch_num = chan; chan_addr = sc->sc_addr + (0x100 * chan); ch->ch_base = (void *)MIPS_PHYS_TO_KSEG1(chan_addr); ch->ch_isr_base = (void *)MIPS_PHYS_TO_KSEG1(sc->sc_addr + 0x220 + (0x20 * chan)); ch->ch_imr_base = (void *)MIPS_PHYS_TO_KSEG1(sc->sc_addr + 0x230 + (0x20 * chan)); #ifdef XXXCGDnotyet ch->ch_inchg_base = (void *)MIPS_PHYS_TO_KSEG1(sc->sc_addr + 0x2d0 + (0x10 * chan)); #endif ch->ch_i_dcd = ch->ch_i_dcd_pin = 0 /* XXXCGD */; ch->ch_i_cts = ch->ch_i_cts_pin = 0 /* XXXCGD */; ch->ch_i_dsr = ch->ch_i_dsr_pin = 0 /* XXXCGD */; ch->ch_i_ri = ch->ch_i_ri_pin = 0 /* XXXCGD */; ch->ch_i_mask = ch->ch_i_dcd | ch->ch_i_cts | ch->ch_i_dsr | ch->ch_i_ri; ch->ch_o_dtr = ch->ch_o_dtr_pin = 0 /* XXXCGD */; ch->ch_o_rts = ch->ch_o_rts_pin = 0 /* XXXCGD */; ch->ch_o_mask = ch->ch_o_dtr | ch->ch_o_rts; ch->ch_intrhand = cpu_intr_establish(intr, IPL_SERIAL, sbscn_intr, ch); callout_init(&ch->ch_diag_callout, 0); /* Disable interrupts before configuring the device. */ ch->ch_imr = 0; WRITE_REG(ch->ch_imr_base, ch->ch_imr); if (sbscn_cons_present && sbscn_cons_addr == chan_addr && sbscn_cons_chan == chan) { sbscn_cons_attached = 1; /* Make sure the console is always "hardwired". */ delay(1000); /* wait for output to finish */ SET(ch->ch_hwflags, SBSCN_HW_CONSOLE); SET(ch->ch_swflags, TIOCFLAG_SOFTCAR); } tp = ttymalloc(); tp->t_oproc = sbscn_start; tp->t_param = sbscn_param; tp->t_hwiflow = sbscn_hwiflow; ch->ch_tty = tp; ch->ch_rbuf = malloc(sbscn_rbuf_size << 1, M_DEVBUF, M_NOWAIT); if (ch->ch_rbuf == NULL) { printf("%s: channel %d: unable to allocate ring buffer\n", sc->sc_dev.dv_xname, chan); return; } ch->ch_ebuf = ch->ch_rbuf + (sbscn_rbuf_size << 1); tty_attach(tp); if (ISSET(ch->ch_hwflags, SBSCN_HW_CONSOLE)) { int maj; /* locate the major number */ maj = cdevsw_lookup_major(&sbscn_cdevsw); cn_tab->cn_dev = makedev(maj, (device_unit(&sc->sc_dev) << 1) + chan); printf("%s: channel %d: console\n", sc->sc_dev.dv_xname, chan); } #ifdef KGDB /* * Allow kgdb to "take over" this port. If this is * the kgdb device, it has exclusive use. */ if (sbscn_kgdb_present && sbscn_kgdb_addr == chan_addr && sbscn_kgdb_chan == chan) { sbscn_kgdb_attached = 1; SET(sc->sc_hwflags, SBSCN_HW_KGDB); printf("%s: channel %d: kgdb\n", sc->sc_dev.dv_xname, chan); } #endif ch->ch_si = softint_establish(SOFTINT_SERIAL, sbscn_soft, ch); #if NRND > 0 && defined(RND_SBSCN) rnd_attach_source(&ch->ch_rnd_source, sc->sc_dev.dv_xname, RND_TYPE_TTY, 0); #endif sbscn_config(ch); SET(ch->ch_hwflags, SBSCN_HW_DEV_OK); }
pulsesequence() { double gzlvl2 = getval("gzlvl2"), gt2 = getval("gt2"), gzlvl0 = getval("gzlvl0"), gt0 = getval("gt0"), gstab = getval("gstab"), phincr1 = getval("phincr1"), trim = getval("trim"), trimpwr = getval("trimpwr"), flippwr = getval("flippwr"), flippwrf = getval("flippwrf"), flippw = getval("flippw"), wrefpwr = getval("wrefpwr"), wrefpw = getval("wrefpw"), wrefpwrf = getval("wrefpwrf"); char sspul[MAXSTR],wrefshape[MAXSTR],flipshape[MAXSTR],flipback[MAXSTR], trim_flg[MAXSTR],alt_grd[MAXSTR]; /* LOAD VARIABLES */ rof1 = getval("rof1"); if (rof1 > 2.0e-6) rof1=2.0e-6; getstr("sspul",sspul); getstr("wrefshape", wrefshape); getstr("flipshape", flipshape); getstr("flipback", flipback); getstr("trim_flg", trim_flg); getstr("alt_grd",alt_grd); if (phincr1 < 0.0) phincr1=360+phincr1; initval(phincr1,v9); /* CALCULATE PHASECYCLE */ settable(t1,1,ph1); settable(t2,16,ph2); settable(t3,16,ph3); settable(t4,4,ph4); settable(t5,4,ph5); settable(t6,16,phr); sub(ct,ssctr,v12); getelem(t1,v12,v1); getelem(t2,v12,v2); getelem(t3,v12,v3); getelem(t4,v12,v4); getelem(t5,v12,v5); getelem(t6,v12,oph); if (alt_grd[0] == 'y') mod2(ct,v6); /* alternate gradient sign on every 2nd transient */ /* BEGIN THE ACTUAL PULSE SEQUENCE */ status(A); obspower(tpwr); if (sspul[A] == 'y') { zgradpulse(gzlvl0,gt0); rgpulse(pw,zero,rof1,rof1); zgradpulse(gzlvl0,gt0); } if (satmode[A] == 'y') { if (d1>satdly) delay(d1-satdly); if (fabs(tof-satfrq)>0.0) obsoffset(satfrq); obspower(satpwr); rgpulse(satdly,zero,rof1,rof1); if (fabs(tof-satfrq)>0.0) obsoffset(tof); obspower(tpwr); } else delay(d1); status(B); if (flipback[A] == 'y') { obsstepsize(1.0); xmtrphase(v9); add(v1,two,v8); obspower(flippwr+6); obspwrf(flippwrf); shaped_pulse(flipshape,flippw,v8,rof1,rof1); xmtrphase(zero); obspower(tpwr); obspwrf(4095.0); } rgpulse(pw, v1, rof1, rof1); ifzero(v6); zgradpulse(gzlvl2,gt2); elsenz(v6); zgradpulse(-gzlvl2,gt2); endif(v6); obspower(wrefpwr+6); obspwrf(wrefpwrf); delay(gstab); shaped_pulse(wrefshape,wrefpw,v2,rof1,rof1); obspower(tpwr); obspwrf(4095.0); rgpulse(2.0*pw,v3,rof1,rof1); ifzero(v6); zgradpulse(gzlvl2,gt2); elsenz(v6); zgradpulse(-gzlvl2,gt2); endif(v6); obspower(wrefpwr+6); obspwrf(wrefpwrf); delay(gstab); ifzero(v6); zgradpulse(1.2*gzlvl2,gt2); elsenz(v6); zgradpulse(-1.2*gzlvl2,gt2); endif(v6); delay(gstab); shaped_pulse(wrefshape,wrefpw,v4,rof1,rof1); obspower(tpwr); obspwrf(4095.0); if (trim_flg[A] == 'y') rgpulse(2.0*pw,v5,rof1,0.0); else rgpulse(2.0*pw,v5,rof1,rof2); ifzero(v6); zgradpulse(1.2*gzlvl2,gt2); elsenz(v6); zgradpulse(-1.2*gzlvl2,gt2); endif(v6); delay(gstab); if (trim_flg[A] == 'y') { obspower(trimpwr); add(v1,one,v10); rgpulse(trim,v10,rof1,rof2); } status(C); }
// Mount the specified SD card, returning true if done, false if needs to be called again. // If an error occurs, return true with the error message in 'reply'. // This may only be called to mount one card at a time. GCodeResult MassStorage::Mount(size_t card, const StringRef& reply, bool reportSuccess) { if (card >= NumSdCards) { reply.copy("SD card number out of range"); return GCodeResult::error; } SdCardInfo& inf = info[card]; MutexLocker lock1(fsMutex); MutexLocker lock2(inf.volMutex); if (!inf.mounting) { if (inf.isMounted) { if (AnyFileOpen(&inf.fileSystem)) { // Don't re-mount the card if any files are open on it reply.copy("SD card has open file(s)"); return GCodeResult::error; } (void)InternalUnmount(card, false); } inf.mountStartTime = millis(); inf.mounting = true; delay(2); } if (inf.cardState == CardDetectState::notPresent) { reply.copy("No SD card present"); inf.mounting = false; return GCodeResult::error; } if (inf.cardState != CardDetectState::present) { return GCodeResult::notFinished; // wait for debounce to finish } const sd_mmc_err_t err = sd_mmc_check(card); if (err != SD_MMC_OK && millis() - inf.mountStartTime < 5000) { delay(2); return GCodeResult::notFinished; } inf.mounting = false; if (err != SD_MMC_OK) { reply.printf("Cannot initialise SD card %u: %s", card, TranslateCardError(err)); return GCodeResult::error; } // Mount the file systems const char path[3] = { (char)('0' + card), ':', 0 }; const FRESULT mounted = f_mount(&inf.fileSystem, path, 1); if (mounted != FR_OK) { reply.printf("Cannot mount SD card %u: code %d", card, mounted); return GCodeResult::error; } inf.isMounted = true; if (reportSuccess) { float capacity = ((float)sd_mmc_get_capacity(card) * 1024) / 1000000; // get capacity and convert from Kib to Mbytes const char* capUnits; if (capacity >= 1000.0) { capacity /= 1000; capUnits = "Gb"; } else { capUnits = "Mb"; } reply.printf("%s card mounted in slot %u, capacity %.2f%s", TranslateCardType(sd_mmc_get_type(card)), card, (double)capacity, capUnits); } return GCodeResult::ok; }
uint16_t WaspSensorGas::pulse(uint16_t sensor) { uint16_t aux=0; switch( sensor ) { case SENS_SOCKET3B : digitalWrite(DIGITAL7, HIGH); delay(14); digitalWrite(DIGITAL7, LOW); delay(980); digitalWrite(DIGITAL1, HIGH); delay(3); aux = analogRead(ANALOG7); delay(2); digitalWrite(DIGITAL1, LOW); break; case SENS_SOCKET3C : digitalWrite(DIGITAL7, HIGH); delay(2); digitalWrite(DIGITAL1, HIGH); delay(4); aux = analogRead(ANALOG7); delay(1); digitalWrite(DIGITAL1, LOW); delay(7); digitalWrite(DIGITAL7, LOW); delay(236); break; case SENS_SOCKET4B : digitalWrite(DIGITAL5, HIGH); delay(14); digitalWrite(DIGITAL5, LOW); delay(980); digitalWrite(DIGITAL3, HIGH); delay(3); aux = analogRead(ANALOG6); delay(2); digitalWrite(DIGITAL3, LOW); break; case SENS_SOCKET4C : digitalWrite(DIGITAL5, HIGH); delay(2); digitalWrite(DIGITAL3, HIGH); delay(4); aux = analogRead(ANALOG6); delay(1); digitalWrite(DIGITAL3, LOW); delay(7); digitalWrite(DIGITAL5, LOW); delay(236); break; } return aux; }
// VBUS or counting frames // Any frame counting? u8 USBConnected() { u8 f = UDFNUML; delay(3); return f != UDFNUML; }
// Process buttons: void procButton(KeypadEvent b) { b -= 48; switch (keypad.getState()) { case RELEASED: // drop right away return; case PRESSED: // momentary if(mode==2) { // Signal Switching 4 ss4Signal(b); break; } else if(mode==3) { pulse(b); // pulse it return; } if(mode==4&&(b<10&&b>=0||b==-13||b==-6||(b>=49&&b<=52))) { // MF tone mf(b); } if(b<10&&b>=0||b==-13||b==-6) { // MF tone mf(b); } else if(b==52) { // D if (stored) playStored(); // don't copy function onto stack if not needed return; } else if(mode==1) { // international kp2/st2 if(b>=49&&b<=51) { mf(b); return; } } else if(mode==0&&(b<=51&&b>=49)) { // A,B,C redbox redBox(b); // pass it to RedBox() return; } break; case HOLD: // HELD (special functions) if(b==50&&mode==3) { // HOLD B for MF2 in PD Mode (mf2)? mf2 = 0 : mf2 = 1; // turn off if on, or on if off freq[0].play(440,70); delay(140); freq[0].play(440,70); delay(140); } if(b<10&&b>=0||b==-13||b==-6) { dial(b); } else if(b==51) { // C takes care of recording now if(rec) { // we are done recording: digitalWrite(13, LOW); // turn off LED rec = 0; stored=1; // we have digits stored recNotify(); } else { // we start recording digitalWrite(13, HIGH); // light up LED rec = 1; for(int i=0; i<=23; i++) { // reset array store[i] = -1; } recNotify(); } // END recording code } else if(b==49) { // ('A' HELD) switching any mode "on" changes to mode, all "off" is domestic if(mode==0) { // mf to international mode=1; } else if(mode==1) { // international to ss4 mode mode=2; } else if(mode==2) { // ss4 mode to pulse mode mode=3; } else if(mode==3) { // pulse mode to DTMF mode=4; } else if(mode==4) { // DTMF to domestic mode=0; } notifyMode(); return; } break; } return; }
/** * Method to send an HTTP Request. Allocate variables in your application code * in the aResponse struct and set the headers and the options in the aRequest * struct. */ void HttpClientMod::request(http_request_t &aRequest, http_response_t &aResponse, http_header_t headers[], const char* aHttpMethod) { // If a proper response code isn't received it will be set to -1. aResponse.status = -1; // NOTE: The default port tertiary statement is unpredictable if the request structure is not initialised // http_request_t request = {0} or memset(&request, 0, sizeof(http_request_t)) should be used // to ensure all fields are zero bool connected = false; if(aRequest.hostname!=NULL) { connected = client.connect(aRequest.hostname.c_str(), (aRequest.port) ? aRequest.port : 80 ); } else { connected = client.connect(aRequest.ip, aRequest.port); } #ifdef LOGGING if (connected) { if(aRequest.hostname!=NULL) { Serial.print("HttpClient>\tConnecting to: "); Serial.print(aRequest.hostname); } else { Serial.print("HttpClient>\tConnecting to IP: "); Serial.print(aRequest.ip); } Serial.print(":"); Serial.println(aRequest.port); } else { Serial.println("HttpClient>\tConnection failed."); } #endif if (!connected) { client.stop(); // If TCP Client can't connect to host, exit here. return; } // // Send HTTP Headers // // Send initial headers (only HTTP 1.0 is supported for now). client.print(aHttpMethod); client.print(" "); client.print(aRequest.path); client.print(" HTTP/1.0\r\n"); #ifdef LOGGING Serial.println("HttpClient>\tStart of HTTP Request."); Serial.print(aHttpMethod); Serial.print(" "); Serial.print(aRequest.path); Serial.print(" HTTP/1.0\r\n"); #endif // Send General and Request Headers. sendHeader("Connection", "close"); // Not supporting keep-alive for now. if(aRequest.hostname!=NULL) { sendHeader("HOST", aRequest.hostname.c_str()); } //Send Entity Headers // TODO: Check the standard, currently sending Content-Length : 0 for empty // POST requests, and no content-length for other types. if (aRequest.body != NULL) { sendHeader("Content-Length", (aRequest.body).length()); } else if (strcmp(aHttpMethod, HTTP_METHOD_POST) == 0) { //Check to see if its a Post method. sendHeader("Content-Length", 0); } if (headers != NULL) { int i = 0; while (headers[i].header != NULL) { if (headers[i].value != NULL) { sendHeader(headers[i].header, headers[i].value); } else { sendHeader(headers[i].header); } i++; } } // Empty line to finish headers client.println(); client.flush(); // // Send HTTP Request Body // if (aRequest.body != NULL) { client.println(aRequest.body); #ifdef LOGGING Serial.println(aRequest.body); #endif } #ifdef LOGGING Serial.println("HttpClient>\tEnd of HTTP Request."); #endif // clear response buffer buffer->clear(); // // Receive HTTP Response // // The first value of client.available() might not represent the // whole response, so after the first chunk of data is received instead // of terminating the connection there is a delay and another attempt // to read data. // The loop exits when the connection is closed, or if there is a // timeout or an error. unsigned long lastRead = millis(); unsigned long firstRead = millis(); bool error = false; bool timeout = false; char lastChar = 0; bool inHeaders = true; do { #ifdef LOGGING int bytes = client.available(); if(bytes) { Serial.print("\r\nHttpClient>\tReceiving TCP transaction of "); Serial.print(bytes); Serial.println(" bytes."); } #endif while (client.available()) { char c = client.read(); #ifdef LOGGING Serial.print(c); #endif lastRead = millis(); if (c == -1) { error = true; #ifdef LOGGING Serial.println("HttpClient>\tError: No data available."); #endif break; } if (inHeaders) { if ((c == '\n') && (lastChar == '\n')) { // End of headers. Grab the status code and reset the buffer. const char * const ptr = buffer->getBuffer(); if (ptr != NULL) { aResponse.status = atoi(&ptr[9]); } buffer->clear(); inHeaders = false; #ifdef LOGGING Serial.print("\r\nHttpClient>\tEnd of HTTP Headers ("); Serial.print(aResponse.status); Serial.println(")"); #endif continue; } else if (c != '\r') { lastChar = c; } } if (!buffer->append(c)) { client.stop(); error = true; #ifdef LOGGING Serial.println("\r\nHttpClient>\tError: Response body larger than buffer."); #endif break; } } #ifdef LOGGING if (bytes) { Serial.print("\r\nHttpClient>\tEnd of TCP transaction."); } #endif // Check that there hasn't been more than 5s since last read. timeout = millis() - lastRead > TIMEOUT; // Unless there has been an error or timeout wait 200ms to allow server // to respond or close connection. if (!error && !timeout) { delay(200); } } while (client.connected() && !timeout && !error); #ifdef LOGGING if (timeout) { Serial.println("\r\nHttpClient>\tError: Timeout while reading response."); } Serial.print("\r\nHttpClient>\tEnd of HTTP Response ("); Serial.print(millis() - firstRead); Serial.println("ms)."); #endif client.stop(); #ifdef LOGGING Serial.print("HttpClient>\tStatus Code: "); Serial.println(aResponse.status); #endif if (inHeaders) { #ifdef LOGGING Serial.println("HttpClient>\tError: Can't find HTTP response body."); #endif return; } // Return the entire message body from bodyPos+4 till end. aResponse.body = buffer->getBuffer(); buffer->clear(); }
void Adafruit_PCD8544::begin(uint8_t contrast, uint8_t bias) { if (isHardwareSPI()) { // Setup hardware SPI. SPI.begin(); SPI.setClockDivider(PCD8544_SPI_CLOCK_DIV); SPI.setDataMode(SPI_MODE0); SPI.setBitOrder(MSBFIRST); } else { // Setup software SPI. // Set software SPI specific pin outputs. pinMode(_din, OUTPUT); pinMode(_sclk, OUTPUT); // Set software SPI ports and masks. // clkport = portOutputRegister(digitalPinToPort(_sclk)); // clkpinmask = digitalPinToBitMask(_sclk); // mosiport = portOutputRegister(digitalPinToPort(_din)); // mosipinmask = digitalPinToBitMask(_din); } // Set common pin outputs. pinMode(_dc, OUTPUT); if (_rst > 0) pinMode(_rst, OUTPUT); if (_cs > 0) pinMode(_cs, OUTPUT); // toggle RST low to reset if (_rst > 0) { digitalWrite(_rst, LOW); delay(500); digitalWrite(_rst, HIGH); } // get into the EXTENDED mode! command(PCD8544_FUNCTIONSET | PCD8544_EXTENDEDINSTRUCTION ); // LCD bias select (4 is optimal?) command(PCD8544_SETBIAS | bias); // set VOP if (contrast > 0x7f) contrast = 0x7f; command( PCD8544_SETVOP | contrast); // Experimentally determined // normal mode command(PCD8544_FUNCTIONSET); // Set display to Normal command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL); // initial display line // set page address // set column address // write display data // set up a bounding box for screen updates updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1); // Push out pcd8544_buffer to the Display (will show the AFI logo) display(); }
/*----------------------------------------------------------------------------- -----------------------------------------------------------------------------*/ void delay_milliseconds::operator ()() { delay(saved_delay); }
boolean WiFlyDevice::findInResponse(const char *toMatch, unsigned int timeOut = 0) { /* */ // TODO: Change 'sendCommand' to use 'findInResponse' and have timeouts, // and then use 'sendCommand' in routines that call 'findInResponse'? // TODO: Don't reset timer after successful character read? Or have two // types of timeout? int byteRead; unsigned int timeOutTarget; // in milliseconds DEBUG_LOG(1, "Entered findInResponse"); DEBUG_LOG(2, "Want to match2:"); DEBUG_LOG(2, toMatch); DEBUG_LOG(3, "Found:"); for (unsigned int offset = 0; offset < strlen(toMatch); offset++) { // Reset after successful character read timeOutTarget = millis() + timeOut; // Doesn't handle timer wrapping while (!uart.available()) { // Wait, with optional time out. if (timeOut > 0) { if (millis() > timeOutTarget) { return false; } } delay(1); // This seems to improve reliability slightly } // We read this separately from the conditional statement so we can // log the character read when debugging. byteRead = uart.read(); delay(1); // Removing logging may affect timing slightly DEBUG_LOG(7, "Offset:"); DEBUG_LOG(7, offset); DEBUG_LOG(7, (char) byteRead); DEBUG_LOG(7, byteRead); /* //DEBUG_LOG(6,(char)byteRead); //DEBUG_LOG(6," <-> "); //DEBUG_LOG(6,toMatch[offset]); //DEBUG_LOG(6,toMatch[0]); if(byteRead==toMatch[offset]){ DEBUG_LOG(6,"Match --> "); DEBUG_LOG(6,byteRead==toMatch[offset]); } */ Serial.print((char)byteRead); Serial.print(" <-> "); Serial.print(toMatch[offset]); if(byteRead==toMatch[offset]){ Serial.print("Match --> "); Serial.print(byteRead==toMatch[offset]); } Serial.println(); if (byteRead != toMatch[offset]) { offset = 0; // Ignore character read if it's not a match for the start of the string if (byteRead != toMatch[offset]) { offset = -1; } continue; } } return true; }
void setup(){ pinMode(piezoTriggerPin, OUTPUT); //delay(10000); //setup the accelerometer and screen //Serial.begin(9600); //Serial.print("IPA"); //to vdip logger //Serial.print(13, BYTE); //to vdip logger //delay(10000); //pinMode(sprayTriggerPin, OUTPUT); //digitalWrite(sprayTriggerPin, LOW); Serial.begin(9600); //put wait code to look and see if there is a //response from the VDIP1. If there isn't try connecting again //read the root dir in the memstick to set the //log file's name/number (its sequential) //Serial.print("DIR"); //Serial.print(13, BYTE); //Serial.print(0xFE, BYTE); //command flag //Serial.print(128, BYTE); //while(Serial.available() > 0){ //Serial.print(Serial.read()); //} //Serial.print(0xFE, BYTE); //command flag //Serial.print(128, BYTE); //Serial.print("initialized"); //read //int tfilenum = 0; /*if(Serial.available() > 0){ //look for "LOG" int input = Serial.read(); Serial.print(input); if (input == 76){ //L input = Serial.read(); if (input == 79){ //O input = Serial.read(); if (input == 71){ //G //get the numers after "LOG" input = Serial.read(); tfilenum = input - 48; input = Serial.read(); while (input > 48 && input < 58){ input = Serial.read(); tfilenum = tfilenum * 10 + input - 48; } } } } }*/ //logfilecount = tfilenum + 1; // Serial.print("OPW LOG555"); //Serial.print(13, BYTE); Serial.print(0xFE, BYTE); Serial.print(128, BYTE); Serial.print("Welcome!"); //change this to the users greeting...also useful as a LCD communication test Serial.print(0xFE, BYTE); Serial.print(192, BYTE); Serial.print(" Ben"); //line two of the users splash screen /* for (int i=0; i<100; i++){ play_piezo(); } */ delay(1000); //how long to delay on the //Serial.print("file write"); //Serial.print("CFL LOG555"); //Serial.print(13,BYTE); //this next line for debug only //delay(10000); Serial.print(0x7C, BYTE); Serial.print(157, BYTE); //light level to 150 out of 157 //Serial.print(0xFE, BYTE); //Serial.print(0x01, BYTE); //zero the accelerometer...but only for small tilts delay(1000); int tempreading = analogRead(yval); if ((tempreading < 800) && (tempreading > 200)){ zerogy = tempreading; } else { zerogy = 512; } tempreading = analogRead(xval); if (true) { //((tempreading < 800) && (tempreading > 200)){ zerogx = tempreading; } else { zerogx = 512; } //setup the buttons as inputs pinMode(buttonApin, INPUT); pinMode(buttonBpin, INPUT); Serial.print(0xFE, BYTE); Serial.print(0x01, BYTE); //clear LCD }
void testallblock(void) { Uint32 i; Uint32 temp; Uint32 *SDRAM_StartAdd; Uint32 *temp_add; Uint32 Length=96; SDRAM_StartAdd = (Uint32 *)0xc0000000; for(i=0;i<Length;i++) { temp_add = SDRAM_StartAdd+i; *(temp_add) = 0; } for(i=0;i<Length;i++) { temp = *(SDRAM_StartAdd+i); if(temp != 0x00000000) { temp = *(SDRAM_StartAdd+i); printf("\nWhen writing 0x00000000, Address 0x%x is error!",i); SW_BREAKPOINT; } } printf("\nWriting 0x00000000 is ok."); for(i=0;i<Length;i++) { *(SDRAM_StartAdd+i) = 0xffff; } for(i=0;i<Length;i++) { if(*(SDRAM_StartAdd+i) != 0xffff) { printf("\nWhen writing 0xffff, Address 0x%x is error!",i); SW_BREAKPOINT; } } printf("\nWriting 0xffff is ok."); for(i=0;i<Length;i++) { *(SDRAM_StartAdd+i) = 0xAAAA; } for(i=0;i<Length;i++) { if(*(SDRAM_StartAdd+i) != 0xAAAA) { printf("\nWhen writing 0xAAAA, Address 0x%x is error!",i); SW_BREAKPOINT; } } printf("\nWriting 0xAAAA is ok."); for(i=0;i<Length;i++) { *(SDRAM_StartAdd+i) = 0x5555; } delay(10); for(i=0;i<Length;i++) { if(*(SDRAM_StartAdd+i) != 0x5555) { printf("\nWhen writing 0x5555, Address 0x%x is error!",i); } } printf("\nWriting 0x5555 is ok."); for(i=0;i<Length;i++) { // *(SDRAM_StartAdd+i) = i; temp_add = SDRAM_StartAdd+i; *(temp_add) = i; } i=0; for(i=0;i<Length;i++) { if(*(SDRAM_StartAdd+i) != i) { printf("\nWhen writing sequence data, Address 0x%x is error!",i); SW_BREAKPOINT; } } printf("\nTesting is success."); }
void main() { randomize(); clrscr(); int i; int xcoord; int ycoord; int xleft; int yup; int soundon; xcoord=1; ycoord=1; xleft=0; yup=0; int col; while(!kbhit()) { if(xcoord>=55) { xleft=1; goto sstart; } if(xcoord<=1) { xleft=0; goto sstart; } if(ycoord>=25) { yup=1; goto sstart; } if(ycoord<=1) { yup=0; goto sstart; } goto paststart; sstart: sound(1000); soundon=1; col=(random(14))+1; textcolor(col); paststart: gotoxy(xcoord,ycoord); cout << "Chops is God"; clrscr(); if(xleft==0) { xcoord++; } if(xleft==1) { xcoord=xcoord-1; } if(yup==0) { ycoord++; } if(yup==1) { ycoord=ycoord-1; } //gotoxy(xcoord,ycoord); //cout << xcoord << endl << ycoord << endl; gotoxy(xcoord,ycoord); cout << "Chops made this in C++"; delay(15); if(soundon==1) { nosound(); soundon=0; } //delay(10); } clrscr(); gotoxy(35,12); { //textcolor(); cout << "Coded by Chops"<< endl; cout << "Mike Gaynor is my god"<<endl; cout << "Mike Gaynor is better than I can ever hope to be"; sleep(3); } }