# functions

ident: SEL
name: Mode Selector
created_at: 2016-06-16 11:08:25.733501
updated_at: 2017-02-17 17:38:21.333725
description:
  This functionality converts the user Requests into mode selectors.  So, it decides at every moment if the UP or DOWN functionality is executed.


ident: CTRL
name: Servo Control
created_at: 2016-06-16 11:11:15.249028
updated_at: 2017-02-17 17:38:54.542635
description:
  This functionality calculates the action to be performed on the actuator in order to achieve the selected mode (UP/DOWN functionalities enabled).


# function_types

name: Control realimentado sencillo
created_at: 2013-03-04 21:22:06.579975
updated_at: 2013-03-04 21:22:06.579975
description:
  Control sencillo que toma una señal para realimentarse, el algoritmo de control es sencillo (PID o inferior sin saturadores complicados).


name: Algoritmo FSM Complejo
created_at: 2013-03-04 21:24:34.434432
updated_at: 2013-03-04 21:32:06.327279
description:
  Algoritmo secuencial que requerirá un uso intensivo de autómatas y muchas entradas y salidas así como controles realimentados de otros dispositivos.


# state_machines

name: ActEnabler
created_at: 2016-06-16 11:34:00.364627
updated_at: 2017-02-17 18:00:01.833430
graphviz_size: &amp;chs=500x500
graphviz_link:
  ?cht=gv:neato&amp;chl=digraph{edge[fontsize=10];fontsize=11;nodesep=1;ranksep=1;sep=1;overlap=scale;


name: ActRectifier
created_at: 2016-06-16 15:13:23.615824
updated_at: 2017-02-17 18:02:50.576940
graphviz_size: &amp;chs=600x500
graphviz_link:
  ?cht=gv:neato&amp;chl=digraph{edge[fontsize=10];fontsize=11;nodesep=1;ranksep=1;sep=2;overlap=scale;


name: ActDriving
created_at: 2016-06-16 16:29:09.514681
updated_at: 2017-02-17 19:19:08.371244
graphviz_size: &amp;chs=600x500
graphviz_link:
  ?cht=gv:neato&amp;chl=digraph{edge[fontsize=10];fontsize=11;nodesep=1;ranksep=2;sep=1;overlap=scale;


# state_machine_states

name: DISSIPATE
initial: f
final: f
created_at: 2016-06-16 16:45:08.735781
updated_at: 2016-06-16 16:45:08.735781
description:
  The actuation was working (different from quiet) and the system has been told to change direction or stop.  The control will wait here for current dissipation in the devices involved in the commutation.


# state_machine_transitions

name: dirChangeDuringStab
created_at: 2016-06-16 18:44:32.791936
updated_at: 2017-03-06 20:30:26.207450
description:
  A new direction arrived during stabilization, the new direction has to be applied and the stab time has to be resetted.


name: cancel
created_at: 2017-02-20 21:02:24.892635
updated_at: 2017-03-06 20:39:08.818956
description:
  By selecting UP, the DOWN is cancelled and the the system will wait for no request before accepting another request.


name: cancel
created_at: 2017-02-20 21:07:53.559291
updated_at: 2017-03-06 20:38:56.913366
description:
  By selecting DOWN, the UP is cancelled and the the system will wait for no request before accepting another request.


# state_machine_conditions

name: stabTimeExpiredToMove
implementation: (actDirection!=CFG_ACT_DIRECTION_QUIET) && (actDrvTimer>=CFG_%PREFIX%_ACT_DRIVER_STAB_TIME)
created_at: 2016-06-16 20:22:16.651442
updated_at: 2017-03-07 14:09:10.036051
short_name: stbTimExp2Mv
description:
  The timer to control the stabilization stage of the actuator driver has expired, and the action is not to be quiet.


name: stabTimeExpiredToStop
description: The stabilization time expired and the desired actuator direction is QUIET
created_at: 2016-06-16 20:34:08.063490
updated_at: 2017-03-07 14:09:35.242058
short_name: stbTimExp2Stop
implementation:
  (actDirection==CFG_ACTUATOR_DIRECTION_QUIET) && (actrDrvTimer>=CFG_%PREFIX%_ACTUATOR_DRIVER_STAB_TIME)


name: expiredTimeUpButtonPressed
description: The Up button is being pressed more than a given time
created_at: 2017-02-17 23:37:22.005563
updated_at: 2017-03-07 14:11:23.656687
short_name: timUpPress
implementation:
  ((upReqDI==TRUE) || (hmibuttons & CFG_%PREFIX%_BUTACQ_HMI_UP_MASK)) && (upButTimer > CFG_%PREFIX%_UP_BUT_PRESS_TIMER)


name: expiredTimeUpButtonNotPressed
description: The Up button is not being pressed during a given time.
created_at: 2017-02-17 23:38:16.983604
updated_at: 2017-03-07 14:11:39.639934
short_name: timUpNotPress
implementation:
  ((upReqDI==FALSE) && !(hmibuttons & CFG_%PREFIX%_BUTACQ_HMI_UP_MASK)) && (upButTimer > CFG_%PREFIX%_UP_BUT_UNPRESS_TIMER)


name: expiredTimeDownButtonPressed
description: The Down button is being pressed more than a given time
created_at: 2017-02-18 00:20:14.483522
updated_at: 2017-03-07 14:12:38.120984
short_name: timDwnPress
implementation:
  ((downReqDI==TRUE) || (hmibuttons & CFG_%PREFIX%_BUTACQ_HMI_DOWN_MASK)) && (downButTimer > CFG_%PREFIX%_DWN_BUT_PRESS_TIMER)


name: expiredTimeDownButtonNotPressed
description: The Down button is not being pressed during a given time.
created_at: 2017-02-18 00:22:14.727400
updated_at: 2017-03-07 14:12:52.508691
short_name: timDwnNotPress
implementation:
  ((downReqDI==FALSE) && !(hmibuttons & CFG_%PREFIX%_BUTACQ_HMI_DOWN_MASK)) && (downButTimer > CFG_%PREFIX%_DWN_BUT_UNPRESS_TIMER)


# state_machine_actions

name: goSleepActions
created_at: 2013-04-27 01:22:39.418539
updated_at: 2013-04-27 01:22:39.418539
short_name: goSleep
description:
  VARIABLES BCM: 
  User_ID:0 
  statusBCM: 0 
  MENSAJES CAN Confort: 
  Ninguno 
  Salidas BCM 
  Power DIM: OFF (Modulo DIM no operativa). 
  Power BOT: OFF (Botonera no operativa) 
  Ignition _BMS: OFF (Batería 60 V no operativa) 
  Main_SW: OFF (Conversor DC/DC (KL15) no operativo) 
  Ready_on: OFF. (DM no operativo y Sistema de plegado operativo pero no alimentado ya que no hay KL15) 

implementation:
  userId=0;
  statusBCM=0;
  OUT_POWER_DIM=FALSE;
  OUT_POWER_BOT=FALSE;
  OUT_IGNITION_BMS=FALSE;
  OUT_MAIN_SW=FALSE;
  READY_ON=FALSE;


name: goKL30Actions
created_at: 2013-04-27 01:33:56.978082
updated_at: 2013-04-27 01:51:21.367141
short_name: goKL30
description:
  VARIABLES BCM: 
  User_ID: 0 o 1 
  statusBCM: 1 
  MENSAJES CAN Confort: 
  Por definir 
  Salidas BCM 
  Power DIM: OFF (Modulo DIM no operativa). 
  Power BOT: OFF (Botonera no operativa) 
  Ignition _BMS: OFF (Batería 60 V no operativa) 
  Main_SW: OFF (Conversor DC/DC (KL15) no operativo) 
  Ready_on: OFF. (DM no operativo y Sistema de plegado operativo pero no alimentado ya que no hay KL15) 

implementation:
  userId=0; 
  statusBCM=1; 
  OUT_POWER_DIM=FALSE; 
  OUT_POWER_BOT=FALSE; 
  OUT_IGNITION_BMS=FALSE; 
  OUT_MAIN_SW=FALSE; 
  READY_ON=FALSE; 


name: goOpenActions
created_at: 2013-04-27 01:40:50.099907
updated_at: 2013-04-27 02:05:21.232593
short_name: goOpen
description:
  VARIABLES BCM: 
  User_ID:1 
  statusBCM: 2 
  MENSAJES CAN Confort: 
  Por definir 
  Salidas BCM 
  Power DIM: ON (Modulo DIM operativo). 
  Power BOT: ON (Botonera operativa) 
  Ignition _BMS: OFF (Batería 60 V no operativa) 
  Main_SW: OFF (Conversor DC/DC (KL15) no operativo) 
  Ready_on: OFF. (DM no operativo y Sistema de plegado operativo pero no alimentado ya que no hay KL15) 

implementation:
  userId=1;
  statusBCM=2; 
  OUT_POWER_DIM=TRUE; 
  OUT_POWER_BOT=TRUE; 
  OUT_IGNITION_BMS=FALSE; 
  OUT_MAIN_SW=FALSE; 
  READY_ON=FALSE;


name: goKL15Actions
created_at: 2013-04-27 01:52:39.782240
updated_at: 2013-04-27 01:52:39.782240
short_name: goKL15
description:
  VARIABLES BCM: 
  User_ID:1 
  statusBCM: 3 
  MENSAJES CAN Confort 
  Por definir 
  Salidas BCM 
  Power DIM : ON (Modulo DIM operativo) 
  Power BOT : ON (Botonera operativa) 
  Ignition _BMS: OFF (Batería 60 V no operativa) 
  Main_SW: OFF(Conversor DC/DC no operativo) 
  Ready_on: OFF. (DM no operativo y sistema de plegado operativo pero con su funcionalidad inhabilitada). 

implementation:
  userId=1; 
  statusBCM=3; 
  OUT_POWER_DIM=TRUE; 
  OUT_POWER_BOT=TRUE; 
  OUT_IGNITION_BMS=TRUE; 
  OUT_MAIN_SW=FALSE; 
  READY_ON=FALSE;


name: goDriveActions
created_at: 2013-04-27 01:56:54.888767
updated_at: 2013-04-27 01:56:54.888767
short_name: goDrive
description:
  VARIABLES BCM: 
  User_ID:1 
  statusBCM: 5 
  MENSAJES CAN Confort 
  Por definir 
  Salidas BCM 
  Power DIM: ON (Modulo DIM operativo). 
  Power BOT: ON (Botonera operativa) 
  Ignition _BMS: ON (Batería 60 V operativa) 
  Main_SW: ON (Conversor DC/DC (KL15) operativo) 
  Ready_on: ON (DM operativo y sistema de plegado no operativo) 

implementation:
  userId=1;
  statusBCM=5;
  OUT_POWER_DIM=TRUE;
  OUT_POWER_BOT=TRUE;
  OUT_IGNITION_BMS=TRUE;
  OUT_MAIN_SW=TRUE;
  READY_ON=TRUE;


name: goChargeActions
created_at: 2013-04-27 02:02:03.445739
updated_at: 2013-04-27 02:02:03.445739
short_name: goCharge
description:
  VARIABLES BCM: 
  User_ID:0/1 
  statusBCM: 5 
  MENSAJES CAN Confort 
  Por definir 
  Salidas BCM: 
  Power DIM: ON (Modulo DIM operativo) 
  Power BOT: ON (Botonera operativa) 
  Ignition _BMS: OFF(Batería 60 V no operativa) 
  Main_SW: ON (Conversor DC/DC (KL15) operativo, para cargar la batería aux de 12V) 
  Ready_on: OFF. (DM no operativo y sistema de plegado no operativo) 

implementation:
  userId=1;
  statusBCM=5;
  OUT_POWER_DIM=TRUE;
  OUT_POWER_BOT=TRUE;
  OUT_IGNITION_BMS=FALSE;
  OUT_MAIN_SW=TRUE;
  READY_ON=FALSE;


name: setActuationModule
description: The actuation output must equal the module of the actuation request.
created_at: 2016-06-16 11:25:58.463608
updated_at: 2017-02-17 21:06:11.925612
short_name: setActMod
implementation:
  if (actAction>=0){
    rectifiedActAction=(t_pwm)actAction;
  } else {
    rectifiedActAction=(t_pwm)(-actAction);
  }


# flow_types

name: DIO
created_at: 2013-04-10 06:09:03
updated_at: 2017-03-07 13:54:35.510516
c_type: BOOL
enable_input: true
enable_output: true
arg_by_reference: false
custom_type: false
phantom_type: f
is_float: f
is_symbol: f
c_input_patron:
  %CTYP% acquire_%PREFIX%%FLOW%(void){ 
  #ifdef _DIAG_ACTIVE
  	if (diag%PREFIX%.enable_%FLOW%==TRUE) {
  		return diag%PREFIX%.%FLOW%;
  	} else {
  #endif
  		return %TYP%_read(PORT_%PREFIX%%FLOW%,value); 
  #ifdef _DIAG_ACTIVE
  	}
  #endif
  };

c_output_patron:
  void synthesize_%PREFIX%%FLOW%(%CTYP% %REF%value){ 
  #ifdef _DIAG_ACTIVE
  	if (diag%PREFIX%.enable_%FLOW%==TRUE) {
  		%TYP%_write(PORT_%PREFIX%%FLOW%,diag%PREFIX%.%FLOW%); 
  	} else {
  #endif
  	%TYP%_write(PORT_%PREFIX%%FLOW%,value); 
  #ifdef _DIAG_ACTIVE
  	}
  #endif
  };


name: ADC
created_at: 2013-04-10 06:09:03
updated_at: 2017-03-07 13:54:51.569011
c_type: UI_10
enable_input: true
enable_output: f
arg_by_reference: false
custom_type: false
phantom_type: f
is_float: f
is_symbol: f
c_input_patron:
  %CTYP% acquire_%PREFIX%%FLOW%(void){ 
  	return %TYP%_read(CANAL_%PREFIX%%FLOW%K,PORT_%PREFIX%%FLOW%); 
  };


name: PWM
created_at: 2013-04-10 06:09:03
updated_at: 2017-03-07 13:55:07.409407
enable_input: f
enable_output: true
arg_by_reference: f
custom_type: false
phantom_type: f
is_float: f
is_symbol: f
c_output_patron:
  void synthesize_%PREFIX%%FLOW%(%CTYP% value){ 
  	%TYP%_write(PORT_%PREFIX%%FLOW%, CANAL_%PREFIX%%FLOW%, value); 
  };


name: CAN_signal
created_at: 2013-04-10 06:09:03
updated_at: 2017-03-07 13:55:33.559327
enable_input: true
enable_output: true
arg_by_reference: t
custom_type: t
phantom_type: f
is_float: f
is_symbol: f
c_input_patron:
  BOOL acquire_%PREFIX%%FLOW%(%CTYP% %REF%value){ 
  	return %TYP%_read(MENSAJE%PREFIX%_%FLOW%,SENYAL_%PREFIX%%FLOW%,value,sizeof(%CTYP%)); 
  };

c_output_patron:
  void synthesize_%PREFIX%%FLOW%(%CTYP% %REF%value){ 
  	%TYP%_write(MENSAJE_%PREFIX%%FLOW%, SENYAL_%PREFIX%%FLOW%, value,sizeof(%CTYP%)); 
  };"


name: DIO_Signal
created_at: 2014-05-22 17:38:18.314654
updated_at: 2017-03-07 13:56:17.164567
enable_input: t
enable_output: t
arg_by_reference: f
custom_type: t
phantom_type: f
is_float: f
is_symbol: f
c_input_patron:
  %CTYP% acquire_%PREFIX%%FLOW%(){ 
  	return %TYP%_read(PORT_%PREFIX%%FLOW%,MASK_%PREFIX%%FLOW%); 
  };

c_output_patron:
  void synthesize_%PREFIX%%FLOW%(%CTYP% value){ 
  	%TYP%_write(PORT_%PREFIX%%FLOW%, MASK_%PREFIX%%FLOW%, value); 
  };"


name: message
created_at: 2014-05-22 18:07:22.453082
updated_at: 2017-03-07 13:56:48.371192
enable_input: t
enable_output: t
arg_by_reference: t
custom_type: f
phantom_type: f
is_float: f
is_symbol: f
c_input_patron:
  BOOL acquire_%PREFIX%%FLOW%(%CTYP% %REF%value, %CTYP%_length buffer_length, %CTYP%_length %REF%read_length){ 
  	return %TYP%_read(MSGPORT_%PREFIX%%FLOW%,SENYAL_%PREFIX%%FLOW%,value,sizeof(%CTYP%)*length,read_length); 
  };

c_output_patron:
  %CTYP%_length  synthesize_%PREFIX%%FLOW%(%CTYP% %REF%value, %CTYP%_length length){ 
  	return %TYP%_write(MENSAJE_%PREFIX%%FLOW%, SENYAL_%PREFIX%%FLOW%, value,sizeof(%CTYP%)); 
  };"


name: DI_pu
created_at: 2016-02-12 16:44:35.927980
updated_at: 2017-03-07 13:57:08.021809
c_type: BOOL
enable_input: t
enable_output: f
arg_by_reference: f
custom_type: f
phantom_type: f
is_float: f
is_symbol: f
c_input_patron:
  %CTYP% acquire_%PREFIX%%FLOW%(void){ 
  #ifdef _DIAG_ACTIVE 
  if (diag%PREFIX%.enable_%FLOW%==TRUE) { 
  return diag%PREFIX%.%FLOW%; 
  } else { 
  #endif 
  return %TYP%_read(PORT_%PREFIX%%FLOW%,value); 
  #ifdef _DIAG_ACTIVE 
  } 
  #endif 
  };


name: DO
created_at: 2018-03-03 19:10:06.769210
updated_at: 2018-03-03 19:10:06.769210
c_type: BOOL
enable_input: f
enable_output: t
arg_by_reference: f
custom_type: f
phantom_type: f
is_float: f
is_symbol: f
c_output_patron:
  void synthesize_%PREFIX%%FLOW%(%CTYP% %REF%value){ 
  #ifdef _DIAG_ACTIVE 
  if (diag%PREFIX%.enable_%FLOW%==TRUE) { 
  %TYP%_write(PORT_%PREFIX%%FLOW%,diag%PREFIX%.%FLOW%);
  } else { 
  #endif 
  %TYP%_write(PORT_%PREFIX%%FLOW%,value); 
  #ifdef _DIAG_ACTIVE 
  } 
  #endif 
  };


name: Sonar
created_at: 2018-03-05 20:15:56.722048
updated_at: 2018-03-07 01:46:39.099131
c_type: t_sonar
enable_input: t
enable_output: f
arg_by_reference: t
custom_type: f
phantom_type: f
is_float: f
is_symbol: f
c_input_patron:
  // %PREFIX%%FLOW% flow acquisition
  void acquire_%PREFIX%%FLOW%(void){
  #ifdef _DIAG_ACTIVE
    if (diag.enable_%PREFIX%%FLOW%==TRUE) {
      dre.%PREFIX%%FLOW%.duration = diag.%PREFIX%%FLOW%.duration;
    } else {
  #endif
      if (dre.%PREFIX%%FLOW%.duration != dre.%PREFIX%%FLOW%._duration){
  #ifdef CFG_DBG_SONAR_DURATION_%PREFIX%%FLOW%
        Serial.print("%PREFIX%%FLOW%: ");Serial.println(dre.%PREFIX%%FLOW%._duration);
  #endif
      dre.%PREFIX%%FLOW%.duration = dre.%PREFIX%%FLOW%._duration;
      }
  #ifdef _DIAG_ACTIVE
    }
  #endif
  };
  void reset_sonar_%PREFIX%%FLOW%(void){
    if (dre.%PREFIX%%FLOW%.pingPending == TRUE){
      // TIMEOUT
      dre.%PREFIX%%FLOW%._duration = 0L;
    #ifdef CFG_DBG_SONAR_TIMEOUT_%PREFIX%%FLOW%
      Serial.println("** TIMEOUT %PREFIX%%FLOW% **");
    #endif
    }
    dre.%PREFIX%%FLOW%.pingPending = TRUE;
  }

c_setup_input_patron:
  // %PREFIX%%FLOW% flow acquisition
  void setup_%PREFIX%%FLOW%(void){
    // declared volatile because used in two different places
    dre.%PREFIX%%FLOW%.echoTime = 0L;
    dre.%PREFIX%%FLOW%.duration = 0L;

    // setup for the HC-SR04 sensor
    pinMode(PORT_%PREFIX%%FLOW%, INPUT);
    // setup callacbk for the echo signal from the HC-SR04 sensor
    attachInterrupt(PORT_%PREFIX%%FLOW%, echo_interrupt_%PREFIX%%FLOW%, CHANGE);
   }
   void echo_interrupt_%PREFIX%%FLOW%()
   {
     switch (digitalRead(PORT_%PREFIX%%FLOW%))
     {
       case HIGH: // start of the echo pulse
         dre.%PREFIX%%FLOW%.pingTime = micros();
         break;
       case LOW: // end of the echo pulse
         dre.%PREFIX%%FLOW%.echoTime = micros();
         dre.%PREFIX%%FLOW%._duration = dre.%PREFIX%%FLOW%.echoTime - dre.%PREFIX%%FLOW%.pingTime;
         dre.%PREFIX%%FLOW%.pingPending = FALSE;
         break;
     }
   }


name: Trigger
created_at: 2018-03-07 01:03:37.900349
updated_at: 2018-03-08 20:35:58.132648
c_type: t_trigger
enable_input: f
enable_output: t
arg_by_reference: f
custom_type: f
phantom_type: f
is_float: f
is_symbol: f
c_output_patron:
  void synthesize_%PREFIX%%FLOW%(void){
    if (millis() >= dre.%PREFIX%%FLOW%.pingTimer) {
     reset_sonar_%PREFIX%%FLOW%();
      dre.%PREFIX%%FLOW%.pingTimer += CFG_%PREFIX%%FLOW%_PERIOD_mS;
      // trigger a distance measurement
      digitalWrite(PORT_%PREFIX%%FLOW%, HIGH);
      delayMicroseconds(CFG_%PREFIX%%FLOW%_WIDTH_uS);
      digitalWrite(PORT_%PREFIX%%FLOW%, LOW);
    }
  }

c_setup_output_patron:
  void setup_%PREFIX%%FLOW%(void){ 
    dre.%PREFIX%%FLOW%.pingTimer = CFG_%PREFIX%%FLOW%_PERIOD_mS;
    digitalWrite(PORT_%PREFIX%%FLOW%,LOW);
    pinMode(PORT_%PREFIX%%FLOW%,OUTPUT);; 
  } 


name: LaserEnab
created_at: 2018-03-08 17:42:49.523791
updated_at: 2018-04-30 18:00:12.588010
c_type: t_laser
enable_input: t
enable_output: f
arg_by_reference: f
custom_type: f
phantom_type: f
is_float: f
is_symbol: f
c_input_patron:
  void acquire_%PREFIX%%FLOW%(void){
    if (millis() >= dre.%PREFIX%%FLOW%.readPeriod) {
      dre.%PREFIX%%FLOW%.readPeriod += CFG_%PREFIX%%FLOW%_PERIOD_mS;
      dre.%PREFIX%%FLOW%._duration = dre.%PREFIX%%FLOW%.sensor.readRangeContinuousMillimeters();
      if (dre.%PREFIX%%FLOW%.sensor.timeoutOccurred()) { 
  #ifdef CFG_DBG_LASER_TIMEOUT_%PREFIX%%FLOW%
        Serial.println("%PREFIX%%FLOW%: TIMEOUT --- ");
  #endif
        dre.%PREFIX%%FLOW%._duration = 0L;
      }
    }
  #ifdef _DIAG_ACTIVE
    if (diag.enable_%PREFIX%%FLOW%==TRUE) {
        dre.%PREFIX%%FLOW%.duration = diag.%PREFIX%%FLOW%.duration;
    } else {
  #endif
      if (dre.%PREFIX%%FLOW%.duration != dre.%PREFIX%%FLOW%._duration){
  #ifdef CFG_DBG_LASER_DURATION_%PREFIX%%FLOW%
        Serial.print("%PREFIX%%FLOW%: ");Serial.println(dre.%PREFIX%%FLOW%._duration);
  #endif
      dre.%PREFIX%%FLOW%.duration = dre.%PREFIX%%FLOW%._duration;
      }
  #ifdef _DIAG_ACTIVE
    }
  #endif
  };

c_setup_input_patron:
  void setup_%PREFIX%%FLOW%(void){
    dre.%PREFIX%%FLOW%.sensor.setTimeout(CFG_%PREFIX%%FLOW%_TIMEOUT);
    dre.%PREFIX%%FLOW%.readPeriod = CFG_%PREFIX%%FLOW%_PERIOD_mS;
    dre.%PREFIX%%FLOW%.sensor.startContinuous();
  }

  void setup_%PREFIX%%FLOW%_id(void){
    dre.%PREFIX%%FLOW%._duration= 0L;
    dre.%PREFIX%%FLOW%.duration = 0L;
  #ifdef CFG_USE_PCF8575
    pcf8575.write(PORT_%PREFIX%%FLOW%, HIGH);
  #else
    pinMode(PORT_%PREFIX%%FLOW%,INPUT);
  #endif
    delay(10);
    dre.%PREFIX%%FLOW%.sensor.setAddress(CFG_%PREFIX%%FLOW%_ID);
    dre.%PREFIX%%FLOW%.sensor.init();
  }
  void setup_%PREFIX%%FLOW%_boot(void){
  #ifdef CFG_USE_PCF8575
    pcf8575.write(PORT_%PREFIX%%FLOW%, LOW);
  #else
    digitalWrite(PORT_%PREFIX%%FLOW%,LOW);
    pinMode(PORT_%PREFIX%%FLOW%,OUTPUT);
  #endif
  }


name: OctoSonarInt
created_at: 2018-04-17 16:34:11.886781
updated_at: 2018-04-30 17:52:59.349682
c_type: t_octosonar
enable_input: t
enable_output: f
arg_by_reference: f
custom_type: f
phantom_type: f
is_float: f
is_symbol: f
c_input_patron:
  void acquire_%PREFIX%%FLOW%(void){
    OctoSonar::doSonar();  // call every cycle, OctoSonar handles the spacing
    for (uint8_t i = 0; i < CFG_OCTOSONAR_SIZE; i++) {
      if ((1 << i) & PORT_%PREFIX%%FLOW%_ACTIVE_SONARS) {
        dre.%PREFIX%%FLOW%.values[i] = dre.%PREFIX%%FLOW%.octo->read(i);
  #ifdef CFG_DBG_OCTOSONAR
        if (dre.%PREFIX%%FLOW%.last_debug_print + PORT_%PREFIX%%FLOW%_DBG_PERIOD < millis()) { 
          Serial.print(i);Serial.print(":");Serial.print(dre.%PREFIX%%FLOW%.values[i]); Serial.print("   ");
        }
  #endif
      }
  #ifdef CFG_DBG_OCTOSONAR
    if (dre.%PREFIX%%FLOW%.last_debug_print + PORT_%PREFIX%%FLOW%_DBG_PERIOD < millis()) {   // serial output every 200ms
        Serial.println(".");
        dre.%PREFIX%%FLOW%.last_debug_print = millis();
    }
  #endif
    }
  }

c_setup_input_patron:
  void setup_%PREFIX%%FLOW%(void){ 
    /* You should declare 'octo_%PREFIX%%FLOW%' in your input module, like this:
    OctoSonar octo_%PREFIX%%FLOW%(PORT_%PREFIX%%FLOW%_I2CADDR, PORT_%PREFIX%%FLOW%_INT);  // Or OctoSonarX2
     */
    /* and add the external declaration in the ProjectFlows.h */
    dre.%PREFIX%%FLOW%.octo = &octo_%PREFIX%%FLOW%;
    /* Declare 'PORT_%PREFIX%%FLOW%_ACTIVE_SONARS' and 'PORT_%PREFIX%%FLOW%_INT' 
    in ProjectFlows.h */
    /* In ProjectTypes.h you should declare the t_octosonar like this: 
    typedef struct{
      OctoSonar *octo;  // Or OctoSonarX2
      uint16_t values[CFG_OCTOSONAR_SIZE];
  #ifdef CFG_DBG_OCTOSONAR
      uint32_t last_debug_print = 0;
  #endif
    }t_octosonar;
  */
    /* In project_variants.h you should declare constants like this:
    #define CFG_USE_OCTOSONAR
    #define CFG_DBG_OCTOSONAR
    #define CFG_OCTOSONAR_SIZE 8 // Or 16 if using OctoSonarX2
  */
    dre.%PREFIX%%FLOW%.octo->begin(PORT_%PREFIX%%FLOW%_ACTIVE_SONARS);
    pinMode(PORT_%PREFIX%%FLOW%_INT,INPUT);
  } 


# flow_type_targets

c_type: BOOL
enable_input: t
enable_output: t
arg_by_reference: f
custom_type: f
phantom_type: f
created_at: 2014-06-03 00:18:03.853426
updated_at: 2018-04-30 18:07:57.599858
c_setup_input_patron:
  void setup_%PREFIX%%FLOW%_input(void){
  pinMode(PORT_%PREFIX%%FLOW%, INPUT);
  };

c_setup_output_patron:
  void setup_%PREFIX%%FLOW%_output(void){
  pinMode(PORT_%PREFIX%%FLOW%, OUTPUT);
  };

c_input_patron:
  %CTYP% acquire_%PREFIX%%FLOW%(void){ 
  #ifdef _DIAG_ACTIVE 
  if (diag%PREFIX%.enable_%FLOW%==TRUE) { 
  return diag%PREFIX%.%FLOW%; 
  } else { 
  #endif 
  return digitalRead(PORT_%PREFIX%%FLOW%); 
  #ifdef _DIAG_ACTIVE 
  } 
  #endif 
  };

c_output_patron:
  void synthesize_%PREFIX%%FLOW%(%CTYP% %REF%valor){ 
  #ifdef _DIAG_ACTIVE 
  if (diag%PREFIX%.enable_%FLOW%==TRUE) { 
  digitalWrite(PORT_%PREFIX%%FLOW%,diag%PREFIX%.%FLOW%); 
  } else { 
  #endif 
  digitalWrite(PORT_%PREFIX%%FLOW%,valor); 
  #ifdef _DIAG_ACTIVE 
  } 
  #endif 
  };


c_output_patron:
  void synthesize_%PREFIX%%FLOW%(%CTYP% value){
  analogWrite(PORT_%PREFIX%%FLOW%, value);
  };

enable_input: f
enable_output: t
arg_by_reference: f
custom_type: f
phantom_type: f
created_at: 2017-02-02 12:55:17.766198
updated_at: 2017-03-07 13:49:10.376736
c_setup_output_patron:
  void setup_%PREFIX%%FLOW%(void){ 
  #ifndef _PWM_RES_SET_
  #define _PWM_RES_SET_
  analogWriteResolution(CFG_PWM_RESOLUTION);
  #endif
  analogWriteFrequency(PORT_%PREFIX%%FLOW%, PORT_%PREFIX%%FLOW%_FREQ);
  };


c_type: BOOL
enable_input: t
enable_output: f
arg_by_reference: f
custom_type: f
phantom_type: f
created_at: 2018-03-03 19:14:24.180850
updated_at: 2018-04-30 18:07:16.313556
c_setup_input_patron:
  void setup_%PREFIX%%FLOW%(void){
  pinMode(PORT_%PREFIX%%FLOW%,INPUT);
  };

c_input_patron:
  %CTYP% acquire_%PREFIX%%FLOW%(void){ 
  #ifdef _DIAG_ACTIVE 
  if (diag%PREFIX%.enable_%FLOW%==TRUE) { 
  return diag%PREFIX%.%FLOW%; 
  } else { 
  #endif 
  return digitalRead(PORT_%PREFIX%%FLOW%); 
  #ifdef _DIAG_ACTIVE 
  } 
  #endif 
  };


