chelper/hello.c
#include <stdio.h>
#include "compiler.h"
int __visible hello_fun(int value)
{
printf("hello world %d\n", value);
return 0;
}
chelper/init.py
添加hello.c到c_helper.so
如果c_helper.so不存在,则会生成。所以要删掉c_helper.so生成新的
SOURCE_FILES = [
'hello.c',
]
defs_hello = """
int hello_fun(int value);
"""
defs_all = [
defs_hello
]
extras/hello.py
import chelper
class hello_class(object):
def __init__(self, config):
self.printer = config.get_printer()
self.gcode = self.printer.lookup_object("gcode")
# 注册HELLO命令
self.gcode.register_command("HELLO", self.cmd_HELLO, desc=self.cmd_HELLO_help)
# 从printer.cfg配置的hello中获取参数
self.a = config.getfloat("a", 0, minval=0.0, maxval=100)
def hello_fun(self, value):