亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? example-codelock.c

?? Embedded Thread Library
?? C
字號:
/* * Copyright (c) 2004-2005, Swedish Institute of Computer Science. * All rights reserved.  * * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions  * are met:  * 1. Redistributions of source code must retain the above copyright  *    notice, this list of conditions and the following disclaimer.  * 2. Redistributions in binary form must reproduce the above copyright  *    notice, this list of conditions and the following disclaimer in the  *    documentation and/or other materials provided with the distribution.  * 3. Neither the name of the Institute nor the names of its contributors  *    may be used to endorse or promote products derived from this software  *    without specific prior written permission.  * * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF  * SUCH DAMAGE.  * * This file is part of the protothreads library. * * Author: Adam Dunkels <adam@sics.se> * * $Id: example-codelock.c,v 1.5 2005/10/06 07:57:08 adam Exp $ *//* * * This example shows how to implement a simple code lock. The code * lock waits for key presses from a numeric keyboard and if the * correct code is entered, the lock is unlocked. There is a maximum * time of one second between each key press, and after the correct * code has been entered, no more keys must be pressed for 0.5 seconds * before the lock is opened. * * This is an example that shows two things: * - how to implement a code lock key input mechanism, and * - how to implement a sequential timed routine. * * The program consists of two protothreads, one that implements the * code lock reader and one that implements simulated keyboard input. * * */#ifdef _WIN32#include <windows.h>#else#include <unistd.h>#include <sys/time.h>#endif#include <stdio.h>#include "pt.h"/*---------------------------------------------------------------------------*//* * The following definitions are just for the simple timer library * used in this example. The actual implementation of the functions * can be found at the end of this file. */struct timer { int start, interval; };static int  timer_expired(struct timer *t);static void timer_set(struct timer *t, int usecs);/*---------------------------------------------------------------------------*//* * This example uses two timers: one for the code lock protothread and * one for the simulated key input protothread. */static struct timer codelock_timer, input_timer;/*---------------------------------------------------------------------------*//* * This is the code that has to be entered. */static const char code[4] = {'1', '4', '2', '3'};/*---------------------------------------------------------------------------*//* * This example has two protothread and therefor has two protothread * control structures of type struct pt. These are initialized with * PT_INIT() in the main() function below. */static struct pt codelock_pt, input_pt;/*---------------------------------------------------------------------------*//* * The following code implements a simple key input. Input is made * with the press_key() function, and the function key_pressed() * checks if a key has been pressed. The variable "key" holds the * latest key that was pressed. The variable "key_pressed_flag" is set * when a key is pressed and cleared when a key press is checked. */static char key, key_pressed_flag;static voidpress_key(char k){  printf("--- Key '%c' pressed\n", k);  key = k;  key_pressed_flag = 1;}static intkey_pressed(void){  if(key_pressed_flag != 0) {    key_pressed_flag = 0;    return 1;  }  return 0;}/*---------------------------------------------------------------------------*//* * Declaration of the protothread function implementing the code lock * logic. The protothread function is declared using the PT_THREAD() * macro. The function is declared with the "static" keyword since it * is local to this file. The name of the function is codelock_thread * and it takes one argument, pt, of the type struct pt. * */staticPT_THREAD(codelock_thread(struct pt *pt)){  /* This is a local variable that holds the number of keys that have   * been pressed. Note that it is declared with the "static" keyword   * to make sure that the variable is *not* allocated on the stack.   */  static int keys;  /*   * Declare the beginning of the protothread.   */  PT_BEGIN(pt);  /*   * We'll let the protothread loop until the protothread is   * expliticly exited with PT_EXIT().   */  while(1) {    /*     * We'll be reading key presses until we get the right amount of     * correct keys.     */     for(keys = 0; keys < sizeof(code); ++keys) {      /*       * If we haven't gotten any keypresses, we'll simply wait for one.       */      if(keys == 0) {	/*	 * The PT_WAIT_UNTIL() function will block until the condition	 * key_pressed() is true.	 */	PT_WAIT_UNTIL(pt, key_pressed());      } else {		/*	 * If the "key" variable was larger than zero, we have already	 * gotten at least one correct key press. If so, we'll not	 * only wait for the next key, but we'll also set a timer that	 * expires in one second. This gives the person pressing the	 * keys one second to press the next key in the code.	 */	timer_set(&codelock_timer, 1000);	/*	 * The following statement shows how complex blocking	 * conditions can be easily expressed with protothreads and	 * the PT_WAIT_UNTIL() function.	 */	PT_WAIT_UNTIL(pt, key_pressed() || timer_expired(&codelock_timer));	/*	 * If the timer expired, we should break out of the for() loop	 * and start reading keys from the beginning of the while(1)	 * loop instead.	 */	if(timer_expired(&codelock_timer)) {	  printf("Code lock timer expired.\n");	  	  /*	   * Break out from the for() loop and start from the	   * beginning of the while(1) loop.	   */	  break;	}      }      /*       * Check if the pressed key was correct.       */      if(key != code[keys]) {	printf("Incorrect key '%c' found\n", key);	/*	 * Break out of the for() loop since the key was incorrect.	 */	break;      } else {	printf("Correct key '%c' found\n", key);      }    }    /*     * Check if we have gotten all keys.     */    if(keys == sizeof(code)) {      printf("Correct code entered, waiting for 500 ms before unlocking.\n");      /*       * Ok, we got the correct code. But to make sure that the code       * was not just a fluke of luck by an intruder, but the correct       * code entered by a person that knows the correct code, we'll       * wait for half a second before opening the lock. If another       * key is pressed during this time, we'll assume that it was a       * fluke of luck that the correct code was entered the first       * time.       */      timer_set(&codelock_timer, 500);            PT_WAIT_UNTIL(pt, key_pressed() || timer_expired(&codelock_timer));      /*       * If we continued from the PT_WAIT_UNTIL() statement without       * the timer expired, we don't open the lock.       */      if(!timer_expired(&codelock_timer)) {	printf("Key pressed during final wait, code lock locked again.\n");      } else {	/*	 * If the timer expired, we'll open the lock and exit from the	 * protothread.	 */	printf("Code lock unlocked.\n");	PT_EXIT(pt);      }    }  }  /*   * Finally, we'll mark the end of the protothread.   */  PT_END(pt);}/*---------------------------------------------------------------------------*//* * This is the second protothread in this example. It implements a * simulated user pressing the keys. This illustrates how a linear * sequence of timed instructions can be implemented with * protothreads. */staticPT_THREAD(input_thread(struct pt *pt)){  PT_BEGIN(pt);  printf("Waiting 1 second before entering first key.\n");    timer_set(&input_timer, 1000);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));  press_key('1');    timer_set(&input_timer, 100);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('2');  timer_set(&input_timer, 100);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('3');  timer_set(&input_timer, 2000);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('1');  timer_set(&input_timer, 200);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('4');  timer_set(&input_timer, 200);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('2');    timer_set(&input_timer, 2000);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('3');  timer_set(&input_timer, 200);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('1');  timer_set(&input_timer, 200);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('4');  timer_set(&input_timer, 200);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('2');    timer_set(&input_timer, 100);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('3');  timer_set(&input_timer, 100);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('4');  timer_set(&input_timer, 1500);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('1');  timer_set(&input_timer, 300);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('4');  timer_set(&input_timer, 400);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('2');  timer_set(&input_timer, 500);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    press_key('3');  timer_set(&input_timer, 2000);  PT_WAIT_UNTIL(pt, timer_expired(&input_timer));    PT_END(pt);}/*---------------------------------------------------------------------------*//* * This is the main function. It initializes the two protothread * control structures and schedules the two protothreads. The main * function returns when the protothread the runs the code lock exits. */intmain(void){  /*   * Initialize the two protothread control structures.   */  PT_INIT(&input_pt);  PT_INIT(&codelock_pt);  /*   * Schedule the two protothreads until the codelock_thread() exits.   */  while(PT_SCHEDULE(codelock_thread(&codelock_pt))) {    PT_SCHEDULE(input_thread(&input_pt));        /*     * When running this example on a multitasking system, we must     * give other processes a chance to run too and therefore we call     * usleep() resp. Sleep() here. On a dedicated embedded system,     * we usually do not need to do this.     */#ifdef _WIN32    Sleep(0);#else    usleep(10);#endif  }  return 0;}/*---------------------------------------------------------------------------*//* * Finally, the implementation of the simple timer library follows. */#ifdef _WIN32static int clock_time(void){ return (int)GetTickCount(); }#else /* _WIN32 */static int clock_time(void){  struct timeval tv;  struct timezone tz;     gettimeofday(&tv, &tz);   return tv.tv_sec * 1000 + tv.tv_usec / 1000;}#endif /* _WIN32 */static int timer_expired(struct timer *t){ return (int)(clock_time() - t->start) >= (int)t->interval; }static void timer_set(struct timer *t, int interval){ t->interval = interval; t->start = clock_time(); }/*---------------------------------------------------------------------------*/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲va天堂va国产va久| 欧美一区二区三区在| 国产精品毛片无遮挡高清| 成人app软件下载大全免费| 国产精品夫妻自拍| 一本色道久久加勒比精品 | 国产精品免费视频观看| 99这里只有精品| 亚洲香肠在线观看| 欧美日本国产视频| 久久97超碰色| 国产精品久久久久久妇女6080 | 九九精品视频在线看| 久久精品亚洲精品国产欧美kt∨| 高清国产午夜精品久久久久久| 国产精品乱人伦| 日本精品视频一区二区| 麻豆精品精品国产自在97香蕉| 2019国产精品| 色欧美乱欧美15图片| 日本一不卡视频| 中文字幕在线观看一区二区| 欧美精品日韩综合在线| 国产成人自拍高清视频在线免费播放| 亚洲视频在线观看一区| 欧美一区二区三区免费在线看| 国产麻豆精品theporn| 伊人婷婷欧美激情| 精品久久久久久综合日本欧美| 成人av在线网站| 麻豆视频一区二区| 亚洲乱码日产精品bd | 国产视频一区二区在线| 日本电影欧美片| 国产一区不卡在线| 日日夜夜免费精品视频| 亚洲欧美中日韩| 精品少妇一区二区三区| 91成人免费网站| 国产成人无遮挡在线视频| 日日夜夜精品视频天天综合网| 国产精品国产精品国产专区不蜜 | 国产 欧美在线| 天天免费综合色| 亚洲精品亚洲人成人网| 国产亚洲欧美中文| 日韩视频免费观看高清完整版 | 一区二区三区四区视频精品免费| 久久夜色精品一区| 91精品国产综合久久福利软件 | 日韩精品一区二区三区视频播放 | 91久久一区二区| 风流少妇一区二区| 日本不卡一区二区| 亚洲精品国产视频| 亚洲欧洲三级电影| 久久久精品国产免费观看同学| 欧美一区二区三区爱爱| 欧美视频中文字幕| 色综合久久99| 91麻豆精品在线观看| 成人av影院在线| 成人性生交大片免费看视频在线| 久久se精品一区精品二区| 日韩影院免费视频| 丝袜亚洲精品中文字幕一区| 亚洲制服欧美中文字幕中文字幕| 亚洲免费观看在线视频| 最近中文字幕一区二区三区| 中文字幕在线一区二区三区| 中文字幕乱码久久午夜不卡| 欧美xxxxx牲另类人与| 日韩一级欧美一级| 欧美一区二区三区啪啪| 欧美一区二区三区四区久久| 337p亚洲精品色噜噜狠狠| 欧美久久一二三四区| 欧美日韩亚洲综合在线| 欧美日本免费一区二区三区| 欧美日韩成人综合在线一区二区| 欧美男女性生活在线直播观看| 在线免费观看一区| 欧美乱妇20p| 欧美本精品男人aⅴ天堂| 久久青草国产手机看片福利盒子| 久久夜色精品一区| 日本一区二区电影| 亚洲精品成人悠悠色影视| 夜夜嗨av一区二区三区网页| 亚洲国产精品麻豆| 奇米777欧美一区二区| 激情亚洲综合在线| 成人av免费网站| 欧美日韩精品欧美日韩精品一 | 日韩精品免费专区| 麻豆传媒一区二区三区| 国产成人亚洲精品狼色在线| 91麻豆产精品久久久久久 | 老色鬼精品视频在线观看播放| 韩国三级中文字幕hd久久精品| 成人一区二区三区中文字幕| 91免费小视频| 日韩欧美亚洲另类制服综合在线| 国产亚洲精品7777| 亚洲免费观看高清完整版在线 | 久久综合99re88久久爱| 中文字幕在线一区| 午夜影院在线观看欧美| 国产精品一级片在线观看| 91高清视频在线| 日韩精品中文字幕一区二区三区 | 亚洲免费毛片网站| 久久国产综合精品| 成人免费毛片嘿嘿连载视频| 欧美在线free| 国产日韩欧美电影| 午夜私人影院久久久久| 国产成人高清视频| 欧美精品乱人伦久久久久久| 欧美激情中文字幕| 日本午夜一区二区| 972aa.com艺术欧美| 精品久久久影院| 亚洲综合在线视频| 狠狠色狠狠色合久久伊人| 色爱区综合激月婷婷| 久久婷婷成人综合色| 天天做天天摸天天爽国产一区 | 欧美一区二区三区日韩| 《视频一区视频二区| 国产一区二区三区四区五区美女| 欧美视频你懂的| 国产精品嫩草影院com| 免费在线观看日韩欧美| 色噜噜狠狠色综合欧洲selulu| 欧美国产国产综合| 丝袜a∨在线一区二区三区不卡| 国产精品18久久久久| 91精品国产一区二区| 亚洲视频一区二区免费在线观看| 麻豆精品一区二区三区| 精品视频在线免费| 亚洲天堂免费看| 国产精华液一区二区三区| 欧美电视剧免费观看| 丝袜诱惑制服诱惑色一区在线观看| 97se亚洲国产综合自在线| 国产日产亚洲精品系列| 久久激情综合网| 欧美一区二区福利视频| 亚洲成人激情社区| 色婷婷一区二区| 亚洲私人影院在线观看| 国产成a人无v码亚洲福利| 久久亚洲二区三区| 免费成人性网站| 91精品一区二区三区在线观看| 亚洲一区二区欧美| 欧美在线播放高清精品| 亚洲黄色性网站| 91丨porny丨首页| 18欧美亚洲精品| 91网上在线视频| 亚洲视频狠狠干| 色一区在线观看| 一区二区三区高清不卡| 欧美色综合久久| 亚洲综合图片区| 欧美日韩国产一级| 免费在线看一区| 2021久久国产精品不只是精品| 黄色资源网久久资源365| 久久久国产综合精品女国产盗摄| 国产一区在线不卡| 欧美高清在线精品一区| 不卡视频在线看| 亚洲免费大片在线观看| 日本道免费精品一区二区三区| 夜夜揉揉日日人人青青一国产精品| 欧美午夜精品一区二区蜜桃| 日日摸夜夜添夜夜添精品视频| 日韩一区二区三区观看| 国产一区二区免费视频| 国产精品国产精品国产专区不蜜 | 91免费版在线看| 午夜日韩在线电影| 日韩精品中文字幕在线一区| 国产大陆a不卡| 亚洲蜜臀av乱码久久精品| 欧美精品欧美精品系列| 麻豆精品国产传媒mv男同| 国产日韩欧美一区二区三区综合| 成人国产电影网| 亚洲成人精品在线观看| 欧美成人video| 一本色道久久综合亚洲精品按摩| 天堂va蜜桃一区二区三区 | 天堂久久久久va久久久久| 精品国产不卡一区二区三区| av亚洲精华国产精华精|