本文整理汇总了C++中Ticker::attach_us方法的典型用法代码示例。如果您正苦于以下问题:C++ Ticker::attach_us方法的具体用法?C++ Ticker::attach_us怎么用?C++ Ticker::attach_us使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ticker
的用法示例。
在下文中一共展示了Ticker::attach_us方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASYNCHRONOUS_DNS_CACHE
void ASYNCHRONOUS_DNS_CACHE()
{
rtos::Semaphore semaphore;
dns_application_data data;
data.semaphore = &semaphore;
Ticker ticker;
ticker.attach_us(&test_dns_query_ticker, 100);
for (unsigned int i = 0; i < 5; i++) {
int started_us = ticker_us;
nsapi_error_t err = get_interface()->gethostbyname_async(dns_test_hosts[0],
mbed::Callback<void(nsapi_error_t, SocketAddress *)>(hostbyname_cb, (void *) &data));
TEST_ASSERT(err >= 0);
semaphore.wait();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, data.result);
TEST_ASSERT(strlen(data.addr.get_ip_address()) > 1);
int delay_ms = (ticker_us - started_us) / 1000;
static int delay_first = delay_ms / 2;
printf("Delays: first: %i, delay_ms: %i\n", delay_first, delay_ms);
// Check that cached accesses are at least twice as fast as the first one
TEST_ASSERT_TRUE(i == 0 || delay_ms <= delay_first);
printf("DNS: query \"%s\" => \"%s\", time %i ms\n",
dns_test_hosts[0], data.addr.get_ip_address(), delay_ms);
}
}
示例2: setup
/*******************************************************************************
* 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);
}
示例3:
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;
}
示例4: app_start
void app_start(int, char*[])
{
MBED_HOSTTEST_TIMEOUT(15);
MBED_HOSTTEST_SELECT(wait_us_auto);
MBED_HOSTTEST_DESCRIPTION(Ticker Int us);
MBED_HOSTTEST_START("MBED_23");
tick.attach_us(togglePin, 1000);
}
示例5: lib_init
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;
}
示例6: app_start
void app_start(int, char **)
{
#ifndef MBED_CONF_RTOS_PRESENT
// set the baud rate for output printing
pc.baud(YOTTA_CFG_K64F_BORDER_ROUTER_BAUD);
// set heap size and memory error handler for this application
ns_dyn_mem_init(app_stack_heap, APP_DEFINED_HEAP_SIZE, app_heap_error_handler, 0);
#else
pc.baud(MBED_CONF_APP_TRACE_BAUD_RATE);
ns_hal_init(app_stack_heap, APP_DEFINED_HEAP_SIZE, app_heap_error_handler, 0);
#endif
trace_init(); // set up the tracing library
set_trace_print_function(trace_printer);
set_trace_config(TRACE_MODE_COLOR | APP_TRACE_LEVEL | TRACE_CARRIAGE_RETURN);
const char *mac_src;
#ifndef MBED_CONF_RTOS_PRESENT
mac_src = STR(YOTTA_CFG_K64F_BORDER_ROUTER_BACKHAUL_MAC_SRC);
#else
mac_src = STR(MBED_CONF_APP_BACKHAUL_MAC_SRC);
#endif
if (strcmp(mac_src, "BOARD") == 0) {
/* Setting the MAC Address from UID (A yotta function)
* Takes UID Mid low and UID low and shuffles them around. */
mbed_mac_address((char *)mac);
} else if (strcmp(mac_src, "CONFIG") == 0) {
/* MAC is defined by the user through yotta configuration */
#ifndef MBED_CONF_RTOS_PRESENT
const uint8_t mac48[] = YOTTA_CFG_K64F_BORDER_ROUTER_BACKHAUL_MAC;
#else
const uint8_t mac48[] = MBED_CONF_APP_BACKHAUL_MAC;
#endif
for (uint32_t i = 0; i < sizeof(mac); ++i) {
mac[i] = mac48[i];
}
}
#ifndef MBED_CONF_RTOS_PRESENT
// run LED toggler in the Minar scheduler
minar::Scheduler::postCallback(mbed::util::FunctionPointer0<void>
(toggle_led1).bind()).period(minar::milliseconds(500));
#else
led_ticker.attach_us(toggle_led1, 500000);
#endif
tr_info("Starting K64F border router...");
border_router_start();
}
示例7: main
int main()
{
rightMotor.setPwm(1.0);
leftMotor.setPwm(1.0);
Systicker.attach_us(&systick,1000);
//loop();
// pc.printf("test\n");
return 0;
}
示例8: equeue_tick_init
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;
}
示例9: do_blink
void do_blink() {
for (;;) {
// blink the LED
red_led = !red_led;
// up the position, if we reached the end of the vector
if (blink_args->position >= blink_args->blink_pattern.size()) {
// send delayed response after blink is done
M2MObjectInstance* inst = led_object->object_instance();
M2MResource* led_res = inst->resource("5850");
led_res->send_delayed_post_response();
red_led = LED_OFF;
status_ticker.attach_us(blinky, 250000);
return;
}
// Wait requested time, then continue prosessing the blink pattern from next position.
Thread::wait(blink_args->blink_pattern.at(blink_args->position));
blink_args->position++;
}
}
示例10: main
int main()
{
ticker_motor_ctrl.attach_us(&tickerInterrupt, MOTOR_CTRL_TICKER_PERIOD);
//pc.attach(&ComPC, &USBSerialCom::serialCallback);
ComPC.setAsser(&asser);
t_com.start();
//TODO: Enable a WatchDog !!!
int count = 0;
while (1)
{
if (t_com.read_ms() > 20)
{
ComPC.processSerialPort();
if(ComPC.checkTimeOut()) ComPC.sendHeartBeat(88288);
asser.UpdateCmd();
asser.DataAvailable();
asser.ComputeOdometry();
asser.Compute();
/*pc.printf("X%ld!",long(asser.getODO_X()*100));
pc.printf("Y%ld!",long(asser.getODO_Y()*100));
pc.printf("A%ld!",long(asser.getODO_Theta()*100));
pc.printf("L%ld!",asser.getWheelL());
pc.printf("R%ld!",asser.getWheelR());
if (count > 0) { pc.printf("D:To!"); }
count = 0;*/
ComPC.printOdo();
t_com.reset();
}
}
}
示例11: main
int main() {
controls.setPC(comm.getPC());
controls.setup();
// comm.printPosition();
comm.printGains();
controlsInterrupt.attach_us(&controls, &Controls::loop, 1000);
while(1) {
controls.updateIMUS();
comm.check();
if (serialCounter++>100) {
// comm.printPosition();
// comm.getPC()->printf("%f\n", controls.getTheta1());
// comm.getPC()->printf("%f", controls.motor.getPWM());
serialCounter = 0;
// float z[4] = {1,2,0,0};
// comm.getPC()->printf("%f\n",controls.target.getTheta2ForTarget(z));
}
}
}
示例12: main
int main()
{
PC.baud(115200);
TFC_TickerObj.attach_us(&TFC_TickerUpdate,2000); // update ticker array every 2mS (2000 uS)
TFC_Init();
TFC_HBRIDGE_ENABLE;
InterruptIn button(PTA17);//Interrupção no pino
button.rise(&flip); // attach the address of the flip function to the rising edge
TFC_Ticker[0] = 0;
update();
while(1)
{
//PC.printf("Hello World!\n");
//button.rise(NULL); // Disable interruptions
comm(&commands[0]); //Pass commands as a parameter of comm
//update();
//TFC_Task must be called in your main loop. This keeps certain processing happy (I.E. Serial port queue check)
// TFC_Task();
}
}
示例13: main
int main()
{
input_button_t button;
input_button_t last_button = W_IDLE;
#if defined(TARGET_LPC1114) && defined(SERIAL_DEBUG)
int i;
for (i = 0; i <= NUM_WHEEL_BUTTONS-1; i++)
dprintf("Threshold %d: 0x%04X\r\n", i, WHEEL_BUTTON_THRESHOLD[i]);
#endif
#if defined(TARGET_LPC1768) && defined(SERIAL_DEBUG)
dbg_serial.baud(115200);
#endif
dprintf("\r\n\r\n############## MBED MAZDA ##############\r\n");
#ifdef ENABLE_RN52
bluetooth.init();
dprintf("Bluetooth init done\r\n");
bluetooth.set_user_defaults();
dprintf("Bluetooth defaults done\r\n");
#endif
dprintf("Entering main loop\r\n");
loop_ticker.attach_us(&loop_ticker_isr, LOOP_TIME_US);
for (;;)
{
if (!main_loop_continue)
goto _main_sleep;
#ifdef ENABLE_RN52
if (bluetooth.status_update)
{
bluetooth.check_status();
#ifdef TARGET_LPC1768
led1 = bluetooth.is_connected;
#endif
}
#endif
button = read_input_button();
if (button != last_button)
{
dprintf("Switched to button %s\r\n", INPUT_BUTTON_STR[button]);
#ifdef ENABLE_RN52
if (bluetooth.is_connected)
{
// button mapping when bluetooth is connected
switch (button)
{
case W_VOLUP:
PIONEER_HOLD(P_VOLUP);
break;
case W_VOLDOWN:
PIONEER_HOLD(P_VOLDOWN);
break;
case W_NEXT:
bluetooth.next_track();
break;
case W_PREV:
bluetooth.prev_track();
break;
case W_MODE:
bluetooth.voice_command();
break;
case W_MUTE:
bluetooth.play_pause();
break;
#ifdef TARGET_LPC1768
case W_STATUSCHECK:
bluetooth.check_status();
led1 = bluetooth.is_connected;
break;
#endif
case W_IDLE:
default:
PIONEER_RELEASE();
break;
}
}
else
#endif
{
switch (button)
{
// button mapping when bluetooth isn't connected
case W_VOLUP:
PIONEER_HOLD(P_VOLUP);
break;
case W_VOLDOWN:
PIONEER_HOLD(P_VOLDOWN);
break;
case W_NEXT:
PIONEER_HOLD(P_NEXT);
break;
case W_PREV:
PIONEER_HOLD(P_PREV);
break;
case W_MODE:
PIONEER_HOLD(P_SOURCE);
//.........这里部分代码省略.........
示例14: main
int main()
{
tick.attach_us(togglePin, 1000);
while (1);
}
示例15: test_case_ticker
control_t test_case_ticker() {
tick.attach_us(togglePin, 1000);
return CaseTimeout(15 * 1000);
}