more code, less void
This commit is contained in:
parent
f63103174a
commit
cf064e6a4d
|
@ -0,0 +1,2 @@
|
|||
*~
|
||||
build
|
|
@ -20,7 +20,7 @@
|
|||
# BOARD # Board name (such as uno, mega2560, ...) [REQUIRED]
|
||||
# SKETCH # Arduino sketch [must have SRCS or SKETCH]
|
||||
# SRCS # Sources [must have SRCS or SKETCH]
|
||||
# HDRS # Headers
|
||||
# HDRS # Headers
|
||||
# LIBS # Libraries to link
|
||||
# PORT # Serial port (enables upload support)
|
||||
# SERIAL # Serial command for serial target
|
||||
|
@ -29,10 +29,10 @@
|
|||
# NO_AUTOLIBS # Disables Arduino library detection
|
||||
#
|
||||
# Here is a short example for a target named test:
|
||||
#
|
||||
#
|
||||
# generate_arduino_firmware(
|
||||
# NAME test
|
||||
# SRCS test.cpp
|
||||
# SRCS test.cpp
|
||||
# test2.cpp
|
||||
# HDRS test.h test2.h
|
||||
# BOARD uno)
|
||||
|
@ -62,15 +62,15 @@
|
|||
# name # The name of the firmware target [REQUIRED]
|
||||
# BOARD # Board name (such as uno, mega2560, ...) [REQUIRED]
|
||||
# SRCS # Sources [REQUIRED]
|
||||
# HDRS # Headers
|
||||
# HDRS # Headers
|
||||
# LIBS # Libraries to link
|
||||
# NO_AUTOLIBS # Disables Arduino library detection
|
||||
#
|
||||
# Here is a short example for a target named test:
|
||||
#
|
||||
#
|
||||
# generate_arduino_library(
|
||||
# NAME test
|
||||
# SRCS test.cpp
|
||||
# SRCS test.cpp
|
||||
# test2.cpp
|
||||
# HDRS test.h test2.h
|
||||
# BOARD uno)
|
||||
|
@ -163,7 +163,7 @@ include(CMakeParseArguments)
|
|||
|
||||
|
||||
#=============================================================================#
|
||||
# User Functions
|
||||
# User Functions
|
||||
#=============================================================================#
|
||||
|
||||
#=============================================================================#
|
||||
|
@ -234,7 +234,7 @@ function(GENERATE_ARDUINO_LIBRARY INPUT_NAME)
|
|||
set(INPUT_BOARD ${ARDUINO_DEFAULT_BOARD})
|
||||
endif()
|
||||
required_variables(VARS INPUT_SRCS INPUT_BOARD MSG "must define for target ${INPUT_NAME}")
|
||||
|
||||
|
||||
set(ALL_LIBS)
|
||||
set(ALL_SRCS ${INPUT_SRCS} ${INPUT_HDRS})
|
||||
|
||||
|
@ -251,7 +251,7 @@ function(GENERATE_ARDUINO_LIBRARY INPUT_NAME)
|
|||
endif()
|
||||
|
||||
list(APPEND ALL_LIBS ${CORE_LIB} ${INPUT_LIBS})
|
||||
|
||||
|
||||
add_library(${INPUT_NAME} ${ALL_SRCS})
|
||||
|
||||
get_arduino_flags(ARDUINO_COMPILE_FLAGS ARDUINO_LINK_FLAGS ${INPUT_BOARD})
|
||||
|
@ -294,7 +294,7 @@ function(GENERATE_ARDUINO_FIRMWARE INPUT_NAME)
|
|||
set(LIB_DEP_INCLUDES)
|
||||
|
||||
setup_arduino_core(CORE_LIB ${INPUT_BOARD})
|
||||
|
||||
|
||||
if(NOT "${INPUT_SKETCH}" STREQUAL "")
|
||||
get_filename_component(INPUT_SKETCH "${INPUT_SKETCH}" ABSOLUTE)
|
||||
setup_arduino_sketch(${INPUT_NAME} ${INPUT_SKETCH} ALL_SRCS)
|
||||
|
@ -311,15 +311,15 @@ function(GENERATE_ARDUINO_FIRMWARE INPUT_NAME)
|
|||
if(NOT INPUT_NO_AUTOLIBS)
|
||||
setup_arduino_libraries(ALL_LIBS ${INPUT_BOARD} "${ALL_SRCS}" "${LIB_DEP_INCLUDES}" "")
|
||||
endif()
|
||||
|
||||
|
||||
list(APPEND ALL_LIBS ${CORE_LIB} ${INPUT_LIBS})
|
||||
|
||||
|
||||
setup_arduino_target(${INPUT_NAME} ${INPUT_BOARD} "${ALL_SRCS}" "${ALL_LIBS}" "${LIB_DEP_INCLUDES}" "")
|
||||
|
||||
|
||||
if(INPUT_PORT)
|
||||
setup_arduino_upload(${INPUT_BOARD} ${INPUT_NAME} ${INPUT_PORT} "${INPUT_PROGRAMMER}" "${INPUT_AFLAGS}")
|
||||
endif()
|
||||
|
||||
|
||||
if(INPUT_SERIAL)
|
||||
setup_serial_target(${INPUT_NAME} "${INPUT_SERIAL}")
|
||||
endif()
|
||||
|
@ -378,21 +378,21 @@ function(GENERATE_ARDUINO_EXAMPLE LIBRARY_NAME EXAMPLE_NAME)
|
|||
setup_arduino_libraries(ALL_LIBS ${INPUT_BOARD} "${ALL_SRCS}" "${LIB_DEP_INCLUDES}" "")
|
||||
|
||||
list(APPEND ALL_LIBS ${CORE_LIB} ${INPUT_LIBS})
|
||||
|
||||
|
||||
setup_arduino_target(${TARGET_NAME} ${INPUT_BOARD} "${ALL_SRCS}" "${ALL_LIBS}" "${LIB_DEP_INCLUDES}" "")
|
||||
|
||||
if(INPUT_PORT)
|
||||
#TODO fill in options (AFLAGS)
|
||||
setup_arduino_upload(${INPUT_BOARD} ${TARGET_NAME} ${INPUT_PORT} "${INPUT_PROGRAMMER}" "")
|
||||
endif()
|
||||
|
||||
|
||||
if(INPUT_SERIAL)
|
||||
setup_serial_target(${TARGET_NAME} "${INPUT_SERIAL}")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
#=============================================================================#
|
||||
# Internal Functions
|
||||
# Internal Functions
|
||||
#=============================================================================#
|
||||
|
||||
#=============================================================================#
|
||||
|
@ -505,7 +505,7 @@ function(get_arduino_flags COMPILE_FLAGS_VAR LINK_FLAGS_VAR BOARD_ID)
|
|||
set(COMPILE_FLAGS "${COMPILE_FLAGS} -I${ARDUINO_VARIANTS_PATH}/${PIN_HEADER}")
|
||||
endif()
|
||||
|
||||
# output
|
||||
# output
|
||||
set(${COMPILE_FLAGS_VAR} "${COMPILE_FLAGS}" PARENT_SCOPE)
|
||||
set(${LINK_FLAGS_VAR} "${LINK_FLAGS}" PARENT_SCOPE)
|
||||
|
||||
|
@ -808,11 +808,9 @@ function(setup_arduino_bootloader_upload TARGET_NAME BOARD_ID PORT AVRDUDE_FLAGS
|
|||
endif()
|
||||
|
||||
list(APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_NAME}.hex")
|
||||
message("\n")
|
||||
message(${AVRDUDE_ARGS})
|
||||
message("\n")
|
||||
|
||||
add_custom_target(${UPLOAD_TARGET}
|
||||
${ARDUINO_AVRDUDE_PROGRAM}
|
||||
${ARDUINO_AVRDUDE_PROGRAM}
|
||||
${AVRDUDE_ARGS}
|
||||
DEPENDS ${TARGET_NAME})
|
||||
endfunction()
|
||||
|
@ -827,7 +825,7 @@ endfunction()
|
|||
# PROGRAMMER - programmer id
|
||||
# PORT - serial port
|
||||
# AVRDUDE_FLAGS - avrdude flags (override)
|
||||
#
|
||||
#
|
||||
# Sets up target for burning firmware via a programmer.
|
||||
#
|
||||
# The target for burning the firmware is ${TARGET_NAME}-burn .
|
||||
|
@ -848,7 +846,7 @@ function(setup_arduino_programmer_burn TARGET_NAME BOARD_ID PROGRAMMER PORT AVRD
|
|||
list(APPEND AVRDUDE_ARGS "-Uflash:w:${TARGET_NAME}.hex")
|
||||
|
||||
add_custom_target(${PROGRAMMER_TARGET}
|
||||
${ARDUINO_AVRDUDE_PROGRAM}
|
||||
${ARDUINO_AVRDUDE_PROGRAM}
|
||||
${AVRDUDE_ARGS}
|
||||
DEPENDS ${TARGET_NAME})
|
||||
endfunction()
|
||||
|
@ -857,7 +855,7 @@ endfunction()
|
|||
# [PRIVATE/INTERNAL]
|
||||
#
|
||||
# setup_arduino_bootloader_burn(TARGET_NAME BOARD_ID PROGRAMMER PORT AVRDUDE_FLAGS)
|
||||
#
|
||||
#
|
||||
# TARGET_NAME - name of target to burn
|
||||
# BOARD_ID - board id
|
||||
# PROGRAMMER - programmer id
|
||||
|
@ -914,7 +912,7 @@ function(setup_arduino_bootloader_burn TARGET_NAME BOARD_ID PROGRAMMER PORT AVRD
|
|||
|
||||
# Create burn bootloader target
|
||||
add_custom_target(${BOOTLOADER_TARGET}
|
||||
${ARDUINO_AVRDUDE_PROGRAM}
|
||||
${ARDUINO_AVRDUDE_PROGRAM}
|
||||
${AVRDUDE_ARGS}
|
||||
WORKING_DIRECTORY ${ARDUINO_BOOTLOADERS_PATH}/${${BOARD_ID}.bootloader.path}
|
||||
DEPENDS ${TARGET_NAME})
|
||||
|
@ -1010,7 +1008,7 @@ function(setup_arduino_bootloader_args BOARD_ID TARGET_NAME PORT AVRDUDE_FLAGS O
|
|||
"-b${${BOARD_ID}.upload.speed}" # Baud rate
|
||||
"-P${PORT}" # Serial port
|
||||
"-D" # Dont erase
|
||||
)
|
||||
)
|
||||
|
||||
list(APPEND AVRDUDE_ARGS ${AVRDUDE_FLAGS})
|
||||
|
||||
|
@ -1099,7 +1097,7 @@ endfunction()
|
|||
# SETTINGS_PATH - File path of settings file to load.
|
||||
#
|
||||
# Load a Arduino style settings file into the cache.
|
||||
#
|
||||
#
|
||||
# Examples of this type of settings file is the boards.txt and
|
||||
# programmers.txt files located in ${ARDUINO_SDK}/hardware/arduino.
|
||||
#
|
||||
|
@ -1128,7 +1126,7 @@ endfunction()
|
|||
# set(uno.SETTINGS name upload build) # List of settings for uno
|
||||
# set(uno.upload.SUBSETTINGS protocol maximum_size) # List of sub-settings for uno.upload
|
||||
# set(uno.build.SUBSETTINGS mcu core) # List of sub-settings for uno.build
|
||||
#
|
||||
#
|
||||
# The ${ENTRY_NAME}.SETTINGS variable lists all settings for the entry, while
|
||||
# ${ENTRY_NAME}.SUBSETTINGS variables lists all settings for a sub-setting of
|
||||
# a entry setting pair.
|
||||
|
@ -1188,7 +1186,7 @@ function(LOAD_ARDUINO_STYLE_SETTINGS SETTINGS_LIST SETTINGS_PATH)
|
|||
# Save setting value
|
||||
set(${FULL_SETTING_NAME} ${SETTING_VALUE}
|
||||
CACHE INTERNAL "Arduino ${ENTRY_NAME} Board setting")
|
||||
|
||||
|
||||
|
||||
endif()
|
||||
endforeach()
|
||||
|
@ -1320,7 +1318,7 @@ function(SETUP_ARDUINO_SKETCH TARGET_NAME SKETCH_PATH OUTPUT_VAR)
|
|||
file(GLOB SKETCH_SOURCES ${SKETCH_PATH}/*.pde ${SKETCH_PATH}/*.ino)
|
||||
list(REMOVE_ITEM SKETCH_SOURCES ${MAIN_SKETCH})
|
||||
list(SORT SKETCH_SOURCES)
|
||||
|
||||
|
||||
generate_cpp_from_sketch("${MAIN_SKETCH}" "${SKETCH_SOURCES}" "${SKETCH_CPP}")
|
||||
|
||||
# Regenerate build system if sketch changes
|
||||
|
@ -1407,7 +1405,7 @@ function(GENERATE_CPP_FROM_SKETCH MAIN_SKETCH_PATH SKETCH_SOURCES SKETCH_CPP)
|
|||
|
||||
# Write function prototypes
|
||||
file(APPEND ${SKETCH_CPP} "\n//=== START Forward: ${SKETCH_SOURCE_PATH}\n")
|
||||
foreach(SKETCH_PROTOTYPE ${SKETCH_PROTOTYPES})
|
||||
foreach(SKETCH_PROTOTYPE ${SKETCH_PROTOTYPES})
|
||||
string(REPLACE "\n" " " SKETCH_PROTOTYPE "${SKETCH_PROTOTYPE}")
|
||||
string(REPLACE "{" "" SKETCH_PROTOTYPE "${SKETCH_PROTOTYPE}")
|
||||
arduino_debug_msg("\tprototype: ${SKETCH_PROTOTYPE};")
|
||||
|
@ -1415,7 +1413,7 @@ function(GENERATE_CPP_FROM_SKETCH MAIN_SKETCH_PATH SKETCH_SOURCES SKETCH_CPP)
|
|||
endforeach()
|
||||
file(APPEND ${SKETCH_CPP} "//=== END Forward: ${SKETCH_SOURCE_PATH}\n")
|
||||
endforeach()
|
||||
|
||||
|
||||
# Write Sketch CPP source
|
||||
get_num_lines("${SKETCH_HEAD}" HEAD_NUM_LINES)
|
||||
file(APPEND ${SKETCH_CPP} "#line ${HEAD_NUM_LINES} \"${MAIN_SKETCH_PATH}\"\n")
|
||||
|
@ -1589,7 +1587,7 @@ endfunction()
|
|||
|
||||
|
||||
#=============================================================================#
|
||||
# C Flags
|
||||
# C Flags
|
||||
#=============================================================================#
|
||||
set(ARDUINO_C_FLAGS "-mcall-prologues -ffunction-sections -fdata-sections")
|
||||
set(CMAKE_C_FLAGS "-Os ${ARDUINO_C_FLAGS}" CACHE STRING "")
|
||||
|
@ -1599,7 +1597,7 @@ set(CMAKE_C_FLAGS_RELEASE "-Os -DNDEBUG -w ${ARDUINO_C_FLAGS}" CACHE STRI
|
|||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -w ${ARDUINO_C_FLAGS}" CACHE STRING "")
|
||||
|
||||
#=============================================================================#
|
||||
# C++ Flags
|
||||
# C++ Flags
|
||||
#=============================================================================#
|
||||
set(ARDUINO_CXX_FLAGS "${ARDUINO_C_FLAGS} -fno-exceptions")
|
||||
set(CMAKE_CXX_FLAGS "-Os ${ARDUINO_CXX_FLAGS}" CACHE STRING "")
|
||||
|
@ -1636,7 +1634,7 @@ set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "${ARDUINO_LINKER_FLAGS}" CACHE STR
|
|||
|
||||
|
||||
#=============================================================================#
|
||||
# Arduino Settings
|
||||
# Arduino Settings
|
||||
#=============================================================================#
|
||||
set(ARDUINO_OBJCOPY_EEP_FLAGS -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load
|
||||
--no-change-warnings --change-section-lma .eeprom=0 CACHE STRING "")
|
||||
|
@ -1644,7 +1642,7 @@ set(ARDUINO_OBJCOPY_HEX_FLAGS -O ihex -R .eeprom CACHE STRING "")
|
|||
set(ARDUINO_AVRDUDE_FLAGS -V CACHE STRING "")
|
||||
|
||||
#=============================================================================#
|
||||
# Initialization
|
||||
# Initialization
|
||||
#=============================================================================#
|
||||
if(NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH)
|
||||
find_file(ARDUINO_CORES_PATH
|
||||
|
@ -1654,7 +1652,7 @@ if(NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH)
|
|||
DOC "Path to directory containing the Arduino core sources.")
|
||||
|
||||
find_file(ARDUINO_VARIANTS_PATH
|
||||
NAMES variants
|
||||
NAMES variants
|
||||
PATHS ${ARDUINO_SDK_PATH}
|
||||
PATH_SUFFIXES hardware/arduino
|
||||
DOC "Path to directory containing the Arduino variant sources.")
|
||||
|
@ -1713,7 +1711,7 @@ if(NOT ARDUINO_FOUND AND ARDUINO_SDK_PATH)
|
|||
set(ARDUINO_DEFAULT_PROGRAMMER CACHE STRING "Default Arduino Programmer ID when not specified.")
|
||||
|
||||
# Ensure that all required paths are found
|
||||
required_variables(VARS
|
||||
required_variables(VARS
|
||||
ARDUINO_CORES_PATH
|
||||
ARDUINO_BOOTLOADERS_PATH
|
||||
ARDUINO_LIBRARIES_PATH
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
unsigned int time = 0; // profile seconds
|
||||
unsigned int degrees = 25; // actual oven temp
|
||||
unsigned int temperatur = 25; // actual oven temp
|
||||
unsigned int last_temperatur = 25;
|
||||
|
||||
unsigned int Ts_max = 200; // °C
|
||||
unsigned int Ts_min = 150; // °C
|
||||
|
@ -13,7 +14,26 @@ unsigned int peak_duration = 30; // 20-40s
|
|||
unsigned int rampdown_max = 6; // 6°C/s max
|
||||
unsigned int time_max = 480; // 8*60s max
|
||||
|
||||
byte state; // 0 = start, 1 = preheat, 2 = tal, 3 = max, 4 = rampdown
|
||||
#define START_STATE 0
|
||||
#define PREHEAT_STATE 1
|
||||
#define TAL_STATE 2
|
||||
#define MAX_STATE 3
|
||||
#define RAMPDOWN_STATE 4
|
||||
#define END_STATE 5
|
||||
#define ERROR_STATE 6
|
||||
|
||||
byte state = START_STATE;
|
||||
|
||||
unsigned int Ts_min_time = 0;
|
||||
unsigned int Ts_max_time = 0;
|
||||
unsigned int Tl_time = 0;
|
||||
unsigned int Tp_time = 0;
|
||||
unsigned int Tl_end_time = 0;
|
||||
|
||||
#define RAMPUP_TOO_FAST 1
|
||||
#define RAMPDOWN_TOO_FAST 2
|
||||
unsigned int error_condition = 0;
|
||||
|
||||
|
||||
void setup() {
|
||||
pinMode(13, OUTPUT);
|
||||
|
@ -21,33 +41,54 @@ void setup() {
|
|||
}
|
||||
|
||||
void get_temp() {
|
||||
// simulating an +1K/s rampup oven
|
||||
last_temperatur = ++temperatur;
|
||||
}
|
||||
|
||||
boolean check_rampup_rate() {
|
||||
if (temperatur - last_temperatur > rampup_rate) {
|
||||
error_condition = RAMPUP_TOO_FAST;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
time = millis() / 1000;
|
||||
get_temp();
|
||||
Serial.print(time);
|
||||
Serial.print(" ");
|
||||
Serial.print(temperatur);
|
||||
Serial.print(" ");
|
||||
Serial.println(last_temperatur);
|
||||
|
||||
|
||||
// wait a second so as not to send massive amounts of data
|
||||
delay(1000);
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
if (degrees > Ts_min) {
|
||||
case START_STATE:
|
||||
// going from room temp to preheat, nothing to check here
|
||||
if (!check_rampup_rate())
|
||||
goto error;
|
||||
if (temperatur > Ts_min) {
|
||||
state++;
|
||||
}
|
||||
case 1:
|
||||
case PREHEAT_STATE:
|
||||
if (temperatur > Ts_max)
|
||||
state++;
|
||||
break;
|
||||
case 2:
|
||||
case TAL_STATE:
|
||||
break;
|
||||
case 3:
|
||||
case MAX_STATE:
|
||||
break;
|
||||
case 4:
|
||||
case RAMPDOWN_STATE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (degrees > 60) {
|
||||
Serial.print("seconds: ");
|
||||
Serial.println(time);
|
||||
}
|
||||
error:
|
||||
state = END_STATE;
|
||||
Serial.println(error_condition);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue