⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ledsp.nc

📁 Develop Zigbee network real-time Os
💻 NC
字号:
/*                                  tab:4 * "Copyright (c) 2000-2005 The Regents of the University  of California.   * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. *  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." *//** * The implementation of the standard 3 LED mote abstraction. * * @author Joe Polastre * @author Philip Levis * * @date   March 21, 2005 */module LedsP {  provides {    interface Init;    interface Leds;  }  uses {    interface GeneralIO as Led0;    interface GeneralIO as Led1;    interface GeneralIO as Led2;    interface GeneralIO as Led3;  }}implementation {  command error_t Init.init() {    atomic {      dbg("Init", "LEDS: initialized.\n");      call Led0.makeOutput();      call Led1.makeOutput();      call Led2.makeOutput();      call Led3.makeOutput();      call Led0.clr();      call Led1.clr();      call Led2.clr();      call Led3.clr();    }    return SUCCESS;  }  /* Note: the call is inside the dbg, as it's typically a read of a volatile     location, so can't be deadcode eliminated */#define DBGLED(n) \  dbg("LedsC", "LEDS: Led" #n " %s.\n", call Led ## n .get() ? "off" : "on");  async command void Leds.led0On() {    call Led0.set();    DBGLED(0);  }  async command void Leds.led0Off() {    call Led0.clr();    DBGLED(0);  }  async command void Leds.led0Toggle() {    call Led0.toggle();    DBGLED(0);  }  async command void Leds.led1On() {    call Led1.set();    DBGLED(1);  }  async command void Leds.led1Off() {    call Led1.clr();    DBGLED(1);  }  async command void Leds.led1Toggle() {    call Led1.toggle();    DBGLED(1);  }  async command void Leds.led2On() {    call Led2.clr();    DBGLED(2);  }  async command void Leds.led2Off() {    call Led2.set();    DBGLED(2);  }  async command void Leds.led2Toggle() {    call Led2.toggle();    DBGLED(2);  }  async command void Leds.led3On() {    call Led3.clr();    DBGLED(3);  }  async command void Leds.led3Off() {    call Led3.set();    DBGLED(3);  }  async command void Leds.led3Toggle() {    call Led3.toggle();    DBGLED(3);  }  async command uint8_t Leds.get() {    uint8_t rval;    atomic {      rval = 0;      if (!call Led0.get()) {    rval |= LEDS_LED0;      }      if (!call Led1.get()) {    rval |= LEDS_LED1;      }      if (!call Led2.get()) {    rval |= LEDS_LED2;      }      if (!call Led3.get()) {    rval |= (1 << 3);      }    }    return rval;  }  async command void Leds.set(uint8_t val) {    atomic {      if (val & LEDS_LED0) {    call Leds.led0On();      }      else {    call Leds.led0Off();      }      if (val & LEDS_LED1) {    call Leds.led1On();      }      else {    call Leds.led1Off();      }      if (val & LEDS_LED2) {    call Leds.led2On();      }      else {    call Leds.led2Off();      }      if (val & (1 << 3)) {    call Leds.led3On();      }      else {    call Leds.led3Off();      }    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -