/** @file * @brief This file contains the definition of the functions associated with the user-defined * application for the Esmacat slave project */ /***************************************************************************************** * INCLUDES ****************************************************************************************/ #include "my_app.h" /***************************************************************************************** * FUNCTIONS ****************************************************************************************/ /** * @brief Identifies the actual Esmacat slave sequence in the EtherCAT communication chain. */ void my_app::assign_slave_sequence(){ // tell the master what type of slave is at which point in the chain assign_esmacat_slave_index(&ease_1, 0); //<-- The arduino is connected in number 0 } /** * @brief Configure your Esmacat slave. * Link Esmacat slave object with the actual Esmacat slave in the EtherCAT communication chain. * Functions beginning with 'configure_slave' must only be executed in this function */ void my_app::configure_slaves(){ // add initialization code here // Functions starting with "configure_slave" work only in configure_slaves() function } /** @brief Initialization that needs to happen on the first iteration of the loop */ void my_app::init() { // prev_analog_value = 1023; } /** * @brief Executes functions at the defined loop rate */ void my_app::loop(){ // add functions below that are to be executed at the loop rate lcd_analog_input_value = ease_1.get_input_variable_0_IN_GEN_INT0(); cout << lcd_analog_input_value << "\t"; // Determine the button pressed based on the analog value received if (lcd_analog_input_value >= 0 && lcd_analog_input_value < 50) { cout << lcd_analog_input_value << "\t"; ease_1.set_output_variable_1_OUT_GEN_INT1(4); // <-- Write the corresponding encoding for right cout << "Right Button Pressed" << endl; // <-- Printing message onto the terminal ease_1.set_output_variable_2_OUT_GEN_INT2(lcd_analog_input_value); //<-- Send the anlog value back to arduino to print in the Serial Monitor } if (lcd_analog_input_value >= 50 && lcd_analog_input_value < 150) { cout << lcd_analog_input_value << "\t"; ease_1.set_output_variable_1_OUT_GEN_INT1(2); // <-- Write the corresponding encoding for up cout << "Up Button Pressed" << endl; ease_1.set_output_variable_2_OUT_GEN_INT2(lcd_analog_input_value); } if (lcd_analog_input_value >= 150 && lcd_analog_input_value < 300) { cout << lcd_analog_input_value << "\t"; ease_1.set_output_variable_1_OUT_GEN_INT1(3); // <-- Write the corresponding encoding for down cout << "Down Button Pressed" << endl; ease_1.set_output_variable_2_OUT_GEN_INT2(lcd_analog_input_value); } if (lcd_analog_input_value >= 300 && lcd_analog_input_value < 500) { cout << lcd_analog_input_value << "\t"; ease_1.set_output_variable_1_OUT_GEN_INT1(1); // <-- Write the corresponding encoding for left cout << "Left Button Pressed" << endl; ease_1.set_output_variable_2_OUT_GEN_INT2(lcd_analog_input_value); } if (lcd_analog_input_value >= 500 && lcd_analog_input_value <= 750) { cout << lcd_analog_input_value << "\t"; ease_1.set_output_variable_1_OUT_GEN_INT1(5); // <-- Write the corresponding encoding for Select cout << "Select Button Pressed" << endl; ease_1.set_output_variable_2_OUT_GEN_INT2(lcd_analog_input_value); } }