コード例 #1
2
ファイル: app.cpp プロジェクト: wotio/mbedos-accel-frdm-k64f
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(&reg,&Registrar::update,20);

	// enable accelerometer
	printf("Initializied accelerometer\r\n");
	accel.enable();
	Ticker sampler;
	sampler.attach(sample,5);

	// schedule 
	FunctionPointer1<void, M2MObjectList> fp(&reg, &Registrar::setup);
	minar::Scheduler::postCallback(fp.bind(list));
	minar::Scheduler::postCallback(sample).period(minar::milliseconds(10000));
	minar::Scheduler::start();
}
コード例 #2
0
ファイル: main.cpp プロジェクト: 1deus/tmk_keyboard
int main() {
    led1 = 0;
    led2 = 0;
    uint32_t initial_handler, final_handler;
    Counter c;

    // Test chaining inside Serial class
    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)

    // Test global chaining (InterruptManager)
    printf("Handler initially: %08X\n", initial_handler = NVIC_GetVector(TIMER_IRQ));
    InterruptManager *pManager = InterruptManager::get();
    pFunctionPointer_t ptm = pManager->add_handler(testme, TIMER_IRQ);
    pFunctionPointer_t pinc = pManager->add_handler_front(&c, &Counter::inc, TIMER_IRQ);
    printf("Handler after calling InterruptManager: %08X\n", NVIC_GetVector(TIMER_IRQ));

    wait(4.0);

    if (!pManager->remove_handler(ptm, TIMER_IRQ) || !pManager->remove_handler(pinc, TIMER_IRQ)) {
        printf ("remove handler failed.\n");
        notify_completion(false);
    }
    printf("Interrupt handler calls: %d\n", c.get_count());
    printf("Handler after removing previously added functions: %08X\n", final_handler = NVIC_GetVector(TIMER_IRQ));

    if (initial_handler != final_handler) {
        printf( "InteruptManager test failed.\n");
        notify_completion(false);
    }

    while(1);
}
コード例 #3
0
ファイル: main.cpp プロジェクト: Illuminux/mbed
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);
    }
}
コード例 #4
0
/*
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;
}
コード例 #5
0
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;
            }
        }
    }
}
コード例 #6
0
ファイル: main.cpp プロジェクト: dinau/mbed
int main (void) {
    GREENTEA_SETUP(20, "default_auto");

    Thread thread(queue_thread, NULL, osPriorityNormal, STACK_SIZE);
    Ticker ticker;
    ticker.attach(queue_isr, 1.0);
    int isr_puts_counter = 0;
    bool result = true;

    while (true) {
        osEvent evt = queue.get();
        if (evt.status != osEventMessage) {
            printf("QUEUE_GET: Status(0x%02X) ... [FAIL]\r\n", evt.status);
            result = false;
            break;
        } else {
            printf("QUEUE_GET: Value(%u) ... [OK]\r\n", evt.value.v);
            if (evt.value.v == QUEUE_PUT_ISR_VALUE) {
                isr_puts_counter++;
            }
            if (isr_puts_counter >= QUEUE_SIZE) {
                break;
            }
        }
    }

    GREENTEA_TESTSUITE_RESULT(result);
    return 0;
}
コード例 #7
0
ファイル: main.cpp プロジェクト: austinxiao-ucsd/falcon
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;
    }
  }
}
コード例 #8
0
ファイル: test.cpp プロジェクト: hirotakaster/hallsensor-bldc
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);
    }
}
コード例 #9
0
/////////////////////////////////////////////////////////////////////////
// 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();
}
コード例 #10
0
ファイル: main.cpp プロジェクト: ahmedlogic/LEDcube
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);
}
コード例 #11
0
int main() {
    isLogging = RJ_LOGGING_EN;
    rjLogLevel = INF2;

    lifeLight.attach(&imAlive, ALIVE_BLINK_RATE);
    pc.baud(BAUD_RATE);

    shared_ptr<SharedSPI> sharedSPI =
        make_shared<SharedSPI>(RJ_SPI_MOSI, RJ_SPI_MISO, RJ_SPI_SCK);
    sharedSPI->format(8, 0);
    FILE* fp = fopen(filename.c_str(), "r");
    AVR910 programmer(sharedSPI, RJ_KICKER_nCS, RJ_KICKER_nRESET);

    if (fp == nullptr) {
        pc.printf("Failed to open file.\r\n");
        return -1;
    }

    pc.printf("Attempting to program...\r\n");
    bool nSuccess =
        programmer.program(fp, ATTINY84A_PAGESIZE, ATTINY84A_NUM_PAGES);

    if (nSuccess) {
        pc.printf("Programming failed.\r\n");
    } else {
        pc.printf("Programming succeeded.\r\n");
    }

    fclose(fp);
    lifeLight.detach();
    return 0;
}
コード例 #12
0
ファイル: main.cpp プロジェクト: TemcoHeng/mbed
int main (void) {
    MBED_HOSTTEST_TIMEOUT(20);
    MBED_HOSTTEST_SELECT(default_auto);
    MBED_HOSTTEST_DESCRIPTION(ISR (Queue));
    MBED_HOSTTEST_START("RTOS_8");

    Thread thread(queue_thread, NULL, osPriorityNormal, STACK_SIZE);
    Ticker ticker;
    ticker.attach(queue_isr, 1.0);
    int isr_puts_counter = 0;
    bool result = true;

    while (true) {
        osEvent evt = queue.get();
        if (evt.status != osEventMessage) {
            printf("QUEUE_GET: Status(0x%02X) ... [FAIL]\r\n", evt.status);
            result = false;
            break;
        } else {
            printf("QUEUE_GET: Value(%u) ... [OK]\r\n", evt.value.v);
            if (evt.value.v == QUEUE_PUT_ISR_VALUE) {
                isr_puts_counter++;
            }
            if (isr_puts_counter >= QUEUE_SIZE) {
                break;
            }
        }
    }

    MBED_HOSTTEST_RESULT(result);
    return 0;
}
コード例 #13
0
ファイル: main.cpp プロジェクト: rix1/master-sensor-software
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);

    /* 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++;
            pc.printf("%d\n", hrmCounter);
            hrService->updateHeartRate(hrmCounter);
        } else {
            ble.waitForEvent(); // low power wait for event
        }
    }
}
コード例 #14
0
ファイル: ticker_main.cpp プロジェクト: dotnfc/arducleo
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...
    }
}
コード例 #15
0
ファイル: main.cpp プロジェクト: pd0wm/flying-dutchman
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) {
        ;
    }
}
コード例 #16
0
void pppSurfing(void const*) {
    while (pppDialingSuccessFlag == 0) {
        Thread::wait(500);
    }
    NetLED_ticker.detach();
    NetLED_ticker.attach(&toggle_NetLed, 0.5);	//net is connect
    startRemoteUpdate();
}
コード例 #17
0
ファイル: ble_conn_params.cpp プロジェクト: 0xc0170/mbed
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;
}
コード例 #18
0
int main(void)
{
    Controlor controlor(data);
    
    tick.attach(&controlor, &Controlor::update, 0.01);
    // commandSource.attach(&controlor, &Controlor::onCommandRecieved);
    
    while (1) {}
}
コード例 #19
0
ファイル: test.cpp プロジェクト: hirotakaster/hallsensor-bldc
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);
}
コード例 #20
0
ファイル: main.cpp プロジェクト: lukevin13/ESE350
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();
    }
}
コード例 #21
0
ファイル: main.cpp プロジェクト: janjongboom/mbed-simulator
int main() {
    printf("Hello world!\n");
    printf("LED1 will blink every second, LED3 will toggle after 2.5 seconds, LED2 can be toggled through BUTTON1.\n");
    printf("-----------------------------------\n\n");

    t1.attach(callback(&blink_led1), 1.0f);
    t2.attach(callback(&turn_led3_on), 2.5f);
    btn.fall(callback(&toggle_led2));

    wait_ms(osWaitForever);
}
コード例 #22
0
ファイル: main.cpp プロジェクト: baserkandehir/mbed
int main() 
{ 
    /* Leds are initially OFF */
    for(int i=0; i<4 ;i++)
        leds[i]=0;            
   
    /* Start debounce timer */
    debounce.start();
    
    /* Attach functions to periodic interrupts */
    toggler1.attach(&toggle_led1,0.1);     // toggles led1 every 100 ms
    toggler2.attach(&toggle_led2,0.5);     // toggles led2 every 500 ms
    
    /* Call toggle_led3 falling edge of the button interrupt */
    button.fall(&led3_debounced);  
    while(1) 
    {
            
    }
}
コード例 #23
0
ファイル: main.cpp プロジェクト: 1deus/tmk_keyboard
int main() {
    printf("main()\n");
    ticker.attach(&send, 1);
#if !defined (TARGET_LPC1549)
    can2.attach(&read);
#endif
    while(1) {
        printf("loop()\n");
        wait(1);
    }
}
コード例 #24
0
////////////////////////////////////////////////////////////////
//Retour partie si Pause//
////////////////////////////////////////////////////////////////
int A40(void)
{
    T_MS1=100;
    T_MS2=150;
    scanShip.attach(&shipscan,0.2);
    space.Play();
    son.MusicSelect(SelectionMusic);
    Chrono.reset();
    Chrono.start();
    printf("Action = A40\n\r");
    printf("Etat = LVL\n\r");
    return LVL;
}
コード例 #25
0
ファイル: CAN_Fuel_Level_v3.cpp プロジェクト: ugracing/T2
//Main loop
int main() {
    //CANout.frequency(CAN_speed);            //Set the CAN frequency of TX
    ticker.attach(&gather, PollFreq);       //Gather the fuel level value at the polling rate
    while(1) {
        if(i >= SendFreq) {
            CANdata_array[0]=0x80;           //Set the data to be of type sensor data
            CANdata_array[1]=(LevelVal/i);   //Find the average fuel level for the defined time length
            send_msg();          //Send the data over CAN bus
            LevelVal = 0;           //Reset the average value
            i=0;                    //Reset the counter
        }
    }
}
コード例 #26
0
ファイル: lin_interp.cpp プロジェクト: Akivashi/net-centric
int main() {
	// Setup and initialize the connection
	AdkTerm.setupDevice();
	USBInit();
	// Find the standard start value
	value = interpolate(5.0);
	// Begin the ticker that calls the servochanger
	flipper.attach(&servoChanger, 0.1);
	// continuously call the USB connection
	while(1) {
		USBLoop();
	}
}
コード例 #27
0
ファイル: main.cpp プロジェクト: masiko/humanoid
int main(){
	pin21.period_ms(20);
	pin21.pulsewidth_us(1500);
	pin22.period_ms(20);
	pin22.pulsewidth_us(1500);
	pin23.period_ms(20);
	pin23.pulsewidth_us(1500);
	pin24.period_ms(20);
	pin24.pulsewidth_us(1500);
	pin25.period_ms(20);
	pin25.pulsewidth_us(1500);
	pin26.period_ms(20);
	pin26.pulsewidth_us(1500);
	servo2.attach(&setPos2, 0.02);
	servo3.attach(&setPos3, 0.02);
	servo4.attach(&setPos4, 0.02);
	servo5.attach(&setPos5, 0.02);

	while(1){
		wait(1.0);
	}
	return 0;
}
コード例 #28
0
ファイル: main.cpp プロジェクト: doniexun/mbed
int main() {
    printf("main()\n");
    ticker.attach(&send, 1);
    CANMessage msg;
    while(1) {
#if (!defined (TARGET_LPC1549) && !defined(TARGET_B96B_F446VE))
      printf("loop()\n");
        if(can2.read(msg)) {
            printmsg("Rx message:", &msg);
            led2 = !led2;
        }
#endif
        wait(0.2);
    }
}
コード例 #29
0
ファイル: main.cpp プロジェクト: 1deus/tmk_keyboard
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);
        }
    }
}
コード例 #30
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(&eth, "mbed.org");
    printf("mbed.org resolved to: %s\r\n", addr.get_ip_address());

    TCPSocket ipv4socket(&eth);
    ipv4socket.connect("4.ifcfg.me", 23);
    ipv4socket.set_blocking(false);
    ipv4socket.attach(network_callback);

    TCPSocket ipv6socket(&eth);
    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");
}