void app_start(int, char**) { // setup the EthernetInterface eth.init(); // DHCP eth.connect(); // initialize the ipv4 tcp/ip stack lwipv4_socket_init(); // setup the M2MInterface srand(time(NULL)); uint16_t port = rand() % 65535 + 12345; srv = M2MInterfaceFactory::create_interface(observer,endpoint,type, lifetime,port,domain,M2MInterface::UDP,M2MInterface::LwIP_IPv4,context_address); // setup the Security object sec = M2MInterfaceFactory::create_security(M2MSecurity::M2MServer); sec->set_resource_value(M2MSecurity::M2MServerUri,address); sec->set_resource_value(M2MSecurity::SecurityMode, M2MSecurity::NoSecurity); // setup the Device object dev = M2MInterfaceFactory::create_device(); dev->create_resource(M2MDevice::Manufacturer,"Freescale"); dev->create_resource(M2MDevice::DeviceType,"frdm-k64f"); dev->create_resource(M2MDevice::ModelNumber,"M64FN1MOVLL12"); dev->create_resource(M2MDevice::SerialNumber,"EB1524XXXX"); // setup the sensor objects obj = M2MInterfaceFactory::create_object("loc"); M2MObjectInstance* ins = obj->create_object_instance(); M2MResource* resx = ins->create_dynamic_resource("x","accel",M2MResourceInstance::INTEGER,true); resx->set_operation(M2MBase::GET_PUT_ALLOWED); resx->set_value((const uint8_t*)"0",1); M2MResource* resy = ins->create_dynamic_resource("y","accel",M2MResourceInstance::INTEGER,true); resy->set_operation(M2MBase::GET_PUT_ALLOWED); resy->set_value((const uint8_t*)"0",1); // Assemble the list of objects to register M2MObjectList list; list.push_back(dev); list.push_back(obj); // setup registration event Ticker timer; timer.attach(®,&Registrar::update,20); // enable accelerometer printf("Initializied accelerometer\r\n"); accel.enable(); Ticker sampler; sampler.attach(sample,5); // schedule FunctionPointer1<void, M2MObjectList> fp(®, &Registrar::setup); minar::Scheduler::postCallback(fp.bind(list)); minar::Scheduler::postCallback(sample).period(minar::milliseconds(10000)); minar::Scheduler::start(); }
int main(void) { led1 = 1; Ticker ticker; ticker.attach(periodicCallback, 1); // blink LED every second BLE& ble = BLE::Instance(BLE::DEFAULT_INSTANCE); ble.init(bleInitComplete); // Instantiate security manager now so that it doesn't need to be done from an ISR later. nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getSecurityManager(); /* SpinWait for initialization to complete. This is necessary because the * BLE object is used in the main loop below. */ while (ble.hasInitialized() == false) { /* spin loop */ } // infinite loop while (1) { // check for trigger from periodicCallback() if (triggerSensorPolling && ble.getGapState().connected) { triggerSensorPolling = false; // Do blocking calls or whatever is necessary for sensor polling. // In our case, we simply update the HRM measurement. hrmCounter++; if (hrmCounter == 175) { // 100 <= HRM bps <=175 hrmCounter = 100; } hrService->updateHeartRate(hrmCounter); } else { ble.waitForEvent(); // low power wait for event } } }
void pppSurfing(void const*) { while (pppDialingSuccessFlag == 0) { Thread::wait(500); } NetLED_ticker.detach(); NetLED_ticker.attach(&toggle_NetLed, 0.5); //net is connect startRemoteUpdate(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); Ticker w; w.setText(QString(QObject::tr("***人的孤独********!"))); w.show(); return a.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); Ticker ticker; ticker.setWindowTitle(QObject::tr("Ticker")); ticker.setText(QObject::tr("How long it lasted was impossible to " "say ++ ")); ticker.show(); return app.exec(); }
int main() { led1 = 0; led2 = 0; flipper_1.attach(&flip_1, 1.0); // the address of the function to be attached (flip) and the interval (1 second) flipper_2.attach(&flip_2, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds) while (true) { wait(1.0); } }
void pushUp(){ freq += FREQ_SIZE; if (freq >= MAX_FREQ) freq = MAX_FREQ; dx = 1.0/(DX_LEN * freq); controller.detach(); controller.attach(&bldcval, dx); DBG("freq = %d\r\n", freq); }
void debounce_handler() { if (debounce.read_ms() >= 500) { debounce.reset(); training_mode = !training_mode; if (training_mode) tcontrol.attach(checkTimers, 1); else tcontrol.detach(); led4 = !led4; turnoffgreen(); greenlightact(); } }
inline void update(FT mFT) override { tlShoot.update(mFT); if(tckShoot.getCurrent() > shootDelay / 1.5f && tckShoot.getCurrent() < shootDelay) game.createPCharge(1, cPhys.getPosPx(), 20); if(tckShoot.update(mFT)) { tlShoot.reset(); tlShoot.start(); } }
static void equeue_tick_init() { MBED_STATIC_ASSERT(sizeof(equeue_timer) >= sizeof(Timer), "The equeue_timer buffer must fit the class Timer"); MBED_STATIC_ASSERT(sizeof(equeue_ticker) >= sizeof(Ticker), "The equeue_ticker buffer must fit the class Ticker"); Timer *timer = new (equeue_timer) Timer; Ticker *ticker = new (equeue_ticker) Ticker; equeue_minutes = 0; timer->start(); ticker->attach_us(equeue_tick_update, 1000 << 16); equeue_tick_inited = true; }
int main (void) { Thread thread(queue_thread); Ticker ticker; ticker.attach(queue_isr, 1.0); while (true) { osEvent evt = queue.get(); if (evt.status != osEventMessage) { printf("queue->get() returned %02x status\n\r", evt.status); } else { printf("queue->get() returned %d\n\r", evt.value.v); } } }
/* for reporting a sample that satisfies the reporting criteria and resetting the state machine */ int report_sample(sample s) { if(send_notification(s)){ // sends current_sample if observing is on last_band = band(s); // limits state machine high_step = s + LWM2M_step; // reset floating band upper limit defined by step low_step = s - LWM2M_step; // reset floating band lower limit defined by step pmin_timer.detach(); pmin_exceeded = false; // state machine to inhibit reporting at intervals < pmin pmin_timer.attach(&on_pmin, LWM2M_pmin); pmax_timer.detach(); pmax_timer.attach(&on_pmax, LWM2M_pmax); return 1; } else return 0; }
int main() { Ticker blinky; blinky.attach(blink, 0.4f); printf("NetworkSocketAPI Example\r\n"); eth.connect(); const char *ip = eth.get_ip_address(); const char *mac = eth.get_mac_address(); printf("IP address is: %s\r\n", ip ? ip : "No IP"); printf("MAC address is: %s\r\n", mac ? mac : "No MAC"); SocketAddress addr(ð, "mbed.org"); printf("mbed.org resolved to: %s\r\n", addr.get_ip_address()); TCPSocket ipv4socket(ð); ipv4socket.connect("4.ifcfg.me", 23); ipv4socket.set_blocking(false); ipv4socket.attach(network_callback); TCPSocket ipv6socket(ð); ipv6socket.connect("6.ifcfg.me", 23); ipv6socket.set_blocking(false); ipv6socket.attach(network_callback); // Tries to get both an IPv4 and IPv6 address while (network_sem.wait(2500) > 0) { int count; char buffer[64]; count = ipv4socket.recv(buffer, sizeof buffer); if (count >= 0) { printf("public IPv4 address is: %.15s\r\n", &buffer[15]); } count = ipv6socket.recv(buffer, sizeof buffer); if (count >= 0) { printf("public IPv6 address is: %.39s\r\n", &buffer[15]); } } ipv4socket.close(); ipv6socket.close(); eth.disconnect(); printf("Done\r\n"); }
void kickExternalWatchdog(void) { static bool locked = false; static bool wdog_state = false; static bool wdog_configured = false; if (!wdog_configured) { pinMode(WATCHDOG_WOUT_PIN, OUTPUT); kickAllSoftwareWatchdogs(); SWWatchdog.attach_ms(300, softwareWatchdog); // Check for stuck tasks and kick external Watchdog // The external wdog trips after 1.6s, but the timing is sloppy for the ESP8266, need this as 300ms. wdog_configured = true; startedTime = millis(); Serial.println(F("Software watchdog initialized.")); } if (!locked) { locked = true; pinMode(WATCHDOG_WOUT_PIN, OUTPUT); if (wdog_state) { digitalWrite(WATCHDOG_WOUT_PIN, HIGH); wdog_state = false; } else { digitalWrite(WATCHDOG_WOUT_PIN, LOW); wdog_state = true; } locked = false; } }
int main() { pc.printf("\r\nHi! Built with keil\r\n"); //leftChannelA.rise(&leftGotPulse); //rightChannelA.rise(&rightGotPulse); bool pressed = false; int motorState = 0; speed = 0.0f; ticker.attach(&printStatus, 0.5); while(1){ if (user_button == 0 && !pressed){ pressed = true; switch (motorState){ case 0: speed = 0.0f; break; case 1: speed = 0.1f; break; case 2: speed = 0.5f; break; case 3: speed = 1.0f; break; case 4: speed = 0.0f; break; case 5: speed = -0.1f; break; case 6: speed = -0.5f; break; case 7: speed = -1.0f; motorState = -1; break; } motorState++; drive(speed); } else if (user_button == 1){ pressed = false; } } }
int main() { // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms) toggle_led_ticker.attach(&toggle_led, 0.1); while (true) { // Do other things... } }
void initializeSnake(LLRoot * master) { /* Start Snake at 3 in length * x, y, z:layer */ //if(master != NULL) // Uh oh, non-empty snake? // freeListLL(master); // No matter initializeLL(master); __disable_irq(); addToHeadLL(master, 0, 0, 0); __enable_irq(); // BEAMMEUPSCOTTY myCube.plotPoint(0, 0, 0); master->direction = XPOS; //master->length = 1; generateFruit(master); // Note: What if fruit is generated on snake? // The user will not be able to see it until all snake nodes have gone // over it tick.attach(&setSnakeFlag, SPEED); }
OBCTurret(Entity& mE, OBCPhys& mCPhys, OBCDraw& mCDraw, OBCKillable& mCKillable, Dir8 mDir, const OBWpnType& mWpn, float mShootDelay, float mPJDelay, int mShootCount) noexcept : OBCActor{mE, mCPhys, mCDraw}, cKillable(mCKillable), direction{mDir}, wpn{game, OBGroup::GFriendlyKillable, mWpn}, shootDelay{mShootDelay}, pjDelay{mPJDelay}, shootCount{mShootCount} { cDraw.setRotation(getDegFromDir8(direction)); getEntity().addGroups(OBGroup::GEnemy, OBGroup::GEnemyKillable); body.setResolve(false); body.addGroups(OBGroup::GSolidGround, OBGroup::GSolidAir, OBGroup::GEnemy, OBGroup::GKillable, OBGroup::GEnemyKillable); tckShoot.restart(shootDelay); repeat(tlShoot, [this] { shoot(); }, shootCount, pjDelay); cKillable.onDeath += [this] { game.createEShard(5, cPhys.getPosI()); }; }
/******************************************************************************* * Sets up the serial port for communication and PWM for the lights, and * initializes the device. ******************************************************************************/ void setup() { pc.baud(BAUD); pc.attach(&serialInterrupt); // Setup the spi for 8 bit data, high steady state clock, // second edge capture, with a 1MHz clock rate cs = 1; spi.format(8,3); spi.frequency(1000000); // set up the lights on this mBed // light initialization on slave mBed handled by its own setup code lights[0] = new PwmOut(p26); lights[1] = new PwmOut(p25); lights[2] = new PwmOut(p24); lights[3] = new PwmOut(p23); lights[4] = new PwmOut(p22); lights[5] = new PwmOut(p21); for (int i = 0; i < 6; i++) { lights[i]->period_us(333); // 3 kHz lights[i]->write(0.5); // 50% duty cycle } row = 0; setRowMux(row); led3.write(0); while(start==0); adcRead.attach_us(&readAdcs, ADC_DELAY); }
static void on_write(ble_evt_t * p_ble_evt) { ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write; // Check if this the correct CCCD if ( (p_evt_write->handle == m_conn_params_config.start_on_notify_cccd_handle) && (p_evt_write->len == 2) ) { // Check if this is a 'start notification' if (ble_srv_is_notification_enabled(p_evt_write->data)) { // Do connection parameter negotiation if necessary conn_params_negotiation(); } else { #ifdef USE_APP_TIMER uint32_t err_code; // Stop timer if running err_code = app_timer_stop(m_conn_params_timer_id); if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) { m_conn_params_config.error_handler(err_code); } #else /* #if !USE_APP_TIMER */ m_conn_params_timer.detach(); #endif /* #if !USE_APP_TIMER */ } } }
int main() { DBG("start main !!\r\n"); // output pwm value pwmu_p.period_us(PWM_T_TIME); pwmv_p.period_us(PWM_T_TIME); pwmw_p.period_us(PWM_T_TIME); pwmu_n.period_us(PWM_T_TIME); pwmv_n.period_us(PWM_T_TIME); pwmw_n.period_us(PWM_T_TIME); // initialize is_initialized = false; start_motor = false; hallonoff = false; dx = 1.0/(DX_LEN * freq); startup.fall(&initialize); frequp.fall(&pushUp); controller.attach(&bldcval, dx); while(1) { wait(1); } }
void pppDialing(void const*) { HuaweiUSBCDMAModem modem(NC, true); NetLED_ticker.attach(&toggle_NetLed, 3); //net is disconnect while (true) { osEvent evt = redial.get(); char *ch; if (evt.status == osEventMessage) { ch = (char *)evt.value.p; INFO("Get redial osEventMessage value id is %d\n", *ch); } if (*ch == 1) { while(pppRedialingSuccessFlag == false) { // connect to redial cellular network if (modem.connect(MODEM_APN, MODEM_USERNAME, MODEM_PASSWORD) != OK) { INFO("Could connect the mobile gprs server, please check the Huawei modem or sim card."); Thread::wait(5000); } } } else { // connect to cellular network if (modem.connect(MODEM_APN, MODEM_USERNAME, MODEM_PASSWORD) != OK) { INFO("Could connect the mobile gprs server, please check the Huawei modem or sim card."); } else { pppDialingSuccessFlag = 1; } } } }
unsigned qCreateSinkForDebugFeedback(void* feedbackChannel) { QAudioSinkForDebugFeedback *sink = new QAudioSinkForDebugFeedback(*((FeedbackChannel**)feedbackChannel)); if (!sink) return 0; g_Ticker.addTickee(sink->ptr()); return sink->key(); }
///////////////////////////////////////////////////////////////////////// // Les actions élémentaires ///////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// //Initialisation// //////////////////////////////////////////////////////////////// void Init(void) { son.MusicOff(); scanShip.attach(&shipscan,0.2); giEvent = RIEN; giEtat = LCDPLAY; giStatelvl = LVL1; lcd.cls(); //efface LCD timemove.stop(); timemove.reset(); //reset timer timemove.start(); timetir.stop(); timetir.reset(); timetir.start(); Scrolling.stop(); Scrolling.reset(); Chrono.stop(); Chrono.reset(); EndTime.stop(); EndTime.reset(); giH = giS = giM = giD = 0; ScIndice=-1; gilen=0; scl=0; IndicePseudo=0; lcd.printf("=>Jouer Score"); lcd.locate(0,1); lcd.printf(" Difficulte"); T_MS1=500; //timer mouvement T_MS2=500; //timer tir //à 500ms dans le menu pour plus de précision //sinon T_MS1=100ms // T_MS2=150ms space.menuAff(); }
/*! * \brief Function to be executed on MAC layer event */ static void OnMacEvent( LoRaMacEventFlags_t *flags, LoRaMacEventInfo_t *info ) { if( flags->Bits.JoinAccept == 1 ) { #if( OVER_THE_AIR_ACTIVATION != 0 ) JoinReqTimer.detach( ); #endif IsNetworkJoined = true; } if( flags->Bits.Tx == 1 ) { } if( flags->Bits.Rx == 1 ) { if( flags->Bits.RxData == true ) { ProcessRxFrame( flags, info ); } } // Schedule a new transmission TxDone = true; }
int main(void) { led1 = 1; Ticker ticker; ticker.attach(periodicCallback, 1); // blink LED every second ble.init(); ble.gap().onDisconnection(disconnectionCallback); /* Setup primary service. */ uint8_t hrmCounter = 100; // init HRM to 100bps HeartRateService hrService(ble, hrmCounter, HeartRateService::LOCATION_FINGER); /* Setup auxiliary service. */ DeviceInformationService deviceInfo(ble, "ARM", "Model1", "SN1", "hw-rev1", "fw-rev1", "soft-rev1"); /* Setup advertising. */ ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list)); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::GENERIC_HEART_RATE_SENSOR); ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME)); ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.gap().setAdvertisingInterval(1000); /* 1000ms */ ble.gap().startAdvertising(); // infinite loop while (1) { // check for trigger from periodicCallback() if (triggerSensorPolling && ble.getGapState().connected) { triggerSensorPolling = false; // Do blocking calls or whatever is necessary for sensor polling. // In our case, we simply update the HRM measurement. hrmCounter++; // 100 <= HRM bps <=175 if (hrmCounter == 175) { hrmCounter = 100; } // update bps hrService.updateHeartRate(hrmCounter); } else { ble.waitForEvent(); // low power wait for event } } }
int main(void) { //setup zender zender.baud(115200); zender.attach(&newData); //attach tickers blinker.attach(&blink, 0.5); updater.attach(&update, 0.1); //echo off state["echo"] = 0; while (1) { ; } }
BOOL xMBPortSerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity ) { simISR.attach_us(&prvvUARTISR,1000); // Cam - attach prvvUARTISR to a 1mS ticker to simulate serial interrupt behaviour // 1mS is just short of a character time at 9600 bps, so quick enough to pick // up status on a character by character basis. return TRUE; }
void lib_init(){ timer.start(); ticker.attach_us(handleTick, 1000); fader.period_ms(10); fader.pulsewidth_ms(5); spi.format(8,0); spi.frequency(250000); pin20 = 1; }
static void conn_params_negotiation(void) { // Start negotiation if the received connection parameters are not acceptable if (!is_conn_params_ok(&m_current_conn_params)) { #ifdef USE_APP_TIMER uint32_t err_code; #endif uint32_t timeout_ticks; if (m_change_param) { // Notify the application that the procedure has failed if (m_conn_params_config.evt_handler != NULL) { ble_conn_params_evt_t evt; evt.evt_type = BLE_CONN_PARAMS_EVT_FAILED; m_conn_params_config.evt_handler(&evt); } } else { if (m_update_count == 0) { // First connection parameter update timeout_ticks = m_conn_params_config.first_conn_params_update_delay; } else { timeout_ticks = m_conn_params_config.next_conn_params_update_delay; } #ifdef USE_APP_TIMER err_code = app_timer_start(m_conn_params_timer_id, timeout_ticks, NULL); if ((err_code != NRF_SUCCESS) && (m_conn_params_config.error_handler != NULL)) { m_conn_params_config.error_handler(err_code); } #else m_conn_params_timer.attach(update_timeout_handler, timeout_ticks / 32768); #endif } } else { // Notify the application that the procedure has succeded if (m_conn_params_config.evt_handler != NULL) { ble_conn_params_evt_t evt; evt.evt_type = BLE_CONN_PARAMS_EVT_SUCCEEDED; m_conn_params_config.evt_handler(&evt); } } m_change_param = false; }