Echelon Neuron C Instrukcja Użytkownika Strona 71

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 268
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 70
Neuron C Programmer’s Guide 59
Example:
A lamp and switch example could also be written to use explicit polling of the
switch network variable. Complete programs illustrating polling are shown
below.
Listing 1. Lamp Program Using Polling
// LAMP.NC -- Sample lamp actuator program,
// polls the switch periodically
///////////////////// Network Variables ////////////////
network input SNVT_switch nviLampState;
//////////////////////// Constants /////////////////////
#define LED_ON 0
#define LED_OFF 1
/////////////////////// I/O Objects ////////////////////
IO_0 output bit ioLED = LED_OFF;
//////////////////////// Timers ////////////////////////
mtimer tmPoll;
/////////////////////////// Tasks //////////////////////
// NV update task -- handle update to lamp state
// Use the network variable’s value as the new
// state for the lamp
when (nv_update_occurs(nviLampState)) {
io_out(ioLED,
nviLampState.value && nviLampState.state
? LED_ON : LED_OFF);
tmPoll = 500; // Wait 500 msec before polling again
}
////////////////////////////////////////////////////////
// Reset and timer task
// request last value from any switch attached
when (reset) {
tmPoll = 4ul * random(); // >= 1 second
}
when (timer_expires(tmPoll) ) {
poll(nviLampState);
}
Listing 2. Switch Program Using Polling
// SWITCH.NC -- Sample switch sensor program
// Only transmits switch state when polled by the lamp
//////////////////// Network Variables ////////////////
network output polled SNVT_switch nvoSwitchState;
//////////////////////// Constants ////////////////////
#define BUTTON_DOWN 0
#define BUTTON_UP 1
/////////////////////// I/O Objects ////////////////////
Przeglądanie stron 70
1 2 ... 66 67 68 69 70 71 72 73 74 75 76 ... 267 268

Komentarze do niniejszej Instrukcji

Brak uwag