summaryrefslogtreecommitdiff
path: root/OpenModelica-Arduino-MDD-Windows
diff options
context:
space:
mode:
Diffstat (limited to 'OpenModelica-Arduino-MDD-Windows')
-rw-r--r--OpenModelica-Arduino-MDD-Windows/Arduino.mo1783
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_bothbin0 -> 10112 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_both.hex121
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_both_main.c217
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clockbin0 -> 9328 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clock.hex94
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clock_main.c213
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_loop_main.c235
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_both.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_clock.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_loop.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldrbin0 -> 9368 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_ledbin0 -> 9900 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_led.hex120
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_led_main.c243
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_readbin0 -> 9676 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_read.hex110
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_read_main.c226
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/run_ldr_led.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/run_ldr_read.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blinkbin0 -> 9876 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blink.hex114
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blink_main.c253
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_bluebin0 -> 9280 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue.hex91
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delaybin0 -> 9608 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delay.hex100
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delay_main.c212
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_main.c212
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_redbin0 -> 9688 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_red.hex106
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_red_main.c215
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_binkbin0 -> 10188 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blinkbin0 -> 10188 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blink.hex127
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blink_main.c212
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blink.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue_delay.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue_red.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_green_blink.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_thresholdbin0 -> 10348 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_threshold.hex147
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_threshold_main.c264
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/pot/run_pot_threshold.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_buttonbin0 -> 9360 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_button.hex94
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_button_main.c234
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/push/run_led_push_button.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/push/run_led_push_button_status.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/runMDDAvr.mos8
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzerbin0 -> 9936 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzer.hex121
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzer_main.c253
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/run_therm_buzzer.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/run_therm_read.mos11
-rw-r--r--OpenModelica-Arduino-MDD-Windows/README.md24
-rw-r--r--OpenModelica-Arduino-MDD-Windows/Resources/Images/Icons/tqfp32.pngbin0 -> 11905 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/Resources/Library/SerialComm.dllbin0 -> 270139 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/Resources/Library/SerialComm.obin0 -> 16527 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/Resources/include/serial.h34
-rw-r--r--OpenModelica-Arduino-MDD-Windows/Resources/src/SerialComm.c1021
-rw-r--r--OpenModelica-Arduino-MDD-Windows/SerialComm.dllbin0 -> 270139 bytes
-rw-r--r--OpenModelica-Arduino-MDD-Windows/testfirmware.mo12
-rw-r--r--OpenModelica-Arduino-MDD-Windows/tools/arduino-firmware/arduino-firmware.ino795
65 files changed, 8176 insertions, 0 deletions
diff --git a/OpenModelica-Arduino-MDD-Windows/Arduino.mo b/OpenModelica-Arduino-MDD-Windows/Arduino.mo
new file mode 100644
index 0000000..42d690e
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/Arduino.mo
@@ -0,0 +1,1783 @@
+package Arduino
+ extends Arduino.SerialCommunication.Icons.GenericICPackage;
+
+ package SerialCommunication "Serial Communication Package for Arduino"
+ extends Arduino.SerialCommunication.Icons.FunctionLayerIcon;
+ import ModelicaReference.Operators;
+
+ package Functions
+ extends Modelica.Icons.Package;
+ import Modelica;
+
+ function open_serial "Command to initialize the serial port which is connected to Arduino"
+ extends Modelica.Icons.Function;
+ input Integer handle, port, baudrate;
+ output Integer OK;
+
+ external OK = open_serial(handle, port, baudrate) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+<h4>Syntax</h4>
+<blockquote><pre>
+Arduino.SerialCommunication.Functions.<b>open_serial</b>(handle,port,baudrate);
+</pre></blockquote>
+<h4>Description</h4>
+<p>
+Establishes a serial communication using port number \"port\".To connect to the Arduino board, check the port number from the device manager or check it from the Arduino software.
+</p>
+</html>"));
+ end open_serial;
+
+ function read_serial "read characters from serial port"
+ extends Modelica.Icons.Function;
+ input Integer handle;
+ input Integer size;
+ output Integer r_OK;
+ protected
+ Integer buf[size + 1];
+
+ external r_OK = read_serial(handle, buf, size) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+<h4>Syntax</h4>
+<blockquote><pre>
+Arduino.SerialCommunication.Functions.<b>read_serial</b>(handle,size);
+</pre></blockquote>
+<h4>Description</h4>
+<p>The translation setting of openserial can come in the way, affecting the number of characters effectively read. If that is the case, omitting the parameter n might be a bad idea, as scilab can hang. This would happen if the input stream contains CR or LF characters which are filtered out: in such cases serialstatus counts them, but readserial does not see them and keeps wating (if the blocking mode of openserial was true) until the total number is received.
+</p>
+</html>"));
+ end read_serial;
+
+ function write_serial "write to the serial port"
+ extends Modelica.Icons.Function;
+ input Integer handle;
+ input String str;
+ input Integer size;
+ output Integer w_OK;
+
+ external w_OK = write_serial(handle, str, size) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+<h4>Syntax</h4>
+<blockquote><pre>
+Arduino.SerialCommunication.Functions.<b>write_serial</b>(handle,str,size);
+</pre></blockquote>
+<h4>Description</h4>
+<p>No end of line character is appended to the string; the user might have to add it if the device being talked to requires it. The Tcl command puts -nonewline is used. In addition, the translation mode of openserial can come into way.
+</p>
+</html>"));
+ end write_serial;
+
+ function close_serial "Command to close the serial port which is connected to Arduino"
+ extends Modelica.Icons.Function;
+ input Integer handle;
+ output Integer c_OK;
+
+ external c_OK = close_serial(handle) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+<h4>Syntax</h4>
+<blockquote><pre>
+Arduino.SerialCommunication.Functions.<b>close_serial</b>(handle);
+</pre></blockquote>
+<h4>Description</h4>
+<p>Closes the port for serial communication specified by \"handle\".It is important to close the serial port after use, else the port would be busy and restart of Scilab might required to connect to it again.
+</p>
+</html>"));
+ end close_serial;
+
+ function status_serial "get status of the serial port"
+ extends Modelica.Icons.Function;
+ input Integer handle;
+ output Integer stat_OK;
+ protected
+ Integer bytes[2];
+
+ external stat_OK = status_serial(handle, bytes) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+<h4>Syntax</h4>
+<blockquote><pre>
+Arduino.SerialCommunication.Functions.<b>status_serial</b>(handle);
+</pre></blockquote>
+<h4>Description</h4>
+<p>Provides status of serial communication channel specified by \"handle\".Get some information about the number of characters present in the input and output buffers of the serial port, and about the status lines (DTS, CTS, etc.).The translation setting of openserial can come in the way. If the input stream contains CR or LF characters which are filtered out, openserial counts them but readserial does not see them.
+</p>
+</html>"));
+ end status_serial;
+
+ function cmd_digital_out "Command to sent out digital signal to a connected Arduino board"
+ extends Modelica.Icons.Function;
+ input Integer h, pin_no, val;
+ output Integer digital_w_OK;
+
+ external digital_w_OK = cmd_digital_out(h, pin_no, val) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+<h4>Syntax</h4>
+<blockquote><pre>
+Arduino.SerialCommunication.Functions.<b>cmd_digital_out</b>(handle,pin_no,value);
+</pre></blockquote>
+<h4>Description</h4>
+<p>The Arduino board has a set of logical ports (digital) that are used for writing or reading data from a component.
+To map a UNO, ports 2-13 are available (0 and 1 are used for serial transmission). For MEGA board, ports 2-53 are available. The port takes the low logic level (0) or logic high (1) which corresponds to the reference voltage.
+</p>
+</html>"));
+ end cmd_digital_out;
+
+ function cmd_digital_in "Command to read in digital signal from a connected Arduino board"
+ extends Modelica.Icons.Function;
+ input Integer h, pin_no;
+ output Integer digital_in;
+
+ external digital_in = cmd_digital_in(h, pin_no) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+<h4>Syntax</h4>
+<blockquote><pre>
+Arduino.SerialCommunication.Functions.<b>cmd_digital_in</b>(handle,pin_no);
+</pre></blockquote>
+<h4>Description</h4>
+<p>The Arduino board has a set of logical ports (digital) that are used for writing or reading data from a component.
+To map a UNO, ports 2-13 are available (0 and 1 are used for serial transmission). For MEGA board, ports 2-53 are available. The port takes the low logic level (0) or logic high (1) which corresponds to the reference voltage.
+</p>
+</html>"));
+ end cmd_digital_in;
+
+ function delay "Provides delay.Suspends Openmodelica."
+ extends Modelica.Icons.Function;
+ input Integer t;
+
+ external delay(t) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Functions.<b>delay</b>(milliseconds);
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>Delay process for specified number of miliseconds specified by the argument. The actual suspension time may be longer because of other activities in the system, or because of the time spent in processing the call.
+ </p>
+ </html>"));
+ end delay;
+
+ function cmd_analog_in "Command to read in analog signal from a connected Arduino board"
+ extends Modelica.Icons.Function;
+ input Integer h, pin_no;
+ output Integer val;
+
+ external val = cmd_analog_in(h, pin_no) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+<h4>Syntax</h4>
+<blockquote><pre>
+Arduino.SerialCommunication.Functions.<b>cmd_analog_in</b>(handle,pin_no);
+</pre></blockquote>
+<h4>Description</h4>
+<p>Arduino UNO board has 6 analog input ports (A0 to A5), the Arduino Mega board has 16 analog input ports (A0 to A15). The 10 bits channels convert the analog input from 0 to 5 volts, to a digital value between 0 and 1023.
+</p>
+</html>"));
+ end cmd_analog_in;
+
+ function cmd_analog_out "Command to sent out analog signal to a connected Arduino board"
+ extends Modelica.Icons.Function;
+ input Integer h, pin_no;
+ input Real val;
+ output Integer analog_w_OK;
+
+ external analog_w_OK = cmd_analog_out(h, pin_no, val) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+<h4>Syntax</h4>
+<blockquote><pre>
+Arduino.SerialCommunication.Functions.<b>cmd_analog_out</b>(handle,pin_no,val);
+</pre></blockquote>
+<h4>Description</h4>
+<p>The analog outputs of the Arduino Uno is available at the pins 3,5,6,9,10 and 11, while on the Mega board, the outputs are on pins 1-13 and 44-46. It is a bit misleading to use the term 'analog output', because in order to generate this output while minimizing energy losses, the Arduino uses PWM (Pulse Width Modulation) available on these ports. By varying the duty cycle of the PWM is altered the average voltage across the component connected to this port, which has the effect of having a analog output voltage.
+The input port accepts the value from 0 to 255 which is correspoding to the duty cycle of 0 to 100%. In other words, sending 0 to the block will generate 0 V output at the port, 127 generates 2.5V and 255 generates 5V. (the port is 8 bits, so the resolutions of output would be 2^8 =256).
+</p>
+</html>"));
+ end cmd_analog_out;
+
+ function cmd_analog_in_volt "Command to read in analog signal from a connected Arduino board"
+ extends Modelica.Icons.Function;
+ input Integer h, pin_no;
+ output Integer val;
+
+ external val = cmd_analog_in_volt(h, pin_no) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Functions.<b>cmd_analog_in_volt</b>(handle,pin_no);
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>Arduino UNO board has 6 analog input ports (A0 to A5), the Arduino Mega board has 16 analog input ports (A0 to A15). The 10 bits channels convert the analog input from 0 to 5 volts, to a digital value between 0 and 1023. This function scale the reading to 0-5 so the user could get the measured voltage directly.
+ </p>
+ </html>"));
+ end cmd_analog_in_volt;
+
+ function cmd_analog_out_volt "Command to sent out analog signal to a connected Arduino board"
+ extends Modelica.Icons.Function;
+ input Integer h, pin_no;
+ input Real val;
+ output Integer analog_v_wOK;
+
+ external analog_v_wOK = cmd_analog_out_volt(h, pin_no, val) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Functions.<b>cmd_analog_out_volt</b>(handle,pin_no,val);
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>The analog outputs of the Arduino Uno is available at the pins 3,5,6,9,10 and 11, while on the Mega board, the outputs are on pins 1-13 and 44-46. It is a bit misleading to use the term 'analog output', because in order to generate this output while minimizing energy losses, the Arduino uses PWM (Pulse Width Modulation) available on these ports. By varying the duty cycle of the PWM is altered the average voltage across the component connected to this port, which has the effect of having a analog output voltage.
+ </p>
+ </html>"));
+ end cmd_analog_out_volt;
+
+ function cmd_dcmotor_setup "Command to setup pins to control DC motor"
+ extends Modelica.Icons.Function;
+ input Integer handle, driver_type, motor_no, pin1, pin2;
+
+ external cmd_dcmotor_setup(handle, driver_type, motor_no, pin1, pin2) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Functions.<b>cmd_dcmotor_setup</b>(handle,driver_type,motor_no,pin_no1,pin_no2);
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>Arduino board does not deliver enough power, so it is necessary to use a H-bridge circuit/IC to control the motor. There are several types of H-bridge IC that do not all operate on the same principle. For example, the L298 requires the use of a PWM signal with current sense. The L293 uses two PWM to set the speed and direction. Ready-to-use Shields are also available.
+ Remember that the PWM is 8-bit (0 to 255). The input of the block could accept any value, but it would saturate at +- 255.
+ </p>
+ </html>"));
+ end cmd_dcmotor_setup;
+
+ function cmd_dcmotor_run "Command to run DC motor after setting up"
+ extends Modelica.Icons.Function;
+ input Integer handle, motor_no, val;
+
+ external cmd_dcmotor_run(handle, motor_no, val) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Functions.<b>cmd_dcmotor_run</b>(handle,motor_no,value);
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>Arduino board does not deliver enough power, so it is necessary to use a H-bridge circuit/IC to control the motor. There are several types of H-bridge IC that do not all operate on the same principle. For example, the L298 requires the use of a PWM signal with current sense. The L293 uses two PWM to set the speed and direction. Ready-to-use Shields are also available.
+ Remember that the PWM is 8-bit (0 to 255). The input of the block could accept any value, but it would saturate at +- 255.
+ </p>
+ </html>"));
+ end cmd_dcmotor_run;
+
+ function cmd_dcmotor_release "Command to release pins which have setup for DC motor"
+ extends Modelica.Icons.Function;
+ input Integer handle, motor_no;
+
+ external cmd_dcmotor_release(handle, motor_no) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Functions.<b>cmd_dcmotor_release</b>(handle,motor_no);
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>Arduino board does not deliver enough power, so it is necessary to use a H-bridge circuit/IC to control the motor. There are several types of H-bridge IC that do not all operate on the same principle. For example, the L298 requires the use of a PWM signal with current sense. The L293 uses two PWM to set the speed and direction. Ready-to-use Shields are also available.
+ Remember that the PWM is 8-bit (0 to 255). The input of the block could accept any value, but it would saturate at +- 255.
+ </p>
+ </html>"));
+ end cmd_dcmotor_release;
+
+ function cmd_servo_attach "Command to attach servo motor to Arduino"
+ extends Modelica.Icons.Function;
+ input Integer handle, servo_no;
+
+ external cmd_servo_attach(handle, servo_no) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Functions.<b>cmd_servo_attach</b>(handle,servo_no);
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>A servomotor is an rotary actuator consist of an electric motor, gears, a potentiometer and an analogue or digital electronics for control. The servomotor usualy used for a position control application (or speed for continuous rotation servos).
+ The user must give the command of the position setpoint or desired speed. This command is sent to the actuator in pulses spaced by 10 to 20 ms. The coding of these pulses is made such that a pulse of 1.5 ms corresponding to the centered position (rest), a pulse of 1 ms corresponds to an angle of 90° in the anticlockwise direction, and a pulse 2 ms corresponds to an angle of 90° clockwise. All other pulse widths give intermediate values​​.
+ A servomotor for continuous rotation, the pulse width control the rotational speed and the direction. It is recommended to use a voltage regulator to power the servomotor instead of using the Arduino board power. For simplicity, the function takes an input commnad in degrees from 0 to 180. Two actuators can be controlled with this toolbox. (modified version of 3 motors available)
+ </p>
+ </html>"));
+ end cmd_servo_attach;
+
+ function cmd_servo_move "Command to run servo motor which has been setup"
+ extends Modelica.Icons.Function;
+ input Integer handle, servo_no, val;
+
+ external cmd_servo_move(handle, servo_no, val) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Functions.<b>cmd_servo_move</b>(handle,servo_no,value);
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>A servomotor is an rotary actuator consist of an electric motor, gears, a potentiometer and an analogue or digital electronics for control. The servomotor usualy used for a position control application (or speed for continuous rotation servos).
+ The user must give the command of the position setpoint or desired speed. This command is sent to the actuator in pulses spaced by 10 to 20 ms. The coding of these pulses is made such that a pulse of 1.5 ms corresponding to the centered position (rest), a pulse of 1 ms corresponds to an angle of 90° in the anticlockwise direction, and a pulse 2 ms corresponds to an angle of 90° clockwise. All other pulse widths give intermediate values​​.
+ A servomotor for continuous rotation, the pulse width control the rotational speed and the direction. It is recommended to use a voltage regulator to power the servomotor instead of using the Arduino board power. For simplicity, the function takes an input commnad in degrees from 0 to 180. Two actuators can be controlled with this toolbox. (modified version of 3 motors available)
+ </p>
+ </html>"));
+ end cmd_servo_move;
+
+ function cmd_servo_detach "Command to release the pin which has been setup for servo motor"
+ extends Modelica.Icons.Function;
+ input Integer handle, servo_no;
+
+ external cmd_servo_attach(handle, servo_no) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Functions.<b>cmd_servo_detach</b>(handle,servo_no);
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>A servomotor is an rotary actuator consist of an electric motor, gears, a potentiometer and an analogue or digital electronics for control. The servomotor usualy used for a position control application (or speed for continuous rotation servos).
+ The user must give the command of the position setpoint or desired speed. This command is sent to the actuator in pulses spaced by 10 to 20 ms. The coding of these pulses is made such that a pulse of 1.5 ms corresponding to the centered position (rest), a pulse of 1 ms corresponds to an angle of 90° in the anticlockwise direction, and a pulse 2 ms corresponds to an angle of 90° clockwise. All other pulse widths give intermediate values​​.
+ A servomotor for continuous rotation, the pulse width control the rotational speed and the direction. It is recommended to use a voltage regulator to power the servomotor instead of using the Arduino board power. For simplicity, the function takes an input commnad in degrees from 0 to 180. Two actuators can be controlled with this toolbox. (modified version of 3 motors available)
+ </p>
+ </html>"));
+ end cmd_servo_detach;
+
+ function ieeesingle2num "ieee-745 floating point converter"
+ extends Modelica.Icons.Function;
+ input String hexa;
+ output Real y;
+
+ external y = ieeesingle2num(hexa) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+<h4>Syntax</h4>
+<blockquote><pre>
+Arduino.SerialCommunication.Functions.<b>ieeesingle2num</b>(hexa);
+</pre></blockquote>
+<h4>Description</h4>
+<p>Converts an hexadecimal integer to ieee single precision format
+ </p>
+</html>"));
+ end ieeesingle2num;
+
+ function math_floor "Floor function"
+ extends Modelica.Icons.Function;
+ input Real x;
+ output Integer y;
+
+ external y = mfloor(x) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Functions.<b>math_floor</b>(x);
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>Returns the greatest integer less than or equal to x
+ </p>
+ </html>"));
+ end math_floor;
+
+ package MDD_Servo
+ extends Modelica.Icons.Package;
+
+ class Init
+ extends ExternalObject;
+
+ function constructor "Return device handle"
+ extends .Modelica.Icons.Function;
+ import Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions;
+ import Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import Arduino.SerialCommunication.Functions.MDD_Servo;
+ input sComm.Types.Servo_no servo_no;
+ output sComm.Functions.MDD_Servo.Init servo;
+
+ external "C" servo = MDD_avr_servo_initialize(servo_no) annotation(
+ Include = "#include \"/home/souradip/OpenModelica/Resources/Include/MDDAVRServo.h\"");
+ end constructor;
+
+ function destructor "Destructor"
+ extends .Modelica.Icons.Function;
+ import Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import Arduino.SerialCommunication.Functions.MDD_Servo;
+ input sComm.Types.Servo_no servo_no "Device handle";
+
+ external "C" MDD_avr_servo_finalize(servo_no) annotation(
+ Include = "#include \"/home/souradip/OpenModelica/Resources/Include/MDDAVRServo.h\"");
+ end destructor;
+ end Init;
+
+ function Move
+ extends Modelica.Icons.Function;
+ import sComm = Arduino.SerialCommunication.Functions;
+ input sComm.Functions.MDD_Servo.Init servo;
+ input Integer value;
+
+ external "C" MDD_avr_servo_move(servo, value) annotation(
+ Include = "#include \"/home/souradip/OpenModelica/Resources/Include/MDDAVRServo.h\"");
+ end Move;
+ end MDD_Servo;
+ end Functions;
+
+ package Examples
+ extends Modelica.Icons.ExamplesPackage;
+
+ package led
+ extends Modelica.Icons.ExamplesPackage;
+
+ model led_blue "Turn on Blue LED"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer digital_out(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
+ if ok <> 0 then
+ strm.print("Check the serial port and try again");
+ else
+ sComm.delay(1000);
+ digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn ON the blue LED";
+ end if;
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+//strm.print(String(time));
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10));
+ end led_blue;
+
+ model led_blue_delay "Turn on Blue LED for a period of 2 seconds"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer digital_out(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
+ sComm.delay(2000);
+ if ok <> 0 then
+ strm.print("Check the serial port and try again");
+ else
+ digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn the blue LED";
+ sComm.delay(2000) "let the blue LED be on for two seconds";
+ digital_out := sComm.cmd_digital_out(1, 9, 0) "turn off blue LED";
+ sComm.delay(2000) "let the blue LED be off for two seconds";
+ end if;
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+//strm.print(String(time));
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10));
+ end led_blue_delay;
+
+
+
+ model led_blue_red "Turn on Red & Blue LED"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer digital_out(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
+ sComm.delay(2000);
+ if ok <> 0 then
+ strm.print("Check the serial port and try again");
+ else
+ digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn the blue LED";
+ digital_out := sComm.cmd_digital_out(1, 11, 1) "This will turn the red LED";
+ sComm.delay(5000) "Delay for 5 seconds";
+ digital_out := sComm.cmd_digital_out(1, 9, 0) "This turns off the blue Led";
+ sComm.delay(3000) "Delay for 3 seconds";
+ digital_out := sComm.cmd_digital_out(1, 11, 0) "This turns off the red Led";
+ end if;
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+//strm.print(String(time));
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10));
+ end led_blue_red;
+
+ model led_blink "This will turn on and turn off the user LED for every second for 10 times"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer digital_out(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
+ sComm.delay(2000);
+ if ok <> 0 then
+ strm.print("Check the serial port and try again");
+ else
+ for i in 1:1000 loop
+ digital_out := sComm.cmd_digital_out(1, 13, 0) "This will turn off the LED";
+ sComm.delay(1000) "Delay for 1 second";
+ digital_out := sComm.cmd_digital_out(1, 13, 1) "This turns the Led";
+ sComm.delay(1000) "Delay for 1 second";
+ end for;
+ end if;
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10));
+ end led_blink;
+
+ model led_green_blink "This will turn on and turn off the green LED for every second for 5 times"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer digital_out(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 0 with baudrate of 115200";
+ sComm.delay(2000);
+ if ok <> 0 then
+ strm.print("Check the serial port and try again");
+ else
+ for i in 1:10 loop
+ digital_out := sComm.cmd_digital_out(1, 10, 0) "This will turn off the green LED";
+ sComm.delay(1000) "Delay for 1 second";
+ digital_out := sComm.cmd_digital_out(1, 10, 1) "This turns the green Led";
+ sComm.delay(1000) "Delay for 1 second";
+ end for;
+ end if;
+ strm.print(String(time));
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10));
+ end led_green_blink;
+
+ end led;
+
+ package push
+ extends Modelica.Icons.ExamplesPackage;
+
+ model led_push_button "Conrolling LED with PushButton"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer digital_in(fixed = false);
+ Integer digital_out(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
+ sComm.delay(2000);
+ end when;
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ digital_in := sComm.cmd_digital_in(1, 12) "";
+ if digital_in == 0 then
+ digital_out := sComm.cmd_digital_out(1, 9, 0) "This will turn OFF the blue LED";
+ sComm.delay(200);
+ else
+ digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn ON the blue LED";
+ sComm.delay(200);
+ end if;
+ end if;
+//for i in 1:1000 loop
+//end for;
+ strm.print(String(time));
+ when terminal() then
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.1));
+ end led_push_button;
+
+
+ model push_button_status "Checking Status of PushButton"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer digital_in(fixed = false);
+ Integer digital_out(start = 0, fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 0 with baudrate of 115200";
+ end when;
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ digital_in := sComm.cmd_digital_in(1, 12);
+ if digital_in == 0 then
+ digital_out := sComm.cmd_digital_out(1, 9, 0) "This will turn OFF the blue LED";
+ strm.print("LOW");
+ sComm.delay(200);
+ else
+ digital_out := sComm.cmd_digital_out(1, 9, 1) "This will turn ON the blue LED";
+ strm.print("HIGH");
+ sComm.delay(200);
+ end if;
+ end if;
+//for i in 1:1000 loop
+//end for;
+ when terminal() then
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+//sComm.cmd_arduino_meter(digital_in);
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.1));
+ end push_button_status;
+
+ end push;
+
+ package ldr
+ extends Modelica.Icons.ExamplesPackage;
+
+ model ldr_led "LED indicating light sensor readings"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer analog_in(fixed = false);
+ Integer digital_out(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 0 with baudrate of 115200";
+ sComm.delay(2000);
+ end when;
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ analog_in := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)";
+ if analog_in < 300 then
+ digital_out := sComm.cmd_digital_out(1, 9, 1) "Turn ON LED";
+ else
+ digital_out := sComm.cmd_digital_out(1, 9, 0) "Turn OFF LED";
+ end if;
+ sComm.delay(500);
+ end if;
+//strm.print(String(time));
+ when time >=10 then
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+//Setting Threshold value of 300
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.2));
+ end ldr_led;
+
+
+
+ model ldr_read "Reading light intensity using ldr"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer analog_in(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 0 with baudrate of 115200";
+ sComm.delay(2000);
+ end when;
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ analog_in := sComm.cmd_analog_in(1, 5) "read analog pin 5 (ldr)";
+ strm.print("LDR Readings" + " : " + String(analog_in));
+ sComm.delay(500);
+ end if;
+ when time >=10 then
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 1));
+ end ldr_read;
+
+
+ end ldr;
+
+ package pot
+ extends Modelica.Icons.ExamplesPackage;
+
+ model pot_threshold
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer analog_in(fixed = false);
+ Integer digital_out(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
+ end when;
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ analog_in := sComm.cmd_analog_in(1, 2) "read analog pin 2";
+ strm.print("Potentiometer Readings:" + String(analog_in));
+ if analog_in >= 0 and analog_in < 320 then
+ digital_out := sComm.cmd_digital_out(1, 11, 1) "Turn ON LED";
+ sComm.delay(1000);
+ digital_out := sComm.cmd_digital_out(1, 11, 0) "Turn OFF LED";
+ elseif analog_in >= 320 and analog_in <= 900 then
+ digital_out := sComm.cmd_digital_out(1, 10, 1) "Turn ON LED";
+ sComm.delay(1000);
+ digital_out := sComm.cmd_digital_out(1, 10, 0) "Turn OFF LED";
+ elseif analog_in > 900 and analog_in <= 1023 then
+ digital_out := sComm.cmd_digital_out(1, 9, 1) "Turn ON LED";
+ sComm.delay(1000);
+ digital_out := sComm.cmd_digital_out(1, 9, 0) "Turn OFF LED";
+ end if;
+ end if;
+//Threshold 1
+//Threshold 2
+ when time >= 10 then
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 1));
+ end pot_threshold;
+ end pot;
+
+ package thermistor
+ extends Modelica.Icons.ExamplesPackage;
+
+ model therm_buzzer "Sound buzzer depending on thermistor readings"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer analog_in(fixed = false);
+ Integer digital_out(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
+ sCOmm.delay(2000);
+ end when;
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ analog_in := sComm.cmd_analog_in(1, 4) "read analog pin 4";
+ if analog_in > 500 then
+ digital_out := sComm.cmd_digital_out(1, 3, 1) "Turn ON Buzzer";
+ else
+ digital_out := sComm.cmd_digital_out(1, 3, 0) "Turn OFF Buzzer";
+ end if;
+ sComm.delay(500);
+ end if;
+//for i in 1:500 loop
+//end for;
+//Run for 500 iterations
+//Setting Threshold value of 500
+ when terminal() then
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 0.1));
+ end therm_buzzer;
+
+
+ model therm_read "Thermistor Readings"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer analog_in(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "At port 2 with baudrate of 115200";
+ sComm.delay(2000);
+ end when;
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ analog_in := sComm.cmd_analog_in(1, 4) "read analog pin 5 (ldr)";
+ strm.print("Thermistor Readings " + " : " + String(analog_in));
+ sComm.delay(500);
+ end if;
+ when terminal() then
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 20, Tolerance = 1e-6, Interval = 1));
+ end therm_read;
+
+ end thermistor;
+
+ package dcmotor
+ extends Modelica.Icons.ExamplesPackage;
+
+ model dcmotor_clock "Rotate DC Motor clockwise"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "COM port is 2 and baud rate is 115200";
+ sComm.delay(2000);
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ sComm.delay(1000);
+ sComm.cmd_dcmotor_setup(1, 3, 1, 9, 10) "Setup DC motor of type 3 (L293D), motor 1, pin 9 and 10";
+ sComm.cmd_dcmotor_run(1, 1, 100) "Motor 1 runs at PWM 100";
+ sComm.delay(3000) "This is allowed to continue for 3 seconds";
+ sComm.cmd_dcmotor_release(1, 1) "Motor 1 is released";
+ end if;
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10));
+ end dcmotor_clock;
+
+ model dcmotor_both "Rotate DC Motor in both directions"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "COM port is 2 and baud rate is 115200";
+ sComm.delay(2000);
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ sComm.cmd_dcmotor_setup(1, 3, 1, 9, 10) "Setup DC motor of type 3 (L293D), motor 1, pin 9 and 10";
+ sComm.cmd_dcmotor_run(1, 1, 100) "Motor 1 runs at PWM 100";
+ sComm.delay(3000) "for 3 seconds";
+ sComm.cmd_dcmotor_run(1, 1, -100) "Motor 1 runs at PWM -100 in reverse direction";
+ sComm.delay(2000) "for 2 seconds";
+ sComm.cmd_dcmotor_release(1, 1) "Motor 1 is released";
+ end if;
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10));
+ end dcmotor_both;
+
+ model dcmotor_loop "Rotate DC Motor in both directions in a loop"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "COM port is 2 and baud rate is 115200";
+ sComm.delay(2000);
+ if ok <> 0 then
+ strm.print("Unable to open serial port, please check");
+ else
+ sComm.cmd_dcmotor_setup(1, 3, 1, 9, 10) "Setup DC motor of type 3 (L293D), motor 1, pins 9 and 10";
+ for i in 1:4 loop
+ sComm.cmd_dcmotor_run(1, 1, 100) "Motor 1 runs at PWM 100";
+ sComm.delay(3000) "for 3 seconds";
+ sComm.cmd_dcmotor_run(1, 1, 0) "Halt the motor";
+ sComm.delay(2000) "for 2 seconds";
+ sComm.cmd_dcmotor_run(1, 1, -100) "Run it at PWM 100 in reverse direction";
+ sComm.delay(2000) "for 2 seconds";
+ end for;
+ sComm.cmd_dcmotor_release(1, 1) "Motor 1 is released";
+ end if;
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-6, Interval = 10));
+ end dcmotor_loop;
+
+
+ end dcmotor;
+
+ package servo
+ extends Modelica.Icons.ExamplesPackage;
+
+ model servo_init "Rotate Servo Motor "
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "COM port is 2 and baud rate is 115200";
+ if ok <> 0 then
+ strm.print("Check the serial port and try again");
+ else
+ sComm.cmd_servo_attach(1, 1) "To attach the motor to pin 9 of servo1";
+ sComm.cmd_servo_move(1, 1, 30) "tell servo to rotate by 30 degrees";
+ sComm.delay(3000);
+ //sComm.cmd_servo_detach(1,1);
+ end if;
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+
+ annotation(
+ experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5));
+ end servo_init;
+
+
+
+
+
+
+
+ model servo_loop "Rotate servo motor by 20 degrees 10 times"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer c_ok(fixed = false);
+ Integer angle(fixed = true);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "COM port is 2 and baud rate is 115200";
+ if ok <> 0 then
+ strm.print("Check the serial port and try again");
+ else
+ sComm.cmd_servo_attach(1, 1) "Attach motor to pin 9. 1 means pin 9.";
+ sComm.delay(2000);
+ angle := 20 "Angle by which it has to move";
+ for i in 1:10 loop
+ sComm.cmd_servo_move(1, 1, angle * i) "tell servo to rotate by 20 degrees";
+ sComm.delay(1000) "waits for a sec";
+ end for;
+ sComm.cmd_servo_detach(1, 1) "Detach the motor";
+ end if;
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5));
+ end servo_loop;
+
+ model servo_reverse
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "COM port is 2 and baud rate is 115200";
+ sComm.delay(2000);
+ if ok <> 0 then
+ strm.print("Check the serial port and try again");
+ else
+ sComm.cmd_servo_attach(1, 1) "Attach the motor to pin 9. 1 means 9";
+ sComm.cmd_servo_move(1, 1, 90) "Move the servo to 90 degree";
+ sComm.delay(1000) "be there for one second";
+ sComm.cmd_servo_move(1, 1, 45) "Move the servo to 45 degree";
+ sComm.delay(1000) "be there for one second";
+ sComm.cmd_servo_detach(1, 1) "Detach the motor";
+ sComm.delay(1000);
+ end if;
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+ annotation(
+ experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5));
+ end servo_reverse;
+
+ model servo_pot "Control Servo Motor using Potentiometer"
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import strm = Modelica.Utilities.Streams;
+ Integer ok(fixed = false);
+ Integer c_ok(fixed = false);
+ Integer analog_in(fixed = false);
+ algorithm
+ when initial() then
+ ok := sComm.open_serial(1, 2, 115200) "COM port is 2 and baud rate is 115200";
+ sComm.delay(2000);
+ if ok <> 0 then
+ strm.print("Check the serial port and try again");
+ else
+ sComm.cmd_servo_attach(1, 1) "Attach the motor to pin 9";
+ sComm.delay(2000);
+ for i in 1:5000 loop
+ analog_in := sComm.cmd_analog_in(1, 2) "Read potentiometer value";
+ sComm.cmd_servo_move(1, 1, analog_in) "Command the servo motor";
+ sComm.delay(1000) "sleep for 1000 milliseconds";
+ end for;
+ sComm.cmd_servo_detach(1, 1) "Detach the motor";
+ end if;
+ analog_in := sComm.math_floor(analog_in * (180 / 1023)) "Scale Potentiometer value to 0-180";
+ c_ok := sComm.close_serial(1) "To close the connection safely";
+ end when;
+//5,000 itterations
+//strm.print(String(analog_in));
+ annotation(
+ experiment(StartTime = 0, StopTime = 5, Tolerance = 1e-6, Interval = 5));
+ end servo_pot;
+
+ end servo;
+
+ package modbus
+ extends Modelica.Icons.ExamplesPackage;
+
+ function read_voltage
+ extends Modelica.Icons.Function;
+
+ external read_voltage() annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Examples.modbus.<b>read_voltage</b>();
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>
+ </p>
+ </html>"));
+ end read_voltage;
+
+ function read_current
+ extends Modelica.Icons.Function;
+
+ external read_current() annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Examples.modbus.<b>read_current</b>();
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>
+ </p>
+ </html>"));
+ end read_current;
+
+
+ function read_val
+ extends Modelica.Icons.Function;
+ input Integer addr_byte;
+ output Real p;
+
+ external p = read_val(addr_byte) annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Examples.modbus.<b>read_val</b>(address_byte);
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>
+ </p>
+ </html>"));
+ end read_val;
+
+ function read_active_power
+ extends Modelica.Icons.Function;
+
+ external read_active_power() annotation(
+ Library = "SerialComm");
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.Examples.modbus.<b>read_active_power</b>();
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>
+ </p>
+ </html>"));
+ end read_active_power;
+
+ model modbus_test
+ extends Modelica.Icons.Example;
+ import sComm = Arduino.SerialCommunication.Functions;
+ import modbus = Arduino.SerialCommunication.Examples.modbus;
+ //Integer ok(fixed = false);
+ //Integer c_ok(fixed = false);
+ algorithm
+ when initial() then
+ //ok:=sComm.open_serial(1,2,9600);
+ modbus.read_voltage();
+ modbus.read_current();
+ modbus.read_active_power();
+ sComm.delay(2000);
+ //c_ok:=sComm.close_serial(1);
+ end when;
+ end modbus_test;
+
+
+
+
+
+
+
+ end modbus;
+ end Examples;
+
+ package MDD_Examples "Interfacing arduino with OpenModelica using Modelica Device Drivers"
+ extends Modelica.Icons.ExamplesPackage;
+
+ package MDD_led
+ extends Modelica.Icons.ExamplesPackage;
+
+ model MDD_led_blue ""
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {39, 41}, extent = {{-17, -17}, {17, 17}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {39, -21}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation(
+ Placement(visible = true, transformation(origin = {-41, -21}, extent = {{-15, -17}, {15, 17}}, rotation = 0)));
+ equation
+ connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation(
+ Line(points = {{-24, -20}, {14, -20}, {14, -20}, {16, -20}}, color = {255, 0, 255}));
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.MDD_Examples.MDD_led.<b>MDD-led_blue</b>();
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>
+ </p>
+ </html>"));
+ end MDD_led_blue;
+
+ model MDD_led_blue_delay
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {31, 41}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {41, -17}, extent = {{-17, -17}, {17, 17}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = if time < 5 then true else false) annotation(
+ Placement(visible = true, transformation(origin = {-27, -16}, extent = {{-21, -16}, {21, 16}}, rotation = 0)));
+ equation
+ connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation(
+ Line(points = {{-4, -16}, {20, -16}}, color = {255, 0, 255}));
+ end MDD_led_blue_delay;
+
+ model MDD_led_blink
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-45, 71}, extent = {{-23, -23}, {23, 23}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'5', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {42, -22}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {23, 71}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = mod(time, 2) >= 1) annotation(
+ Placement(visible = true, transformation(origin = {-24, -21}, extent = {{-16, -15}, {16, 15}}, rotation = 0)));
+ equation
+ connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation(
+ Line(points = {{-6, -21}, {16, -21}, {16, -22}, {18, -22}}, color = {255, 0, 255}));
+ end MDD_led_blink;
+
+ model MDD_led_blue_red
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-47, 47}, extent = {{-21, -21}, {21, 21}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {38, -16}, extent = {{-16, -16}, {16, 16}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {40, 44}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean2(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'3', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {38, -62}, extent = {{-16, -16}, {16, 16}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = if time < 1 then true else false) annotation(
+ Placement(visible = true, transformation(origin = {-32, -16}, extent = {{-18, -14}, {18, 14}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = if time < 1.6 then true else false) annotation(
+ Placement(visible = true, transformation(origin = {-32, -62}, extent = {{-18, -16}, {18, 16}}, rotation = 0)));
+ equation
+ connect(digitalWriteBoolean2.u, booleanExpression2.y) annotation(
+ Line(points = {{18, -62}, {-12, -62}, {-12, -62}, {-12, -62}}, color = {255, 0, 255}));
+ connect(booleanExpression2.y, digitalWriteBoolean2.u) annotation(
+ Line(points = {{-12, -62}, {18, -62}, {18, -62}, {18, -62}}, color = {255, 0, 255}));
+ connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation(
+ Line(points = {{-12, -16}, {18, -16}, {18, -16}, {18, -16}}, color = {255, 0, 255}));
+ end MDD_led_blue_red;
+
+ model MDD_led_green_blink
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'2', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {46, -30}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {39, 39}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = mod(time, 2) >= 1) annotation(
+ Placement(visible = true, transformation(origin = {-17, -30}, extent = {{-15, -14}, {15, 14}}, rotation = 0)));
+ equation
+ connect(booleanExpression1.y, digitalWriteBoolean1.u) annotation(
+ Line(points = {{0, -30}, {24, -30}, {24, -30}, {24, -30}}, color = {255, 0, 255}));
+ end MDD_led_green_blink;
+ end MDD_led;
+
+ package MDD_push
+ extends Modelica.Icons.ExamplesPackage;
+
+ model MDD_led_push_button
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-38, 40}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {64, -26}, extent = {{-16, -16}, {16, 16}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1) annotation(
+ Placement(visible = true, transformation(origin = {39, 41}, extent = {{-17, -17}, {17, 17}}, rotation = 0)));
+ Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation(
+ Placement(visible = true, transformation(origin = {16, -26}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation(
+ Placement(visible = true, transformation(origin = {-20, 8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = false) annotation(
+ Placement(visible = true, transformation(origin = {-18, -62}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalReadBoolean digitalReadBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'4', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.D) annotation(
+ Placement(visible = true, transformation(origin = {-60, -26}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ equation
+ connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation(
+ Line(points = {{28, -26}, {44, -26}, {44, -26}, {44, -26}}, color = {255, 0, 255}));
+ connect(digitalReadBoolean1.y, logicalSwitch1.u2) annotation(
+ Line(points = {{-48, -26}, {2, -26}, {2, -26}, {4, -26}}, color = {255, 0, 255}));
+ connect(booleanExpression1.y, logicalSwitch1.u1) annotation(
+ Line(points = {{-8, 8}, {-2, 8}, {-2, -18}, {4, -18}, {4, -18}}, color = {255, 0, 255}));
+ connect(booleanExpression2.y, logicalSwitch1.u3) annotation(
+ Line(points = {{-6, -62}, {-2, -62}, {-2, -34}, {4, -34}, {4, -34}}, color = {255, 0, 255}));
+ end MDD_led_push_button;
+
+ model MDD_push_button_status
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-43, 43}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {20, 42}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalReadBoolean digitalReadBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'4', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {-39, -19}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica.Blocks.Interaction.Show.BooleanValue booleanValue1(use_activePort = true) annotation(
+ Placement(visible = true, transformation(origin = {31, -19}, extent = {{-15, -17}, {15, 17}}, rotation = 0)));
+ equation
+ connect(digitalReadBoolean1.y, booleanValue1.activePort) annotation(
+ Line(points = {{-18, -18}, {14, -18}, {14, -18}, {14, -18}}, color = {255, 0, 255}));
+ end MDD_push_button_status;
+ end MDD_push;
+
+ package MDD_ldr
+ extends Modelica.Icons.ExamplesPackage;
+
+ model MDD_ldr_led
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-45, 65}, extent = {{-21, -21}, {21, 21}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {79, -23}, extent = {{-17, -17}, {17, 17}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = true) annotation(
+ Placement(visible = true, transformation(origin = {-60, 12}, extent = {{-14, -16}, {14, 16}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression2 annotation(
+ Placement(visible = true, transformation(origin = {-59, -79}, extent = {{-13, -17}, {13, 17}}, rotation = 0)));
+ Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation(
+ Placement(visible = true, transformation(origin = {28, -22}, extent = {{-16, -16}, {16, 16}}, rotation = 0)));
+ Modelica.Blocks.Logical.GreaterThreshold greaterThreshold1(threshold = 600) annotation(
+ Placement(visible = true, transformation(origin = {-21, -23}, extent = {{-11, -11}, {11, 11}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A5, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation(
+ Placement(visible = true, transformation(origin = {-72, -22}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ equation
+ connect(adc.y, greaterThreshold1.u) annotation(
+ Line(points = {{-50, -22}, {-34, -22}}, color = {0, 0, 127}));
+ connect(greaterThreshold1.y, logicalSwitch1.u2) annotation(
+ Line(points = {{-8, -22}, {8, -22}, {8, -22}, {8, -22}}, color = {255, 0, 255}));
+ connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation(
+ Line(points = {{46, -22}, {58, -22}, {58, -22}, {58, -22}}, color = {255, 0, 255}));
+ connect(booleanExpression1.y, logicalSwitch1.u1) annotation(
+ Line(points = {{-44, 12}, {8, 12}, {8, -10}, {8, -10}}, color = {255, 0, 255}));
+ connect(booleanExpression2.y, logicalSwitch1.u3) annotation(
+ Line(points = {{-44, -78}, {6, -78}, {6, -34}, {8, -34}}, color = {255, 0, 255}));
+ end MDD_ldr_led;
+
+ model MDD_ldr_read
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-37, 39}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {50, 38}, extent = {{-22, -22}, {22, 22}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A5, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation(
+ Placement(visible = true, transformation(origin = {-39, -17}, extent = {{-17, -17}, {17, 17}}, rotation = 0)));
+ Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort = true) annotation(
+ Placement(visible = true, transformation(origin = {30, -17}, extent = {{-18, -17}, {18, 17}}, rotation = 0)));
+ equation
+ connect(adc.y, realValue1.numberPort) annotation(
+ Line(points = {{-20, -17}, {7, -17}}, color = {0, 0, 127}));
+ end MDD_ldr_read;
+ end MDD_ldr;
+
+ package MDD_pot
+ extends Modelica.Icons.ExamplesPackage;
+
+ model MDD_pot_threshold ""
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-79, 79}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {80, 80}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
+ Modelica.Blocks.Logical.Switch switch11 annotation(
+ Placement(visible = true, transformation(origin = {2, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Logical.Switch switch12 annotation(
+ Placement(visible = true, transformation(origin = {10, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Logical.Greater greater1 annotation(
+ Placement(visible = true, transformation(origin = {42, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Logical.Greater greater2 annotation(
+ Placement(visible = true, transformation(origin = {36, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'1', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {82, 40}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean2(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'2', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {82, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean3(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'3', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.B) annotation(
+ Placement(visible = true, transformation(origin = {82, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold1(threshold = 0) annotation(
+ Placement(visible = true, transformation(origin = {-42, 44}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold2(threshold = 320) annotation(
+ Placement(visible = true, transformation(origin = {-42, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold3(threshold = 900) annotation(
+ Placement(visible = true, transformation(origin = {-40, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Sources.RealExpression realExpression1(y = 0) annotation(
+ Placement(visible = true, transformation(origin = {-40, -92}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Sources.RealExpression realExpression2(y = 1) annotation(
+ Placement(visible = true, transformation(origin = {-44, 84}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Logical.Switch switch1 annotation(
+ Placement(visible = true, transformation(origin = {0, 70}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Math.RealToBoolean realToBoolean1(threshold = 0.5) annotation(
+ Placement(visible = true, transformation(origin = {44, -64}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A2, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation(
+ Placement(visible = true, transformation(origin = {-88, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ equation
+ connect(adc.y, greaterEqualThreshold1.u) annotation(
+ Line(points = {{-76, 0}, {-70, 0}, {-70, 46}, {-54, 46}}, color = {0, 0, 127}));
+ connect(greaterEqualThreshold1.y, switch1.u2) annotation(
+ Line(points = {{-31, 46}, {-24, 46}, {-24, 70}, {-12, 70}}, color = {255, 0, 255}));
+ connect(adc.y, greaterEqualThreshold3.u) annotation(
+ Line(points = {{-76, 0}, {-70, 0}, {-70, -64}, {-52, -64}, {-52, -64}}, color = {0, 0, 127}));
+ connect(adc.y, greaterEqualThreshold2.u) annotation(
+ Line(points = {{-76, 0}, {-54, 0}, {-54, 0}, {-54, 0}}, color = {0, 0, 127}));
+ connect(realToBoolean1.y, digitalWriteBoolean3.u) annotation(
+ Line(points = {{56, -64}, {70, -64}, {70, -64}, {70, -64}}, color = {255, 0, 255}));
+ connect(switch12.y, realToBoolean1.u) annotation(
+ Line(points = {{22, -64}, {32, -64}, {32, -64}, {32, -64}}, color = {0, 0, 127}));
+ connect(realExpression1.y, switch1.u3) annotation(
+ Line(points = {{-28, -92}, {-16, -92}, {-16, 62}, {-12, 62}, {-12, 62}}, color = {0, 0, 127}));
+ connect(realExpression2.y, switch1.u1) annotation(
+ Line(points = {{-32, 84}, {-20, 84}, {-20, 78}, {-12, 78}, {-12, 78}}, color = {0, 0, 127}));
+ connect(switch1.y, greater2.u1) annotation(
+ Line(points = {{12, 70}, {22, 70}, {22, 70}, {24, 70}}, color = {0, 0, 127}));
+ connect(greater1.y, digitalWriteBoolean2.u) annotation(
+ Line(points = {{54, 0}, {70, 0}}, color = {255, 0, 255}));
+ connect(switch11.y, greater2.u2) annotation(
+ Line(points = {{14, 0}, {18, 0}, {18, 62}, {24, 62}, {24, 62}}, color = {0, 0, 127}));
+ connect(switch11.y, greater1.u1) annotation(
+ Line(points = {{14, 0}, {30, 0}}, color = {0, 0, 127}));
+ connect(switch12.y, greater1.u2) annotation(
+ Line(points = {{22, -64}, {22, -64}, {22, -8}, {30, -8}, {30, -8}}, color = {0, 0, 127}));
+ connect(greaterEqualThreshold2.y, switch11.u2) annotation(
+ Line(points = {{-30, 0}, {-10, 0}, {-10, 0}, {-10, 0}}, color = {255, 0, 255}));
+ connect(greater2.y, digitalWriteBoolean1.u) annotation(
+ Line(points = {{48, 70}, {56, 70}, {56, 40}, {70, 40}, {70, 40}}, color = {255, 0, 255}));
+ connect(realExpression2.y, switch12.u1) annotation(
+ Line(points = {{-32, 84}, {-20, 84}, {-20, -56}, {-2, -56}, {-2, -56}}, color = {0, 0, 127}));
+ connect(realExpression2.y, switch11.u1) annotation(
+ Line(points = {{-32, 84}, {-20, 84}, {-20, 8}, {-10, 8}, {-10, 8}}, color = {0, 0, 127}));
+ connect(realExpression1.y, switch11.u3) annotation(
+ Line(points = {{-28, -92}, {-16, -92}, {-16, -8}, {-10, -8}, {-10, -8}}, color = {0, 0, 127}));
+ connect(realExpression1.y, switch12.u3) annotation(
+ Line(points = {{-28, -92}, {-16, -92}, {-16, -72}, {-2, -72}, {-2, -72}}, color = {0, 0, 127}));
+ connect(greaterEqualThreshold3.y, switch12.u2) annotation(
+ Line(points = {{-28, -64}, {-2, -64}, {-2, -64}, {-2, -64}}, color = {255, 0, 255}));
+ annotation(
+ Documentation(info = "<html>
+ <h4>Syntax</h4>
+ <blockquote><pre>
+ Arduino.SerialCommunication.MDD_Examples.MDD_pot.<b>MDD_pot_threshold</b>();
+ </pre></blockquote>
+ <h4>Description</h4>
+ <p>Voltage reference used to represent 10 bit precision(1024) of ADC along with prescaling by by 128.Internal voltage reference is applied to adc.
+ </p>
+ </html>"));
+ end MDD_pot_threshold;
+ end MDD_pot;
+
+ package MDD_thermistor
+ extends Modelica.Icons.ExamplesPackage;
+
+ model MDD_therm_read
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {40, 42}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A4, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation(
+ Placement(visible = true, transformation(origin = {-40, -20}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort = true) annotation(
+ Placement(visible = true, transformation(origin = {39, -21}, extent = {{-15, -19}, {15, 19}}, rotation = 0)));
+ equation
+ connect(adc.y, realValue1.numberPort) annotation(
+ Line(points = {{-18, -20}, {20, -20}, {20, -20}, {22, -20}}, color = {0, 0, 127}));
+ end MDD_therm_read;
+
+ model MDD_therm_buzzer
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-61, 61}, extent = {{-21, -21}, {21, 21}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A4, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1024, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation(
+ Placement(visible = true, transformation(origin = {-68, 1.77636e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {41, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica.Blocks.Interaction.Show.RealValue realValue1(use_numberPort = true) annotation(
+ Placement(visible = true, transformation(origin = {12, -56}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.DigitalWriteBoolean digitalWriteBoolean1(pin = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Pin.'3', port = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Port.D) annotation(
+ Placement(visible = true, transformation(origin = {78, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Logical.LogicalSwitch logicalSwitch1 annotation(
+ Placement(visible = true, transformation(origin = {40, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression1(y = false) annotation(
+ Placement(visible = true, transformation(origin = {10, -32}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression2(y = true) annotation(
+ Placement(visible = true, transformation(origin = {10, 32}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Logical.GreaterEqualThreshold greaterEqualThreshold1(threshold = 550) annotation(
+ Placement(visible = true, transformation(origin = {-4, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ equation
+ connect(greaterEqualThreshold1.y, logicalSwitch1.u2) annotation(
+ Line(points = {{8, 0}, {28, 0}, {28, 0}, {28, 0}}, color = {255, 0, 255}));
+ connect(adc.y, greaterEqualThreshold1.u) annotation(
+ Line(points = {{-46, 0}, {-16, 0}, {-16, 0}, {-16, 0}}, color = {0, 0, 127}));
+ connect(adc.y, realValue1.numberPort) annotation(
+ Line(points = {{-46, 0}, {-32, 0}, {-32, -56}, {0, -56}}, color = {0, 0, 127}));
+ connect(logicalSwitch1.y, digitalWriteBoolean1.u) annotation(
+ Line(points = {{52, 0}, {66, 0}, {66, 0}, {66, 0}}, color = {255, 0, 255}));
+ connect(booleanExpression2.y, logicalSwitch1.u1) annotation(
+ Line(points = {{22, 32}, {24, 32}, {24, 8}, {28, 8}, {28, 8}}, color = {255, 0, 255}));
+ connect(booleanExpression1.y, logicalSwitch1.u3) annotation(
+ Line(points = {{22, -32}, {24, -32}, {24, -8}, {28, -8}, {28, -8}}, color = {255, 0, 255}));
+ end MDD_therm_buzzer;
+ end MDD_thermistor;
+
+ package MDD_dcmotor
+ extends Modelica.Icons.ExamplesPackage;
+
+ model MDD_dcmotor_clock
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {39, 41}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation(
+ Placement(visible = true, transformation(origin = {51, -3}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = if time < 5 then 100 else 0) annotation(
+ Placement(visible = true, transformation(origin = {-40, -3}, extent = {{-16, -13}, {16, 13}}, rotation = 0)));
+ equation
+ connect(pwm.u[1], integerExpression1.y) annotation(
+ Line(points = {{28, -3}, {-22, -3}}, color = {255, 127, 0}, thickness = 0.5));
+ end MDD_dcmotor_clock;
+
+ model MDD_dcmotor_both
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {56, 60}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation(
+ Placement(visible = true, transformation(origin = {54, 1.77636e-15}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = if mod(time, 5) >= 2.5 then 100 else 0) annotation(
+ Placement(visible = true, transformation(origin = {-41, 3.55271e-15}, extent = {{-23, -20}, {23, 20}}, rotation = 0)));
+ Modelica.Blocks.Sources.IntegerExpression integerExpression2(y = if mod(time, 5) < 2.5 then 100 else 0) annotation(
+ Placement(visible = true, transformation(origin = {-39, -48}, extent = {{-23, -20}, {23, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm1(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.B}) annotation(
+ Placement(visible = true, transformation(origin = {54, -48}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ equation
+ connect(integerExpression2.y, pwm1.u[1]) annotation(
+ Line(points = {{-14, -48}, {28, -48}, {28, -48}, {30, -48}}, color = {255, 127, 0}));
+ connect(integerExpression1.y, pwm.u[1]) annotation(
+ Line(points = {{-16, 0}, {28, 0}, {28, 0}, {30, 0}}, color = {255, 127, 0}));
+ end MDD_dcmotor_both;
+
+ model MDD_dcmotor_loop
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-40, 62}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.A}) annotation(
+ Placement(visible = true, transformation(origin = {44, 16}, extent = {{-16, -16}, {16, 16}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.PWM pwm1(fastPWM = true, initialValues = {0}, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1, timerNumbers = {Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerNumber.B}) annotation(
+ Placement(visible = true, transformation(origin = {44, -30}, extent = {{-16, -16}, {16, 16}}, rotation = 0)));
+ Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = if time < 3 then 100 else 0) annotation(
+ Placement(visible = true, transformation(origin = {-53, 16}, extent = {{-17, -16}, {17, 16}}, rotation = 0)));
+ Modelica.Blocks.Sources.IntegerExpression integerExpression2(y = if time >= 3 then 100 else 0) annotation(
+ Placement(visible = true, transformation(origin = {-52, -30}, extent = {{-16, -14}, {16, 14}}, rotation = 0)));
+ equation
+ connect(integerExpression2.y, pwm1.u[1]) annotation(
+ Line(points = {{-34, -30}, {24, -30}}, color = {255, 127, 0}));
+ connect(integerExpression1.y, pwm.u[1]) annotation(
+ Line(points = {{-34, 16}, {24, 16}}, color = {255, 127, 0}));
+ end MDD_dcmotor_loop;
+ end MDD_dcmotor;
+
+ package MDD_servo
+ extends Modelica.Icons.ExamplesPackage;
+
+ model MDD_servo_init
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-40, 40}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {61, 41}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = 30) annotation(
+ Placement(visible = true, transformation(origin = {-39, -7}, extent = {{-15, -15}, {15, 15}}, rotation = 0)));
+ Arduino.SerialCommunication.Blocks.Servo Servo(prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', servo_no = Arduino.SerialCommunication.Types.Servo_no.'1', timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer1) annotation(
+ Placement(visible = true, transformation(origin = {36, -8}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
+ equation
+ connect(integerExpression1.y, Servo.u) annotation(
+ Line(points = {{-22.5, -7}, {14, -7}, {14, -8}}, color = {255, 127, 0}));
+ end MDD_servo_init;
+
+ model MDD_servo_loop
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-41, 41}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1 annotation(
+ Placement(visible = true, transformation(origin = {39, 41}, extent = {{-17, -17}, {17, 17}}, rotation = 0)));
+ Modelica.Blocks.Math.Gain gain1(k = 20) annotation(
+ Placement(visible = true, transformation(origin = {38, -6}, extent = {{-14, -14}, {14, 14}}, rotation = 0)));
+ Modelica.Blocks.Sources.Clock clock1(offset = 0, startTime = 0) annotation(
+ Placement(visible = true, transformation(origin = {-74, 2}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
+ Modelica.Blocks.Logical.LessEqual lessEqual1 annotation(
+ Placement(visible = true, transformation(origin = {-58, -50}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Logical.Switch switch1 annotation(
+ Placement(visible = true, transformation(origin = {-22, -6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = 0) annotation(
+ Placement(visible = true, transformation(origin = {-30, -42}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Sources.IntegerExpression integerExpression2(y = 10) annotation(
+ Placement(visible = true, transformation(origin = {-84, -84}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Math.RealToInteger realToInteger1 annotation(
+ Placement(visible = true, transformation(origin = {4, -34}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Blocks.Servo Servo(prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', servo_no = 1, timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {78, -6}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ equation
+ connect(gain1.y, Servo.u) annotation(
+ Line(points = {{54, -6}, {66, -6}, {66, -6}, {66, -6}}, color = {0, 0, 127}));
+ connect(integerExpression2.y, lessEqual1.u2) annotation(
+ Line(points = {{-73, -84}, {-64, -84}, {-64, -68}, {-84, -68}, {-84, -58}, {-70, -58}}, color = {255, 127, 0}));
+ connect(realToInteger1.y, gain1.u) annotation(
+ Line(points = {{16, -34}, {16, -6}, {21, -6}}, color = {255, 127, 0}));
+ connect(clock1.y, lessEqual1.u1) annotation(
+ Line(points = {{-54, 2}, {-50, 2}, {-50, -32}, {-84, -32}, {-84, -50}, {-70, -50}, {-70, -50}}, color = {0, 0, 127}));
+ connect(clock1.y, switch1.u1) annotation(
+ Line(points = {{-54, 2}, {-34, 2}}, color = {0, 0, 127}));
+ connect(integerExpression1.y, switch1.u3) annotation(
+ Line(points = {{-18, -42}, {-16, -42}, {-16, -24}, {-40, -24}, {-40, -14}, {-34, -14}, {-34, -14}}, color = {255, 127, 0}));
+ connect(lessEqual1.y, switch1.u2) annotation(
+ Line(points = {{-46, -50}, {-44, -50}, {-44, -6}, {-34, -6}, {-34, -6}}, color = {255, 0, 255}));
+ connect(switch1.y, realToInteger1.u) annotation(
+ Line(points = {{-10, -6}, {-8, -6}, {-8, -34}, {-8, -34}}, color = {0, 0, 127}));
+ end MDD_servo_loop;
+
+ model MDD_servo_pot
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-40, 60}, extent = {{-20, -20}, {20, 20}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {39, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.ADC adc(analogPort = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPort.A2, prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.AnalogPrescaler.'1/128', voltageReference = 1023, voltageReferenceSelect = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.VRefSelect.Internal) annotation(
+ Placement(visible = true, transformation(origin = {-52, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Math.RealToInteger realToInteger1 annotation(
+ Placement(visible = true, transformation(origin = {-4, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Blocks.Servo Servo(prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', servo_no = 1, timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {46, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ equation
+ connect(realToInteger1.y, Servo.u) annotation(
+ Line(points = {{8, -10}, {34, -10}, {34, -10}, {34, -10}}, color = {255, 127, 0}));
+ connect(adc.y, realToInteger1.u) annotation(
+ Line(points = {{-40, -10}, {-16, -10}, {-16, -10}, {-16, -10}}, color = {0, 0, 127}));
+ end MDD_servo_pot;
+
+ model MDD_servo_reverse
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-59, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {55, 61}, extent = {{-19, -19}, {19, 19}}, rotation = 0)));
+ Modelica.Blocks.Sources.IntegerExpression integerExpression1(y = 90) annotation(
+ Placement(visible = true, transformation(origin = {-44, 0}, extent = {{-22, -22}, {22, 22}}, rotation = 0)));
+ Blocks.Servo Servo(prescaler = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerPrescaler.'1/1024', servo_no = 1, timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {26, 0}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ equation
+ connect(integerExpression1.y, Servo.u) annotation(
+ Line(points = {{-20, 0}, {14, 0}, {14, 0}, {14, 0}}, color = {255, 127, 0}));
+ end MDD_servo_reverse;
+ end MDD_servo;
+
+ package MDD_modbus
+ extends Modelica.Icons.ExamplesPackage;
+
+ model MDD_read_val
+ extends Modelica.Icons.Example;
+ inner Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu(desiredPeriod = 0.002, platform = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.Platform.ATmega328P) annotation(
+ Placement(visible = true, transformation(origin = {-45, 67}, extent = {{-15, -15}, {15, 15}}, rotation = 0)));
+ Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.SynchronizeRealtime synchronizeRealtime1(timer = Modelica_DeviceDrivers.EmbeddedTargets.AVR.Types.TimerSelect.Timer0) annotation(
+ Placement(visible = true, transformation(origin = {28, 68}, extent = {{-12, -12}, {12, 12}}, rotation = 0)));
+ Modelica.Blocks.MathInteger.MultiSwitch multiSwitch1(expr = {86, 88, 78}, nu = 3, use_pre_as_default = true, y_default = 0) annotation(
+ Placement(visible = true, transformation(origin = {-32.6577, -10}, extent = {{-10.0019, -22}, {30.0056, 22}}, rotation = 0)));
+ Modelica.Blocks.Sources.BooleanExpression booleanExpression1 annotation(
+ Placement(visible = true, transformation(origin = {-78, -12}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Modelica.Blocks.Interaction.Show.RealValue realValue1 annotation(
+ Placement(visible = true, transformation(origin = {60, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ Blocks.Read_Val read_Val1 annotation(
+ Placement(visible = true, transformation(origin = {26, -10}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
+ equation
+ connect(read_Val1.y, realValue1.numberPort) annotation(
+ Line(points = {{38, -10}, {48, -10}, {48, -10}, {48, -10}}, color = {0, 0, 127}));
+ connect(multiSwitch1.y, read_Val1.u) annotation(
+ Line(points = {{-2, -10}, {14, -10}, {14, -10}, {14, -10}}, color = {255, 127, 0}));
+ end MDD_read_val;
+ end MDD_modbus;
+ end MDD_Examples;
+
+ package Blocks
+ extends Modelica.Icons.Package;
+
+ model Servo
+ extends Modelica.Blocks.Icons.Block;
+ import Modelica_DeviceDrivers.EmbeddedTargets.AVR;
+ import sComm = Arduino.SerialCommunication.Functions;
+ outer Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu;
+ constant AVR.Types.TimerSelect timer annotation(
+ Dialog(enable = true, tab = "General", group = "Constants"));
+ constant AVR.Types.TimerPrescaler prescaler "Pre-scaler for the clock." annotation(
+ Dialog(enable = true, tab = "General", group = "Constants"));
+ constant sComm.Types.Servo_no servo_no annotation(
+ Dialog(enable = true, tab = "General", group = "Constants"));
+ Modelica.Blocks.Interfaces.IntegerInput u "Connector of Servo input signals (integer 0..255)" annotation(
+ Placement(transformation(extent = {{-140, -20}, {-100, 20}})));
+ protected
+ AVR.Functions.Timers.Timer clock = AVR.Functions.Timers.Timer(timer, prescaler, clearTimerOnMatch = true);
+ sComm.Functions.MDD_Servo.Init servo = sComm.Functions.MDD_Servo.Init(servo_no);
+ algorithm
+ sComm.Functions.MDD_Servo.Move(servo, u);
+ annotation(
+ defaultComponentName = "Servo",
+ Icon(graphics = {Text(extent = {{-95, -95}, {95, 95}}, textString = "Servo %servo_no", fontName = "Arial")}));
+ end Servo;
+
+ model Read_Val
+ extends Modelica.Blocks.Interfaces.SISO;
+ import Modelica_DeviceDrivers.EmbeddedTargets.AVR;
+ import sComm = Arduino.SerialCommunication.Functions;
+ outer Modelica_DeviceDrivers.EmbeddedTargets.AVR.Blocks.Microcontroller mcu;
+ annotation(
+ defaultComponentName = "Read_Val",
+ Icon(graphics = {Text(extent = {{-95, -95}, {95, 95}}, textString = "Read_Val", fontName = "Arial")}));
+ end Read_Val;
+ end Blocks;
+
+ type Types
+ extends Modelica.Icons.TypesPackage;
+ type Servo_no = enumeration('1' "Servo1", '2' "Servo2") "Servo ID";
+ end Types;
+
+ package Icons "Collection of icons used for library components"
+ extends Modelica.Icons.IconsPackage;
+
+ partial package GenericICPackage "Icon with a generic IC"
+ annotation(Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Bitmap(extent = {{-95, -95}, {95, 95}}, fileName = "Resources/Images/Icons/tqfp32.png", rotation = 0)}), Documentation(info = "<html>
+<p>
+This partial class is intended to design a <em>default icon for microcontrollers</em>.
+</p>
+</html>"));
+end GenericICPackage;
+
+
+
+partial block GenericIC "Icon with a generic IC"
+ annotation(Icon(coordinateSystem(preserveAspectRatio = true, extent = {{-100, -100}, {100, 100}}), graphics = {Bitmap(extent = {{-95, -95}, {95, 95}}, fileName = "Resources/Images/Icons/tqfp32.png", rotation = 0)}), Documentation(info = "<html>
+<p>
+This partial class is intended to design a <em>default icon for microcontrollers</em>.
+</p>
+</html>"));
+end GenericIC;
+
+
+
+partial package FunctionLayerIcon
+ "Icon for packages that represent the function layer"
+ extends Modelica.Icons.Package;
+
+ annotation (Icon(coordinateSystem(preserveAspectRatio=false, extent={{-100,-100},{100,100}}), graphics={
+ Text(
+ lineColor={128,128,128},
+ extent={{-90,-90},{90,90}},
+ textString="f"),
+ Ellipse(
+ lineColor={128,128,128},
+ extent={{-80,-80},{80,80}})}),
+Documentation(info="<html>
+<p>This icon indicates Modelica functions.</p>
+</html>"));
+end FunctionLayerIcon;
+
+
+ annotation (
+ preferredView="info",
+ Documentation(
+ info="<html>
+<p>
+A collection of basic icons to be used for different elements of the library.
+</p>
+</html>"));
+end Icons;
+
+ annotation(
+ Documentation(info = "<html>
+<h4>Description</h4>
+<p>
+A serial communication package for hardware interfacing.
+</p>
+</html>"));
+ end SerialCommunication;
+ annotation(
+ uses(Modelica_DeviceDrivers(version = "1.5.0"), Modelica(version = "3.2.2")));
+end Arduino;
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_both b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_both
new file mode 100644
index 0000000..8e427ab
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_both
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_both.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_both.hex
new file mode 100644
index 0000000..d0aa91f
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_both.hex
@@ -0,0 +1,121 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C942C0140
+:100020000C9451000C9451000C9451000C94FB0062
+:100030000C9451000C9451000C94CA000C94510083
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E4E5F7E002C0F3
+:1000800005900D92A831B107D9F711E0A8E1B1E0D0
+:1000900001C01D92AD31B107E1F70E94A4010C949B
+:1000A000A8030C940000CF92DF92EF92FF92CF93BF
+:1000B000DF93EC01C880D980EA80FB80C701B601DC
+:1000C0000E9479029B01AC01C701B6010E94D301D5
+:1000D0006B017C0120E030E040E05FE30E944103DF
+:1000E00087FF03C080E090E002C084E690E09D833B
+:1000F0008C8320E030E040E05FE3C701B6010E945E
+:10010000380287FD03C080E090E002C084E690E002
+:100110009F838E838E899F898230910561F0833021
+:10012000910599F00197C9F416BC80916E00826028
+:1001300080936E0016C0109285001092840080910A
+:100140006F00826080936F000CC01092B2008091AB
+:10015000700082608093700004C081E090E00E9493
+:10016000A80378949FB7F89480911A019FBF8823C1
+:10017000C9F310921A01EE85FF858C818083EA898C
+:10018000FB898E818083DF91CF91FF90EF90DF908C
+:10019000CF9008951F920F920FB60F9211242F93B4
+:1001A0003F938F939F93809118019091190101962D
+:1001B000909319018093180180911A01813091F078
+:1001C000209118013091190180911B0190911C011F
+:1001D0002817390738F081E080931A01109219012D
+:1001E000109218019F918F913F912F910F900FBE08
+:1001F0000F901F9018951F920F920FB60F92112417
+:100200002F933F938F939F938091180190911901A1
+:100210000196909319018093180180911A01813001
+:1002200091F0209118013091190180911B0190915A
+:100230001C012817390738F081E080931A011092C9
+:100240001901109218019F918F913F912F910F905A
+:100250000FBE0F901F9018951F920F920FB60F921E
+:1002600011242F933F938F939F9380911801909126
+:1002700019010196909319018093180180911A0138
+:10028000813091F0209118013091190180911B016A
+:1002900090911C012817390738F081E080931A01EA
+:1002A00010921901109218019F918F913F912F91F7
+:1002B0000F900FBE0F901F901895CF93DF93FC0106
+:1002C000C1E8D0E088818D60888322E030E0318B06
+:1002D000208B229A40E850E0DA018C9181628C9365
+:1002E0008AE890E0DC0111961C921E921C92938B7E
+:1002F000828B88818D60888335872487219ADA01F3
+:100300008C9181688C93A8E8B0E011961C921E92A3
+:100310001C92B787A68785B5836085BD21E030E054
+:10032000358B248B8AE090E090931C0180931B0115
+:1003300084B5826084BD89EF87BD378B268B80E0D2
+:1003400090E0DF91CF910895CF92DF92EF92FF92EC
+:1003500080E091E00E945D01C12CD12C760160E02B
+:1003600070E0CB0160930001709301018093020162
+:100370009093030180E091E00E9453008FEFC81A30
+:10038000D80AE80AF80AC701B6010E943C022FE623
+:1003900032E143E05BE30E94450320E030E0A90145
+:1003A0000E94D401DFCF5058BB27AA270ED018C116
+:1003B00009D130F00ED120F031F49F3F11F41EF43A
+:1003C000FEC00EF4E095E7FBCBC0E92F1AD180F315
+:1003D000BA17620773078407950718F071F49EF542
+:1003E00049C10EF4E0950B2EBA2FA02D0B01B901D7
+:1003F00090010C01CA01A0011124FF27591B99F09B
+:10040000593F50F4503E68F11A16F040A22F232FA6
+:10041000342F4427585FF3CF469537952795A795F6
+:10042000F0405395C9F77EF41F16BA0B620B730B9D
+:10043000840BBAF09150A1F0FF0FBB1F661F771F0E
+:10044000881FC2F70EC0BA0F621F731F841F48F4C3
+:10045000879577956795B795F7959E3F08F0B3CF49
+:100460009395880F08F09927EE0F97958795089533
+:1004700053D008F481E00895E89409C097FB3EF456
+:1004800090958095709561957F4F8F4F9F4F9923E1
+:10049000A9F0F92F96E9BB279395F695879577955F
+:1004A0006795B795F111F8CFFAF4BB0F11F460FF1F
+:1004B0001BC06F5F7F4F8F4F9F4F16C0882311F077
+:1004C00096E911C0772321F09EE8872F762F05C08B
+:1004D000662371F096E8862F70E060E02AF09A9526
+:1004E000660F771F881FDAF7880F9695879597F91B
+:1004F0000895A9D080F09F3740F491110EF0BBC051
+:1005000060E070E080E89FEB089526F41B16611D03
+:10051000711D811D2BC045C0990F0008550FAA0BF6
+:10052000E0E8FEEF16161706E807F907C0F0121606
+:100530001306E407F50798F0621B730B840B950B09
+:1005400039F40A2661F0232B242B252B21F408955E
+:100550000A2609F4A140A6958FEF811D811D0895FB
+:1005600097F99F6780E870E060E00895882371F450
+:10057000772321F09850872B762F07C0662311F43C
+:1005800099270DC09051862B70E060E02AF09A9573
+:10059000660F771F881FDAF7880F9695879597F96A
+:1005A00008959F3F31F0915020F487957795679596
+:1005B000B795880F911D9695879597F908959FEFA8
+:1005C00080EC089500240A941616170618060906EA
+:1005D000089500240A9412161306140605060895B9
+:1005E000092E0394000C11F4882352F0BB0F40F441
+:1005F000BF2B11F460FF04C06F5F7F4F8F4F9F4F81
+:10060000089557FD9058440F551F59F05F3F71F002
+:100610004795880F97FB991F61F09F3F79F0879569
+:100620000895121613061406551FF2CF4695F1DFF2
+:1006300008C0161617061806991FF1CF8695710582
+:10064000610508940895E5DFA0F0BEE7B91788F4C6
+:10065000BB279F3860F41616B11D672F782F8827A7
+:10066000985FF7CF869577956795B11D93959639E5
+:10067000C8F30895E894BB2766277727CB0197F93D
+:1006800008954ADF08F48FEF08950BD0A9CF9ADFC1
+:1006900028F09FDF18F0952309F062CF90CF112446
+:1006A000EACFAFDFA0F3959FD1F3950F50E0551F30
+:1006B000629FF001729FBB27F00DB11D639FAA27B7
+:1006C000F00DB11DAA1F649F6627B00DA11D661F06
+:1006D000829F2227B00DA11D621F739FB00DA11D27
+:1006E000621F839FA00D611D221F749F3327A00DE1
+:1006F000611D231F849F600D211D822F762F6A2F7D
+:1007000011249F5750408AF0E1F088234AF0EE0F01
+:10071000FF1FBB1F661F771F881F91505040A9F70E
+:100720009E3F510570F01CCFA6CF5F3FECF3983E83
+:10073000DCF3869577956795B795F795E7959F5F75
+:10074000C1F7FE2B880F911D9695879597F908950F
+:04075000F894FFCF4B
+:1007540000000000000000000AD7233C0000000055
+:0807640000000000000000008D
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_both_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_both_main.c
new file mode 100644
index 0000000..08a9ca0
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_both_main.c
@@ -0,0 +1,217 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_dcmotor_both_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_dcmotor_both_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Integer fmi2IntegerVars[2];
+ fmi2Real fmi2RealParameter[1];
+ void* extObjs[6];
+} MDD_dcmotor_both_fmi2Component;
+
+MDD_dcmotor_both_fmi2Component MDD_dcmotor_both_component = {
+ .fmi2IntegerVars = {
+ 0 /*pwm._u[1]*/,
+ 0 /*pwm1._u[1]*/,
+ },
+ .fmi2RealParameter = {
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRAnalog.h"
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value)
+{
+ MDD_avr_pwm_set(om_pwm, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted)
+{
+ void* om_pwm;
+ om_pwm = MDD_avr_pwm_init(om_timer, om_pin, om_initialValue, om_inverted);
+ return om_pwm;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm)
+{
+ MDD_avr_pwm_close(om_pwm);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_dcmotor_both_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_dcmotor_both_component;
+}
+
+fmi2Status MDD_dcmotor_both_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_dcmotor_both_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[2] /* pwm1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True);
+ comp->extObjs[3] /* pwm1._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[2] /* pwm1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 2, 0, fmi2False);
+ comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True);
+ comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 1, 0, fmi2False);
+ comp->extObjs[4] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[5] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[4] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ return fmi2OK;
+}
+
+fmi2Status MDD_dcmotor_both_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_dcmotor_both_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_dcmotor_both_functionOutputs(fmi2Component comp)
+{
+ comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */ = ((om_mod(comp->currentTime,1.0))>=(0.5)) ? (100) : (0); /* equation 4 */
+ comp->fmi2IntegerVars[1] /* pwm1._u[1] DISCRETE */ = ((om_mod(comp->currentTime,1.0))<(0.5)) ? (100) : (0); /* equation 5 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[5] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[3] /* pwm1._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, comp->fmi2IntegerVars[1] /* pwm1._u[1] DISCRETE */);
+}
+
+fmi2Status MDD_dcmotor_both_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_dcmotor_both_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_dcmotor_both_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_dcmotor_both_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_dcmotor_both_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_dcmotor_both_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_dcmotor_both_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clock b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clock
new file mode 100644
index 0000000..249910a
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clock
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clock.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clock.hex
new file mode 100644
index 0000000..afe0f97
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clock.hex
@@ -0,0 +1,94 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E50088
+:100020000C9451000C9451000C9451000C94B400A9
+:100030000C9451000C9451000C9483000C945100CA
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E6EAF5E002C0EE
+:1000800005900D92A231B107D9F711E0A2E1B1E0DC
+:1000900001C01D92A731B107E1F70E9445010C9400
+:1000A000D1020C9400008230910561F083309105FB
+:1000B00099F00197C9F416BC80916E00826080931C
+:1000C0006E0016C0109285001092840080916F001F
+:1000D000826080936F000CC01092B200809170001B
+:1000E00082608093700004C081E090E00E94D102A1
+:1000F00078949FB7F894809114019FBF8823C9F327
+:100100001092140108951F920F920FB60F921124AE
+:100110002F933F938F939F9380911201909113019E
+:100120000196909313018093120180911401813004
+:1001300091F020911201309113018091150190915D
+:1001400016012817390738F081E0809314011092C6
+:100150001301109212019F918F913F912F910F9057
+:100160000FBE0F901F9018951F920F920FB60F920F
+:1001700011242F933F938F939F938091120190911D
+:100180001301019690931301809312018091140141
+:10019000813091F02091120130911301809115016D
+:1001A000909116012817390738F081E080931401E7
+:1001B00010921301109212019F918F913F912F91F4
+:1001C0000F900FBE0F901F9018951F920F920FB6B1
+:1001D0000F9211242F933F938F939F93809112013D
+:1001E00090911301019690931301809312018091D5
+:1001F0001401813091F0209112013091130180910E
+:100200001501909116012817390738F081E0809385
+:10021000140110921301109212019F918F913F913E
+:100220002F910F900FBE0F901F901895FC01A1E821
+:10023000B0E08C918D608C9382E090E09387828710
+:10024000219AA0E8B0E08C9181688C93A8E8B0E096
+:1002500011961C921E921C92B587A48785B5836067
+:1002600085BD21E030E0378726878AE090E09093D3
+:1002700016018093150184B5826084BD89EF87BD26
+:10028000318B208B80E090E00895CF92DF92EF9247
+:10029000FF9280E091E00E941601C12CD12C7601E2
+:1002A00060E070E0CB0160930001709301018093E6
+:1002B00002019093030180911001909111010E941D
+:1002C0005300E0910C01F0910D0110828FEFC81ADC
+:1002D000D80AE80AF80AC701B6010E94E0012FE631
+:1002E00032E143E05BE30E946E0220E030E0A901CE
+:1002F0000E947C01D8CF5058BB27AA270ED0B4C08B
+:10030000A5D030F0AAD020F031F49F3F11F41EF4B4
+:100310009AC00EF4E095E7FB90C0E92FB6D080F3C9
+:10032000BA17620773078407950718F071F49EF5F2
+:10033000CEC00EF4E0950B2EBA2FA02D0B01B90103
+:1003400090010C01CA01A0011124FF27591B99F04B
+:10035000593F50F4503E68F11A16F040A22F232F57
+:10036000342F4427585FF3CF469537952795A795A7
+:10037000F0405395C9F77EF41F16BA0B620B730B4E
+:10038000840BBAF09150A1F0FF0FBB1F661F771FBF
+:10039000881FC2F70EC0BA0F621F731F841F48F474
+:1003A000879577956795B795F7959E3F08F0B3CFFA
+:1003B0009395880F08F09927EE0F979587950895E4
+:1003C000E89409C097FB3EF49095809570956195EF
+:1003D0007F4F8F4F9F4F9923A9F0F92F96E9BB27A5
+:1003E0009395F695879577956795B795F111F8CF21
+:1003F000FAF4BB0F11F460FF1BC06F5F7F4F8F4F8C
+:100400009F4F16C0882311F096E911C0772321F081
+:100410009EE8872F762F05C0662371F096E8862F19
+:1004200070E060E02AF09A95660F771F881FDAF770
+:10043000880F9695879597F9089597F99F6780E8B3
+:1004400070E060E008959FEF80EC089500240A9426
+:100450001616170618060906089500240A9412169F
+:100460001306140605060895092E0394000C11F4D2
+:10047000882352F0BB0F40F4BF2B11F460FF04C07F
+:100480006F5F7F4F8F4F9F4F089557FD9058440FD8
+:10049000551F59F05F3F71F04795880F97FB991FE3
+:1004A00061F09F3F79F087950895121613061406A0
+:1004B000551FF2CF4695F1DF08C01616170618062D
+:1004C000991FF1CF86957105610508940895E89408
+:1004D000BB2766277727CB0197F908950BD0C4CFA8
+:1004E000B5DF28F0BADF18F0952309F0A6CFABCF1F
+:1004F0001124EECFCADFA0F3959FD1F3950F50E002
+:10050000551F629FF001729FBB27F00DB11D639FC5
+:10051000AA27F00DB11DAA1F649F6627B00DA11D6B
+:10052000661F829F2227B00DA11D621F739FB00D11
+:10053000A11D621F839FA00D611D221F749F332781
+:10054000A00D611D231F849F600D211D822F762F1A
+:100550006A2F11249F5750408AF0E1F088234AF017
+:10056000EE0FFF1FBB1F661F771F881F9150504063
+:10057000A9F79E3F510570F060CFAACF5F3FECF323
+:10058000983EDCF3869577956795B795F795E7954F
+:100590009F5FC1F7FE2B880F911D9695879597F960
+:0605A0000895F894FFCF5E
+:1005A6000000000000000AD7233C00000000000005
+:0205B600000043
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clock_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clock_main.c
new file mode 100644
index 0000000..f11c915
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_clock_main.c
@@ -0,0 +1,213 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_dcmotor_clock_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_dcmotor_clock_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Integer fmi2IntegerVars[1];
+ fmi2Real fmi2RealParameter[1];
+ void* extObjs[4];
+} MDD_dcmotor_clock_fmi2Component;
+
+MDD_dcmotor_clock_fmi2Component MDD_dcmotor_clock_component = {
+ .fmi2IntegerVars = {
+ 0 /*integerExpression1._y*/,
+ },
+ .fmi2RealParameter = {
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRAnalog.h"
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value)
+{
+ MDD_avr_pwm_set(om_pwm, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted)
+{
+ void* om_pwm;
+ om_pwm = MDD_avr_pwm_init(om_timer, om_pin, om_initialValue, om_inverted);
+ return om_pwm;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm)
+{
+ MDD_avr_pwm_close(om_pwm);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_dcmotor_clock_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_dcmotor_clock_component;
+}
+
+fmi2Status MDD_dcmotor_clock_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_dcmotor_clock_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True);
+ comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 1, 0, fmi2False);
+ comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ return fmi2OK;
+}
+
+fmi2Status MDD_dcmotor_clock_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_dcmotor_clock_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_dcmotor_clock_functionOutputs(fmi2Component comp)
+{
+ Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, 0);
+}
+
+fmi2Status MDD_dcmotor_clock_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_dcmotor_clock_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_dcmotor_clock_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_dcmotor_clock_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_dcmotor_clock_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_dcmotor_clock_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_dcmotor_clock_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_loop_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_loop_main.c
new file mode 100644
index 0000000..4a0dad8
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/MDD_dcmotor_loop_main.c
@@ -0,0 +1,235 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_dcmotor_loop_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_dcmotor_loop_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Real fmi2RealVars[4];
+ fmi2Integer fmi2IntegerVars[1];
+ fmi2Real fmi2RealParameter[4];
+ void* extObjs[4];
+} MDD_dcmotor_loop_fmi2Component;
+
+MDD_dcmotor_loop_fmi2Component MDD_dcmotor_loop_component = {
+ .fmi2RealVars = {
+ 100.0 /*add31._u1*/,
+ 0.0 /*add31._u2*/,
+ 0.0 /*add31._u3*/,
+ 100.0 /*add31._y*/,
+ },
+ .fmi2IntegerVars = {
+ 0 /*pwm._u[1]*/,
+ },
+ .fmi2RealParameter = {
+ 1.0 /*add31._k1*/,
+ -1.0 /*add31._k2*/,
+ 1.0 /*add31._k3*/,
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRAnalog.h"
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(fmi2Component comp, void* om_pwm, fmi2Integer om_value)
+{
+ MDD_avr_pwm_set(om_pwm, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_pin, fmi2Integer om_initialValue, fmi2Boolean om_inverted)
+{
+ void* om_pwm;
+ om_pwm = MDD_avr_pwm_init(om_timer, om_pin, om_initialValue, om_inverted);
+ return om_pwm;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_destructor(fmi2Component comp, void* om_pwm)
+{
+ MDD_avr_pwm_close(om_pwm);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_dcmotor_loop_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_dcmotor_loop_component;
+}
+
+fmi2Status MDD_dcmotor_loop_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_dcmotor_loop_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 2, 7, fmi2True);
+ comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_Init_constructor(comp, comp->extObjs[0] /* pwm._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 1, 0, fmi2False);
+ comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ return fmi2OK;
+}
+
+fmi2Status MDD_dcmotor_loop_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_dcmotor_loop_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_dcmotor_loop_functionOutputs(fmi2Component comp)
+{
+ comp->fmi2RealVars[0] /* add31._u1 variable */ = (
+ #error "[CodegenEmbeddedC.tpl:474:14-474:14] daeExpBinary: Not supporting operator? time <= 1.0"
+ ) ? (100.0) : (0.0); /* equation 7 */
+ comp->fmi2RealVars[1] /* add31._u2 variable */ = (
+ #error "[CodegenEmbeddedC.tpl:460:14-460:14] daeExp: Not supporting time <= 1.4 and time > 1.0"
+ ) ? (100.0) : (0.0); /* equation 8 */
+ comp->fmi2RealVars[2] /* add31._u3 variable */ = ((comp->currentTime)>(1.4)) ? (100.0) : (0.0); /* equation 9 */
+ comp->fmi2RealVars[3] /* add31._y variable */ = ((comp->fmi2RealParameter[0] /* add31._k1 PARAM */)*(comp->fmi2RealVars[0] /* add31._u1 variable */))+(((comp->fmi2RealParameter[1] /* add31._k2 PARAM */)*(comp->fmi2RealVars[1] /* add31._u2 variable */))+((comp->fmi2RealParameter[2] /* add31._k3 PARAM */)*(comp->fmi2RealVars[2] /* add31._u3 variable */))); /* equation 10 */
+ comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */ = ((comp->fmi2RealVars[3] /* add31._y variable */)>(0.0)) ? (((int)
+ #error "[CodegenEmbeddedC.tpl:490:28-490:28] daeExpCallBuiltin: Not supported: floor(0.5 + add31.y, 1)"
+ )) : (((int)
+ #error "[CodegenEmbeddedC.tpl:490:28-490:28] daeExpCallBuiltin: Not supported: ceil(-0.5 + add31.y, 3)"
+ )); /* equation 11 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_PWM_set(comp, comp->extObjs[1] /* pwm._pwm[1] EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.PWM.Init */, comp->fmi2IntegerVars[0] /* pwm._u[1] DISCRETE */);
+}
+
+fmi2Status MDD_dcmotor_loop_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_dcmotor_loop_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_dcmotor_loop_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_dcmotor_loop_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_dcmotor_loop_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_dcmotor_loop_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_dcmotor_loop_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_both.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_both.mos
new file mode 100644
index 0000000..876a5d6
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_both.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_dcmotor.MDD_dcmotor_both, fileNamePrefix="MDD_dcmotor_both");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_clock.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_clock.mos
new file mode 100644
index 0000000..cdd2767
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_clock.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_dcmotor.MDD_dcmotor_clock, fileNamePrefix="MDD_dcmotor_clock");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_loop.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_loop.mos
new file mode 100644
index 0000000..e9207ed
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/dcmotor/run_dcmotor_loop.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_dcmotor.MDD_dcmotor_loop, fileNamePrefix="MDD_dcmotor_loop");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr
new file mode 100644
index 0000000..c87ce1f
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_led b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_led
new file mode 100644
index 0000000..542fc5b
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_led
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_led.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_led.hex
new file mode 100644
index 0000000..f845f70
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_led.hex
@@ -0,0 +1,120 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C9431013B
+:100020000C9451000C9451000C9451000C9400015C
+:100030000C9451000C9451000C94CF000C9451007E
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E4E4F7E002C0F4
+:1000800005900D92AE31B107D9F711E0AEE1B1E0C4
+:1000900001C01D92A332B107E1F70E948B010C94BD
+:1000A000A0030C9400000F931F93CF93DF93EC01F8
+:1000B00080917C00857E856080937C0080917A00B1
+:1000C000806480937A0080917A0086FDFCCF6091F5
+:1000D00078007091790080E090E00E94870220E033
+:1000E00030E040E854E40E94190320E030EC4FE790
+:1000F00054E40E941F026C837D838E839F8301E002
+:1001000010E02E853F85488959890E9415031816ED
+:1001100014F000E010E01D870C878C8D9D8D8230DF
+:10012000910561F08330910599F00197C9F416BCEF
+:1001300080916E00826080936E0016C010928500E0
+:100140001092840080916F00826080936F000CC0D9
+:100150001092B2008091700082608093700004C0A1
+:1001600081E090E00E94A00378949FB7F89480917A
+:1001700020019FBF8823C9F310922001E88DF98DDB
+:100180008C859D85892B19F08081826002C08081D9
+:100190008D7F8083DF91CF911F910F9108951F92E2
+:1001A0000F920FB60F9211242F933F938F939F932B
+:1001B00080911E0190911F01019690931F018093E1
+:1001C0001E0180912001813091F020911E0130911B
+:1001D0001F0180912101909122012817390738F0E1
+:1001E00081E08093200110921F0110921E019F91C7
+:1001F0008F913F912F910F900FBE0F901F901895E8
+:100200001F920F920FB60F9211242F933F938F934B
+:100210009F9380911E0190911F01019690931F0161
+:1002200080931E0180912001813091F020911E0168
+:1002300030911F01809121019091220128173907E7
+:1002400038F081E08093200110921F0110921E016E
+:100250009F918F913F912F910F900FBE0F901F9004
+:1002600018951F920F920FB60F9211242F933F9360
+:100270008F939F9380911E0190911F0101969093FF
+:100280001F0180931E0180912001813091F0209107
+:100290001E0130911F0180912101909122012817A8
+:1002A000390738F081E08093200110921F011092ED
+:1002B0001E019F918F913F912F910F900FBE0F9034
+:1002C0001F901895FC01ACE7B0E08C91806C8C938A
+:1002D000AAE7B0E08C9187688C93178A168A219AD6
+:1002E00085E290E0918F808F85B5836085BD21E0A8
+:1002F00030E0338F228F8AE090E090932201809348
+:10030000210184B5826084BD89EF87BD358F248F3C
+:1003100080E090E00895CF92DF92EF92FF9280E02C
+:1003200091E00E946201C12CD12C760160E070E066
+:10033000CB016093000170930101809302019093BF
+:10034000030180E091E00E9453008FEFC81AD80AA1
+:10035000E80AF80AC701B6010E9487022FE632E1D7
+:1003600043E05BE30E94190320E030E0A9010E9412
+:10037000BB01DFCF5058BB27AA270ED01CC10DD11F
+:1003800030F012D120F031F49F3F11F41EF402C17D
+:100390000EF4E095E7FBF8C0E92F1ED180F3BA1701
+:1003A000620773078407950718F071F49EF536C14C
+:1003B0000EF4E0950B2EBA2FA02D0B01B901900180
+:1003C0000C01CA01A0011124FF27591B99F0593FC4
+:1003D00050F4503E68F11A16F040A22F232F342F0C
+:1003E0004427585FF3CF469537952795A795F0405A
+:1003F0005395C9F77EF41F16BA0B620B730B840B6F
+:10040000BAF09150A1F0FF0FBB1F661F771F881F26
+:10041000C2F70EC0BA0F621F731F841F48F487957E
+:1004200077956795B795F7959E3F08F0B3CF93956D
+:10043000880F08F09927EE0F9795879508950CD0AF
+:10044000BAC0B2D040F0A9D030F021F45F3F19F02B
+:100450009BC05111E4C09EC0BFD098F39923C9F34B
+:100460005523B1F3951B550BBB27AA2762177307BA
+:10047000840738F09F5F5F4F220F331F441FAA1F6E
+:10048000A9F333D00E2E3AF0E0E830D0915050402E
+:10049000E695001CCAF729D0FE2F27D0660F771FDC
+:1004A000881FBB1F261737074807AB07B0E809F0BE
+:1004B000BB0B802DBF01FF2793585F4F2AF09E3F53
+:1004C000510568F061C0ABC05F3FECF3983EDCF3D0
+:1004D000869577956795B795F7959F5FC9F7880FCC
+:1004E000911D9695879597F90895E1E0660F771F1E
+:1004F000881FBB1F621773078407BA0720F0621BAF
+:10050000730B840BBA0BEE1F88F7E0950895E894FF
+:1005100009C097FB3EF490958095709561957F4F4B
+:100520008F4F9F4F9923A9F0F92F96E9BB279395F9
+:10053000F695879577956795B795F111F8CFFAF409
+:10054000BB0F11F460FF1BC06F5F7F4F8F4F9F4F3A
+:1005500016C0882311F096E911C0772321F09EE898
+:10056000872F762F05C0662371F096E8862F70E0FE
+:1005700060E02AF09A95660F771F881FDAF7880FD8
+:100580009695879597F9089597F99F6780E870E0A9
+:1005900060E008959FEF80EC089500240A941616F9
+:1005A000170618060906089500240A941216130661
+:1005B000140605060895092E0394000C11F48823EF
+:1005C00052F0BB0F40F4BF2B11F460FF04C06F5F0B
+:1005D0007F4F8F4F9F4F089557FD9058440F551FE1
+:1005E00059F05F3F71F04795880F97FB991F61F0B5
+:1005F0009F3F79F087950895121613061406551F2C
+:10060000F2CF4695F1DF08C0161617061806991F97
+:10061000F1CF86957105610508940895E894BB278C
+:1006200066277727CB0197F9089566D008F48FEFF6
+:1006300008950BD0C0CFB1DF28F0B6DF18F09523B6
+:1006400009F0A2CFA7CF1124EACFC6DFA0F3959F70
+:10065000D1F3950F50E0551F629FF001729FBB27A9
+:10066000F00DB11D639FAA27F00DB11DAA1F649F55
+:100670006627B00DA11D661F829F2227B00DA11D08
+:10068000621F739FB00DA11D621F839FA00D611D8E
+:10069000221F749F3327A00D611D231F849F600DAF
+:1006A000211D822F762F6A2F11249F5750408AF0E8
+:1006B000E1F088234AF0EE0FFF1FBB1F661F771F74
+:1006C000881F91505040A9F79E3F510570F05CCFB4
+:1006D000A6CF5F3FECF3983EDCF386957795679560
+:1006E000B795F795E7959F5FC1F7FE2B880F911D92
+:1006F0009695879597F90895990F0008550FAA0BBD
+:10070000E0E8FEEF16161706E807F907C0F0121624
+:100710001306E407F50798F0621B730B840B950B27
+:1007200039F40A2661F0232B242B252B21F408957C
+:100730000A2609F4A140A6958FEF811D811D089519
+:04074000F894FFCF5B
+:1007440000000000000000000000000000000000A5
+:0E07540016440AD7233C0000000000000000FD
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_led_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_led_main.c
new file mode 100644
index 0000000..36a97c9
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_led_main.c
@@ -0,0 +1,243 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_ldr_led_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_ldr_led_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Real fmi2RealVars[1];
+ fmi2Boolean fmi2BooleanVars[3];
+ fmi2Real fmi2RealParameter[2];
+ void* extObjs[4];
+} MDD_ldr_led_fmi2Component;
+
+MDD_ldr_led_fmi2Component MDD_ldr_led_component = {
+ .fmi2RealVars = {
+ 0.0 /*adc._y*/,
+ },
+ .fmi2BooleanVars = {
+ fmi2False /*booleanExpression1._y*/,
+ fmi2False /*booleanExpression2._y*/,
+ fmi2False /*digitalWriteBoolean1._u*/,
+ },
+ .fmi2RealParameter = {
+ 600.0 /*greaterThreshold1._threshold*/,
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+static const char * const OMCLIT0 = "ElectricPotential";
+static const char * const OMCLIT1 = "V";
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRDigital.h"
+#include "MDDAVRAnalog.h"
+
+static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution)
+{
+ fmi2Real om_value;
+ om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution);
+ return om_value;
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage)
+{
+ void* om_avr;
+ om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage);
+ return om_avr;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr)
+{
+ MDD_avr_analog_close(om_avr);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value)
+{
+ MDD_avr_digital_pin_write(om_port, om_pin, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin)
+{
+ void* om_dig;
+ om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True);
+ return om_dig;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital)
+{
+ MDD_avr_digital_pin_close(om_digital);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_ldr_led_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_ldr_led_component;
+}
+
+fmi2Status MDD_ldr_led_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_ldr_led_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 7, 4);
+ comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2);
+ comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ return fmi2OK;
+}
+
+fmi2Status MDD_ldr_led_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_ldr_led_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_ldr_led_functionOutputs(fmi2Component comp)
+{
+ comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 6, 1024.0, 10); /* equation 6 */
+ comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>(comp->fmi2RealParameter[0] /* greaterThreshold1._threshold PARAM */); /* equation 7 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */);
+}
+
+fmi2Status MDD_ldr_led_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_ldr_led_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_ldr_led_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_ldr_led_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_ldr_led_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_ldr_led_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_ldr_led_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_read b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_read
new file mode 100644
index 0000000..f939bf9
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_read
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_read.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_read.hex
new file mode 100644
index 0000000..1040803
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_read.hex
@@ -0,0 +1,110 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94130159
+:100020000C9451000C9451000C9451000C94E2007B
+:100030000C9451000C9451000C94B1000C9451009C
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0EEEAF6E002C0E5
+:1000800005900D92AC31B107D9F711E0ACE1B1E0C8
+:1000900001C01D92A132B107E1F70E9468010C94E2
+:1000A00055030C940000CF93DF93EC0190917C00FA
+:1000B000957E956090937C0080917A008064809317
+:1000C0007A0080917A0086FDFCCF60917800709173
+:1000D000790080E090E00E94640220E030E040E897
+:1000E00054E40E94F20220E030EC4FE754E40E9416
+:1000F000FC016C837D838E839F838A8D9B8D8230F0
+:10010000910561F08330910599F00197C9F416BC0F
+:1001100080916E00826080936E0016C01092850000
+:100120001092840080916F00826080936F000CC0F9
+:100130001092B2008091700082608093700004C0C1
+:1001400081E090E00E94550378949FB7F8948091E5
+:100150001E019FBF8823C9F310921E01DF91CF912A
+:1001600008951F920F920FB60F9211242F933F9371
+:100170008F939F9380911C0190911D010196909304
+:100180001D0180931C0180911E01813091F020910E
+:100190001C0130911D0180911F01909120012817B1
+:1001A000390738F081E080931E0110921D011092F2
+:1001B0001C019F918F913F912F910F900FBE0F9037
+:1001C0001F9018951F920F920FB60F9211242F9324
+:1001D0003F938F939F9380911C0190911D010196F5
+:1001E00090931D0180931C0180911E01813091F03C
+:1001F00020911C0130911D0180911F0190912001DF
+:100200002817390738F081E080931E0110921D01F4
+:1002100010921C019F918F913F912F910F900FBED3
+:100220000F901F9018951F920F920FB60F921124E6
+:100230002F933F938F939F9380911C0190911D0169
+:10024000019690931D0180931C0180911E018130C5
+:1002500091F020911C0130911D0180911F0190911E
+:1002600020012817390738F081E080931E01109291
+:100270001D0110921C019F918F913F912F910F9022
+:100280000FBE0F901F901895FC01ACE7B0E08C9169
+:10029000806C8C93AAE7B0E08C9187688C93178A66
+:1002A000168A85B5836085BD21E030E0318F208FCF
+:1002B0008AE090E09093200180931F0184B58260D2
+:1002C00084BD89EF87BD338F228F80E090E0089551
+:1002D000CF92DF92EF92FF9280E091E00E94440182
+:1002E000C12CD12C760160E070E0CB01609300015D
+:1002F00070930101809302019093030180E091E0EB
+:100300000E9453008FEFC81AD80AE80AF80AC701FA
+:10031000B6010E9464022FE632E143E05BE30E94F3
+:10032000F20220E030E0A9010E949801DFCF50588E
+:10033000BB27AA270ED01CC10DD130F012D120F05E
+:1003400031F49F3F11F41EF402C10EF4E095E7FB77
+:10035000F8C0E92F1ED180F3BA176207730784072C
+:10036000950718F071F49EF536C10EF4E0950B2E4A
+:10037000BA2FA02D0B01B90190010C01CA01A001F7
+:100380001124FF27591B99F0593F50F4503E68F152
+:100390001A16F040A22F232F342F4427585FF3CF93
+:1003A000469537952795A795F0405395C9F77EF464
+:1003B0001F16BA0B620B730B840BBAF09150A1F0AD
+:1003C000FF0FBB1F661F771F881FC2F70EC0BA0F33
+:1003D000621F731F841F48F4879577956795B795BB
+:1003E000F7959E3F08F0B3CF9395880F08F09927B3
+:1003F000EE0F9795879508950CD0BAC0B2D040F013
+:10040000A9D030F021F45F3F19F09BC05111E4C036
+:100410009EC0BFD098F39923C9F35523B1F3951B20
+:10042000550BBB27AA2762177307840738F09F5F15
+:100430005F4F220F331F441FAA1FA9F333D00E2E84
+:100440003AF0E0E830D091505040E695001CCAF7F1
+:1004500029D0FE2F27D0660F771F881FBB1F2617B6
+:1004600037074807AB07B0E809F0BB0B802DBF0189
+:10047000FF2793585F4F2AF09E3F510568F061C0F7
+:10048000ABC05F3FECF3983EDCF3869577956795BC
+:10049000B795F7959F5FC9F7880F911D969587953A
+:1004A00097F90895E1E0660F771F881FBB1F621759
+:1004B00073078407BA0720F0621B730B840BBA0B17
+:1004C000EE1F88F7E0950895E89409C097FB3EF485
+:1004D00090958095709561957F4F8F4F9F4F992391
+:1004E000A9F0F92F96E9BB279395F695879577950F
+:1004F0006795B795F111F8CFFAF4BB0F11F460FFCF
+:100500001BC06F5F7F4F8F4F9F4F16C0882311F026
+:1005100096E911C0772321F09EE8872F762F05C03A
+:10052000662371F096E8862F70E060E02AF09A95D5
+:10053000660F771F881FDAF7880F9695879597F9CA
+:10054000089597F99F6780E870E060E008959FEF55
+:1005500080EC089500240A9416161706180609065A
+:10056000089500240A941216130614060506089529
+:10057000092E0394000C11F4882352F0BB0F40F4B1
+:10058000BF2B11F460FF04C06F5F7F4F8F4F9F4FF1
+:10059000089557FD9058440F551F59F05F3F71F073
+:1005A0004795880F97FB991F61F09F3F79F08795DA
+:1005B0000895121613061406551FF2CF4695F1DF63
+:1005C00008C0161617061806991FF1CF86957105F3
+:1005D000610508940895E894BB2766277727CB0127
+:1005E00097F908950BD0C4CFB5DF28F0BADF18F023
+:1005F000952309F0A6CFABCF1124EECFCADFA0F32D
+:10060000959FD1F3950F50E0551F629FF001729FA7
+:10061000BB27F00DB11D639FAA27F00DB11DAA1FC6
+:10062000649F6627B00DA11D661F829F2227B00D13
+:10063000A11D621F739FB00DA11D621F839FA00D9E
+:10064000611D221F749F3327A00D611D231F849FEE
+:10065000600D211D822F762F6A2F11249F57504045
+:100660008AF0E1F088234AF0EE0FFF1FBB1F661FE0
+:10067000771F881F91505040A9F79E3F510570F099
+:1006800060CFAACF5F3FECF3983EDCF38695779579
+:100690006795B795F795E7959F5FC1F7FE2B880F94
+:0E06A000911D9695879597F90895F894FFCFD0
+:1006AE000000000000000000000000000AD7233CFC
+:0C06BE000200010000000000000000002D
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_read_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_read_main.c
new file mode 100644
index 0000000..fa60b33
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/MDD_ldr_read_main.c
@@ -0,0 +1,226 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_ldr_read_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_ldr_read_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Real fmi2RealVars[2];
+ fmi2Real fmi2RealParameter[1];
+ fmi2Integer fmi2IntegerParameter[1];
+ fmi2Boolean fmi2BooleanParameter[1];
+ fmi2String fmi2StringParameter[1];
+ void* extObjs[3];
+} MDD_ldr_read_fmi2Component;
+
+MDD_ldr_read_fmi2Component MDD_ldr_read_component = {
+ .fmi2RealVars = {
+ 0.0 /*adc._y*/,
+ 0.0 /*realValue1._number*/,
+ },
+ .fmi2RealParameter = {
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+ .fmi2IntegerParameter = {
+ 2 /*realValue1._significantDigits*/,
+ },
+ .fmi2BooleanParameter = {
+ fmi2True /*realValue1._use_numberPort*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+static const char * const OMCLIT0 = "ElectricPotential";
+static const char * const OMCLIT1 = "V";
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRAnalog.h"
+
+static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution)
+{
+ fmi2Real om_value;
+ om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution);
+ return om_value;
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage)
+{
+ void* om_avr;
+ om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage);
+ return om_avr;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr)
+{
+ MDD_avr_analog_close(om_avr);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_ldr_read_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_ldr_read_component;
+}
+
+fmi2Status MDD_ldr_read_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_ldr_read_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 7, 4);
+ comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ return fmi2OK;
+}
+
+fmi2Status MDD_ldr_read_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_ldr_read_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_ldr_read_functionOutputs(fmi2Component comp)
+{
+ comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 6, 1024.0, 10); /* equation 4 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);
+}
+
+fmi2Status MDD_ldr_read_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_ldr_read_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_ldr_read_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_ldr_read_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_ldr_read_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_ldr_read_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_ldr_read_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/run_ldr_led.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/run_ldr_led.mos
new file mode 100644
index 0000000..312d62a
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/run_ldr_led.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_ldr.MDD_ldr_led, fileNamePrefix="MDD_ldr_led");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/run_ldr_read.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/run_ldr_read.mos
new file mode 100644
index 0000000..9e99912
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/ldr/run_ldr_read.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_ldr.MDD_ldr_read, fileNamePrefix="MDD_ldr_read");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blink b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blink
new file mode 100644
index 0000000..cdb6635
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blink
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blink.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blink.hex
new file mode 100644
index 0000000..a896b22
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blink.hex
@@ -0,0 +1,114 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C942A0142
+:100020000C9451000C9451000C9451000C94F90064
+:100030000C9451000C9451000C94C8000C94510085
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E4EFF6E002C0EA
+:1000800005900D92A031B107D9F711E0A0E1B1E0E0
+:1000900001C01D92A531B107E1F70E9478010C94CF
+:1000A00078030C940000CF92DF92EF92FF920F93AF
+:1000B0001F93CF93DF93EC01C880D980EA80FB8047
+:1000C00020E030E040E05FE3C701B6010E94F102AA
+:1000D0000E9449029B01AC010E94A8019B01AC0156
+:1000E000C701B6010E94A70101E010E020E030E066
+:1000F00040E85FE30E94ED0287FF02C000E010E0ED
+:100100001D830C838E859F858230910561F083303D
+:10011000910599F00197C9F416BC80916E00826038
+:1001200080936E0016C0109285001092840080911A
+:100130006F00826080936F000CC01092B2008091BB
+:10014000700082608093700004C081E090E00E94A3
+:10015000780378949FB7F894809112019FBF882309
+:10016000C9F310921201EA85FB858C819D81892B50
+:1001700019F08081806202C080818F7D8083DF9151
+:10018000CF911F910F91FF90EF90DF90CF90089546
+:100190001F920F920FB60F9211242F933F938F93BC
+:1001A0009F938091100190911101019690931101FC
+:1001B0008093100180911201813091F02091100103
+:1001C0003091110180911301909114012817390782
+:1001D00038F081E080931201109211011092100109
+:1001E0009F918F913F912F910F900FBE0F901F9075
+:1001F00018951F920F920FB60F9211242F933F93D1
+:100200008F939F938091100190911101019690938B
+:1002100011018093100180911201813091F02091A1
+:100220001001309111018091130190911401281750
+:10023000390738F081E08093120110921101109279
+:1002400010019F918F913F912F910F900FBE0F90B2
+:100250001F9018951F920F920FB60F9211242F9393
+:100260003F938F939F93809110019091110101967C
+:10027000909311018093100180911201813091F0CF
+:10028000209110013091110180911301909114017E
+:100290002817390738F081E080931201109211017C
+:1002A000109210019F918F913F912F910F900FBE4F
+:1002B0000F901F901895FC0185B5836085BD21E0E6
+:1002C00030E0358724878AE090E090931401809392
+:1002D000130184B5826084BD89EF87BD3787268787
+:1002E000259A85E290E09387828780E090E00895E8
+:1002F000CF92DF92EF92FF9280E091E00E945B014B
+:10030000C12CD12C760160E070E0CB01609300013C
+:1003100070930101809302019093030180E091E0CA
+:100320000E9453008FEFC81AD80AE80AF80AC701DA
+:10033000B6010E940C022FE632E143E05BE30E942B
+:10034000F10220E030E0A9010E94A801DFCF50585F
+:10035000BB27AA270ED0F0C0E1D030F0E6D020F0C5
+:1003600031F49F3F11F41EF4D6C00EF4E095E7FB84
+:10037000A3C0E92FF2D080F3BA176207730784078E
+:10038000950718F071F49EF521C10EF4E0950B2E3F
+:10039000BA2FA02D0B01B90190010C01CA01A001D7
+:1003A0001124FF27591B99F0593F50F4503E68F132
+:1003B0001A16F040A22F232F342F4427585FF3CF73
+:1003C000469537952795A795F0405395C9F77EF444
+:1003D0001F16BA0B620B730B840BBAF09150A1F08D
+:1003E000FF0FBB1F661F771F881FC2F70EC0BA0F13
+:1003F000621F731F841F48F4879577956795B7959B
+:10040000F7959E3F08F0B3CF9395880F08F0992792
+:10041000EE0F979587950895E89409C097FB3EF4F1
+:1004200090958095709561957F4F8F4F9F4F992341
+:10043000A9F0F92F96E9BB279395F69587957795BF
+:100440006795B795F111F8CFFAF4BB0F11F460FF7F
+:100450001BC06F5F7F4F8F4F9F4F16C0882311F0D7
+:1004600096E911C0772321F09EE8872F762F05C0EB
+:10047000662371F096E8862F70E060E02AF09A9586
+:10048000660F771F881FDAF7880F9695879597F97B
+:10049000089585D080F09F3740F491110EF097C0F9
+:1004A00060E070E080E89FEB089526F41B16611D64
+:1004B000711D811D07C021C097F99F6780E870E01A
+:1004C00060E00895882371F4772321F09850872BFA
+:1004D000762F07C0662311F499270DC09051862B03
+:1004E00070E060E02AF09A95660F771F881FDAF7B0
+:1004F000880F9695879597F908959F3F31F0915011
+:1005000020F4879577956795B795880F911D9695F7
+:10051000879597F908959FEF80EC089500240A9439
+:100520001616170618060906089500240A941216CE
+:100530001306140605060895092E0394000C11F401
+:10054000882352F0BB0F40F4BF2B11F460FF04C0AE
+:100550006F5F7F4F8F4F9F4F089557FD9058440F07
+:10056000551F59F05F3F71F04795880F97FB991F12
+:1005700061F09F3F79F087950895121613061406CF
+:10058000551FF2CF4695F1DF08C01616170618065C
+:10059000991FF1CF86957105610508940895E5DFEF
+:1005A000A0F0BEE7B91788F4BB279F3860F4161691
+:1005B000B11D672F782F8827985FF7CF869577959D
+:1005C0006795B11D93959639C8F30895E894BB27B4
+:1005D00066277727CB0197F9089566D008F48FEF47
+:1005E00008950BD0A9CF9ADF28F09FDF18F095234C
+:1005F00009F062CF90CF1124EACFAFDFA0F3959F2F
+:10060000D1F3950F50E0551F629FF001729FBB27F9
+:10061000F00DB11D639FAA27F00DB11DAA1F649FA5
+:100620006627B00DA11D661F829F2227B00DA11D58
+:10063000621F739FB00DA11D621F839FA00D611DDE
+:10064000221F749F3327A00D611D231F849F600DFF
+:10065000211D822F762F6A2F11249F5750408AF038
+:10066000E1F088234AF0EE0FFF1FBB1F661F771FC4
+:10067000881F91505040A9F79E3F510570F01CCF44
+:10068000A6CF5F3FECF3983EDCF3869577956795B0
+:10069000B795F795E7959F5FC1F7FE2B880F911DE2
+:1006A0009695879597F90895990F0008550FAA0B0D
+:1006B000E0E8FEEF16161706E807F907C0F0121675
+:1006C0001306E407F50798F0621B730B840B950B78
+:1006D00039F40A2661F0232B242B252B21F40895CD
+:1006E0000A2609F4A140A6958FEF811D811D08956A
+:0406F000F894FFCFAC
+:1006F4000000000000000AD7233C000000000000B6
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blink_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blink_main.c
new file mode 100644
index 0000000..cb41d72
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blink_main.c
@@ -0,0 +1,253 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_led_blink_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_led_blink_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Real fmi2RealVars[2];
+ fmi2Boolean fmi2BooleanVars[3];
+ fmi2Real fmi2RealParameter[2];
+ fmi2Integer fmi2IntegerParameter[1];
+ fmi2Boolean fmi2BooleanParameter[1];
+ fmi2String fmi2StringParameter[1];
+ void* extObjs[4];
+} MDD_led_blink_fmi2Component;
+
+MDD_led_blink_fmi2Component MDD_led_blink_component = {
+ .fmi2RealVars = {
+ 0.0 /*adc._y*/,
+ 0.0 /*realValue1._number*/,
+ },
+ .fmi2BooleanVars = {
+ fmi2False /*booleanExpression1._y*/,
+ fmi2False /*booleanExpression2._y*/,
+ fmi2False /*digitalWriteBoolean1._u*/,
+ },
+ .fmi2RealParameter = {
+ 550.0 /*greaterEqualThreshold1._threshold*/,
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+ .fmi2IntegerParameter = {
+ 2 /*realValue1._significantDigits*/,
+ },
+ .fmi2BooleanParameter = {
+ fmi2True /*realValue1._use_numberPort*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+static const char * const OMCLIT0 = "ElectricPotential";
+static const char * const OMCLIT1 = "V";
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRDigital.h"
+#include "MDDAVRAnalog.h"
+
+static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution)
+{
+ fmi2Real om_value;
+ om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution);
+ return om_value;
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage)
+{
+ void* om_avr;
+ om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage);
+ return om_avr;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr)
+{
+ MDD_avr_analog_close(om_avr);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value)
+{
+ MDD_avr_digital_pin_write(om_port, om_pin, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin)
+{
+ void* om_dig;
+ om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True);
+ return om_dig;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital)
+{
+ MDD_avr_digital_pin_close(om_digital);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_led_blink_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_led_blink_component;
+}
+
+fmi2Status MDD_led_blink_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_blink_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 4, 4);
+ comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 7, 4);
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_blink_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_led_blink_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_led_blink_functionOutputs(fmi2Component comp)
+{
+ comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 5, 1024.0, 10); /* equation 7 */
+ comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>=(comp->fmi2RealParameter[0] /* greaterEqualThreshold1._threshold PARAM */); /* equation 8 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 4, comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */);
+}
+
+fmi2Status MDD_led_blink_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_led_blink_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_led_blink_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_led_blink_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_led_blink_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_led_blink_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_led_blink_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue
new file mode 100644
index 0000000..75f1105
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue.hex
new file mode 100644
index 0000000..46afcd9
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue.hex
@@ -0,0 +1,91 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E50088
+:100020000C9451000C9451000C9451000C94B400A9
+:100030000C9451000C9451000C9483000C945100CA
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E6E8F5E002C0F0
+:1000800005900D92A031B107D9F711E0A0E1B1E0E0
+:1000900001C01D92A531B107E1F70E9433010C9414
+:1000A000C1020C9400008230910561F0833091050B
+:1000B00099F00197C9F416BC80916E00826080931C
+:1000C0006E0016C0109285001092840080916F001F
+:1000D000826080936F000CC01092B200809170001B
+:1000E00082608093700004C081E090E00E94C102B1
+:1000F00078949FB7F894809112019FBF8823C9F329
+:100100001092120108951F920F920FB60F921124B0
+:100110002F933F938F939F938091100190911101A2
+:10012000019690931101809310018091120181300A
+:1001300091F0209110013091110180911301909163
+:1001400014012817390738F081E0809312011092CA
+:100150001101109210019F918F913F912F910F905B
+:100160000FBE0F901F9018951F920F920FB60F920F
+:1001700011242F933F938F939F938091100190911F
+:100180001101019690931101809310018091120149
+:10019000813091F020911001309111018091130173
+:1001A000909114012817390738F081E080931201EB
+:1001B00010921101109210019F918F913F912F91F8
+:1001C0000F900FBE0F901F9018951F920F920FB6B1
+:1001D0000F9211242F933F938F939F93809110013F
+:1001E00090911101019690931101809310018091DB
+:1001F0001201813091F02091100130911101809114
+:100200001301909114012817390738F081E0809389
+:10021000120110921101109210019F918F913F9144
+:100220002F910F900FBE0F901F901895FC01219AEF
+:1002300085E290E09387828785B5836085BD21E064
+:1002400030E03587248785E090E090931401809317
+:10025000130184B5826084BD89EF87BD3787268707
+:1002600080E090E00895CF92DF92EF92FF9280E0DD
+:1002700091E00E941601C12CD12C760160E070E063
+:10028000CB01609300017093010180930201909370
+:10029000030180910E0190910F010E945300E091A3
+:1002A0000A01F0910B018081826080838FEFC81A70
+:1002B000D80AE80AF80AC701B6010E94D0012FE661
+:1002C00032E143E05BE30E945E0220E030E0A901FE
+:1002D0000E946C01D6CF5058BB27AA270ED0B4C0BD
+:1002E000A5D030F0AAD020F031F49F3F11F41EF4D5
+:1002F0009AC00EF4E095E7FB90C0E92FB6D080F3EA
+:10030000BA17620773078407950718F071F49EF512
+:10031000CEC00EF4E0950B2EBA2FA02D0B01B90123
+:1003200090010C01CA01A0011124FF27591B99F06B
+:10033000593F50F4503E68F11A16F040A22F232F77
+:10034000342F4427585FF3CF469537952795A795C7
+:10035000F0405395C9F77EF41F16BA0B620B730B6E
+:10036000840BBAF09150A1F0FF0FBB1F661F771FDF
+:10037000881FC2F70EC0BA0F621F731F841F48F494
+:10038000879577956795B795F7959E3F08F0B3CF1A
+:100390009395880F08F09927EE0F97958795089504
+:1003A000E89409C097FB3EF490958095709561950F
+:1003B0007F4F8F4F9F4F9923A9F0F92F96E9BB27C5
+:1003C0009395F695879577956795B795F111F8CF41
+:1003D000FAF4BB0F11F460FF1BC06F5F7F4F8F4FAC
+:1003E0009F4F16C0882311F096E911C0772321F0A2
+:1003F0009EE8872F762F05C0662371F096E8862F3A
+:1004000070E060E02AF09A95660F771F881FDAF790
+:10041000880F9695879597F9089597F99F6780E8D3
+:1004200070E060E008959FEF80EC089500240A9446
+:100430001616170618060906089500240A941216BF
+:100440001306140605060895092E0394000C11F4F2
+:10045000882352F0BB0F40F4BF2B11F460FF04C09F
+:100460006F5F7F4F8F4F9F4F089557FD9058440FF8
+:10047000551F59F05F3F71F04795880F97FB991F03
+:1004800061F09F3F79F087950895121613061406C0
+:10049000551FF2CF4695F1DF08C01616170618064D
+:1004A000991FF1CF86957105610508940895E89428
+:1004B000BB2766277727CB0197F908950BD0C4CFC8
+:1004C000B5DF28F0BADF18F0952309F0A6CFABCF3F
+:1004D0001124EECFCADFA0F3959FD1F3950F50E022
+:1004E000551F629FF001729FBB27F00DB11D639FE6
+:1004F000AA27F00DB11DAA1F649F6627B00DA11D8C
+:10050000661F829F2227B00DA11D621F739FB00D31
+:10051000A11D621F839FA00D611D221F749F3327A1
+:10052000A00D611D231F849F600D211D822F762F3A
+:100530006A2F11249F5750408AF0E1F088234AF037
+:10054000EE0FFF1FBB1F661F771F881F9150504083
+:10055000A9F79E3F510570F060CFAACF5F3FECF343
+:10056000983EDCF3869577956795B795F795E7956F
+:100570009F5FC1F7FE2B880F911D9695879597F980
+:060580000895F894FFCF7E
+:100586000000000000000AD7233C00000000000025
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delay b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delay
new file mode 100644
index 0000000..9d821fe
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delay
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delay.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delay.hex
new file mode 100644
index 0000000..f120f88
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delay.hex
@@ -0,0 +1,100 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C940E015E
+:100020000C9451000C9451000C9451000C94DD0080
+:100030000C9451000C9451000C94AC000C945100A1
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E6E1F6E002C0F6
+:1000800005900D92A031B107D9F711E0A0E1B1E0E0
+:1000900001C01D92A531B107E1F70E945C010C94EB
+:1000A00009030C9400000F931F93CF93DF93EC018F
+:1000B00001E010E020E030E040E85FE36881798112
+:1000C0008A819B810E94F00187FD02C000E010E060
+:1000D0001D830C838E859F858230910561F083306E
+:1000E000910599F00197C9F416BC80916E00826069
+:1000F00080936E0016C0109285001092840080914B
+:100100006F00826080936F000CC01092B2008091EB
+:10011000700082608093700004C081E090E00E94D3
+:10012000090378949FB7F894809112019FBF8823A8
+:10013000C9F310921201EA85FB858C819D81892B80
+:1001400019F08081826002C080818D7F8083DF9181
+:10015000CF911F910F9108951F920F920FB60F929A
+:1001600011242F933F938F939F938091100190912F
+:100170001101019690931101809310018091120159
+:10018000813091F020911001309111018091130183
+:10019000909114012817390738F081E080931201FB
+:1001A00010921101109210019F918F913F912F9108
+:1001B0000F900FBE0F901F9018951F920F920FB6C1
+:1001C0000F9211242F933F938F939F93809110014F
+:1001D00090911101019690931101809310018091EB
+:1001E0001201813091F02091100130911101809124
+:1001F0001301909114012817390738F081E080939A
+:10020000120110921101109210019F918F913F9154
+:100210002F910F900FBE0F901F9018951F920F9265
+:100220000FB60F9211242F933F938F939F9380913A
+:10023000100190911101019690931101809310018A
+:1002400080911201813091F02091100130911101C3
+:1002500080911301909114012817390738F081E03B
+:100260008093120110921101109210019F918F91B1
+:100270003F912F910F900FBE0F901F901895FC018A
+:10028000219A85E290E09387828785B5836085BD5A
+:1002900021E030E0358724878AE090E090931401D4
+:1002A0008093130184B5826084BD89EF87BD378751
+:1002B000268780E090E00895CF92DF92EF92FF9240
+:1002C00080E091E00E943F01C12CD12C760160E0DA
+:1002D00070E0CB01609300017093010180930201F3
+:1002E0009093030180E091E00E9453008FEFC81AC1
+:1002F000D80AE80AF80AC701B6010E94F4012FE6FD
+:1003000032E143E05BE30E94A60220E030E0A90175
+:100310000E948C01DFCF5058BB27AA270ED0DCC02B
+:10032000CDD030F0D2D020F031F49F3F11F41EF444
+:10033000C2C00EF4E095E7FBB8C0E92FDED080F331
+:10034000BA17620773078407950718F071F49EF5D2
+:10035000F6C00EF4E0950B2EBA2FA02D0B01B901BB
+:1003600090010C01CA01A0011124FF27591B99F02B
+:10037000593F50F4503E68F11A16F040A22F232F37
+:10038000342F4427585FF3CF469537952795A79587
+:10039000F0405395C9F77EF41F16BA0B620B730B2E
+:1003A000840BBAF09150A1F0FF0FBB1F661F771F9F
+:1003B000881FC2F70EC0BA0F621F731F841F48F454
+:1003C000879577956795B795F7959E3F08F0B3CFDA
+:1003D0009395880F08F09927EE0F979587950895C4
+:1003E00040D008F481E00895E89409C097FB3EF4FA
+:1003F00090958095709561957F4F8F4F9F4F992372
+:10040000A9F0F92F96E9BB279395F69587957795EF
+:100410006795B795F111F8CFFAF4BB0F11F460FFAF
+:100420001BC06F5F7F4F8F4F9F4F16C0882311F007
+:1004300096E911C0772321F09EE8872F762F05C01B
+:10044000662371F096E8862F70E060E02AF09A95B6
+:10045000660F771F881FDAF7880F9695879597F9AB
+:100460000895990F0008550FAA0BE0E8FEEF161645
+:100470001706E807F907C0F012161306E407F50798
+:1004800098F0621B730B840B950B39F40A2661F00C
+:10049000232B242B252B21F408950A2609F4A140AF
+:1004A000A6958FEF811D811D089597F99F6780E8BC
+:1004B00070E060E008959FEF80EC089500240A94B6
+:1004C0001616170618060906089500240A9412162F
+:1004D0001306140605060895092E0394000C11F462
+:1004E000882352F0BB0F40F4BF2B11F460FF04C00F
+:1004F0006F5F7F4F8F4F9F4F089557FD9058440F68
+:10050000551F59F05F3F71F04795880F97FB991F72
+:1005100061F09F3F79F0879508951216130614062F
+:10052000551FF2CF4695F1DF08C0161617061806BC
+:10053000991FF1CF86957105610508940895E89497
+:10054000BB2766277727CB0197F908950BD0C4CF37
+:10055000B5DF28F0BADF18F0952309F0A6CFABCFAE
+:100560001124EECFCADFA0F3959FD1F3950F50E091
+:10057000551F629FF001729FBB27F00DB11D639F55
+:10058000AA27F00DB11DAA1F649F6627B00DA11DFB
+:10059000661F829F2227B00DA11D621F739FB00DA1
+:1005A000A11D621F839FA00D611D221F749F332711
+:1005B000A00D611D231F849F600D211D822F762FAA
+:1005C0006A2F11249F5750408AF0E1F088234AF0A7
+:1005D000EE0FFF1FBB1F661F771F881F91505040F3
+:1005E000A9F79E3F510570F060CFAACF5F3FECF3B3
+:1005F000983EDCF3869577956795B795F795E795DF
+:100600009F5FC1F7FE2B880F911D9695879597F9EF
+:060610000895F894FFCFED
+:100616000000000001000AD7233C00000000000093
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delay_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delay_main.c
new file mode 100644
index 0000000..e369c99
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_delay_main.c
@@ -0,0 +1,212 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_led_blue_delay_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_led_blue_delay_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Boolean fmi2BooleanVars[1];
+ fmi2Real fmi2RealParameter[1];
+ void* extObjs[3];
+} MDD_led_blue_delay_fmi2Component;
+
+MDD_led_blue_delay_fmi2Component MDD_led_blue_delay_component = {
+ .fmi2BooleanVars = {
+ fmi2True /*booleanExpression1._y*/,
+ },
+ .fmi2RealParameter = {
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRDigital.h"
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value)
+{
+ MDD_avr_digital_pin_write(om_port, om_pin, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin)
+{
+ void* om_dig;
+ om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True);
+ return om_dig;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital)
+{
+ MDD_avr_digital_pin_close(om_digital);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_led_blue_delay_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_led_blue_delay_component;
+}
+
+fmi2Status MDD_led_blue_delay_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_blue_delay_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2);
+ comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_blue_delay_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_led_blue_delay_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_led_blue_delay_functionOutputs(fmi2Component comp)
+{
+ comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */ = (comp->currentTime)<(1.0); /* equation 3 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */);
+}
+
+fmi2Status MDD_led_blue_delay_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_led_blue_delay_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_led_blue_delay_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_led_blue_delay_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_led_blue_delay_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_led_blue_delay_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_led_blue_delay_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_main.c
new file mode 100644
index 0000000..19d0a0f
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_main.c
@@ -0,0 +1,212 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_led_blue_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_led_blue_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Boolean fmi2BooleanVars[1];
+ fmi2Real fmi2RealParameter[1];
+ void* extObjs[3];
+} MDD_led_blue_fmi2Component;
+
+MDD_led_blue_fmi2Component MDD_led_blue_component = {
+ .fmi2BooleanVars = {
+ fmi2False /*booleanExpression1._y*/,
+ },
+ .fmi2RealParameter = {
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRDigital.h"
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value)
+{
+ MDD_avr_digital_pin_write(om_port, om_pin, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin)
+{
+ void* om_dig;
+ om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True);
+ return om_dig;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital)
+{
+ MDD_avr_digital_pin_close(om_digital);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_led_blue_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_led_blue_component;
+}
+
+fmi2Status MDD_led_blue_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_blue_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2);
+ comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 5);
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_blue_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_led_blue_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_led_blue_functionOutputs(fmi2Component comp)
+{
+ Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, fmi2True);
+}
+
+fmi2Status MDD_led_blue_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_led_blue_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_led_blue_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_led_blue_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_led_blue_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_led_blue_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_led_blue_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_red b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_red
new file mode 100644
index 0000000..06777b5
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_red
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_red.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_red.hex
new file mode 100644
index 0000000..37cdb21
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_red.hex
@@ -0,0 +1,106 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94340138
+:100020000C9451000C9451000C9451000C94030159
+:100030000C9451000C9451000C94D2000C9451007B
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E8E6F6E002C0EF
+:1000800005900D92A431B107D9F711E0A4E1B1E0D8
+:1000900001C01D92A931B107E1F70E9485010C94BE
+:1000A00032030C940000CF92DF92EF92FF920F93F5
+:1000B0001F93CF93DF93EC01C880D980EA80FB8047
+:1000C00001E010E020E030E040E85FE3C701B60166
+:1000D0000E94190287FD02C000E010E01D830C831E
+:1000E00001E010E02DEC3CEC4CEC5FE3C701B60105
+:1000F0000E94190287FD02C000E010E01F830E83FA
+:100100008A899B898230910561F08330910599F04D
+:100110000197C9F416BC80916E00826080936E00D6
+:1001200016C0109285001092840080916F0082604A
+:1001300080936F000CC01092B200809170008260BA
+:100140008093700004C081E090E00E9432037894B4
+:100150009FB7F894809116019FBF8823C9F310922E
+:100160001601EC85FD858C819D81892B19F080819C
+:10017000826002C080818D7F8083EE85FF858E81C5
+:100180009F81892B19F08081886002C08081877FE0
+:100190008083DF91CF911F910F91FF90EF90DF90BF
+:1001A000CF9008951F920F920FB60F9211242F93A4
+:1001B0003F938F939F938091140190911501019625
+:1001C000909315018093140180911601813091F074
+:1001D000209114013091150180911701909118011F
+:1001E0002817390738F081E0809316011092150125
+:1001F000109214019F918F913F912F910F900FBEFC
+:100200000F901F9018951F920F920FB60F92112406
+:100210002F933F938F939F93809114019091150199
+:1002200001969093150180931401809116018130FD
+:1002300091F0209114013091150180911701909156
+:1002400018012817390738F081E0809316011092C1
+:100250001501109214019F918F913F912F910F9052
+:100260000FBE0F901F9018951F920F920FB60F920E
+:1002700011242F933F938F939F938091140190911A
+:100280001501019690931501809314018091160138
+:10029000813091F020911401309115018091170166
+:1002A000909118012817390738F081E080931601E2
+:1002B00010921501109214019F918F913F912F91EF
+:1002C0000F900FBE0F901F901895FC01239A25E206
+:1002D00030E03787268785B5836085BD41E050E0F3
+:1002E000518B408B8AE090E0909318018093170126
+:1002F00084B5826084BD89EF87BD538B428B219A80
+:100300003587248780E090E00895CF92DF92EF92C6
+:10031000FF9280E091E00E946501C12CD12C760112
+:1003200060E070E0CB016093000170930101809365
+:1003300002019093030180E091E00E9453008FEF4F
+:10034000C81AD80AE80AF80AC701B6010E941D02B5
+:100350002FE632E143E05BE30E94CF0220E030E091
+:10036000A9010E94B501DFCF5058BB27AA270ED0A4
+:10037000DCC0CDD030F0D2D020F031F49F3F11F46A
+:100380001EF4C2C00EF4E095E7FBB8C0E92FDED042
+:1003900080F3BA17620773078407950718F071F4A2
+:1003A0009EF5F6C00EF4E0950B2EBA2FA02D0B0192
+:1003B000B90190010C01CA01A0011124FF27591BAA
+:1003C00099F0593F50F4503E68F11A16F040A22FB0
+:1003D000232F342F4427585FF3CF46953795279521
+:1003E000A795F0405395C9F77EF41F16BA0B620B20
+:1003F000730B840BBAF09150A1F0FF0FBB1F661F67
+:10040000771F881FC2F70EC0BA0F621F731F841FA9
+:1004100048F4879577956795B795F7959E3F08F0CF
+:10042000B3CF9395880F08F09927EE0F979587958E
+:10043000089540D008F481E00895E89409C097FB3E
+:100440003EF490958095709561957F4F8F4F9F4FAB
+:100450009923A9F0F92F96E9BB279395F6958795EF
+:1004600077956795B795F111F8CFFAF4BB0F11F4B2
+:1004700060FF1BC06F5F7F4F8F4F9F4F16C0882359
+:1004800011F096E911C0772321F09EE8872F762F8F
+:1004900005C0662371F096E8862F70E060E02AF0D0
+:1004A0009A95660F771F881FDAF7880F96958795BC
+:1004B00097F90895990F0008550FAA0BE0E8FEEF91
+:1004C00016161706E807F907C0F012161306E40718
+:1004D000F50798F0621B730B840B950B39F40A2611
+:1004E00061F0232B242B252B21F408950A2609F4EF
+:1004F000A140A6958FEF811D811D089597F99F67F3
+:1005000080E870E060E008959FEF80EC089500249B
+:100510000A941616170618060906089500240A9468
+:1005200012161306140605060895092E0394000CEE
+:1005300011F4882352F0BB0F40F4BF2B11F460FF7D
+:1005400004C06F5F7F4F8F4F9F4F089557FD9058A6
+:10055000440F551F59F05F3F71F04795880F97FB87
+:10056000991F61F09F3F79F0879508951216130641
+:100570001406551FF2CF4695F1DF08C01616170670
+:100580001806991FF1CF86957105610508940895A5
+:10059000E894BB2766277727CB0197F908950BD0FE
+:1005A000C4CFB5DF28F0BADF18F0952309F0A6CF45
+:1005B000ABCF1124EECFCADFA0F3959FD1F3950FF7
+:1005C00050E0551F629FF001729FBB27F00DB11DD7
+:1005D000639FAA27F00DB11DAA1F649F6627B00D67
+:1005E000A11D661F829F2227B00DA11D621F739F50
+:1005F000B00DA11D621F839FA00D611D221F749F5E
+:100600003327A00D611D231F849F600D211D822FA4
+:10061000762F6A2F11249F5750408AF0E1F08823EB
+:100620004AF0EE0FFF1FBB1F661F771F881F9150F8
+:100630005040A9F79E3F510570F060CFAACF5F3FB1
+:10064000ECF3983EDCF3869577956795B795F7952B
+:10065000E7959F5FC1F7FE2B880F911D96958795B3
+:0806600097F90895F894FFCF0B
+:1006680000000000010001000AD7233C0000000040
+:04067800000000007E
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_red_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_red_main.c
new file mode 100644
index 0000000..8118bcc
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_blue_red_main.c
@@ -0,0 +1,215 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_led_blue_red_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_led_blue_red_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Boolean fmi2BooleanVars[2];
+ fmi2Real fmi2RealParameter[1];
+ void* extObjs[4];
+} MDD_led_blue_red_fmi2Component;
+
+MDD_led_blue_red_fmi2Component MDD_led_blue_red_component = {
+ .fmi2BooleanVars = {
+ fmi2True /*booleanExpression1._y*/,
+ fmi2True /*booleanExpression2._y*/,
+ },
+ .fmi2RealParameter = {
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRDigital.h"
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value)
+{
+ MDD_avr_digital_pin_write(om_port, om_pin, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin)
+{
+ void* om_dig;
+ om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True);
+ return om_dig;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital)
+{
+ MDD_avr_digital_pin_close(om_digital);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_led_blue_red_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_led_blue_red_component;
+}
+
+fmi2Status MDD_led_blue_red_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_blue_red_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[1] /* digitalWriteBoolean2._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 4);
+ comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2);
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_blue_red_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_led_blue_red_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_led_blue_red_functionOutputs(fmi2Component comp)
+{
+ comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */ = (comp->currentTime)<(1.0); /* equation 4 */
+ comp->fmi2BooleanVars[1] /* booleanExpression2._y DISCRETE */ = (comp->currentTime)<(1.6); /* equation 5 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean2._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 4, comp->fmi2BooleanVars[1] /* booleanExpression2._y DISCRETE */);
+}
+
+fmi2Status MDD_led_blue_red_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_led_blue_red_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_led_blue_red_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_led_blue_red_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_led_blue_red_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_led_blue_red_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_led_blue_red_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_bink b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_bink
new file mode 100644
index 0000000..d4a1f15
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_bink
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blink b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blink
new file mode 100644
index 0000000..d4a1f15
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blink
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blink.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blink.hex
new file mode 100644
index 0000000..30ec824
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blink.hex
@@ -0,0 +1,127 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C942C0140
+:100020000C9451000C9451000C9451000C94FB0062
+:100030000C9451000C9451000C94CA000C94510083
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E8ECF7E002C0E8
+:1000800005900D92A031B107D9F711E0A0E1B1E0E0
+:1000900001C01D92A531B107E1F70E947A010C94CD
+:1000A000E2030C940000CF92DF92EF92FF920F9345
+:1000B0001F93CF93DF93EC01C880D980EA80FB8047
+:1000C0002DEC3CEC4CEC5EE3C701B6010E940E0245
+:1000D0000E94B3022DEC3CEC4CEC5EE30E945B030F
+:1000E0009B01AC01C701B6010E94A90101E010E02B
+:1000F0002DEC3CEC4CE45EE30E94570387FF02C00A
+:1001000000E010E01D830C838E859F858230910571
+:1001100061F08330910599F00197C9F416BC809184
+:100120006E00826080936E0016C01092850010925F
+:10013000840080916F00826080936F000CC01092E9
+:10014000B2008091700082608093700004C081E0F2
+:1001500090E00E94E20378949FB7F8948091120196
+:100160009FBF8823C9F310921201EA85FB858C8119
+:100170009D81892B19F08081846002C080818B7FF2
+:100180008083DF91CF911F910F91FF90EF90DF90CF
+:10019000CF9008951F920F920FB60F9211242F93B4
+:1001A0003F938F939F93809110019091110101963D
+:1001B000909311018093100180911201813091F090
+:1001C000209110013091110180911301909114013F
+:1001D0002817390738F081E080931201109211013D
+:1001E000109210019F918F913F912F910F900FBE10
+:1001F0000F901F9018951F920F920FB60F92112417
+:100200002F933F938F939F938091100190911101B1
+:100210000196909311018093100180911201813019
+:1002200091F0209110013091110180911301909172
+:1002300014012817390738F081E0809312011092D9
+:100240001101109210019F918F913F912F910F906A
+:100250000FBE0F901F9018951F920F920FB60F921E
+:1002600011242F933F938F939F938091100190912E
+:100270001101019690931101809310018091120158
+:10028000813091F020911001309111018091130182
+:10029000909114012817390738F081E080931201FA
+:1002A00010921101109210019F918F913F912F9107
+:1002B0000F900FBE0F901F901895FC0185B58360BD
+:1002C00085BD21E030E0358724878AE090E0909377
+:1002D00014018093130184B5826084BD89EF87BDCA
+:1002E00037872687229A85E290E09387828780E08D
+:1002F00090E00895CF92DF92EF92FF9280E091E03C
+:100300000E945D01C12CD12C760160E070E0CB0130
+:1003100060930001709301018093020190930301A7
+:1003200080E091E00E9453008FEFC81AD80AE80AD3
+:10033000F80AC701B6010E9476022FE632E143E0D7
+:100340005BE30E945B0320E030E0A9010E94AA0168
+:10035000DFCF5058BB27AA270ED058C149D130F063
+:100360004ED120F031F49F3F11F41EF43EC10EF443
+:10037000E095E7FB0BC1E92F5AD180F3BA1762076A
+:1003800073078407950718F071F49EF589C10EF480
+:10039000E0950B2EBA2FA02D0B01B90190010C0195
+:1003A000CA01A0011124FF27591B99F0593F50F4AD
+:1003B000503E68F11A16F040A22F232F342F442705
+:1003C000585FF3CF469537952795A795F0405395FD
+:1003D000C9F77EF41F16BA0B620B730B840BBAF0CD
+:1003E0009150A1F0FF0FBB1F661F771F881FC2F738
+:1003F0000EC0BA0F621F731F841F48F4879577954C
+:100400006795B795F7959E3F08F0B3CF9395880F02
+:1004100008F09927EE0F9795879508950CD0F6C0B0
+:10042000EED040F0E5D030F021F45F3F19F0AEC0DF
+:10043000511137C1DAC0FBD098F39923C9F3552382
+:10044000B1F3951B550BBB27AA27621773078407C7
+:1004500038F09F5F5F4F220F331F441FAA1FA9F37D
+:1004600033D00E2E3AF0E0E830D091505040E6956F
+:10047000001CCAF729D0FE2F27D0660F771F881FD0
+:10048000BB1F261737074807AB07B0E809F0BB0BBF
+:10049000802DBF01FF2793585F4F2AF09E3F5105E3
+:1004A00068F074C0FEC05F3FECF3983EDCF38695C5
+:1004B00077956795B795F7959F5FC9F7880F911D59
+:1004C0009695879597F90895E1E0660F771F881F45
+:1004D000BB1F621773078407BA0720F0621B730BF8
+:1004E000840BBA0BEE1F88F7E0950895E89409C0D5
+:1004F00097FB3EF490958095709561957F4F8F4F57
+:100500009F4F9923A9F0F92F96E9BB279395F6956C
+:10051000879577956795B795F111F8CFFAF4BB0FEA
+:1005200011F460FF1BC06F5F7F4F8F4F9F4F16C04E
+:10053000882311F096E911C0772321F09EE8872FD8
+:10054000762F05C0662371F096E8862F70E060E094
+:100550002AF09A95660F771F881FDAF7880F96950D
+:10056000879597F9089585D080F09F3740F49111D1
+:100570000EF097C060E070E080E89FEB089526F4ED
+:100580001B16611D711D811D07C021C097F99F6752
+:1005900080E870E060E00895882371F4772321F00B
+:1005A0009850872B762F07C0662311F499270DC02A
+:1005B0009051862B70E060E02AF09A95660F771FC5
+:1005C000881FDAF7880F9695879597F908959F3FCA
+:1005D00031F0915020F4879577956795B795880FFE
+:1005E000911D9695879597F908959FEF80EC089552
+:1005F00000240A9416161706180609060895002402
+:100600000A9412161306140605060895092E03947B
+:10061000000C11F4882352F0BB0F40F4BF2B11F4EF
+:1006200060FF04C06F5F7F4F8F4F9F4F089557FD4E
+:100630009058440F551F59F05F3F71F04795880F50
+:1006400097FB991F61F09F3F79F0879508951216E7
+:1006500013061406551FF2CF4695F1DF08C0161693
+:1006600017061806991FF1CF869571056105089444
+:100670000895E5DFA0F0BEE7B91788F4BB279F38DF
+:1006800060F41616B11D672F782F8827985FF7CF73
+:10069000869577956795B11D93959639C8F308951A
+:1006A000E894BB2766277727CB0197F9089566D092
+:1006B00008F48FEF08950BD0A9CF9ADF28F09FDFC1
+:1006C00018F0952309F062CF90CF1124EACFAFDF65
+:1006D000A0F3959FD1F3950F50E0551F629FF00155
+:1006E000729FBB27F00DB11D639FAA27F00DB11DAE
+:1006F000AA1F649F6627B00DA11D661F829F222737
+:10070000B00DA11D621F739FB00DA11D621F839FBD
+:10071000A00D611D221F749F3327A00D611D231F93
+:10072000849F600D211D822F762F6A2F11249F57E1
+:1007300050408AF0E1F088234AF0EE0FFF1FBB1F04
+:10074000661F771F881F91505040A9F79E3F5105A3
+:1007500070F01CCFA6CF5F3FECF3983EDCF386959C
+:1007600077956795B795F795E7959F5FC1F7FE2B4E
+:10077000880F911D9695879597F90895990F000810
+:10078000550FAA0BE0E8FEEF16161706E807F90763
+:10079000C0F012161306E407F50798F0621B730BFE
+:1007A000840B950B39F40A2661F0232B242B252B7F
+:1007B00021F408950A2609F4A140A6958FEF811D22
+:0807C000811D0895F894FFCF9C
+:1007C8000000000000000AD7233C000000000000E1
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blink_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blink_main.c
new file mode 100644
index 0000000..e01a62c
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/MDD_led_green_blink_main.c
@@ -0,0 +1,212 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_led_green_blink_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_led_green_blink_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Boolean fmi2BooleanVars[1];
+ fmi2Real fmi2RealParameter[1];
+ void* extObjs[3];
+} MDD_led_green_blink_fmi2Component;
+
+MDD_led_green_blink_fmi2Component MDD_led_green_blink_component = {
+ .fmi2BooleanVars = {
+ fmi2False /*booleanExpression1._y*/,
+ },
+ .fmi2RealParameter = {
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRDigital.h"
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value)
+{
+ MDD_avr_digital_pin_write(om_port, om_pin, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin)
+{
+ void* om_dig;
+ om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True);
+ return om_dig;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital)
+{
+ MDD_avr_digital_pin_close(om_digital);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_led_green_blink_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_led_green_blink_component;
+}
+
+fmi2Status MDD_led_green_blink_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_green_blink_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[1] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 3);
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_green_blink_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_led_green_blink_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_led_green_blink_functionOutputs(fmi2Component comp)
+{
+ comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */ = (om_mod(comp->currentTime,0.4))>=(0.2); /* equation 3 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[2] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[0] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 3, comp->fmi2BooleanVars[0] /* booleanExpression1._y DISCRETE */);
+}
+
+fmi2Status MDD_led_green_blink_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_led_green_blink_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_led_green_blink_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_led_green_blink_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_led_green_blink_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_led_green_blink_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_led_green_blink_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blink.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blink.mos
new file mode 100644
index 0000000..35a7bde
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blink.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blink, fileNamePrefix="MDD_led_blink");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue.mos
new file mode 100644
index 0000000..7ba6686
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blue, fileNamePrefix="MDD_led_blue");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue_delay.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue_delay.mos
new file mode 100644
index 0000000..f5e8f16
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue_delay.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blue_delay, fileNamePrefix="MDD_led_blue_delay");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue_red.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue_red.mos
new file mode 100644
index 0000000..9e1c130
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_blue_red.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_blue_red, fileNamePrefix="MDD_led_blue_red");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_green_blink.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_green_blink.mos
new file mode 100644
index 0000000..dc3fad8
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/led/run_led_green_blink.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_led.MDD_led_green_blink, fileNamePrefix="MDD_led_green_blink");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_threshold b/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_threshold
new file mode 100644
index 0000000..a272504
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_threshold
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_threshold.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_threshold.hex
new file mode 100644
index 0000000..70434e9
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_threshold.hex
@@ -0,0 +1,147 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94E30189
+:100020000C9451000C9451000C9451000C94B201AA
+:100030000C9451000C9451000C9481010C945100CB
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E2ECF8E002C0ED
+:1000800005900D92A834B107D9F711E0A8E4B1E0CA
+:1000900001C01D92AD34B107E1F70E944A020C94F1
+:1000A0005F040C9400004F925F926F927F928F9248
+:1000B0009F92AF92BF92CF92DF92EF92FF920F93F7
+:1000C0001F93CF93DF93EC0180917C00857E82604B
+:1000D00080937C0080917A00806480937A00809184
+:1000E0007A0086FDFCCF609178007091790080E005
+:1000F00090E00E94460320E030E040E854E40E9493
+:10010000D80320E030EC4FE754E40E94DE026B019C
+:100110007C016C837D838E839F8311E028A939A99C
+:100120004AA95BA90E94D40387FD10E0812F90E0CB
+:100130009FA38EA3111104C0812C912C540106C0E1
+:10014000812C912C90E8A92E9FE3B92E8C869D8658
+:10015000AE86BF8601E010E02CA93DA94EA95FA99B
+:10016000C501B4010E94D40387FF02C000E010E083
+:1001700019A308A311E02CA53DA54EA55FA5C701B5
+:10018000B6010E94D40387FD10E0812F90E09DA36B
+:100190008CA3111104C0412C512C320106C0412CFA
+:1001A000512C80E8682E8FE3782E488659866A861F
+:1001B0007B8601E010E0A5019401C301B2010E9419
+:1001C000D403181614F000E010E01F8F0E8F11E01A
+:1001D00028A539A54AA55BA5C701B6010E94D4038D
+:1001E00087FD10E0812F90E09BA38AA3111104C02A
+:1001F00060E070E0CB0104C060E070E080E89FE365
+:10020000688B798B8A8B9B8B01E010E0A3019201B4
+:100210000E94D403181614F000E010E01D8F0C8F1C
+:10022000FE01EA5BFF4F808191818230910561F090
+:100230008330910599F00197C9F416BC80916E0046
+:10024000826080936E0016C0109285001092840028
+:1002500080916F00826080936F000CC01092B2009A
+:100260008091700082608093700004C081E090E013
+:100270000E945F0478949FB7F89480914A019FBFD1
+:100280008823C9F310924A01EEADFFAD8C8D9D8D90
+:10029000892B19F08081826002C080818D7F8083EC
+:1002A000FE01E05CFF4F0190F081E02D8E8D9F8D6F
+:1002B000892B19F08081846002C080818B7F8083CC
+:1002C000FE01EE5BFF4F0190F081E02D88A199A126
+:1002D000892B19F08081886002C08081877F8083AC
+:1002E000DF91CF911F910F91FF90EF90DF90CF9012
+:1002F000BF90AF909F908F907F906F905F904F9046
+:1003000008951F920F920FB60F9211242F933F93CF
+:100310008F939F938091480190914901019690930A
+:1003200049018093480180914A01813091F02091E8
+:1003300048013091490180914B0190914C0128175F
+:10034000390738F081E080934A01109249011092F8
+:1003500048019F918F913F912F910F900FBE0F9069
+:100360001F9018951F920F920FB60F9211242F9382
+:100370003F938F939F9380914801909149010196FB
+:10038000909349018093480180914A01813091F016
+:10039000209148013091490180914B0190914C018D
+:1003A0002817390738F081E080934A0110924901FB
+:1003B000109248019F918F913F912F910F900FBE06
+:1003C0000F901F9018951F920F920FB60F92112445
+:1003D0002F933F938F939F93809148019091490170
+:1003E0000196909349018093480180914A018130A0
+:1003F00091F0209148013091490180914B019091F9
+:100400004C012817390738F081E080934A01109297
+:100410004901109248019F918F913F912F910F9028
+:100420000FBE0F901F901895ECE7F0E02081206C34
+:100430002083EAE7F0E0208127682083FC0115AEE5
+:1004400014AE239AEE5BFF4F25E230E03183208328
+:10045000229A329731832083219AFC0137AF26AF4D
+:1004600025B5236025BDEC5BFF4F41E050E0518393
+:1004700040832AE030E030934C0120934B0124B5B7
+:10048000226024BD29EF27BD32965183408380E04E
+:1004900090E00895CF92DF92EF92FF9280E091E09A
+:1004A0000E941402C12CD12C760160E070E0CB01D7
+:1004B0006093000170930101809302019093030106
+:1004C00080E091E00E9453008FEFC81AD80AE80A32
+:1004D000F80AC701B6010E9446032FE632E143E065
+:1004E0005BE30E94D80320E030E0A9010E947A0279
+:1004F000DFCF5058BB27AA270ED01CC10DD130F03A
+:1005000012D120F031F49F3F11F41EF402C10EF419
+:10051000E095E7FBF8C0E92F1ED180F3BA17620718
+:1005200073078407950718F071F49EF536C10EF431
+:10053000E0950B2EBA2FA02D0B01B90190010C01F3
+:10054000CA01A0011124FF27591B99F0593F50F40B
+:10055000503E68F11A16F040A22F232F342F442763
+:10056000585FF3CF469537952795A795F04053955B
+:10057000C9F77EF41F16BA0B620B730B840BBAF02B
+:100580009150A1F0FF0FBB1F661F771F881FC2F796
+:100590000EC0BA0F621F731F841F48F487957795AA
+:1005A0006795B795F7959E3F08F0B3CF9395880F61
+:1005B00008F09927EE0F9795879508950CD0BAC04B
+:1005C000B2D040F0A9D030F021F45F3F19F09BC0C9
+:1005D0005111E4C09EC0BFD098F39923C9F35523AD
+:1005E000B1F3951B550BBB27AA2762177307840726
+:1005F00038F09F5F5F4F220F331F441FAA1FA9F3DC
+:1006000033D00E2E3AF0E0E830D091505040E695CD
+:10061000001CCAF729D0FE2F27D0660F771F881F2E
+:10062000BB1F261737074807AB07B0E809F0BB0B1D
+:10063000802DBF01FF2793585F4F2AF09E3F510541
+:1006400068F061C0ABC05F3FECF3983EDCF3869589
+:1006500077956795B795F7959F5FC9F7880F911DB7
+:100660009695879597F90895E1E0660F771F881FA3
+:10067000BB1F621773078407BA0720F0621B730B56
+:10068000840BBA0BEE1F88F7E0950895E89409C033
+:1006900097FB3EF490958095709561957F4F8F4FB5
+:1006A0009F4F9923A9F0F92F96E9BB279395F695CB
+:1006B000879577956795B795F111F8CFFAF4BB0F49
+:1006C00011F460FF1BC06F5F7F4F8F4F9F4F16C0AD
+:1006D000882311F096E911C0772321F09EE8872F37
+:1006E000762F05C0662371F096E8862F70E060E0F3
+:1006F0002AF09A95660F771F881FDAF7880F96956C
+:10070000879597F9089597F99F6780E870E060E012
+:1007100008959FEF80EC089500240A94161617069A
+:1007200018060906089500240A94121613061406E2
+:1007300005060895092E0394000C11F4882352F045
+:10074000BB0F40F4BF2B11F460FF04C06F5F7F4FFD
+:100750008F4F9F4F089557FD9058440F551F59F0E4
+:100760005F3F71F04795880F97FB991F61F09F3F9E
+:1007700079F087950895121613061406551FF2CFC7
+:100780004695F1DF08C0161617061806991FF1CF17
+:1007900086957105610508940895E894BB2766273E
+:1007A0007727CB0197F9089566D008F48FEF089565
+:1007B0000BD0C0CFB1DF28F0B6DF18F0952309F0D9
+:1007C000A2CFA7CF1124EACFC6DFA0F3959FD1F324
+:1007D000950F50E0551F629FF001729FBB27F00DEF
+:1007E000B11D639FAA27F00DB11DAA1F649F662744
+:1007F000B00DA11D661F829F2227B00DA11D621F93
+:10080000739FB00DA11D621F839FA00D611D221F4C
+:10081000749F3327A00D611D231F849F600D211D30
+:10082000822F762F6A2F11249F5750408AF0E1F0D3
+:1008300088234AF0EE0FFF1FBB1F661F771F881F1C
+:1008400091505040A9F79E3F510570F05CCFA6CF64
+:100850005F3FECF3983EDCF3869577956795B79507
+:10086000F795E7959F5FC1F7FE2B880F911D969531
+:10087000879597F90895990F0008550FAA0BE0E89E
+:10088000FEEF16161706E807F907C0F01216130652
+:10089000E407F50798F0621B730B840B950B39F492
+:1008A0000A2661F0232B242B252B21F408950A26F8
+:1008B00009F4A140A6958FEF811D811D0895F8943C
+:0208C000FFCF68
+:1008C2000000000000000000000000000000000026
+:1008D2000000000000000000000000000000000016
+:1008E2000000000000000000000000000000A04323
+:1008F200000061440000003F0AD7233C00000000D2
+:080902000000000000000000ED
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_threshold_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_threshold_main.c
new file mode 100644
index 0000000..d484565
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/MDD_pot_threshold_main.c
@@ -0,0 +1,264 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_pot_threshold_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_pot_threshold_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Real fmi2RealVars[6];
+ fmi2Boolean fmi2BooleanVars[6];
+ fmi2Real fmi2RealParameter[5];
+ void* extObjs[6];
+} MDD_pot_threshold_fmi2Component;
+
+MDD_pot_threshold_fmi2Component MDD_pot_threshold_component = {
+ .fmi2RealVars = {
+ 0.0 /*adc._y*/,
+ 0.0 /*greater1._u1*/,
+ 0.0 /*greater1._u2*/,
+ 0.0 /*greater2._u1*/,
+ 0.0 /*realExpression1._y*/,
+ 0.0 /*realExpression2._y*/,
+ },
+ .fmi2BooleanVars = {
+ fmi2False /*digitalWriteBoolean1._u*/,
+ fmi2False /*digitalWriteBoolean2._u*/,
+ fmi2False /*digitalWriteBoolean3._u*/,
+ fmi2False /*greaterEqualThreshold1._y*/,
+ fmi2False /*greaterEqualThreshold2._y*/,
+ fmi2False /*greaterEqualThreshold3._y*/,
+ },
+ .fmi2RealParameter = {
+ 0.0 /*greaterEqualThreshold1._threshold*/,
+ 320.0 /*greaterEqualThreshold2._threshold*/,
+ 900.0 /*greaterEqualThreshold3._threshold*/,
+ 0.5 /*realToBoolean1._threshold*/,
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+static const char * const OMCLIT0 = "ElectricPotential";
+static const char * const OMCLIT1 = "V";
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRDigital.h"
+#include "MDDAVRAnalog.h"
+
+static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution)
+{
+ fmi2Real om_value;
+ om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution);
+ return om_value;
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage)
+{
+ void* om_avr;
+ om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage);
+ return om_avr;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr)
+{
+ MDD_avr_analog_close(om_avr);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value)
+{
+ MDD_avr_digital_pin_write(om_port, om_pin, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin)
+{
+ void* om_dig;
+ om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True);
+ return om_dig;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital)
+{
+ MDD_avr_digital_pin_close(om_digital);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_pot_threshold_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_pot_threshold_component;
+}
+
+fmi2Status MDD_pot_threshold_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_pot_threshold_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 7, 4);
+ comp->extObjs[3] /* digitalWriteBoolean3._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 4);
+ comp->extObjs[2] /* digitalWriteBoolean2._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 3);
+ comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2);
+ comp->extObjs[4] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[5] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[4] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ return fmi2OK;
+}
+
+fmi2Status MDD_pot_threshold_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_pot_threshold_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_pot_threshold_functionOutputs(fmi2Component comp)
+{
+ comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 3, 1024.0, 10); /* equation 14 */
+ comp->fmi2BooleanVars[5] /* greaterEqualThreshold3._y DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>=(comp->fmi2RealParameter[2] /* greaterEqualThreshold3._threshold PARAM */); /* equation 15 */
+ comp->fmi2RealVars[2] /* greater1._u2 variable */ = (comp->fmi2BooleanVars[5] /* greaterEqualThreshold3._y DISCRETE */) ? (1.0) : (0.0); /* equation 16 */
+ comp->fmi2BooleanVars[2] /* digitalWriteBoolean3._u DISCRETE */ = (comp->fmi2RealVars[2] /* greater1._u2 variable */)>=(comp->fmi2RealParameter[3] /* realToBoolean1._threshold PARAM */); /* equation 17 */
+ comp->fmi2BooleanVars[4] /* greaterEqualThreshold2._y DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>=(comp->fmi2RealParameter[1] /* greaterEqualThreshold2._threshold PARAM */); /* equation 18 */
+ comp->fmi2RealVars[1] /* greater1._u1 variable */ = (comp->fmi2BooleanVars[4] /* greaterEqualThreshold2._y DISCRETE */) ? (1.0) : (0.0); /* equation 19 */
+ comp->fmi2BooleanVars[1] /* digitalWriteBoolean2._u DISCRETE */ = (comp->fmi2RealVars[1] /* greater1._u1 variable */)>(comp->fmi2RealVars[2] /* greater1._u2 variable */); /* equation 20 */
+ comp->fmi2BooleanVars[3] /* greaterEqualThreshold1._y DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>=(comp->fmi2RealParameter[0] /* greaterEqualThreshold1._threshold PARAM */); /* equation 21 */
+ comp->fmi2RealVars[3] /* greater2._u1 variable */ = (comp->fmi2BooleanVars[3] /* greaterEqualThreshold1._y DISCRETE */) ? (1.0) : (0.0); /* equation 22 */
+ comp->fmi2BooleanVars[0] /* digitalWriteBoolean1._u DISCRETE */ = (comp->fmi2RealVars[3] /* greater2._u1 variable */)>(comp->fmi2RealVars[1] /* greater1._u1 variable */); /* equation 23 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[5] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, comp->fmi2BooleanVars[0] /* digitalWriteBoolean1._u DISCRETE */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[2] /* digitalWriteBoolean2._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 3, comp->fmi2BooleanVars[1] /* digitalWriteBoolean2._u DISCRETE */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[3] /* digitalWriteBoolean3._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 4, comp->fmi2BooleanVars[2] /* digitalWriteBoolean3._u DISCRETE */);
+}
+
+fmi2Status MDD_pot_threshold_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_pot_threshold_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_pot_threshold_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_pot_threshold_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_pot_threshold_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_pot_threshold_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_pot_threshold_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/run_pot_threshold.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/run_pot_threshold.mos
new file mode 100644
index 0000000..843fc0f
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/pot/run_pot_threshold.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_pot.MDD_pot_threshold, fileNamePrefix="MDD_pot_threshold");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_button b/OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_button
new file mode 100644
index 0000000..bd67382
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_button
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_button.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_button.hex
new file mode 100644
index 0000000..dc5d712
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_button.hex
@@ -0,0 +1,94 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C94FB0072
+:100020000C9451000C9451000C9451000C94CA0093
+:100030000C9451000C9451000C9499000C945100B4
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E6EAF5E002C0EE
+:1000800005900D92A631B107D9F711E0A6E1B1E0D4
+:1000900001C01D92AB31B107E1F70E944C010C94F5
+:1000A000D1020C940000DC0154968D919C915597DF
+:1000B0008230910561F08330910599F00197C9F480
+:1000C00016BC80916E00826080936E0016C0109204
+:1000D00085001092840080916F00826080936F0091
+:1000E0000CC01092B200809170008260809370000A
+:1000F00004C081E090E00E94D10278949FB7F89408
+:10010000809118019FBF8823C9F31092180150965F
+:10011000ED91FC91519718968D919C9119970097AC
+:1001200021F4808182608083089580818D7F808327
+:1001300008951F920F920FB60F9211242F933F93A1
+:100140008F939F9380911601909117010196909340
+:1001500017018093160180911801813091F0209150
+:100160001601309117018091190190911A012817F9
+:10017000390738F081E0809318011092170110922E
+:1001800016019F918F913F912F910F900FBE0F906D
+:100190001F9018951F920F920FB60F9211242F9354
+:1001A0003F938F939F938091160190911701019631
+:1001B000909317018093160180911801813091F07E
+:1001C00020911601309117018091190190911A0127
+:1001D0002817390738F081E0809318011092170131
+:1001E000109216019F918F913F912F910F900FBE0A
+:1001F0000F901F9018951F920F920FB60F92112417
+:100200002F933F938F939F938091160190911701A5
+:100210000196909317018093160180911801813007
+:1002200091F0209116013091170180911901909160
+:100230001A012817390738F081E0809318011092CD
+:100240001701109216019F918F913F912F910F905E
+:100250000FBE0F901F901895FC01249825E230E006
+:100260003787268785B5836085BD41E050E0538B95
+:10027000428B8AE090E090931A018093190184B533
+:10028000826084BD89EF87BD558B448B219A318B69
+:10029000208B80E090E00895CF92DF92EF92FF9262
+:1002A00080E091E00E942C01C12CD12C760160E00D
+:1002B00070E0CB0160930001709301018093020113
+:1002C0009093030180E091E00E9453008FEFC81AE1
+:1002D000D80AE80AF80AC701B6010E94E0012FE631
+:1002E00032E143E05BE30E946E0220E030E0A901CE
+:1002F0000E947C01DFCF5058BB27AA270ED0B4C084
+:10030000A5D030F0AAD020F031F49F3F11F41EF4B4
+:100310009AC00EF4E095E7FB90C0E92FB6D080F3C9
+:10032000BA17620773078407950718F071F49EF5F2
+:10033000CEC00EF4E0950B2EBA2FA02D0B01B90103
+:1003400090010C01CA01A0011124FF27591B99F04B
+:10035000593F50F4503E68F11A16F040A22F232F57
+:10036000342F4427585FF3CF469537952795A795A7
+:10037000F0405395C9F77EF41F16BA0B620B730B4E
+:10038000840BBAF09150A1F0FF0FBB1F661F771FBF
+:10039000881FC2F70EC0BA0F621F731F841F48F474
+:1003A000879577956795B795F7959E3F08F0B3CFFA
+:1003B0009395880F08F09927EE0F979587950895E4
+:1003C000E89409C097FB3EF49095809570956195EF
+:1003D0007F4F8F4F9F4F9923A9F0F92F96E9BB27A5
+:1003E0009395F695879577956795B795F111F8CF21
+:1003F000FAF4BB0F11F460FF1BC06F5F7F4F8F4F8C
+:100400009F4F16C0882311F096E911C0772321F081
+:100410009EE8872F762F05C0662371F096E8862F19
+:1004200070E060E02AF09A95660F771F881FDAF770
+:10043000880F9695879597F9089597F99F6780E8B3
+:1004400070E060E008959FEF80EC089500240A9426
+:100450001616170618060906089500240A9412169F
+:100460001306140605060895092E0394000C11F4D2
+:10047000882352F0BB0F40F4BF2B11F460FF04C07F
+:100480006F5F7F4F8F4F9F4F089557FD9058440FD8
+:10049000551F59F05F3F71F04795880F97FB991FE3
+:1004A00061F09F3F79F087950895121613061406A0
+:1004B000551FF2CF4695F1DF08C01616170618062D
+:1004C000991FF1CF86957105610508940895E89408
+:1004D000BB2766277727CB0197F908950BD0C4CFA8
+:1004E000B5DF28F0BADF18F0952309F0A6CFABCF1F
+:1004F0001124EECFCADFA0F3959FD1F3950F50E002
+:10050000551F629FF001729FBB27F00DB11D639FC5
+:10051000AA27F00DB11DAA1F649F6627B00DA11D6B
+:10052000661F829F2227B00DA11D621F739FB00D11
+:10053000A11D621F839FA00D611D221F749F332781
+:10054000A00D611D231F849F600D211D822F762F1A
+:100550006A2F11249F5750408AF0E1F088234AF017
+:10056000EE0FFF1FBB1F661F771F881F9150504063
+:10057000A9F79E3F510570F060CFAACF5F3FECF323
+:10058000983EDCF3869577956795B795F795E7954F
+:100590009F5FC1F7FE2B880F911D9695879597F960
+:0605A0000895F894FFCF5E
+:1005A600000000000000000000000AD7233C000005
+:0605B6000000000000003F
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_button_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_button_main.c
new file mode 100644
index 0000000..8deaf13
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/push/MDD_led_push_button_main.c
@@ -0,0 +1,234 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_led_push_button_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_led_push_button_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Boolean fmi2BooleanVars[3];
+ fmi2Real fmi2RealParameter[1];
+ void* extObjs[4];
+} MDD_led_push_button_fmi2Component;
+
+MDD_led_push_button_fmi2Component MDD_led_push_button_component = {
+ .fmi2BooleanVars = {
+ fmi2False /*booleanExpression1._y*/,
+ fmi2False /*booleanExpression2._y*/,
+ fmi2False /*digitalReadBoolean1._y*/,
+ },
+ .fmi2RealParameter = {
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRDigital.h"
+
+static inline fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_destructor(fmi2Component comp, void* om_digital);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline fmi2Boolean Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_read(fmi2Component comp, void* om_port, fmi2Integer om_pin)
+{
+ fmi2Boolean om_b;
+ om_b = MDD_avr_digital_pin_read(om_port, om_pin);
+ return om_b;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value)
+{
+ MDD_avr_digital_pin_write(om_port, om_pin, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin)
+{
+ void* om_dig;
+ om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2False);
+ return om_dig;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_destructor(fmi2Component comp, void* om_digital)
+{
+ MDD_avr_digital_pin_close(om_digital);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin)
+{
+ void* om_dig;
+ om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True);
+ return om_dig;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital)
+{
+ MDD_avr_digital_pin_close(om_digital);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_led_push_button_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_led_push_button_component;
+}
+
+fmi2Status MDD_led_push_button_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_push_button_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[0] /* digitalReadBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitRead */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitRead_constructor(comp, 2, 5);
+ comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 2, 2);
+ return fmi2OK;
+}
+
+fmi2Status MDD_led_push_button_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_led_push_button_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_led_push_button_functionOutputs(fmi2Component comp)
+{
+ Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 2, !(comp->fmi2BooleanVars[2] /* digitalReadBoolean1._y DISCRETE */));
+}
+
+fmi2Status MDD_led_push_button_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_led_push_button_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_led_push_button_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_led_push_button_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_led_push_button_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_led_push_button_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_led_push_button_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/push/run_led_push_button.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/push/run_led_push_button.mos
new file mode 100644
index 0000000..3f96cb9
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/push/run_led_push_button.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_push.MDD_led_push_button, fileNamePrefix="MDD_led_push_button");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/push/run_led_push_button_status.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/push/run_led_push_button_status.mos
new file mode 100644
index 0000000..9c12875
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/push/run_led_push_button_status.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_push.MDD_led_push_button_status, fileNamePrefix="MDD_led_push_button_status");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/runMDDAvr.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/runMDDAvr.mos
new file mode 100644
index 0000000..b794222
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/runMDDAvr.mos
@@ -0,0 +1,8 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+translateModel(Modelica_DeviceDrivers.EmbeddedTargets.AVR.Examples.Arduino.UNO.Blink, fileNamePrefix="Blink");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzer b/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzer
new file mode 100644
index 0000000..18920a7
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzer
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzer.hex b/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzer.hex
new file mode 100644
index 0000000..7623dfb
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzer.hex
@@ -0,0 +1,121 @@
+:100000000C9434000C9451000C9451000C94510049
+:100010000C9451000C9451000C9451000C9431013B
+:100020000C9451000C9451000C9451000C9400015C
+:100030000C9451000C9451000C94CF000C9451007E
+:100040000C9451000C9451000C9451000C945100EC
+:100050000C9451000C9451000C9451000C945100DC
+:100060000C9451000C94510011241FBECFEFD8E026
+:10007000DEBFCDBF11E0A0E0B1E0E4E4F7E002C0F4
+:1000800005900D92A832B107D9F711E0A8E2B1E0CE
+:1000900001C01D92AD32B107E1F70E948B010C94B3
+:1000A000A0030C9400000F931F93CF93DF93EC01F8
+:1000B00080917C00857E846080937C0080917A00B2
+:1000C000806480937A0080917A0086FDFCCF6091F5
+:1000D00078007091790080E090E00E94870220E033
+:1000E00030E040E854E40E94190320E030EC4FE790
+:1000F00054E40E941F026C837D838E839F8301E002
+:1001000010E02A893B894C895D890E94150387FF8D
+:1001100002C000E010E0198B088B8EA19FA18230F5
+:10012000910561F08330910599F00197C9F416BCEF
+:1001300080916E00826080936E0016C010928500E0
+:100140001092840080916F00826080936F000CC0D9
+:100150001092B2008091700082608093700004C0A1
+:1001600081E090E00E94A00378949FB7F89480917A
+:100170002A019FBF8823C9F310922A01EAA1FBA19B
+:1001800088899989892B19F08081886002C08081D3
+:10019000877F8083DF91CF911F910F9108951F92E8
+:1001A0000F920FB60F9211242F933F938F939F932B
+:1001B00080912801909129010196909329018093C3
+:1001C000280180912A01813091F0209128013091FD
+:1001D000290180912B0190912C012817390738F0C3
+:1001E00081E080932A0110922901109228019F91A9
+:1001F0008F913F912F910F900FBE0F901F901895E8
+:100200001F920F920FB60F9211242F933F938F934B
+:100210009F93809128019091290101969093290143
+:100220008093280180912A01813091F0209128014A
+:100230003091290180912B0190912C0128173907C9
+:1002400038F081E080932A01109229011092280150
+:100250009F918F913F912F910F900FBE0F901F9004
+:1002600018951F920F920FB60F9211242F933F9360
+:100270008F939F93809128019091290101969093EB
+:1002800029018093280180912A01813091F02091E9
+:1002900028013091290180912B0190912C01281780
+:1002A000390738F081E080932A01109229011092D9
+:1002B00028019F918F913F912F910F900FBE0F902A
+:1002C0001F901895FC01539A8BE290E093A382A3B0
+:1002D00085B5836085BD21E030E035A324A38AE0A5
+:1002E00090E090932C0180932B0184B5826084BDB3
+:1002F00089EF87BD37A326A3ACE7B0E08C91806C73
+:100300008C93AAE7B0E08C9187688C9311A210A21D
+:1003100080E090E00895CF92DF92EF92FF9280E02C
+:1003200091E00E946201C12CD12C760160E070E066
+:10033000CB016093000170930101809302019093BF
+:10034000030180E091E00E9453008FEFC81AD80AA1
+:10035000E80AF80AC701B6010E9487022FE632E1D7
+:1003600043E05BE30E94190320E030E0A9010E9412
+:10037000BB01DFCF5058BB27AA270ED01CC10DD11F
+:1003800030F012D120F031F49F3F11F41EF402C17D
+:100390000EF4E095E7FBF8C0E92F1ED180F3BA1701
+:1003A000620773078407950718F071F49EF536C14C
+:1003B0000EF4E0950B2EBA2FA02D0B01B901900180
+:1003C0000C01CA01A0011124FF27591B99F0593FC4
+:1003D00050F4503E68F11A16F040A22F232F342F0C
+:1003E0004427585FF3CF469537952795A795F0405A
+:1003F0005395C9F77EF41F16BA0B620B730B840B6F
+:10040000BAF09150A1F0FF0FBB1F661F771F881F26
+:10041000C2F70EC0BA0F621F731F841F48F487957E
+:1004200077956795B795F7959E3F08F0B3CF93956D
+:10043000880F08F09927EE0F9795879508950CD0AF
+:10044000BAC0B2D040F0A9D030F021F45F3F19F02B
+:100450009BC05111E4C09EC0BFD098F39923C9F34B
+:100460005523B1F3951B550BBB27AA2762177307BA
+:10047000840738F09F5F5F4F220F331F441FAA1F6E
+:10048000A9F333D00E2E3AF0E0E830D0915050402E
+:10049000E695001CCAF729D0FE2F27D0660F771FDC
+:1004A000881FBB1F261737074807AB07B0E809F0BE
+:1004B000BB0B802DBF01FF2793585F4F2AF09E3F53
+:1004C000510568F061C0ABC05F3FECF3983EDCF3D0
+:1004D000869577956795B795F7959F5FC9F7880FCC
+:1004E000911D9695879597F90895E1E0660F771F1E
+:1004F000881FBB1F621773078407BA0720F0621BAF
+:10050000730B840BBA0BEE1F88F7E0950895E894FF
+:1005100009C097FB3EF490958095709561957F4F4B
+:100520008F4F9F4F9923A9F0F92F96E9BB279395F9
+:10053000F695879577956795B795F111F8CFFAF409
+:10054000BB0F11F460FF1BC06F5F7F4F8F4F9F4F3A
+:1005500016C0882311F096E911C0772321F09EE898
+:10056000872F762F05C0662371F096E8862F70E0FE
+:1005700060E02AF09A95660F771F881FDAF7880FD8
+:100580009695879597F9089597F99F6780E870E0A9
+:1005900060E008959FEF80EC089500240A941616F9
+:1005A000170618060906089500240A941216130661
+:1005B000140605060895092E0394000C11F48823EF
+:1005C00052F0BB0F40F4BF2B11F460FF04C06F5F0B
+:1005D0007F4F8F4F9F4F089557FD9058440F551FE1
+:1005E00059F05F3F71F04795880F97FB991F61F0B5
+:1005F0009F3F79F087950895121613061406551F2C
+:10060000F2CF4695F1DF08C0161617061806991F97
+:10061000F1CF86957105610508940895E894BB278C
+:1006200066277727CB0197F9089566D008F48FEFF6
+:1006300008950BD0C0CFB1DF28F0B6DF18F09523B6
+:1006400009F0A2CFA7CF1124EACFC6DFA0F3959F70
+:10065000D1F3950F50E0551F629FF001729FBB27A9
+:10066000F00DB11D639FAA27F00DB11DAA1F649F55
+:100670006627B00DA11D661F829F2227B00DA11D08
+:10068000621F739FB00DA11D621F839FA00D611D8E
+:10069000221F749F3327A00D611D231F849F600DAF
+:1006A000211D822F762F6A2F11249F5750408AF0E8
+:1006B000E1F088234AF0EE0FFF1FBB1F661F771F74
+:1006C000881F91505040A9F79E3F510570F05CCFB4
+:1006D000A6CF5F3FECF3983EDCF386957795679560
+:1006E000B795F795E7959F5FC1F7FE2B880F911D92
+:1006F0009695879597F90895990F0008550FAA0BBD
+:10070000E0E8FEEF16161706E807F907C0F0121624
+:100710001306E407F50798F0621B730B840B950B27
+:1007200039F40A2661F0232B242B252B21F408957C
+:100730000A2609F4A140A6958FEF811D811D089519
+:04074000F894FFCF5B
+:1007440000000000000000000000000000000000A5
+:10075400000000002F440AD7233C020001000000DF
+:0807640000000000000000008D
+:00000001FF
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzer_main.c b/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzer_main.c
new file mode 100644
index 0000000..bd35c9c
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/MDD_therm_buzzer_main.c
@@ -0,0 +1,253 @@
+#define fmi2TypesPlatform_h
+
+#define fmi2TypesPlatform "default" /* Compatible */
+
+typedef struct MDD_therm_buzzer_fmi2Component_s* fmi2Component;
+typedef void* fmi2ComponentEnvironment; /* Pointer to FMU environment */
+typedef void* fmi2FMUstate; /* Pointer to internal FMU state */
+typedef unsigned int fmi2ValueReference;
+typedef double fmi2Real;
+typedef int fmi2Integer;
+typedef int fmi2Boolean;
+typedef char fmi2Char;
+typedef const fmi2Char* fmi2String;
+typedef char fmi2Byte;
+
+#define fmi2True 1
+#define fmi2False 0
+
+#include "fmi2/fmi2Functions.h"
+
+#include <stdint.h>
+#include <stdio.h>
+
+void ModelicaFormatMessage(const char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ vprintf(fmt, args);
+ va_end(args);
+}
+
+typedef struct MDD_therm_buzzer_fmi2Component_s {
+ fmi2Real currentTime;
+ fmi2Real fmi2RealVars[2];
+ fmi2Boolean fmi2BooleanVars[3];
+ fmi2Real fmi2RealParameter[2];
+ fmi2Integer fmi2IntegerParameter[1];
+ fmi2Boolean fmi2BooleanParameter[1];
+ fmi2String fmi2StringParameter[1];
+ void* extObjs[4];
+} MDD_therm_buzzer_fmi2Component;
+
+MDD_therm_buzzer_fmi2Component MDD_therm_buzzer_component = {
+ .fmi2RealVars = {
+ 0.0 /*adc._y*/,
+ 0.0 /*realValue1._number*/,
+ },
+ .fmi2BooleanVars = {
+ fmi2False /*booleanExpression1._y*/,
+ fmi2False /*booleanExpression2._y*/,
+ fmi2False /*digitalWriteBoolean1._u*/,
+ },
+ .fmi2RealParameter = {
+ 700.0 /*greaterEqualThreshold1._threshold*/,
+ 0.01 /*synchronizeRealtime1._actualInterval*/,
+ },
+ .fmi2IntegerParameter = {
+ 2 /*realValue1._significantDigits*/,
+ },
+ .fmi2BooleanParameter = {
+ fmi2True /*realValue1._use_numberPort*/,
+ },
+};
+
+#include <math.h>
+/* TODO: Generate used builtin functions before SimCode */
+static inline double om_mod(double x, double y)
+{
+ return x-floor(x/y)*y;
+}
+
+static const char * const OMCLIT0 = "ElectricPotential";
+static const char * const OMCLIT1 = "V";
+#include "MDDAVRTimer.h"
+#include "MDDAVRRealTime.h"
+#include "MDDAVRDigital.h"
+#include "MDDAVRAnalog.h"
+
+static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt);
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch);
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer);
+
+static inline fmi2Real Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(fmi2Component comp, fmi2Integer om_analogPort, fmi2Real om_vref, fmi2Integer om_voltageResolution)
+{
+ fmi2Real om_value;
+ om_value = MDD_avr_analog_read(om_analogPort, om_vref, om_voltageResolution);
+ return om_value;
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(fmi2Component comp, fmi2Integer om_divisionFactor, fmi2Integer om_referenceVoltage)
+{
+ void* om_avr;
+ om_avr = MDD_avr_analog_init(om_divisionFactor, om_referenceVoltage);
+ return om_avr;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_destructor(fmi2Component comp, void* om_avr)
+{
+ MDD_avr_analog_close(om_avr);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(fmi2Component comp, void* om_port, fmi2Integer om_pin, fmi2Boolean om_value)
+{
+ MDD_avr_digital_pin_write(om_port, om_pin, om_value);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(fmi2Component comp, fmi2Integer om_port, fmi2Integer om_pin)
+{
+ void* om_dig;
+ om_dig = MDD_avr_digital_pin_init(om_port, om_pin, fmi2True);
+ return om_dig;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_destructor(fmi2Component comp, void* om_digital)
+{
+ MDD_avr_digital_pin_close(om_digital);
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_wait(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(fmi2Component comp, void* om_timer, fmi2Integer om_timerValue, fmi2Integer om_numTimerInterruptsPerCycle)
+{
+ void* om_rt;
+ om_rt = MDD_avr_rt_init(om_timer, om_timerValue, om_numTimerInterruptsPerCycle);
+ return om_rt;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_destructor(fmi2Component comp, void* om_rt)
+{
+ MDD_avr_rt_close(om_rt);
+}
+static inline void* Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(fmi2Component comp, fmi2Integer om_timerSelect, fmi2Integer om_clockSelect, fmi2Boolean om_clearTimerOnMatch)
+{
+ void* om_timer;
+ om_timer = MDD_avr_timer_init(om_timerSelect, om_clockSelect, om_clearTimerOnMatch);
+ return om_timer;
+}
+static inline void Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_destructor(fmi2Component comp, void* om_timer)
+{
+ MDD_avr_timer_close(om_timer);
+}
+
+fmi2Component MDD_therm_buzzer_fmi2Instantiate(fmi2String name, fmi2Type ty, fmi2String GUID, fmi2String resources, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn)
+{
+ static int initDone=0;
+ if (initDone) {
+ return NULL;
+ }
+ return &MDD_therm_buzzer_component;
+}
+
+fmi2Status MDD_therm_buzzer_fmi2SetupExperiment(fmi2Component comp, fmi2Boolean toleranceDefined, fmi2Real tolerance, fmi2Real startTime, fmi2Boolean stopTimeDefined, fmi2Real stopTime)
+{
+ return fmi2OK;
+}
+
+fmi2Status MDD_therm_buzzer_fmi2EnterInitializationMode(fmi2Component comp)
+{
+ comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_InitWrite_constructor(comp, 4, 4);
+ comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Timers_Timer_constructor(comp, 1, 4, fmi2False);
+ comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_Init_constructor(comp, comp->extObjs[2] /* synchronizeRealtime1._clock EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Timers.Timer */, 249, 10);
+ comp->extObjs[0] /* adc._analog EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Analog.Init */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_Init_constructor(comp, 7, 4);
+ return fmi2OK;
+}
+
+fmi2Status MDD_therm_buzzer_fmi2ExitInitializationMode(fmi2Component comp)
+{
+ return fmi2OK;
+}
+
+static fmi2Status MDD_therm_buzzer_functionODE(fmi2Component comp)
+{
+}
+
+static fmi2Status MDD_therm_buzzer_functionOutputs(fmi2Component comp)
+{
+ comp->fmi2RealVars[0] /* adc._y variable */ = Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Analog_read__voltage(comp, 5, 1024.0, 10); /* equation 7 */
+ comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */ = (comp->fmi2RealVars[0] /* adc._y variable */)>=(comp->fmi2RealParameter[0] /* greaterEqualThreshold1._threshold PARAM */); /* equation 8 */Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_RealTimeSynchronization_wait(comp, comp->extObjs[3] /* synchronizeRealtime1._sync EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.RealTimeSynchronization.Init */);Modelica__DeviceDrivers_EmbeddedTargets_AVR_Functions_Digital_write(comp, comp->extObjs[1] /* digitalWriteBoolean1._digital EXTOBJ: Modelica_DeviceDrivers.EmbeddedTargets.AVR.Functions.Digital.InitWrite */, 4, comp->fmi2BooleanVars[2] /* digitalWriteBoolean1._u DISCRETE */);
+}
+
+fmi2Status MDD_therm_buzzer_fmi2DoStep(fmi2Component comp, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)
+{
+ comp->currentTime = currentCommunicationPoint;
+ /* TODO: Calculate time/state-dependent variables here... */
+ MDD_therm_buzzer_functionOutputs(comp);
+ return fmi2OK;
+}
+
+int main(int argc, char **argv)
+{
+ int terminateSimulation = 0;
+ fmi2Status status = fmi2OK;
+ fmi2CallbackFunctions cbf = {
+ .logger = NULL,
+ .allocateMemory = NULL /*calloc*/,
+ .freeMemory = NULL /*free*/,
+ .stepFinished = NULL, //synchronous execution
+ .componentEnvironment = NULL
+ };
+
+ fmi2Component comp = MDD_therm_buzzer_fmi2Instantiate("", fmi2CoSimulation, "", "", &cbf, fmi2False, fmi2False);
+ if (comp==NULL) {
+ return 1;
+ }
+ MDD_therm_buzzer_fmi2SetupExperiment(comp, fmi2False, 0.0, 0.0, fmi2False, 1.0);
+ MDD_therm_buzzer_fmi2EnterInitializationMode(comp);
+ // Set start-values? Nah...
+ MDD_therm_buzzer_fmi2ExitInitializationMode(comp);
+
+ double currentTime = 0.0;
+ double h = 0.002;
+ uint32_t i = 0;
+
+ while (status == fmi2OK) {
+ //retrieve outputs
+ // fmi2GetReal(m, ..., 1, &y1);
+ //set inputs
+ // fmi2SetReal(m, ..., 1, &y2);
+
+ //call slave and check status
+ status = MDD_therm_buzzer_fmi2DoStep(comp, currentTime, h, fmi2True);
+ switch (status) {
+ case fmi2Discard:
+ case fmi2Error:
+ case fmi2Fatal:
+ case fmi2Pending /* Cannot happen */:
+ terminateSimulation = 1;
+ break;
+ case fmi2OK:
+ case fmi2Warning:
+ break;
+ }
+ if (terminateSimulation) {
+ break;
+ }
+ i++;
+ /* increment master time */
+ currentTime = 0.0 + h*i;
+ }
+
+#if 0
+ if ((status != fmi2Error) && (status != fmi2Fatal)) {
+ fmi2Terminate(m);
+ }
+ if (status != fmi2Fatal) {
+ fmi2FreeInstance(m);
+ }
+#endif
+}
+
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/run_therm_buzzer.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/run_therm_buzzer.mos
new file mode 100644
index 0000000..a510879
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/run_therm_buzzer.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_thermistor.MDD_therm_buzzer, fileNamePrefix="MDD_therm_buzzer");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/run_therm_read.mos b/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/run_therm_read.mos
new file mode 100644
index 0000000..6a13955
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/MDD_build/thermistor/run_therm_read.mos
@@ -0,0 +1,11 @@
+loadModel(Modelica);
+getErrorString();
+
+loadFile("D:/Modelica_DeviceDrivers/package.mo");
+getErrorString();
+
+loadFile("D:/Arduino.mo");
+getErrorString();
+
+translateModel(Arduino.SerialCommunication.MDD_Examples.MDD_thermistor.MDD_therm_read, fileNamePrefix="MDD_therm_read");
+getErrorString(); \ No newline at end of file
diff --git a/OpenModelica-Arduino-MDD-Windows/README.md b/OpenModelica-Arduino-MDD-Windows/README.md
new file mode 100644
index 0000000..2287de8
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/README.md
@@ -0,0 +1,24 @@
+# OpenModelica-Arduino-Windows
+Free library for interfacing Arduino using Modelica and Modelica_DeviceDrivers models in Windows.
+There is support for serial port.
+
+## Library description
+The `OpenModelica-Arduino-Windows` library is an open source Modelica package.
+
+Main features:
+ * Support for Windows.
+ * (Soft) real-time synchronization of a simulation.
+
+Please note that the library is known to work with
+* OpenModelica (partial support starting with OpenModelica v1.11.0, e.g.serial port).
+
+## Development and contribution
+Main developers:
+* [Vanessa Singh](https://github.com/VanessaSingh), contribution to the Windows specific code
+* [Souradip Pal](https://github.com/Souradip-sopho), bug fixes,repository management.
+* [Disha Agarwal](https://github.com/disha4u), various documentation.
+
+Contributions in shape of [Pull Requests] are always welcome.
+
+The following people have directly contributed to the implementation of the library (many more have contributed by providing feedback and suggestions):
+* Manas Ranjan Das (project mentor), contribution in bug fixes,error removal etc.
diff --git a/OpenModelica-Arduino-MDD-Windows/Resources/Images/Icons/tqfp32.png b/OpenModelica-Arduino-MDD-Windows/Resources/Images/Icons/tqfp32.png
new file mode 100644
index 0000000..f933f6a
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/Resources/Images/Icons/tqfp32.png
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/Resources/Library/SerialComm.dll b/OpenModelica-Arduino-MDD-Windows/Resources/Library/SerialComm.dll
new file mode 100644
index 0000000..37b83b8
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/Resources/Library/SerialComm.dll
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/Resources/Library/SerialComm.o b/OpenModelica-Arduino-MDD-Windows/Resources/Library/SerialComm.o
new file mode 100644
index 0000000..4a0f2c3
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/Resources/Library/SerialComm.o
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/Resources/include/serial.h b/OpenModelica-Arduino-MDD-Windows/Resources/include/serial.h
new file mode 100644
index 0000000..4e687d9
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/Resources/include/serial.h
@@ -0,0 +1,34 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <Windows.h>
+//prototypes for the functions used in SerialComm.c
+
+__declspec (dllexport) __stdcall int open_serial(int handle, int port, int baudrate);
+__declspec (dllexport) __stdcall int write_serial(int handle, char str[],int size);
+__declspec (dllexport) __stdcall int read_serial(int handle,char buf[],int size);
+__declspec (dllexport) __stdcall int status_serial(int handle,int nb[]);
+__declspec (dllexport) __stdcall int close_serial(int handle);
+__declspec (dllexport) __stdcall int cmd_digital_out(int h,int pin_no,int val);
+__declspec (dllexport) __stdcall int cmd_digital_in(int h,int pin_no);
+__declspec (dllexport) __stdcall void delay(long int t);
+__declspec (dllexport) __stdcall int cmd_analog_out(int h,int pin_no,double val);
+__declspec (dllexport) __stdcall uint16_t cmd_analog_in(int h,int pin_no);
+__declspec (dllexport) __stdcall void cmd_dcmotor_setup(int h,int driver_type,int motor_no,int pin_no_1,int pin_no_2);
+__declspec (dllexport) __stdcall void cmd_dcmotor_run(int h,int motor_no,int u1);
+__declspec (dllexport) __stdcall void cmd_dcmotor_release(int h,int motor_no);
+__declspec (dllexport) __stdcall void cmd_servo_attach(int h,int servo_no);
+__declspec (dllexport) __stdcall void cmd_servo_move(int h,int servo_no,int u1);
+__declspec (dllexport) __stdcall void cmd_servo_detach(int h,int servo_no);
+__declspec (dllexport) __stdcall int mfloor(float num);
+__declspec (dllexport) __stdcall int cmd_analog_out_volt(int h,int pin_no,double val);
+__declspec (dllexport) __stdcall uint16_t cmd_analog_in_volt(int h,int pin_no);
+__declspec (dllexport) __stdcall long int hex2dec(char hexadecimal[]);
+__declspec (dllexport) __stdcall void dec2hex(long int decimalnum,char hexadecimalnum[]);
+__declspec (dllexport) __stdcall double ieeesingle2num(char hexa[]);
+__declspec (dllexport) __stdcall void read_active_power();
+__declspec (dllexport) __stdcall void read_current();
+__declspec (dllexport) __stdcall void read_voltage();
+__declspec (dllexport) __stdcall double read_val(int addr_byte);
+__declspec (dllexport) __stdcall int ascii_c(char c);
+__declspec (dllexport) __stdcall char ascii_n(int num);
diff --git a/OpenModelica-Arduino-MDD-Windows/Resources/src/SerialComm.c b/OpenModelica-Arduino-MDD-Windows/Resources/src/SerialComm.c
new file mode 100644
index 0000000..d7f612a
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/Resources/src/SerialComm.c
@@ -0,0 +1,1021 @@
+/**************************************************
+
+file: main.c
+purpose: serial librairie for Scilab
+
+Alain Caignot
+**************************************************/
+#ifdef NAN
+/* NAN is supported */
+#endif
+#ifdef INFINITY
+/* INFINITY is supported */
+#endif
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <Windows.h>
+#include <fcntl.h>
+#include <math.h>
+#include <ctype.h>
+#include <stdint.h>
+#include "../include/serial.h"
+
+#define abs(x) (x>=0?x:-x)
+#define MAXPORTS 5
+// Static definition to stock HANDLE of Port.
+static HANDLE hport;
+
+// Function to open port COM
+__declspec (dllexport) __stdcall int open_serial(int handle,int port, int baudrate){
+ DCB dcbSerialParams ;
+ DWORD dwBytesWrite = 0;
+ DWORD dwBytesRead = 10;
+ COMMTIMEOUTS timeouts={0};
+
+ char tmp[5]="COM5";
+ itoa(port,&tmp[3],10);
+
+ int OK=0;
+
+
+ hport = CreateFile(tmp,
+ GENERIC_READ | GENERIC_WRITE,
+ 0,//FILE_SHARE_READ | FILE_SHARE_WRITE //to test : recuperation COM port if simulation crashes
+ 0,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ 0);
+
+ if(hport==INVALID_HANDLE_VALUE){
+ if(GetLastError()==ERROR_FILE_NOT_FOUND){
+ //serial port does not exist. Inform user.
+ OK = GetLastError();
+ return OK;
+ }
+ //some other error occurred. Inform user.
+ OK = GetLastError();
+ return OK;
+ }
+
+
+
+ dcbSerialParams.DCBlength=sizeof(dcbSerialParams);
+ if (!GetCommState(hport, &dcbSerialParams)) {
+ //error getting state
+ OK = GetLastError();
+ return OK;
+ }
+ dcbSerialParams.BaudRate=baudrate;
+ dcbSerialParams.ByteSize=8;
+ dcbSerialParams.StopBits=ONESTOPBIT;
+ dcbSerialParams.Parity=NOPARITY;
+ if(!SetCommState(hport, &dcbSerialParams)){
+ //error setting serial port state
+ OK = GetLastError();
+ return OK;
+ }
+
+
+ timeouts.ReadIntervalTimeout=50;
+ timeouts.ReadTotalTimeoutConstant=50;
+ timeouts.ReadTotalTimeoutMultiplier=1;
+ timeouts.WriteTotalTimeoutConstant=50;
+ timeouts.WriteTotalTimeoutMultiplier=1;
+ if(!SetCommTimeouts(hport, &timeouts)){
+ //error occureed. Inform user
+ OK = GetLastError();
+ return OK;
+ }
+ Sleep(1000);
+}
+
+//Function to close port COM
+__declspec (dllexport) __stdcall int close_serial(int handle){
+ int res;
+ int OK=0;
+ res=CloseHandle(hport);
+ if (res==0)//error
+ OK = GetLastError();
+ return OK;
+}
+
+//Function to write to the port
+__declspec (dllexport) __stdcall int write_serial(int handle, char str[],int size){
+ DWORD dwBytesWrite = 0;
+ int res;
+ int OK=0;
+ res=WriteFile(hport,str,size,&dwBytesWrite,NULL);
+
+ if (res==0) //error
+ OK = GetLastError();
+
+}
+
+//Function to check status of the port
+__declspec (dllexport) __stdcall int status_serial(int handle, int nb[]){
+ DWORD dwErrorFlags;
+ COMSTAT ComStat;
+ int res;
+
+ int OK=0;
+ res=ClearCommError( hport, &dwErrorFlags, &ComStat );
+ if (res==0) {//error
+ OK = GetLastError();
+ return OK;
+ }
+ nb[0] = 2;
+ nb[1] = 2;
+ OK=0;
+ //printf("Getting status.....\n");
+ return OK;
+}
+
+//Function to read from the port
+__declspec (dllexport) __stdcall int read_serial(int handle,char buf[],int size){
+ DWORD dwBytesRead = 0;
+ int res;
+ res=ReadFile(hport, buf, size, &dwBytesRead, NULL);
+ return res;
+
+}
+//Function to provide delay
+__declspec (dllexport) __stdcall void delay(long int t)
+{
+ Sleep(abs(t));
+ return ;
+}
+
+//digital output
+__declspec (dllexport) __stdcall int cmd_digital_out(int h,int pin_no,int val)
+{
+ int wr=2;
+ char pin[6]="Da";
+ char v[2],temp[2];
+ sprintf(temp,"%c",pin_no+48);
+ strcat(pin,temp);
+ strcat(pin,"1");
+ //printf("%s",pin);
+ wr=write_serial(h,pin,4);
+ if (val > 0.5)
+ val = 1;
+ else
+ val = 0;
+
+ sprintf(v,"%d",val);
+ strcpy(pin,"Dw");
+ strcat(pin,temp);
+ strcat(pin,v);
+ //printf("%s",pin);
+ wr=write_serial(h,pin,4);
+ return wr;
+}
+
+//digital input
+__declspec (dllexport) __stdcall int cmd_digital_in(int h,int pin_no)
+{
+ int value = 0;
+ char pin[6]="Da";
+ char v1[2],v2[2];
+ int wr1, wr2;
+ sprintf(v1,"%c",pin_no+48);
+ strcat(pin,v1);
+ strcat(pin,"0");
+ //printf("%s\n",pin);
+ wr1=write_serial(h,pin,4);
+
+ strcpy(pin,"Dr");
+ sprintf(v2,"%c",pin_no+48);
+ strcat(pin,v2);
+ wr2=write_serial(1,pin,3);
+ //binary transfer
+ int stat;
+ int num_bytes[2];
+ char st[10];
+ stat=status_serial(h,num_bytes);
+ while(num_bytes[0]<1)
+ stat=status_serial(h,num_bytes);
+ char* temp;
+ int wr=read_serial(h,st,1);
+ value=strtod(st,&temp);
+ //printf("%d\n",value);
+ return value;
+}
+//Analog input
+__declspec (dllexport) __stdcall uint16_t cmd_analog_in(int h,int pin_no)
+{
+ char pin[5],v1[2];
+ int stat;
+ int read[3];
+ sprintf(v1,"%c",pin_no+48);
+ strcpy(pin,"A");
+ strcat(pin,v1);
+ int wr=write_serial(h,pin,2);
+ stat=status_serial(h,read);
+ while (read[0] < 2)
+ stat=status_serial(h,read);
+ char values[5];
+ int a_rd=read_serial(h,values,2);
+ values[2]='\0';
+ //printf("%s\n",values);
+ int l=strlen(values);
+ uint8_t temp[l+1];
+ //int temp[l];
+ int i;
+ for (i = 0; i < l; ++i)
+ {
+ temp[i]=(uint8_t)values[i];
+ }
+ //printf("%u %u\n",temp[0],temp[1]);
+ uint16_t result=(uint16_t)(256*temp[1]+temp[0]);
+ //printf("%d\n",result);
+ return result;
+}
+
+//Analog output
+__declspec (dllexport) __stdcall int cmd_analog_out(int h,int pin_no,double val)
+{
+ char v1[2],v2[2];
+ if(val > 255)
+ val = 255;
+ else if(val < 0)
+ val = 0;
+ //printf("%f\n",val);
+ char code_sent[10];
+ strcpy(code_sent,"W");
+ sprintf(v1,"%c",pin_no+48);
+ sprintf(v2,"%c",abs(ceil(val)));
+ strcat(code_sent,v1);
+ strcat(code_sent,v2);
+ //printf("%s\n",code_sent);
+ return write_serial(h,code_sent,3);
+
+}
+
+//Servo Attach
+__declspec (dllexport) __stdcall void cmd_servo_attach(int h,int servo_no)
+{
+ char pin[5];
+ int wr;
+ printf("init servo write");
+ if(servo_no==1)//servo 1 on pin 9
+ {
+ strcpy(pin,"Sa1");
+ wr=write_serial(h,pin,3);
+ }
+ else if(servo_no==2)//servo 2 on pin 10
+ {
+ strcpy(pin,"Sa2");
+ wr=write_serial(h,pin,3);
+ }
+ else
+ perror("Error.");
+}
+
+//Servo Move
+__declspec (dllexport) __stdcall void cmd_servo_move(int h,int servo_no,int u1)
+{
+ int wr;
+ char servo[2];
+ char v[2];
+ char pin[5]="Sw";
+ if (u1<0)
+ {
+ sprintf(servo,"%c",48+servo_no);
+ sprintf(v,"%c",0);
+ strcat(pin,servo);
+ strcat(pin,v);
+ //pin="Sw"+ascii(48+servo_no)+ascii(0);
+ }
+ else if(u1>180)
+ {
+ sprintf(servo,"%c",48+servo_no);
+ sprintf(v,"%c",180);
+ strcat(pin,servo);
+ strcat(pin,v);
+ } //pin="Sw"+ascii(48+servo_no)+ascii(180);
+ else
+ {
+ sprintf(servo,"%c",48+servo_no);
+ sprintf(v,"%c",(uint8_t)u1);
+ strcat(pin,servo);
+ strcat(pin,v);
+ } //pin="Sw"+ascii(48+servo_no)+ascii(uint8(u1));
+ wr=write_serial(1,pin,4);
+}
+
+//Servo Detach
+__declspec (dllexport) __stdcall void cmd_servo_detach(int h,int servo_no)
+{
+ int wr;
+ char pin[5]="Sd";
+ if(servo_no==1) //servo 1 on pin 10
+ {
+ strcat(pin,"1");
+ //pin="Sd1"
+ wr=write_serial(h,pin,3);
+ }
+ else if(servo_no==2) //servo 2 on pin 9
+ {
+ strcat(pin,"2");
+ //pin="Sd2"
+ wr=write_serial(h,pin,3);
+ }
+ else
+ perror("Error.");
+
+}
+//Calculating floor odf a number
+__declspec (dllexport) __stdcall int mfloor(float num)
+{
+ int n = floor(num) ;
+ return n;
+}
+//DC Motor setup
+__declspec (dllexport) __stdcall void cmd_dcmotor_setup(int h,int driver_type,int motor_no,int pin_no_1,int pin_no_2)
+{
+ printf("init DCmotor\n");
+ char code_sent[10]="C";
+ int wr;
+ char v1[2],v2[2],motor[2];
+ if(driver_type==1)
+ {
+ sprintf(v1,"%c",pin_no_1+48);
+ sprintf(v2,"%c",pin_no_2+48);
+ sprintf(motor,"%c",motor_no+48);
+ strcat(code_sent,motor);
+ strcat(code_sent,v1);
+ strcat(code_sent,v2);
+ strcat(code_sent,"1");
+ }
+ //code_sent="C"+string(motor_no)+ascii(48+pin_no_1)+ascii(48+pin_no_2)+"1"; //adafruit
+ else if(driver_type==2)
+ {
+ sprintf(v1,"%c",pin_no_1+48);
+ sprintf(v2,"%c",pin_no_2+48);
+ sprintf(motor,"%c",motor_no+48);
+ strcat(code_sent,motor);
+ strcat(code_sent,v1);
+ strcat(code_sent,v2);
+ strcat(code_sent,"1");
+ }
+ //code_sent="C"+string(motor_no)+ascii(48+pin_no_1)+ascii(48+pin_no_2)+"1"; //code pour initialiser L298
+ else if(driver_type==3)
+ {
+ sprintf(v1,"%c",pin_no_1+48);
+ sprintf(v2,"%c",pin_no_2+48);
+ sprintf(motor,"%c",motor_no+48);
+ strcat(code_sent,motor);
+ strcat(code_sent,v1);
+ strcat(code_sent,v2);
+ strcat(code_sent,"0");
+
+ }
+ // code_sent="C"+string(motor_no)+ascii(48+pin_no_1)+ascii(48+pin_no_2)+"0"; //code pour initialiser L293
+ //printf("%s\n",code_sent);
+ wr=write_serial(h,code_sent,5);
+
+ int stat;
+ int num_bytes[2];
+ //Attente que l'arduino reponde OK
+ stat=status_serial(1,num_bytes);
+ while (num_bytes[0] < 2)
+ stat=status_serial(1,num_bytes);
+ char values[5];
+ int dcm_rd=read_serial(1,values,2);
+ //printf("%d\n",dcm_rd );
+ //printf("%s\n",values );
+ if (dcm_rd == 0)
+ printf("Init motor successful\n");
+ else
+ printf("Init motor unsuccessful\n");
+}
+
+//DC Motor run
+__declspec (dllexport) __stdcall void cmd_dcmotor_run(int h,int motor_no,int u1)
+{
+ char code_dir[2];
+ char code_sent[10]="M";
+ char motor[2];
+ int val;
+ char v[2];
+ if(u1>=0)
+ sprintf(code_dir,"%c",49);
+ //code_dir=ascii(49);
+ else
+ sprintf(code_dir,"%c",48);
+ //code_dir=ascii(48);
+ if(abs(u1)>255)
+ val=255;
+ else
+ val=abs(ceil(u1));
+ //printf("%d\n",val);
+ sprintf(motor,"%c",motor_no+48);
+ sprintf(v,"%c",val);
+ strcat(code_sent,motor);
+ strcat(code_sent,code_dir);
+ strcat(code_sent,v);
+ //printf("%s\n",code_sent);
+ //code_sent="M"+ascii(48+motor_no)+code_dir+ascii(val);
+ int wr=write_serial(h,code_sent,4);
+}
+
+//DC Motor release
+__declspec (dllexport) __stdcall void cmd_dcmotor_release(int h,int motor_no)
+{
+ char code_sent[6]="M";
+ char motor[2];
+ char v[2];
+ sprintf(motor,"%c",motor_no+48);
+ sprintf(v,"%c",0);
+ strcat(code_sent,motor);
+ strcat(code_sent,"1");
+ strcat(code_sent,v);
+ //code_sent="M"+ascii(48+motor_no)+"1"+ascii(0);
+ //printf("%s\n",code_sent);
+ int wr=write_serial(h,code_sent,4);
+ strcpy(code_sent,"M");
+ strcat(code_sent,motor);
+ strcat(code_sent,"r");
+ //printf("%s\n",code_sent);
+ //code_sent="M"+ascii(48+motor_no)+"r";
+ wr=write_serial(h,code_sent,3);
+}
+
+//***********************************MODBUS***********************************************************//
+
+__declspec (dllexport) __stdcall long int hex2dec(char hexadecimal[])
+{
+ long int decimalNumber=0;
+ char hexDigits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
+ '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+ int i, j, power=0;
+
+ //Converting hexadecimal number to decimal number
+ for(i=strlen(hexadecimal)-1; i >= 0; i--) {
+ // search currect character in hexDigits array
+ if(isalpha(hexadecimal[i]))
+ hexadecimal[i]=toupper(hexadecimal[i]);
+ for(j=0; j<16; j++){
+ if(hexadecimal[i] == hexDigits[j]){
+ decimalNumber += j*pow(16, power);
+ }
+ }
+ power++;
+ }
+ return decimalNumber;
+}
+
+__declspec (dllexport) __stdcall void dec2hex(long int decimalnum,char hexadecimalnum[])
+{
+ long quotient, remainder;
+ int j = 1;
+ quotient = decimalnum;
+
+ while (quotient != 0)
+ {
+ remainder = quotient % 16;
+ if (remainder < 10)
+ hexadecimalnum[j--] = 48 + remainder;
+ else
+ hexadecimalnum[j--] = 55 + remainder;
+ quotient = quotient / 16;
+ }
+ hexadecimalnum[2]='\0';
+
+}
+
+__declspec (dllexport) __stdcall double ieeesingle2num(char hexa[])
+{
+ long int x=hex2dec(hexa);
+ long int k =(long int)pow(2,31); //pow2(31);
+ int s = (x >= k);
+ if (s)
+ x = x - k;
+ //t = pow2(x,-23);
+ double t = x*pow(2,-23);
+ long int e = floor(t);
+ double f = t - e;
+ double y;
+ if (e == 255)
+ if(f == 0)
+ y = INFINITY;
+ else
+ y = NAN;
+ else if(e > 0)
+ y = (1+f)*pow(2,e-127);
+ //y = (1+f).*2.^(e-127);
+
+ else
+ y = f*pow(2,-126);
+ //y = f.*2.^-126;
+ if (s)
+ y = -y;
+ return y;
+}
+
+__declspec (dllexport) __stdcall char ascii_n(int num)
+{
+ return (char)num;
+}
+
+__declspec (dllexport) __stdcall int ascii_c(char c)
+{
+ return (uint8_t)c;
+}
+
+
+__declspec (dllexport) __stdcall void read_voltage()
+{
+ int h=open_serial(1,2,9600);
+
+ //printf("Serial port opened ...");//debug
+
+ char arr[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(86),ascii_n(00),ascii_n(2),ascii_n(39),ascii_n(15),'\0'};
+
+ //printf("%s\n",arr);//debug
+
+ int x,wr,rd;
+ char buf[12];
+ for(x=0;x<5;x++)
+ {
+ wr=write_serial(1,arr,8);
+ rd = read_serial(1,buf,11);
+ Sleep(500);
+ }
+ buf[11]='\0';
+
+ //printf("%s\n",buf );//debug
+
+ int b1=0,b2=0,b3=0,b4=0;
+ int myresult[12];
+ int i;
+ for (i = 0; i < 11; ++i)
+ {
+ myresult[i]=ascii_c(buf[i]);
+ //printf("%d",myresult[i]);//debug
+ }
+
+ //printf("%d %d %d %d\n",myresult[4],myresult[5],myresult[6],myresult[7]);//debug
+
+ int a1=myresult[4];
+ if (a1<16)
+ {
+ b1=1;
+ }
+ char v1[3];
+ dec2hex(a1,v1);
+ if (b1)
+ {
+ sprintf(v1,"0%s",v1);
+ }
+ else
+ {
+ sprintf(v1,"%s",v1);
+ }
+ int a2=myresult[5];
+ if (a2<16)
+ {
+ b2=1;
+ }
+ char v2[3];
+ dec2hex(a2,v2);
+ if (b2)
+ {
+ sprintf(v2,"0%s",v2);
+ }
+ else
+ {
+ sprintf(v2,"%s",v2);
+ }
+ int a3=myresult[6];
+ if (a3<16)
+ {
+ b3=1;
+ }
+ char v3[3];
+ dec2hex(a3,v3);
+ if (b3)
+ {
+ sprintf(v3,"0%s",v3);
+ }
+ else
+ {
+ sprintf(v3,"%s",v3);
+ }
+ int a4=myresult[7];
+ if (a4<16)
+ {
+ b4=1;
+ }
+ char v4[3];
+ dec2hex(a4,v4);
+ if (b4)
+ {
+ sprintf(v4,"0%s",v4);
+ }
+ else
+ {
+ sprintf(v4,"%s",v4);
+ }
+ char a6[20]="";
+ strcat(a6,v3);
+ strcat(a6,v4);
+ strcat(a6,v1);
+ strcat(a6,v2);
+ a6[8]='\0';
+
+ //printf("%s",a6);//debug
+
+ int cl=close_serial(1);
+ double p=ieeesingle2num(a6);
+ printf("Voltage(in V)=%f\n",p);
+}
+
+
+__declspec (dllexport) __stdcall void read_current()
+{
+ int h=open_serial(1,2,9600);
+ char arr[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(88),ascii_n(00),ascii_n(2),ascii_n(70),ascii_n(204),'\0'};
+
+ //printf("%s\n",arr);//debug
+
+ int x,wr,rd;
+ char buf[12];
+ for(x=0;x<5;x++)
+ {
+ wr=write_serial(1,arr,8);
+ rd = read_serial(1,buf,11);
+ Sleep(500);
+ }
+ buf[11]='\0';
+
+ //printf("%s\n",buf );//debug
+
+ int b1=0,b2=0,b3=0,b4=0;
+ int myresult[12];
+ int i;
+ for (i = 0; i < 11; ++i)
+ {
+ myresult[i]=ascii_c(buf[i]);
+ //printf("%d",myresult[i]);//debug
+ }
+
+ //printf("%d %d %d %d\n",myresult[4],myresult[5],myresult[6],myresult[7]);//debug
+
+ int a1=myresult[4];
+ if (a1<16)
+ {
+ b1=1;
+ }
+ char v1[3];
+ dec2hex(a1,v1);
+ if (b1)
+ {
+ sprintf(v1,"0%s",v1);
+ }
+ else
+ {
+ sprintf(v1,"%s",v1);
+ }
+ int a2=myresult[5];
+ if (a2<16)
+ {
+ b2=1;
+ }
+ char v2[3];
+ dec2hex(a2,v2);
+ if (b2)
+ {
+ sprintf(v2,"0%s",v2);
+ }
+ else
+ {
+ sprintf(v2,"%s",v2);
+ }
+ int a3=myresult[6];
+ if (a3<16)
+ {
+ b3=1;
+ }
+ char v3[3];
+ dec2hex(a3,v3);
+ if (b3)
+ {
+ sprintf(v3,"0%s",v3);
+ }
+ else
+ {
+ sprintf(v3,"%s",v3);
+ }
+ int a4=myresult[7];
+ if (a4<16)
+ {
+ b4=1;
+ }
+ char v4[3];
+ dec2hex(a4,v4);
+ if (b4)
+ {
+ sprintf(v4,"0%s",v4);
+ }
+ else
+ {
+ sprintf(v4,"%s",v4);
+ }
+ char a6[20]="";
+ strcat(a6,v3);
+ strcat(a6,v4);
+ strcat(a6,v1);
+ strcat(a6,v2);
+ a6[8]='\0';
+
+ //printf("%s",a6);//debug
+
+ int cl=close_serial(1);
+ double p=ieeesingle2num(a6);
+ printf("Current(in A)=%f\n",p);
+}
+
+__declspec (dllexport) __stdcall void read_active_power()
+{
+ int h=open_serial(1,2,9600);
+ char arr[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(78),ascii_n(00),ascii_n(2),ascii_n(167),ascii_n(8),'\0'};
+
+ //printf("%s\n",arr);//debug
+
+ int x,wr,rd;
+ char buf[12];
+ for(x=0;x<5;x++)
+ {
+ wr=write_serial(1,arr,8);
+ rd = read_serial(1,buf,11);
+ Sleep(500);
+ }
+ buf[11]='\0';
+
+ //printf("%s\n",buf );//debug
+
+ int b1=0,b2=0,b3=0,b4=0;
+ int myresult[12];
+ int i;
+ for (i = 0; i < 11; ++i)
+ {
+ myresult[i]=ascii_c(buf[i]);
+ //printf("%d",myresult[i]);//debug
+ }
+
+ //printf("%d %d %d %d\n",myresult[4],myresult[5],myresult[6],myresult[7]);//debug
+
+ int a1=myresult[4];
+ if (a1<16)
+ {
+ b1=1;
+ }
+ char v1[3];
+ dec2hex(a1,v1);
+ if (b1)
+ {
+ sprintf(v1,"0%s",v1);
+ }
+ else
+ {
+ sprintf(v1,"%s",v1);
+ }
+ int a2=myresult[5];
+ if (a2<16)
+ {
+ b2=1;
+ }
+ char v2[3];
+ dec2hex(a2,v2);
+ if (b2)
+ {
+ sprintf(v2,"0%s",v2);
+ }
+ else
+ {
+ sprintf(v2,"%s",v2);
+ }
+ int a3=myresult[6];
+ if (a3<16)
+ {
+ b3=1;
+ }
+ char v3[3];
+ dec2hex(a3,v3);
+ if (b3)
+ {
+ sprintf(v3,"0%s",v3);
+ }
+ else
+ {
+ sprintf(v3,"%s",v3);
+ }
+ int a4=myresult[7];
+ if (a4<16)
+ {
+ b4=1;
+ }
+ char v4[3];
+ dec2hex(a4,v4);
+ if (b4)
+ {
+ sprintf(v4,"0%s",v4);
+ }
+ else
+ {
+ sprintf(v4,"%s",v4);
+ }
+ char a6[20]="";
+ strcat(a6,v3);
+ strcat(a6,v4);
+ strcat(a6,v1);
+ strcat(a6,v2);
+ a6[8]='\0';
+
+ //printf("%s",a6);//debug
+
+ int cl=close_serial(1);
+ double p=ieeesingle2num(a6);
+ printf("Active Power(in W)=%f\n",p);
+}
+
+__declspec (dllexport) __stdcall double read_val(int addr_byte)
+{
+ int h=open_serial(1,2,9600);
+ char* arr;
+ if(addr_byte==86)
+ {
+ char code[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(86),ascii_n(00),ascii_n(2),ascii_n(39),ascii_n(15),'\0'};
+ arr = code;
+ printf("Voltage(in V)=");
+ }
+ else if(addr_byte==88)
+ {
+ char code[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(88),ascii_n(00),ascii_n(2),ascii_n(70),ascii_n(204),'\0'};
+ arr =code;
+ printf("Current(in A)=");
+ }
+ else if(addr_byte==78)
+ {
+ char code[9]={ascii_n(1),ascii_n(3),ascii_n(15),ascii_n(78),ascii_n(00),ascii_n(2),ascii_n(167),ascii_n(8),'\0'};
+ arr = code;
+ printf("Active Power(in W)=");
+ }
+
+ int x,wr,rd;
+ char buf[12];
+ for(x=0;x<5;x++)
+ {
+ wr=write_serial(1,arr,8);
+ rd = read_serial(1,buf,11);
+ Sleep(500);
+ }
+ buf[11]='\0';
+
+ //printf("%s\n",buf );//debug
+
+ int b1=0,b2=0,b3=0,b4=0;
+ int myresult[12];
+ int i;
+ for (i = 0; i < 11; ++i)
+ {
+ myresult[i]=ascii_c(buf[i]);
+ //printf("%d",myresult[i]);//debug
+ }
+
+ //printf("%d %d %d %d\n",myresult[4],myresult[5],myresult[6],myresult[7]);//debug
+
+ int a1=myresult[4];
+ if (a1<16)
+ {
+ b1=1;
+ }
+ char v1[3];
+ dec2hex(a1,v1);
+ if (b1)
+ {
+ sprintf(v1,"0%s",v1);
+ }
+ else
+ {
+ sprintf(v1,"%s",v1);
+ }
+ int a2=myresult[5];
+ if (a2<16)
+ {
+ b2=1;
+ }
+ char v2[3];
+ dec2hex(a2,v2);
+ if (b2)
+ {
+ sprintf(v2,"0%s",v2);
+ }
+ else
+ {
+ sprintf(v2,"%s",v2);
+ }
+ int a3=myresult[6];
+ if (a3<16)
+ {
+ b3=1;
+ }
+ char v3[3];
+ dec2hex(a3,v3);
+ if (b3)
+ {
+ sprintf(v3,"0%s",v3);
+ }
+ else
+ {
+ sprintf(v3,"%s",v3);
+ }
+ int a4=myresult[7];
+ if (a4<16)
+ {
+ b4=1;
+ }
+ char v4[3];
+ dec2hex(a4,v4);
+ if (b4)
+ {
+ sprintf(v4,"0%s",v4);
+ }
+ else
+ {
+ sprintf(v4,"%s",v4);
+ }
+ char a6[20]="";
+ strcat(a6,v3);
+ strcat(a6,v4);
+ strcat(a6,v1);
+ strcat(a6,v2);
+ a6[8]='\0';
+
+ //printf("%s",a6);//debug
+
+ int cl=close_serial(1);
+ double p=ieeesingle2num(a6);
+ printf("%f\n",p);
+ return p;
+}
+
+//Analog reading in volts
+__declspec (dllexport) __stdcall uint16_t cmd_analog_in_volt(int h,int pin_no)
+{
+ char pin[5],v1[2];
+ int stat;
+ int read[3];
+ sprintf(v1,"%c",pin_no+48);
+ strcpy(pin,"A");
+ strcat(pin,v1);
+ int wr=write_serial(h,pin,2);
+ stat=status_serial(h,read);
+ //printf("Read:%d\n",read[0] );
+ while (read[0] < 2)
+ stat=status_serial(h,read);
+ char values[5];
+ int a_rd=read_serial(h,values,2);
+ values[2]='\0';
+ //printf("%s\n",values);
+ int l=strlen(values);
+ //printf("%d\n",l );
+ uint8_t temp[l+1];
+ int i;
+ for (i = 0; i < l; ++i)
+ {
+ temp[i]=(uint8_t)(values[i]);
+ }
+ //printf("%u %u\n",temp[0],temp[1]);
+ uint16_t result=(uint16_t)(256*temp[1]+temp[0]);
+ result/=1023;
+ //printf("%u\n",result);
+ return result;
+}
+
+__declspec (dllexport) __stdcall int cmd_analog_out_volt(int h,int pin_no,double val)
+{
+ char v1[2],v2[2];
+ if(val > 5)
+ val = 5;
+ else if(val < 0)
+ val = 0;
+ val=val*255/5;
+ //printf("%f\n",val);
+ char code_sent[10];
+ strcpy(code_sent,"W");
+ sprintf(v1,"%c",pin_no+48);
+ sprintf(v2,"%c",abs(ceil(val)));
+ strcat(code_sent,v1);
+ strcat(code_sent,v2);
+ //printf("%s\n",code_sent);
+ return write_serial(h,code_sent,3);
+
+}
diff --git a/OpenModelica-Arduino-MDD-Windows/SerialComm.dll b/OpenModelica-Arduino-MDD-Windows/SerialComm.dll
new file mode 100644
index 0000000..37b83b8
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/SerialComm.dll
Binary files differ
diff --git a/OpenModelica-Arduino-MDD-Windows/testfirmware.mo b/OpenModelica-Arduino-MDD-Windows/testfirmware.mo
new file mode 100644
index 0000000..d34c111
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/testfirmware.mo
@@ -0,0 +1,12 @@
+model testfirmware "test serial communication with Arduino"
+import sComm=Arduino.SerialCommunication.Functions;
+Integer h(fixed=false);
+Integer w(fixed=false);
+Integer r(fixed=false);
+Integer c(fixed=false);
+algorithm
+ h := sComm.open_serial(1,2,9600);
+ w := sComm.write_serial(1, "v", 1);
+ r := sComm.read_serial(1,2);
+ c := sComm.close_serial(1);
+end testfirmware;
diff --git a/OpenModelica-Arduino-MDD-Windows/tools/arduino-firmware/arduino-firmware.ino b/OpenModelica-Arduino-MDD-Windows/tools/arduino-firmware/arduino-firmware.ino
new file mode 100644
index 0000000..8d10650
--- /dev/null
+++ b/OpenModelica-Arduino-MDD-Windows/tools/arduino-firmware/arduino-firmware.ino
@@ -0,0 +1,795 @@
+
+ /* This file is meant to be used with the SCILAB arduino
+ toolbox, however, it can be used from the IDE environment
+ (or any other serial terminal) by typing commands like:
+
+ Conversion ascii -> number
+ 48->'0' ... 57->'9' 58->':' 59->';' 60->'<' 61->'=' 62->'>' 63->'?' 64->'@'
+ 65->'A' ... 90->'Z' 91->'[' 92->'\' 93->']' 94->'^' 95->'_' 96->'`'
+ 97->'a' ... 122->'z'
+
+ Dan0 or Dan1 : attach digital pin n (ascii from 2 to b) to input (0) or output (1)
+ Drn : read digital value (0 or 1) on pin n (ascii from 2 to b)
+ Dwn0 or Dwn1 : write 1 or 0 on pin n
+ An : reads analog pin n (ascii from 0 to 19)
+ Wnm : write analog value m (ascii from 0 to 255) on pin n (ascii from 0 to 19)
+ Sa1 or Sa2 : Attach servo 1 (digital pin 9) or 2 (digital pin 10)
+ Sw1n or Sw2n : moves servo 1 or servo 2 to position n (from ascii(0) to ascii(180))
+ Sd1 or Sd2 : Detach servo 1 or 2
+
+ Generic DC_Motor
+ Cijkl : setup for generic DCmotor number i (1 to 4), PW1 on pin number j, PWM2 or direction on pin number k, mode=l
+ l=0 for L293 (2 PWM) and l=1 for L298 (1PWM + 1 bit for direction)
+ Mijk : sets speed for generic DCmotor number i, j=0/1 for direction, k=ascii(0) .. ascii(255)
+ Mir : releases motor i (r=release)
+
+ Generic Interrupt counter
+ Iai : activate counter on INT number i (i=ascii(2 or 3 or 18 or 19 or 20 or 21)
+ Iri : release counter on INT number i
+ Ipi : read counter on INT number i
+ Izi : reset counter on INT number i
+
+ Generic Encoder
+ Eajkl: activate encoder on channelA on INT number j (j=ascii(2 or 3 or 18 or 19 or 20 or 21) et channelB on pin k or INT number k (k=ascii(0)..ascii(53))
+ and l=1 or 2 or 4 for 1x mode (count every rising of chA) or 2x mode (count every change statement of chA)
+ or 4x mode (every change statement of chA et chB)
+ Eri : release encoder on INTi
+ Epi : read position of encoder on INTi
+ Ezi : reset value of encoder on INTi position
+
+ R0 : sets analog reference to DEFAULT
+ R1 : sets analog reference to INTERNAL
+ R2 : sets analog reference to EXTERNAL
+
+ */
+
+#include <Servo.h>
+
+/* define internal for the MEGA as 1.1V (as as for the 328) */
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
+#define INTERNAL INTERNAL1V1
+#endif
+
+/* create and initialize servos */
+Servo servo1;
+Servo servo2;
+
+/* Generic motors */
+int dcm1_pin1,dcm1_pin2,dcm1_mode;
+int dcm2_pin1,dcm2_pin2,dcm2_mode;
+int dcm3_pin1,dcm3_pin2,dcm3_mode;
+int dcm4_pin1,dcm4_pin2,dcm4_mode;
+
+// Generic encoder
+/* Encoders initialisation */
+// volatile declare as those variables will change in interrupts
+volatile long int encoder_0_position = 0,encoder_1_position = 0, encoder_2_position = 0, encoder_3_position = 0, encoder_4_position = 0, encoder_5_position = 0;
+int encoder_0_int2 ; // Pin used for encoder0 chanel B : define from scilab
+int encoder_1_int2 ; // Pin used for encoder1 chanel B : define from scilab
+int encoder_2_int2 ; // Pin used for encoder2 chanel B : define from scilab
+int encoder_3_int2 ; // Pin used for encoder3 chanel B : define from scilab
+int encoder_4_int2 ; // Pin used for encoder4 chanel B : define from scilab
+int encoder_5_int2 ; // Pin used for encoder5 chanel B : define from scilab
+int encoder_num, encoder_int2;
+int corresp[6]={2,3,21,20,19,18}; //Correspondance beetween interrupt number and pin number
+
+//Generic counter
+volatile long int counter_0=0,counter_1=0,counter_2=0,counter_3=0,counter_4=0,counter_5=0;
+
+int initiat=1;
+
+void setup() {
+ /* initialize serial */
+ Serial.begin(115200);
+
+}
+void loop() {
+
+
+
+ /* variables declaration and initialization */
+
+ static int s = -1; /* state */
+ static int pin = 13; /* generic pin number */
+ static int dcm = 4; /* generic dc motor number */
+
+ int val = 0; /* generic value read from serial */
+ int agv = 0; /* generic analog value */
+ int dgv = 0; /* generic digital value */
+ static int enc = 1; /* encoder number 1 (or 2 for Arduino mega) */
+
+ while (Serial.available()==0) {}; // Waiting char
+ val = Serial.read();
+
+ //Checking for availability of firmware
+ if(val==118)
+ {
+ delay(10);
+ Serial.write("ok");
+ }
+
+// if (val==0){// version
+// Serial.print('v3');
+// val=-1;
+// }
+ //case A -> Analog
+ else if (val==65){//A -> Analog read
+ while (Serial.available()==0) {}; // Waiting char
+// val=Serial.read();
+// if (val==114){ //'r'-> read pin
+// while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val>47 && val<67) { //from pin 0, to pin 19
+ pin=val-48; //number of the pin
+ agv=analogRead(pin);
+ //Serial.println(agv);
+ Serial.write((uint8_t*)&agv,2); /* send binary value via serial */
+ }
+ val=-1;
+ }
+ else if (val==87){//W -> Analog write
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val>47 && val<67) { //from pin 0 to pin 19
+ pin=val-48; //number of the pin
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ analogWrite(pin,val);
+ }
+ val=-1;
+ }
+ //}
+
+ //case D -> Digital
+ else if (val==68){//D -> Digital pins
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val==97){ //'a'-> declare pin
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val>49 && val<102) {
+ pin=val-48;
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val==48 || val==49) {
+ if (val==48){//'0' -> input
+ pinMode(pin,INPUT);
+ }
+ else if (val==49){//'1' -> output
+ pinMode(pin,OUTPUT);
+ }
+ }
+ }
+ }
+ if (val==114){ //'r'-> read pin
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val>49 && val<102) {
+ pin=val-48; //number of the digital pin
+ dgv=digitalRead(pin);
+// Serial.println(dgv);
+ Serial.print(dgv);
+ }
+ }
+ if (val==119){ //'w'-> write pin
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val>49 && val<102) {
+ pin=val-48; //number of the digital pin
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val==48 || val==49) { // 0 or 1
+ dgv=val-48;
+ digitalWrite(pin,dgv);
+// Serial.println(dgv);
+ }
+ }
+ }
+ val=-1;
+
+ }
+ //case S -> servomotor
+ else if (val==83){
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val==97){ //'a'-> declare servo
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val==49 || val==50) { //servo 1 or 2
+ pin=val-48; //number of the servo
+ if (pin==1) {
+ servo1.attach(9);
+ servo1.write(0);
+// agv=servo1.read();
+// Serial.println(agv);
+ }
+ if (pin==2) {
+ servo2.attach(10);
+ servo2.write(0);
+// agv=servo2.read();
+// Serial.println(agv);
+ }
+
+ }
+ }
+ if (val==100){ //'d'-> detach servo
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val==49 || val==50) { //servo 1 or 2
+ pin=val-48; //number of the servo
+ if (pin==1) {servo1.detach(); }
+ if (pin==2) {servo2.detach(); }
+ }
+ }
+ if (val==119){ //'w'-> write pin
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val==49 || val==50) { //servo 1 or 2
+ pin=val-48; //number of the servo
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val>=0 && val<=180){
+ if (pin==1) {
+ servo1.write(val);
+// agv=servo1.read();
+// Serial.println(agv);
+ }
+ if (pin==2) {
+ servo2.write(val);
+// agv=servo2.read();
+// Serial.println(agv);
+ }
+ }
+ }
+ }
+ val=-1;
+
+ }
+
+ //case I -> Interrupt
+ else if (val==73){
+ /* ASKING ACTIVATION OF AN COUNTER */
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read();
+ if (val==97) { //a = activation
+ while (Serial.available()==0) {}; // Waiting char
+ val=Serial.read(); // Read int_number (must be 0 or 1 on UNO / 1 to 5 on MEGA) : int_number set to encoder number
+ pinMode(corresp[val],INPUT); // set interrupt pin as input
+ if (val == 0) {attachInterrupt(val, counter_0_change, RISING);counter_0=0;} //counter INT0
+ else if (val == 1) {attachInterrupt(val, counter_1_change, RISING);counter_1=0;} //counter INT1
+ else if (val == 2) {attachInterrupt(val, counter_2_change, RISING);counter_2=0;} //counter INT2
+ else if (val == 3) {attachInterrupt(val, counter_3_change, RISING);counter_3=0;} //counter INT3
+ else if (val == 4) {attachInterrupt(val, counter_4_change, RISING);counter_4=0;} //counter INT4
+ else if (val == 5) {attachInterrupt(val, counter_5_change, RISING);counter_5=0;} //counter INT5
+ }
+ /* ASKING POSITION OF A COUNTER */
+ if (val==112) { //p = sending counting value
+ while (Serial.available()==0) {}; // Waiting char
+ val = Serial.read() ; //reading next value = counter number
+ if (val==0){ Serial.write((uint8_t*)&counter_0,4); }// asking counter 0
+ else if (val==1){ Serial.write((uint8_t*)&counter_1,4); }// asking counter 1
+ else if (val==2){ Serial.write((uint8_t*)&counter_2,4); }// asking counter 2
+ else if (val==3){ Serial.write((uint8_t*)&counter_3,4); }// asking counter 3
+ else if (val==4){ Serial.write((uint8_t*)&counter_4,4); }// asking counter 4
+ else if (val==5){ Serial.write((uint8_t*)&counter_5,4); }// asking counter 5
+ }
+ /* ASKING RELEASE OF AN INTERRUPT */
+ if (val==114) { //r = release counter
+ while (Serial.available()==0) {}; // Waiting char
+ val = Serial.read(); //reading next value = counter number
+ detachInterrupt(val); // Detach interrupt on chanel A of counter num=val
+ if (val==0) { counter_0=0;} // Reset counter
+ else if (val==1) { counter_1=0;} // Reset counter
+ else if (val==2) { counter_2=0;} // Reset counter
+ else if (val==3) { counter_3=0;} // Reset counter
+ else if (val==4) { counter_4=0;} // Reset counter
+ else if (val==5) { counter_5=0;} // Reset counter
+ }
+ /* ASKING RESET VALUE OF AN COUNTER */
+ if (val==122) { //z set to zero
+ while (Serial.available()==0) {}; // Waiting char
+ val = Serial.read(); //reading next value = counter number
+ if (val==0) { counter_0=0;} // Reset counter
+ else if (val==1) { counter_1=0;} // Reset counter
+ else if (val==2) { counter_2=0;} // Reset counter
+ else if (val==3) { counter_3=0;} // Reset counter
+ else if (val==4) { counter_4=0;} // Reset counter
+ else if (val==5) { counter_5=0;} // Reset counter
+ }
+ val=-1;
+
+ }
+
+ //case E -> Encoder
+ else if (val==69){
+ /*Generic encoder functions */
+ while (Serial.available()==0) {};
+ val=Serial.read();
+ /* ASKING ACTIVATION OF AN ENCODER */
+ if (val==97) { //activation
+ while (Serial.available()==0) {}; // Waiting char
+ encoder_num=Serial.read(); // Read int_number (must be 0 or 1 on UNO / 1 to 5 on MEGA) : int_number set to encoer number
+ pinMode(corresp[encoder_num],INPUT); // set interrupt pin as input
+ while (Serial.available()==0) {}; // Waiting char
+ encoder_int2=Serial.read(); // Read int2 (must be a digital PIN with interrupt or not : depends on mode)
+ // no declaration for the moment : wait for encoder mode
+ while (Serial.available()==0) {}; // Waiting char
+ int mode = Serial.read()-48; // Read mode 1 ou 2 (1 counting only rising of chA, 2 counting rising and falling)
+ if (mode == 4) { // mode 4x : 2 cases : chA=pin2 / chB=pin3 or chA=pin3/chB=pin2 [Uno retriction]
+ pinMode(corresp[encoder_int2],INPUT); // set interrupt number as input
+ } else {
+ pinMode(encoder_int2,INPUT); // set pin as input
+ }
+
+ if (encoder_num == 0) { //encoder INT0
+ encoder_0_position=0; // Reset position
+ if (mode==4) {
+ encoder_0_int2=corresp[encoder_int2]; // Save pin of second interruption
+ attachInterrupt(encoder_num , encoder_change_m4_A0, CHANGE); // Attach interrupt on chanel A change
+ attachInterrupt(encoder_int2, encoder_change_m4_B0, CHANGE); // Attach interrupt on chanel B change
+ } else if (mode==2) {
+ encoder_0_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_0_change_m2, CHANGE); // Attach interrupt on chanel A change
+ } else if (mode==1) {
+ encoder_0_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_0_change_m1, RISING); // Attach interrupt on chanel A rising
+ }
+ } else if (encoder_num == 1) { //encoder INT1
+ encoder_1_position=0; // Reset position
+ if (mode==4) {
+ encoder_1_int2=corresp[encoder_int2]; // Save pin of second interruption
+ attachInterrupt(encoder_num , encoder_change_m4_A1, CHANGE); // Attach interrupt on chanel A change
+ attachInterrupt(encoder_int2, encoder_change_m4_B1, CHANGE); // Attach interrupt on chanel B change
+ } else if (mode==2) {
+ encoder_1_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_1_change_m2, CHANGE); // Attach interrupt on chanel A change
+ } else if (mode==1) {
+ encoder_1_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_1_change_m1, RISING); // Attach interrupt on chanel A rising
+ }
+ } else if (encoder_num == 2) { //encoder INT2
+ encoder_2_position=0; // Reset position
+ if (mode==4) {
+ encoder_2_int2=corresp[encoder_int2]; // Save pin of second interruption
+ attachInterrupt(encoder_num , encoder_change_m4_A2, CHANGE); // Attach interrupt on chanel A change
+ attachInterrupt(encoder_int2, encoder_change_m4_B2, CHANGE); // Attach interrupt on chanel B change
+ } else if (mode==2) {
+ encoder_2_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_2_change_m2, CHANGE); // Attach interrupt on chanel A change
+ } else if (mode==1) {
+ encoder_2_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_2_change_m1, RISING); // Attach interrupt on chanel A rising
+ }
+ } else if (encoder_num == 3) { //encoder INT3
+ encoder_3_position=0; // Reset position
+ if (mode==4) {
+ encoder_3_int2=corresp[encoder_int2]; // Save pin of second interruption
+ attachInterrupt(encoder_num , encoder_change_m4_A3, CHANGE); // Attach interrupt on chanel A change
+ attachInterrupt(encoder_int2, encoder_change_m4_B3, CHANGE); // Attach interrupt on chanel B change
+ } else if (mode==2) {
+ encoder_3_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_3_change_m2, CHANGE); // Attach interrupt on chanel A change
+ } else if (mode==1) {
+ encoder_3_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_3_change_m1, RISING); // Attach interrupt on chanel A rising
+ }
+ } else if (encoder_num == 4) { //encoder INT4
+ encoder_4_position=0; // Reset position
+ if (mode==4) {
+ encoder_4_int2=corresp[encoder_int2]; // Save pin of second interruption
+ attachInterrupt(encoder_num , encoder_change_m4_A4, CHANGE); // Attach interrupt on chanel A change
+ attachInterrupt(encoder_int2, encoder_change_m4_B4, CHANGE); // Attach interrupt on chanel B change
+ } else if (mode==2) {
+ encoder_4_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_4_change_m2, CHANGE); // Attach interrupt on chanel A change
+ } else if (mode==1) {
+ encoder_4_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_4_change_m1, RISING); // Attach interrupt on chanel A rising
+ }
+ } else if (encoder_num == 5) { //encoder INT5
+ encoder_5_position=0; // Reset position
+ if (mode==4) {
+ encoder_5_int2=corresp[encoder_int2]; // Save pin of second interruption
+ attachInterrupt(encoder_num , encoder_change_m4_A5, CHANGE); // Attach interrupt on chanel A change
+ attachInterrupt(encoder_int2, encoder_change_m4_B5, CHANGE); // Attach interrupt on chanel B change
+ } else if (mode==2) {
+ encoder_5_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_5_change_m2, CHANGE); // Attach interrupt on chanel A change
+ } else if (mode==1) {
+ encoder_5_int2=encoder_int2;
+ attachInterrupt(encoder_num, encoder_5_change_m1, RISING); // Attach interrupt on chanel A rising
+ }
+ }
+ }
+ /* ASKING POSITION OF AN ENCODER */
+ if (val==112) { //p = sending encoder position
+ while (Serial.available()==0) {}; // Waiting char
+ val = Serial.read() ; //reading next value = encoder number
+ if (val==0){ Serial.write((uint8_t*)&encoder_0_position,4); }// asking encoder 0 position
+ else if (val==1){ Serial.write((uint8_t*)&encoder_1_position,4); }// asking encoder 1 position
+ else if (val==2){ Serial.write((uint8_t*)&encoder_2_position,4); }// asking encoder 2 position
+ else if (val==3){ Serial.write((uint8_t*)&encoder_3_position,4); }// asking encoder 3 position
+ else if (val==4){ Serial.write((uint8_t*)&encoder_4_position,4); }// asking encoder 4 position
+ else if (val==5){ Serial.write((uint8_t*)&encoder_5_position,4); }// asking encoder 5 position
+ }
+ /* ASKING RELEASE OF AN ENCODER */
+ if (val==114) { //r = release encoder
+ while (Serial.available()==0) {}; // Waiting char
+ val = Serial.read(); //reading next value = encoder number
+ detachInterrupt(val); // Detach interrupt on chanel A of encoder num=val
+ if (val==0) { encoder_0_position=0;encoder_0_int2=-1;} // Reset position
+ else if (val==1) { encoder_1_position=0;encoder_1_int2=-1;} // Reset position
+ else if (val==2) { encoder_2_position=0;encoder_2_int2=-1;} // Reset position
+ else if (val==3) { encoder_3_position=0;encoder_3_int2=-1;} // Reset position
+ else if (val==4) { encoder_4_position=0;encoder_4_int2=-1;} // Reset position
+ else if (val==5) { encoder_5_position=0;encoder_5_int2=-1;} // Reset position
+ while (Serial.available()==0) {}; // Waiting char
+ val = Serial.read(); // reading next value = encoder number
+ detachInterrupt(val); // Detach interrupt on chanel B of encoder num=val (may be the same if mode=1 or 2)
+ }
+ /* ASKING RESET POSITION OF AN ENCODER */
+ if (val==122) { // z = encoder position to zero
+ while (Serial.available()==0) {}; // Waiting char
+ val = Serial.read(); //reading next value = encoder number
+ if (val==0) { encoder_0_position=0;} // Reset position
+ else if (val==1) { encoder_1_position=0;} // Reset position
+ else if (val==2) { encoder_2_position=0;} // Reset position
+ else if (val==3) { encoder_3_position=0;} // Reset position
+ else if (val==4) { encoder_4_position=0;} // Reset position
+ else if (val==5) { encoder_5_position=0;} // Reset position
+ }
+ val=-1;
+
+ }
+
+ //case C -> DCmotor init
+ else if(val==67){
+ while (Serial.available()==0) {};
+ val = Serial.read();
+ /* 2nd char = motor number */
+ if (val>48 && val<53) {
+ dcm=val-48;
+ while (Serial.available()==0) {};
+ val = Serial.read();
+ /* the third received value indicates the pin1 number from ascii(2)=50 to ascii(e)=101 */
+ if (val>49 && val<102) {
+ if (dcm==1) dcm1_pin1=val-48;/* calculate motor pin1 */
+ if (dcm==2) dcm2_pin1=val-48;/* calculate motor pin1 */
+ if (dcm==3) dcm3_pin1=val-48;/* calculate motor pin1 */
+ if (dcm==4) dcm4_pin1=val-48;/* calculate motor pin1 */
+ pinMode(val-48, OUTPUT); //set pin as output
+ analogWrite(val-48,0); /* DUTY CYCLE */
+ while (Serial.available()==0) {};
+ val = Serial.read();
+ /* the fourth received value indicates the pin2 number from ascii(2)=50 to ascii(e)=101 */
+ if (val>49 && val<102) {
+ if (dcm==1) dcm1_pin2=val-48;/* calculate motor pin2 */
+ if (dcm==2) dcm2_pin2=val-48;/* calculate motor pin2 */
+ if (dcm==3) dcm3_pin2=val-48;/* calculate motor pin2 */
+ if (dcm==4) dcm4_pin2=val-48;/* calculate motor pin2 */
+ pinMode(val-48, OUTPUT); //set pin as output
+ while (Serial.available()==0) {};
+ val = Serial.read();
+ /* the fifth received value indicates the pin2 number from ascii(2)=50 to ascii(e)=101 */
+ if (val>47 && val<50) {
+ int mode = val-48;
+ if (dcm==1) dcm1_mode=mode;/* calculate motor mode */
+ if (dcm==2) dcm2_mode=mode;/* calculate motor mode */
+ if (dcm==3) dcm3_mode=mode;/* calculate motor mode */
+ if (dcm==4) dcm4_mode=mode;/* calculate motor mode */
+ //initialization of port
+ if(mode==0){//L293
+ if (dcm==1) analogWrite(dcm1_pin2,0); /* DUTY CYCLE */
+ if (dcm==2) analogWrite(dcm2_pin2,0); /* DUTY CYCLE */
+ if (dcm==3) analogWrite(dcm3_pin2,0); /* DUTY CYCLE */
+ if (dcm==4) analogWrite(dcm4_pin2,0); /* DUTY CYCLE */
+ } else if (mode==1) {//L297
+ if (dcm==1) digitalWrite(dcm1_pin2, LOW); /* DIRECTION */
+ if (dcm==2) digitalWrite(dcm2_pin2, LOW); /* DIRECTION */
+ if (dcm==3) digitalWrite(dcm3_pin2, LOW); /* DIRECTION */
+ if (dcm==4) digitalWrite(dcm4_pin2, LOW); /* DIRECTION */
+ }
+ Serial.print("OK"); // tell Scilab that motor s initialization finished
+ // Cette commande sert à rien dans la toolbox de base,
+ // sauf si on prévoit d'ajouter des actions à l'init des moteurs
+ // par exemple chercher la position d'origine !
+ }
+ }
+ }
+ }
+ val=-1;
+
+ }
+
+ //case M -> DC motor
+ else if(val==77){
+ while (Serial.available()==0) {};
+ val = Serial.read();
+ /* the second received value indicates the motor number
+ from abs('1')=49, motor1, to abs('4')=52, motor4 */
+ if (val>48 && val<53) {
+ dcm=val-48; /* calculate motor number */
+ while (Serial.available()==0) {}; // Waiting char
+ val = Serial.read();
+ /* the third received value indicates the sens direction or release*/
+ if (val==48 || val ==49){
+ int direction=val-48;
+ while (Serial.available()==0) {}; // Waiting char
+ val = Serial.read(); //reading next value = 0..255
+ if (dcm==1){
+ if(dcm1_mode==0){//L293
+ if(direction==1){
+ analogWrite(dcm1_pin1,val);
+ analogWrite(dcm1_pin2,0);
+ } else {
+ analogWrite(dcm1_pin2,val);
+ analogWrite(dcm1_pin1,0);
+ }
+ } else {//L298
+ if (direction==0) digitalWrite(dcm1_pin2,LOW);
+ if (direction==1) digitalWrite(dcm1_pin2,HIGH);
+ analogWrite(dcm1_pin1,val);
+ }
+ }
+ if (dcm==2){
+ if(dcm2_mode==0){//L293
+ if(direction==1){
+ analogWrite(dcm2_pin1,val);
+ analogWrite(dcm2_pin2,0);
+ } else {
+ analogWrite(dcm2_pin2,val);
+ analogWrite(dcm2_pin1,0);
+ }
+ } else {//L298
+ if (direction==0) digitalWrite(dcm2_pin2,LOW);
+ if (direction==1) digitalWrite(dcm2_pin2,HIGH);
+ analogWrite(dcm2_pin1,val);
+ }
+ }
+ if (dcm==3){
+ if(dcm3_mode==0){//L293
+ if(direction==1){
+ analogWrite(dcm3_pin1,val);
+ analogWrite(dcm3_pin2,0);
+ } else {
+ analogWrite(dcm3_pin2,val);
+ analogWrite(dcm3_pin1,0);
+ }
+ } else {//L298
+ if (direction==0) digitalWrite(dcm3_pin2,LOW);
+ if (direction==1) digitalWrite(dcm3_pin2,HIGH);
+ analogWrite(dcm3_pin1,val);
+ }
+ }
+ if (dcm==4){
+ if(dcm4_mode==0){//L293
+ if(direction==1){
+ analogWrite(dcm4_pin1,val);
+ analogWrite(dcm4_pin2,0);
+ } else {
+ analogWrite(dcm4_pin2,val);
+ analogWrite(dcm4_pin1,0);
+ }
+ } else {//L298
+ if (direction==0) digitalWrite(dcm4_pin2,LOW);
+ if (direction==1) digitalWrite(dcm4_pin2,HIGH);
+ analogWrite(dcm4_pin1,val);
+ }
+ }
+ }
+ if (val==114){//release motor
+ if(dcm==1) {
+ analogWrite(dcm1_pin1,0);
+ if(dcm1_mode==0) analogWrite(dcm1_pin2,0);
+ }
+ if(dcm==2) {
+ analogWrite(dcm2_pin1,0);
+ if(dcm2_mode==0) analogWrite(dcm2_pin2,0);
+ }
+ if(dcm==3) {
+ analogWrite(dcm3_pin1,0);
+ if(dcm3_mode==0) analogWrite(dcm3_pin2,0);
+ }
+ if(dcm==4) {
+ analogWrite(dcm4_pin1,0);
+ if(dcm4_mode==0) analogWrite(dcm4_pin2,0);
+ }
+ }
+
+ }
+ val=-1;
+
+ }
+
+
+ //case R -> Analog reference
+ if(val==82){
+ while (Serial.available()==0) {};
+ val = Serial.read();
+ if (val==48) analogReference(DEFAULT);
+ if (val==49) analogReference(INTERNAL);
+ if (val==50) analogReference(EXTERNAL);
+ if (val==51) Serial.print("v3");
+ val=-1;
+ }
+
+} /* end loop statement */
+
+
+/**************************************/
+// Generic interrupt encoder functions//
+/**************************************/
+//Encoder on INT0
+void encoder_0_change_m1() { //encoder0 mode 1x
+ int chB=digitalRead(encoder_0_int2);
+ if (!chB) { encoder_0_position++;}
+ else { encoder_0_position--; }
+}
+void encoder_0_change_m2() { //encoder0 mode 2x
+ int chB=digitalRead(encoder_0_int2);
+ int chA=digitalRead(corresp[0]);
+ if ((chA & !chB)|(!chA & chB)) { encoder_0_position++; }
+ else { encoder_0_position--; }
+}
+void encoder_change_m4_A0(){//encoder0 mode 4x chA
+ int chA=digitalRead(corresp[0]);
+ int chB=digitalRead(encoder_0_int2);
+ if ((chA & !chB)|(!chA & chB)) { encoder_0_position++; }
+ else { encoder_0_position--; }
+}
+void encoder_change_m4_B0(){//encoder0 mode 4x chB
+ int chA=digitalRead(corresp[0]);
+ int chB=digitalRead(encoder_0_int2);
+ if ((!chA & !chB)|(chA & chB)) { encoder_0_position++; }
+ else { encoder_0_position--; }
+}
+//Encoder on INT1
+void encoder_1_change_m1() { //encoder1 mode 1x
+ int chB=digitalRead(encoder_1_int2);
+ if (!chB) { encoder_1_position++;}
+ else { encoder_1_position--; }
+}
+void encoder_1_change_m2() { //encoder1 mode 2x
+ int chB=digitalRead(encoder_1_int2);
+ int chA=digitalRead(corresp[1]);
+ if ((chA & !chB)|(!chA & chB)) { encoder_1_position++; }
+ else { encoder_1_position--; }
+}
+void encoder_change_m4_A1(){//encoder1 mode 4x chA
+ int chA=digitalRead(corresp[1]);
+ int chB=digitalRead(encoder_1_int2);
+ if ((chA & !chB)|(!chA & chB)) { encoder_1_position++; }
+ else { encoder_1_position--; }
+}
+void encoder_change_m4_B1(){//encoder1 mode 4x chB
+ int chA=digitalRead(corresp[1]);
+ int chB=digitalRead(encoder_1_int2);
+ if ((!chA & !chB)|(chA & chB)) { encoder_1_position++; }
+ else { encoder_1_position--; }
+}
+//Encoder on INT2
+void encoder_2_change_m1() { //encoder2 mode 1x
+ int chB=digitalRead(encoder_2_int2);
+ if (!chB) { encoder_2_position++;}
+ else { encoder_2_position--; }
+}
+void encoder_2_change_m2() { //encoder2 mode 2x
+ int chB=digitalRead(encoder_2_int2);
+ int chA=digitalRead(corresp[2]);
+ if ((chA & !chB)|(!chA & chB)) { encoder_2_position++; }
+ else { encoder_2_position--; }
+}
+void encoder_change_m4_A2(){//encoder2 mode 4x chA
+ int chA=digitalRead(corresp[2]);
+ int chB=digitalRead(encoder_2_int2);
+ if ((chA & !chB)|(!chA & chB)) { encoder_2_position++; }
+ else { encoder_2_position--; }
+}
+void encoder_change_m4_B2(){//encoder2 mode 4x chB
+ int chA=digitalRead(corresp[2]);
+ int chB=digitalRead(encoder_2_int2);
+ if ((!chA & !chB)|(chA & chB)) { encoder_2_position++; }
+ else { encoder_2_position--; }
+}
+//Encoder on INT3
+void encoder_3_change_m1() { //encoder3 mode 1x
+ int chB=digitalRead(encoder_3_int2);
+ if (!chB) { encoder_3_position++;}
+ else { encoder_3_position--; }
+}
+void encoder_3_change_m2() { //encoder3 mode 2x
+ int chB=digitalRead(encoder_3_int2);
+ int chA=digitalRead(corresp[3]);
+ if ((chA & !chB)|(!chA & chB)) { encoder_3_position++; }
+ else { encoder_3_position--; }
+}
+void encoder_change_m4_A3(){//encoder3 mode 4x chA
+ int chA=digitalRead(corresp[3]);
+ int chB=digitalRead(encoder_3_int2);
+ if ((chA & !chB)|(!chA & chB)) { encoder_3_position++; }
+ else { encoder_3_position--; }
+}
+void encoder_change_m4_B3(){//encoder3 mode 4x chB
+ int chA=digitalRead(corresp[3]);
+ int chB=digitalRead(encoder_3_int2);
+ if ((!chA & !chB)|(chA & chB)) { encoder_3_position++; }
+ else { encoder_3_position--; }
+}
+//Encoder on INT4
+void encoder_4_change_m1() { //encoder4 mode 1x
+ int chB=digitalRead(encoder_4_int2);
+ if (!chB) { encoder_4_position++;}
+ else { encoder_4_position--; }
+}
+void encoder_4_change_m2() { //encoder4 mode 2x
+ int chB=digitalRead(encoder_4_int2);
+ int chA=digitalRead(corresp[4]);
+ if ((chA & !chB)|(!chA & chB)) { encoder_4_position++; }
+ else { encoder_4_position--; }
+}
+void encoder_change_m4_A4(){//encoder4 mode 4x chA
+ int chA=digitalRead(corresp[4]);
+ int chB=digitalRead(encoder_4_int2);
+ if ((chA & !chB)|(!chA & chB)) { encoder_4_position++; }
+ else { encoder_4_position--; }
+}
+void encoder_change_m4_B4(){//encoder4 mode 4x chB
+ int chA=digitalRead(corresp[4]);
+ int chB=digitalRead(encoder_4_int2);
+ if ((!chA & !chB)|(chA & chB)) { encoder_4_position++; }
+ else { encoder_4_position--; }
+}
+//Encoder on INT5
+void encoder_5_change_m1() { //encoder5 mode 1x
+ int chB=digitalRead(encoder_5_int2);
+ if (!chB) { encoder_5_position++;}
+ else { encoder_5_position--; }
+}
+void encoder_5_change_m2() { //encoder5 mode 2x
+ int chB=digitalRead(encoder_5_int2);
+ int chA=digitalRead(corresp[5]);
+ if ((chA & !chB)|(!chA & chB)) { encoder_5_position++; }
+ else { encoder_5_position--; }
+}
+void encoder_change_m4_A5(){//encoder5 mode 4x chA
+ int chA=digitalRead(corresp[5]);
+ int chB=digitalRead(encoder_5_int2);
+ if ((chA & !chB)|(!chA & chB)) { encoder_5_position++; }
+ else { encoder_5_position--; }
+}
+void encoder_change_m4_B5(){//encoder5 mode 4x chB
+ int chA=digitalRead(corresp[5]);
+ int chB=digitalRead(encoder_5_int2);
+ if ((!chA & !chB)|(chA & chB)) { encoder_5_position++; }
+ else { encoder_5_position--; }
+}
+
+/**************************************/
+// Generic interrupt counter functions//
+/**************************************/
+//Counter on INT0
+void counter_0_change() { //counter 0
+ counter_0++;
+}
+//Counter on INT1
+void counter_1_change() { //counter 1
+ counter_1++;
+}
+//Counter on INT2
+void counter_2_change() { //counter 2
+ counter_2++;
+}
+//Counter on INT3
+void counter_3_change() { //counter 3
+ counter_3++;
+}
+//Counter on INT4
+void counter_4_change() { //counter 4
+ counter_4++;
+}
+//Counter on INT5
+void counter_5_change() { //counter 5
+ counter_5++;
+}
+
+