1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-27 08:14:31 +02:00

Moved custom code into Custom/ subdirectory

Also improved the build scripts
This commit is contained in:
Mitch Bradley
2020-03-10 08:52:51 -10:00
parent af8cf26365
commit 8a0a1d82c7
12 changed files with 90 additions and 89 deletions

3
.gitignore vendored
View File

@@ -7,4 +7,5 @@ embedded/dist
*~
.pio/
.vscode/
.history/
.history/
*.pyc

View File

@@ -23,9 +23,10 @@
This contains all the special features required to control an
Atari 1010 Pen Plotter
*/
#include "grbl.h"
#ifdef ATARI_1020
// This file is enabled by defining CUSTOM_CODE_FILENAME "atari_1020.cpp"
// in Machines/atari_1020.h, thus causing this file to be included
// from ../custom_code.cpp
#define HOMING_PHASE_FULL_APPROACH 0 // move to right end
#define HOMING_PHASE_CHECK 1 // check reed switch
@@ -319,6 +320,3 @@ void user_m30() {
sprintf(gcode_line, "G90G0X%3.2f\r", ATARI_PAPER_WIDTH); //
inputBuffer.push(gcode_line);
}
#endif

View File

@@ -30,7 +30,7 @@ Machines/template.h to a similar name.
Example:
Machines/my_machine.h
my_machine.cpp
Custom/my_machine.cpp
Edit machine.h to include your Machines/my_machine.h file
@@ -43,14 +43,6 @@ enabled with USE_ defines in Machines/my_machine.h
*/
// It is necessary to include grbl.h so that the machine definitions
// will be loaded before the remainder of this file is processed.
#include "grbl.h"
// !!! Change this to the MACHINE_name you chose in Machines/my_machine.h
// The compiler will skip the rest of this file unless that name is defined
#ifdef MACHINE_CUSTOM
#ifdef USE_MACHINE_INIT
/*
machine_init() is called when Grbl_ESP32 first starts. You can use it to do any
@@ -173,6 +165,3 @@ void machine_trinamic_setup() {
// If you add any additional functions specific to your machine that
// require calls from common code, guard their calls in the common code with
// #ifdef USE_WHATEVER and add function prototypes (also guarded) to grbl.h
#endif

View File

@@ -28,7 +28,7 @@
How it works...
If you tell it to go to X10 Y10 Z10 in Cartesian space, for example, the equations
will convert those values to the required joint values. In the case of a polar machine, X represents the radius,
will convert those values to the required joint values. In the case of a polar machine, X represents the radius,
Y represents the polar degrees and Z would be unchanged.
In most cases, a straight line in Cartesian space could cause a curve in the new system.
@@ -50,10 +50,9 @@
*/
#include "grbl.h"
#ifdef MACHINE_POLAR_COASTER
#ifdef USE_KINEMATICS
// This file is enabled by defining CUSTOM_CODE_FILENAME "polar_coaster.cpp"
// in Machines/polar_coaster.h, thus causing this file to be included
// from ../custom_code.cpp
void calc_polar(float *target_xyz, float *polar, float last_angle);
float abs_angle(float ang);
@@ -175,7 +174,6 @@ void inverse_kinematics(float *target, plan_line_data_t *pl_data, float *positio
// TO DO don't need a feedrate for rapids
}
/*
Forward kinematics converts position back to the original cartesian system. It is
typically used for reporting
@@ -264,8 +262,6 @@ float abs_angle(float ang) {
return ang;
}
#endif
// Polar coaster has macro buttons, this handles those button pushes.
void user_defined_macro(uint8_t index)
{
@@ -298,6 +294,3 @@ void user_defined_macro(uint8_t index)
void user_m30() {
inputBuffer.push("$H\r");
}
#endif

View File

@@ -9,6 +9,8 @@
#define MACHINE_NAME "MACHINE_ATARI_1020"
#define CUSTOM_CODE_FILENAME "Custom/atari_1020.cpp"
#ifdef USE_RMT_STEPS
#undef USE_RMT_STEPS
#endif

View File

@@ -3,8 +3,9 @@
#define MACHINE_NAME "MACHINE_POLAR_COASTER"
// This must be defined so that polar_coaster.cpp is not skipped
#define MACHINE_POLAR_COASTER
// This causes the custom code file to be included in the build
// via ../custom_code.cpp
#define CUSTOM_CODE_FILENAME "Custom/polar_coaster.cpp"
#define RADIUS_AXIS 0
#define POLAR_AXIS 1

View File

@@ -34,14 +34,16 @@
// === Machine Name
// Change TEMPLATE to some name of your own choosing. That name
// will be shown in a Grbl startup message to identify your
// configuration. If you need to implement custom code functions
// as in custom_code_template.cpp, the beginning #ifdef in
// your custom .cpp file must match your chosen MACHINE_name ,
// so as to enable the compilation of your file and suppress
// compilation of other custom .cpp files.
// configuration.
#define MACHINE_NAME "MACHINE_TEMPLATE"
// If your machine requires custom code as described below in
// Special Features, you must copy Custom/custom_code_template.cpp
// to a new name like Custom/my_custom_code.cpp, implement the
// functions therein, and enable its use by defining:
// #define CUSTOM_CODE_FILENAME "Custom/my_custom_code.cpp"
// === Number of axes
// You can set the number of axes that the machine supports

View File

@@ -0,0 +1,8 @@
// This file loads custom code from the Custom/ subdirectory if
// CUSTOM_CODE_FILENAME is defined.
#include "grbl.h"
#ifdef CUSTOM_CODE_FILENAME
#include CUSTOM_CODE_FILENAME
#endif

View File

@@ -1,5 +1,10 @@
#!/usr/bin/env python2
# Note: If you experience random errors running this script within
# VSCode, try running it from a regular terminal window. Some VSCode
# extensions seem to randomly interfere with the files that platformio
# uses during compilation.
# Compile Grbl_ESP32 for each of the machines defined in Machines/ .
# Add-on files are built on top of a single base.
# This is useful for automated testing, to make sure you haven't broken something
@@ -9,31 +14,16 @@
# contain the word "error". If you need to see everything, for example to
# see the details of an errored build, include -v on the command line.
from __future__ import print_function
import os, subprocess, sys
from builder import buildMachine
import os, sys
cmd = ['platformio','run']
env = dict(os.environ)
verbose = '-v' in sys.argv
def buildMachine(baseName, addName=None):
displayName = baseName
flags = '-DMACHINE_FILENAME=' + baseName
if addName:
displayName += ' + ' + addName
flags += ' -DMACHINE_FILENAME2=' + addName
print('Building machine ' + displayName)
env['PLATFORMIO_BUILD_FLAGS'] = flags
app = subprocess.Popen(['platformio','run'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, env=env)
for line in app.stdout:
if verbose or "Took" in line or "error" in line.lower():
print(line, end='')
print()
adderBase = '3axis_v4.h'
for name in os.listdir('Grbl_Esp32/Machines'):
if name.startswith('add_'):
buildMachine(adderBase, name)
buildMachine(adderBase, addName=name, verbose=verbose)
else:
buildMachine(name)
buildMachine(name, verbose=verbose)

View File

@@ -1,18 +1,20 @@
#!/usr/bin/env python2
# Compile Grbl_ESP32 for the machine listed on the command line, as in
# ./build-machine.py 3xis_v4.h
# Compile Grbl_ESP32 for each of the machines defined in Machines/ .
# Add-on files are built on top of a single base.
# This is useful for automated testing, to make sure you haven't broken something
# Add-ons can be built by listing both the base name and the adder, as in
# ./build-machine.py 3axis_v4.h add_esc_spindle.h
# -q suppresses most messages
# -u uploads the firmware to the target machine
# The output is filtered so that the only lines you see are a single
# success or failure line for each build, plus any preceding lines that
# contain the word "error". If you need to see everything, for example to
# see the details of an errored build, include -v on the command line.
from __future__ import print_function
import os, subprocess, sys
from builder import buildMachine
import os, sys
extraArgs=None
cmd=['platformio','run']
verbose = '-v' in sys.argv or '-q' not in sys.argv
if '-v' in sys.argv:
sys.argv.remove('-v')
@@ -20,32 +22,14 @@ if '-q' in sys.argv:
sys.argv.remove('-q')
if '-u' in sys.argv:
sys.argv.remove('-u')
cmd.append('--target=upload')
env = dict(os.environ)
def buildMachine(baseName, addName=None):
displayName = baseName
flags = '-DMACHINE_FILENAME=' + baseName
if addName:
displayName += ' + ' + addName
flags += ' -DMACHINE_FILENAME2=' + addName
print('Building machine ' + displayName)
env['PLATFORMIO_BUILD_FLAGS'] = flags
if verbose:
subprocess.Popen(cmd, env=env).wait()
else:
app = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, env=env)
for line in app.stdout:
if "Took" in line or 'Uploading' in line or "error" in line.lower():
print(line, end='')
extraArgs = '--target=upload'
if len(sys.argv) == 2:
buildMachine(sys.argv[1], None)
buildMachine(sys.argv[1], addName=None, verbose=verbose, extraArgs=extraArgs)
elif len(sys.argv) == 3:
buildMachine(sys.argv[1], sys.argv[2])
buildMachine(sys.argv[1], addName=sys.argv[2], verbose=verbose, extraArgs=extraArgs)
else:
print("Usage: ./build-machine.py [-q] [-u] machine_name.h [add_name.h]")
print(' Build for the given machine and optional add-on regardless of machine.h')
print(' -q suppresses most messages')
print(' -u uploads to the target after compilation')
print(' -u uploads to the target after compilation')

32
builder.py Normal file
View File

@@ -0,0 +1,32 @@
# This script is imported by build-machine.py and build-all.py
# It performs a platformio build with a given base machine file
# and an optional add-on file. The verbose argument controls
# whether the full output is displayed, or filtered to show
# only summary information. extraArgs can be used to perform
# uploading after compilation.
from __future__ import print_function
import subprocess, os
env = dict(os.environ)
def buildMachine(baseName, addName=None, verbose=True, extraArgs=None):
cmd = ['platformio','run']
if extraArgs:
cmd.append(extraArgs)
displayName = baseName
flags = '-DMACHINE_FILENAME=' + baseName
if addName:
displayName += ' + ' + addName
flags += ' -DMACHINE_FILENAME2=' + addName
print('Building machine ' + displayName)
env['PLATFORMIO_BUILD_FLAGS'] = flags
if verbose:
app = subprocess.Popen(cmd, env=env)
else:
app = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1)
for line in app.stdout:
if "Took" in line or 'Uploading' in line or "error" in line.lower():
print(line, end='')
app.wait()
print()

View File

@@ -28,4 +28,5 @@ framework = arduino
upload_speed = 512000
board_build.partitions = min_spiffs.csv
monitor_speed = 115200
build_flags = -DCORE_DEBUG_LEVEL=0
build_flags = -DCORE_DEBUG_LEVEL=0 -Wno-unused-variable -Wno-unused-function
src_filter = +<*.h> +<*.s> +<*.S> +<*.cpp> +<*.c> +<*.ino> +<src/> -<.git/> -<data/> -<test/> -<tests/> -<Custom/>