PIN Commands: Unterschied zwischen den Versionen

Aus Ethersex_Wiki
Wechseln zu: Navigation, Suche
(typo)
K
 
Zeile 1: Zeile 1:
Every [[control6]] srcipt must be started with `CONTROL_START' and ended with
+
Every [[Control6]] srcipt must be started with `CONTROL_START' and ended with
 
`CONTROL_END'. Within this body you can define various actions, which are
 
`CONTROL_END'. Within this body you can define various actions, which are
 
started with ACTION($action_name) and ended with ACTION_END($action_name),
 
started with ACTION($action_name) and ended with ACTION_END($action_name),
Zeile 5: Zeile 5:
  
 
Inside the action "tags" you add the code for the specific action. Outside of
 
Inside the action "tags" you add the code for the specific action. Outside of
all actions you can write down, how the [[control6]] script should react on
+
all actions you can write down, how the [[Control6]] script should react on
 
events. For example this piece of code, which is placed outside of all
 
events. For example this piece of code, which is placed outside of all
 
actions ( for this example you must enable clock support in your ethersex
 
actions ( for this example you must enable clock support in your ethersex
Zeile 20: Zeile 20:
 
starts the thread always new, when THREAD_RESTART is called.
 
starts the thread always new, when THREAD_RESTART is called.
  
A simple example, which may show you some features of Control6:
+
A simple example, which may show you some features of [[Control6]]:
  
 
<pre>
 
<pre>

Aktuelle Version vom 23. Juli 2011, 11:57 Uhr

Every Control6 srcipt must be started with `CONTROL_START' and ended with `CONTROL_END'. Within this body you can define various actions, which are started with ACTION($action_name) and ended with ACTION_END($action_name), here the $action_name must be replaced with an unique action identifier.

Inside the action "tags" you add the code for the specific action. Outside of all actions you can write down, how the Control6 script should react on events. For example this piece of code, which is placed outside of all actions ( for this example you must enable clock support in your ethersex firmware )

ON CLOCK_MIN == 5 DO THREAD_START(nice_gaudi) END

Here you see how to write such an event handler, this starts the thread `nice_thread', if the minute field of the time is exactly 5 (e.g. 05:05 or 23:05). But be aware of the THREAD_START command. This starts the thread only if it isn't started already. So this piece of code starts the action only the first time after startup ( if the action isn't stopped somewhere with THREAD_STOP). There ist also the possibility to use THREAD_RESTART, which starts the thread always new, when THREAD_RESTART is called.

A simple example, which may show you some features of Control6:

CONTROL_START
  
  PIN_INPUT(KEY)
  PIN_PULLUP(KEY)
  PIN_OUTPUT(LED)

  THREAD(nice_gaudi)
      TIMER_START(new)
      PIN_SET(LED);
      TIMER_WAIT(new, 20)
      PIN_CLEAR(LED);
  THREAD_END(nice_gaudi)

  ON CLOCK_MIN == 5 DO THREAD_RESTART(nice_gaudi) END
  ON PIN_FALLING(KEY) DO THREAD_RESTART(nice_gaudi) END

CONTROL_END
  • The typical CONTROL_START, CONTROL_END enclose the Control6 scripts
  • the pin commands:
    • the names PIN_INPUT and the other PIN_* refers to are the same, which are defined in pinning/*.m4. You also may to add your pins there.
    • PIN_INPUT defines the KEY pin as an input pin (DDRx is set correctly)
    • PIN_PULLUP enabled the pullup for the KEY pin (PORTx is set correctly)
    • PIN_OUTPUT defines the LED pin as an output pin (DDRx is set correctly)
    • PIN_FALLING(KEY) is an event, which is always triggered if there is an falling edge on the pin KEY. Corresponding to PIN_FALLING, PIN_RISING does also exists.
  • THREAD, THREAD_END define a new thread `nice_gaudi' within this thread there is a timer started ( the first call of TIMER_START creates this timer also, the creation of a timer can also be done with TIMER_NEW). After the timer is started the LED key is enabled.
  • The TIMER_WAIT waits, until the created timer has reaced 20 seconds. After that the LED is cleared again. Be aware of the ; at the end of PIN_SET, PIN_CLEAR. This is because this lines are not interpreted with m4, but are plain C code (CPP macros)
  • The two ON commands start the thread nice_gaudi either when the clock minute field is 5 ( be aware of the RESTART ) or the KEY pin has an falling edge.