Ok, I copied the files into the directories:
Sketchbook location: (under file -> preferences)
f:\Evan\projects\arduino\mega_shiled_for_CNC_router\software\arduino-ATC-spindle-controller
header file location:
F:\Evan\projects\arduino\mega_shiled_for_CNC_router\software\arduino-ATC-spindle-controller\libraries\FSM.h
Library file location:
F:\Evan\projects\arduino\mega_shiled_for_CNC_router\software\arduino-ATC-spindle-controller\libraries\FSM.cpp
I then closed the IDE and restarted it.
The library shows up in Sketch-> Include Library under "Contributed Libraries"
If I copy inline the header into the .ino file it compiles without issue. If I include it with
#include <FSM.h> it has the following error:
Using board 'mega' from platform in folder: C:\Users\evan\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3
Using core 'arduino' from platform in folder: C:\Users\evan\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3
Detecting libraries used...
"C:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\mega" "C:\\Users\\evan\\AppData\\Local\\Temp\\arduino-sketch-0232EEA6C455D494983E7C8CA1928504\\sketch\\Spindle_program.ino.cpp" -o nul
Alternatives for LiquidCrystal_I2C.h: [LiquidCrystal_I2C@1.1.1]
ResolveLibrary(LiquidCrystal_I2C.h)
-> candidates: [LiquidCrystal_I2C@1.1.1]
"C:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\mega" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\LiquidCrystal_I2C" "C:\\Users\\evan\\AppData\\Local\\Temp\\arduino-sketch-0232EEA6C455D494983E7C8CA1928504\\sketch\\Spindle_program.ino.cpp" -o nul
Alternatives for Wire.h: [Wire@1.0]
ResolveLibrary(Wire.h)
-> candidates: [Wire@1.0]
"C:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\mega" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\LiquidCrystal_I2C" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\libraries\\Wire\\src" "C:\\Users\\evan\\AppData\\Local\\Temp\\arduino-sketch-0232EEA6C455D494983E7C8CA1928504\\sketch\\Spindle_program.ino.cpp" -o nul
Alternatives for FSM.h: [FSM]
ResolveLibrary(FSM.h)
-> candidates: [FSM]
"C:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\mega" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\LiquidCrystal_I2C" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\libraries\\Wire\\src" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\FSM" "C:\\Users\\evan\\AppData\\Local\\Temp\\arduino-sketch-0232EEA6C455D494983E7C8CA1928504\\sketch\\Spindle_program.ino.cpp" -o nul
"C:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\mega" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\LiquidCrystal_I2C" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\libraries\\Wire\\src" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\FSM" "f:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\LiquidCrystal_I2C\\LiquidCrystal_I2C.cpp" -o nul
"C:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\mega" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\LiquidCrystal_I2C" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\libraries\\Wire\\src" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\FSM" "C:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\libraries\\Wire\\src\\Wire.cpp" -o nul
"C:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\mega" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\LiquidCrystal_I2C" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\libraries\\Wire\\src" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\FSM" "C:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\libraries\\Wire\\src\\utility\\twi.c" -o nul
"C:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\variants\\mega" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\LiquidCrystal_I2C" "-IC:\\Users\\evan\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\libraries\\Wire\\src" "-If:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\FSM" "f:\\Evan\\projects\\arduino\\mega_shiled_for_CNC_router\\software\\arduino-ATC-spindle-controller\\libraries\\FSM\\FSM.cpp" -o nul
Alternatives for ../FSM_Lib/FSM.h: []
ResolveLibrary(../FSM_Lib/FSM.h)
-> candidates: []
Using library LiquidCrystal_I2C at version 1.1.1 in folder: f:\Evan\projects\arduino\mega_shiled_for_CNC_router\software\arduino-ATC-spindle-controller\libraries\LiquidCrystal_I2C
Using library Wire at version 1.0 in folder: C:\Users\evan\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\libraries\Wire
Using library FSM in folder: f:\Evan\projects\arduino\mega_shiled_for_CNC_router\software\arduino-ATC-spindle-controller\libraries\FSM (legacy)
Compilation error: Error: 2 UNKNOWN: exit status 1
Note that the library that works "LiquidCrystal_I2C" was installed through the Library manager and is located in the following path (next to FSM):
F:\Evan\projects\arduino\mega_shiled_for_CNC_router\software\arduino-ATC-spindle-controller\libraries\LiquidCrystal_I2C
Here is the header file.. just in case there is a difference when it is included:
/*
* FMS.h
* The header for the finite state machine
* Created on: Jul 5, 2021
* Author: evan
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef ARDUINO
#include <sys/time.h>
#else
#include <time.h>
#endif
#ifndef FSM_H_
#define FSM_H_
/******************* Actions *****************************/
#define MAX_ACTIONS 6 // The maximum number of actions in an event -1
#define MAX_EVENTS 5 // the maximum number of events for a state
#define MAX_STATES 10 // The maximum number of states in the state machine.
#define MAX_INPUTS 60 // THE MAXIMUM NUMBER OF INPUTS
#define MAX_OUTPUTS 60 // THE MAXIMUM NUMBER OF INPUTS
//#define TRUE 1
//#define FALSE 0
/******************* Structure Definitions *****************************/
struct pins{
int pin_Number ; // the pin number
bool value ; // the digital value of the pin
bool digital_pin ; // when true this is a digital pin, when false it is an analog pin.
int a_value; // the 8 bit analog value for the pin. (A/D)
};
struct userVariables {
struct pins inputs[MAX_INPUTS]; // the input signals
struct pins outputs[MAX_OUTPUTS]; // the output signals
unsigned int input_list[MAX_INPUTS]; // a list of all the active pins. a pin value of -1 indicates the end of the list.
unsigned int output_list[MAX_INPUTS]; // a list of all the active pins. a pin value of -1 indicates the end of the list.
int speed ; // the desired speed setting for the spindle
int current_speed; // the speed that the spindle has been programmed to.
bool pingState; // the previous value of the ping IO
float spindle_temp; // the temperature for the spindle.
};
struct event_struct{
int next_state = -1; // The state to transition to after the event is triggered.
bool action_active; // true when actions are active
bool event_error;
bool (*event_detction)(struct sm_struct *sm); // pointer to the function that checks if it should be triggered.
bool (*Action_Array[MAX_ACTIONS])(struct sm_struct *sm); // array of actions associated with this event (pointers to functions)
char name[100]; // name of the event
};// end event struct definition
struct state_struct{ // a structure for each state in the state machine
int (*one_time_function)(struct sm_struct sm); // function pointer for the one time code
int (*repeated_execution)(struct sm_struct sm);// function pointer for repeated execution
struct event_struct events[MAX_EVENTS]; // array of structures associated with the states
unsigned long stop_time; // a second timer used to indicate a valid time function for the state. All timers are reset upon entering the state
unsigned long watchdog_time; // a second timer used to indicate the maximum time the SM can remain in the current state, at which time an error is triggered. 0 = disabled
unsigned int number; // the state number
char name[100]; // the name of the state
bool first_time_exec = true; // True when this is executed for the first time. Reset when exiting the state.
}; // end state_struct
struct sm_struct { // state machine structure
int current_state;
struct state_struct state_ar[MAX_STATES]; // the array of all of the different states
struct userVariables userVar; // the user variables for this state machine
bool executing_event;
unsigned long start_time; // the time at the start of the program in seconds.
unsigned long current_time; // the current time in seconds since the start of the program
void (*io_function)(); // pointer to the IO functions
// variables for testing
int executed_actions[MAX_ACTIONS]; // the actions executed in the last event.
int action_number; // the action being executed or just executed
char msg_buffer[200]; // a message buffer used for logging.
}; // end state machine structure
struct test_struct_input{ // a structure used for testing the finite state machine
int state =-1;
int input_pins[2][ MAX_INPUTS]; // the pins to be set for the test [pin_number][value] a pin number of -1 indicates the end of the list.
int speed = 0; // the measured speed
float temperature; // the temperature of the spindle
bool pingstate; // the value of the ping from the PLC
bool timeout_triggered; // if the timer has been triggered for watchdog or other timed events
};
struct test_struct_output{ // test structure that holds the outputs / results of a unit test
int output_pins[2][MAX_OUTPUTS]; // the pins to be read out after the test [pin_number][value] a pin number of -1 indicates the end of the list.
int speed = -1;
int state = -1;
bool pingstate = false;
int test_fail_num = 0;
int executed_actions[MAX_ACTIONS]; // the actions executed in the last event.
char expected_event_name[50]; // the name of the expected event to be triggered
};
/******************* General state machine functions *****************************/
void SM_run(struct sm_struct *sm); // The function that runs the state machine
void log_message(struct sm_struct *sm ); // output a message
int FSM_Test(struct sm_struct *sm, struct test_struct_input *input, struct test_struct_output *output);
void load_input_pins(int pin_List1[MAX_INPUTS][2], struct test_struct_input *input);
void load_output_pins(int pin_List1[MAX_OUTPUTS][2], struct test_struct_output *output);
void load_executed_actions(struct test_struct_output *output, int A1, int A2, int A3, int A4 , int A5);
unsigned long get_time(struct sm_struct *sm);
bool watchdog_event(struct sm_struct *sm);
void init_event( // This function takes a list of variables that make up the full definition for the event and fills the event structure.
struct sm_struct *sm, // The event structure to be initialized
int state_num, // the state integer
int event_num, // the event number in the array of events 0 - n
char *name, // The name of the event
int next_state, // The next state if this event is tripped.
bool (*event_detction_ptr)(struct sm_struct*), // A pointer to the function that checks if this event has been tripped. (returns T/F)
bool (*action1)(struct sm_struct* ), // A pointer to the first action to take
bool (*action2)(struct sm_struct* ), // A pointer to the second action to take
bool (*action3)(struct sm_struct* ), // A pointer to the third action to take
bool (*action4)(struct sm_struct* ), // A pointer to the fourth action to take
bool (*action5)(struct sm_struct* ) // A pointer to the fifth action to take
);
/********************************************************************/
/********************************************************************/
#ifndef ARDUINO // if Arduino not defined then put in dummy functions to prevent errors
bool digitalRead(int pin);
int analogRead(int pin);
void digitalWrite(int pin, bool value);
void analogWrite(int pin, int value);
#endif // if Arduino not defined then put in a dummy
#endif /* FSM_H_ */