代码生成器是否适用于arduino文件? [英] Does code generator work on arduino files?

查看:84
本文介绍了代码生成器是否适用于arduino文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了这个 C ++类代码生成器 [ ^ ]以及运行它的python。我想我输入了正确的命令行,但是我收到了无效的语法错误。



TIA



Arduino代码:

  / *   
基本计时器转换为多态/继承形式。
利用虚函数实现定时器复位。

参考Arduino.cc线程http://forum.arduino.cc/index.php?topic=567010.new#new
* /


// 对没有库的用户禁用去抖动
// #include< Bounce2.h>

#定义BUTTON_PIN 6 //启用定时器DIO6
#define RESET_PIN 8 //重置定时器DIO8
#define externalLED1 7 // +5 - / \ / \ / - > | --DIO7

byte LED_PIN = 13 ; // on board LED

// 实例化Bounce对象
// Bounce debouncer = Bounce();

// 创建一个名为'PLCtimer'的类

class PLCtimer {
/ *
这是基类 - 所有类型:
>在达到
预设值时产生正向一次扫描脉冲'os'。
>通过将累计值设置为
零并重置done和tt来响应重置命令。
>达到预设时设置完成位。
* /


public
unsigned long _Accumulator = 0 ;
bool _Reset: 1 ;
bool _Enable: 1 ;
bool _完成: 1 ;
bool _OSRise: 1 ;
bool _Control: 1 ;

private
unsigned _Preset;
unsigned long _CurrentMillis;
unsigned long _LastMillis = 0 ;
bool _TimerRunning: 1 ;
bool _OSFall: 1 ;
bool _OSRSetup: 1 ;
bool _OSFSetup: 1 ;


public
// constructor - 允许在实例化时设置变量
// 定时器默认情况下使用false实例化

@PLCtimer :: PLCtimer( unsigned long pre,boolean en = 0
{
_Preset = pre;
negativePresetWarning(pre); // 预设验证
}; // 结束构造函数
/ *
来自pert @ Arduino.cc的用户添加错误处理程序,发布#13
主题http://forum.arduino.cc/index.php? topic = 559655.new #new
定时器可能没有负预设值。
* /

void negativeError( void )__ attribute __((错误( 负PLCtimer预设!检查实例化!)));
void negativePresetWarning( unsigned long number){
if (number< 0 ){
negativeError( );
}
}
/ *
===== Access计时器状态/控件的功能
* /

// 允许启动/停止计时器
void setEN( bool en){
_Enable = en;
}
// 允许重置计时器
void setres( bool res){
_Reset = res;
}
// 返回启用状态的计时器
byte getEN (){
return _Enable;
}
// 返回计时器的重置状态
bool getres(){
return _Reset;
}
// 返回计时器的完成状态
bool getDn(){
return _Done;
}
// 返回计时器的计时器时间状态
< span class =code-keyword> bool
getTt(){
return _TimerRunning;
}
// 返回计时器的计时器时间状态
< span class =code-keyword> bool getIntv(){
return _TimerRunning;
}
// 返回一次性上升的计时器状态
bool getOSRise(){
return _OSRise;
}
// 返回一次性完成的计时器状态
bool getOSFall(){
return _OSFall;
}
私人
/ *
虚拟计时器重置函数
重置条件由后代确定
* /

virtual bool 重置();

public

// 操作在PLCtimer下创建的计时器的功能
// - ---------------------------------------
// 更新计时器累计值&条件
// flags'tt'(定时器时间)和'dn'(完成)基于
// 关于计时器类型。
// 函数返回已完成的布尔状态,'dn'
// ===========================

boolean update(){
_CurrentMillis = millis(); // 获取系统时钟标记
if (_Enable _Control){ // 计时器已启用
_Accumulator = _Accumulator + _CurrentMillis - _LastMillis;
if (_Accumulator> = _Preset){ // 计时器完成?
_Accumulator = _Preset; // 不要让累加器逃跑
_Done = ;
}
}
_LastMillis = _CurrentMillis;

// 9/25/18 - 修改虚函数Reset()返回
// 布尔值。派生类现在只返回yes / no
// 到基类来处理重置已完成和清算
// 累加器。
// 与派生类中的重置相比,这节省了50多个字节。

if (重置()){ // 了解是否需要根据派生类的标准重置。
_Done = false ;
_Accumulator = 0 ;
}

/ *
-----生成一个计时器上的正向一次性脉冲完成ft转换
* /

_OSRise =(_完成 _OSRSetup);
_OSRSetup =!_完成;
/ *
-----以及计时器完成的另一个正向一次性脉冲转换
* /

_OSFall =(!_Done _OSFSetup);
_OSFSetup = _Done;
/ *
-----条件定时器时间状态
* /

if ((_Enable _Control)!_完成!_Reset){
_TimerRunning = true ;
}
else _TimerRunning = false ;
return _完成;
}; // 基类更新结束定时器操作

}; // 类结束PLCtimer

void setup(){
}

void loop(){

} // 循环结束





我尝试了什么:



代替屏幕截图这里是我正在使用的命令行。



>>> python make_cpp_class.py PLCtimer c:\documents\arduino \PLCtimer_python \PLCtimer_python.ino

解决方案

你好,我也想学习它。我们可以沟通一起?

I downloaded this A C++ Class Code Generator[^] and also python to run it. I think I've entered the right command line but I get an 'invalid syntax' error.

TIA

The Arduino code:

/*
    Basic timer converted to polymorphic/inherited form.
    Utilizes virtual function to effect timer reset.

    reference Arduino.cc thread http://forum.arduino.cc/index.php?topic=567010.new#new
*/

// debounce disabled for users without the library
//#include <Bounce2.h>

#define BUTTON_PIN 6   // to enable the timer DIO6
#define RESET_PIN 8    // to reset a timer DIO8
#define externalLED1 7 //  +5--/\/\/-->|--DIO7

byte LED_PIN = 13;    // on board LED

// Instantiate a Bounce object
//Bounce debouncer = Bounce();

// create a class called 'PLCtimer'

class PLCtimer {
    /*
       This is the base class - All types:
       > produce a positive-going one-scan pulse 'os' upon reaching
       preset value.
       > respond to a reset command by setting accumulated value to
       zero and resetting done and tt.
       > set the done bit upon reaching preset.
    */

  public:
    unsigned long _Accumulator = 0;
    bool _Reset: 1;
    bool _Enable: 1;
    bool _Done: 1;
    bool _OSRise: 1;
    bool _Control: 1;

  private:
    unsigned long _Preset;
    unsigned long _CurrentMillis;
    unsigned long _LastMillis = 0;
    bool _TimerRunning: 1;
    bool _OSFall: 1;
    bool _OSRSetup: 1;
    bool _OSFSetup: 1;


  public:
    // constructor - permits setting of variables upon instantiation
    // Timers are instantiated with enable false by default

    @PLCtimer::PLCtimer(unsigned long pre, boolean en = 0)
    {
      _Preset = pre;
      negativePresetWarning(pre); // preset validation
    }; // end constructor
    /*
       User-added error handler from pert @ Arduino.cc, post #13
       thread http://forum.arduino.cc/index.php?topic=559655.new#new
       Timers may not have a negative preset value.
    */
    void negativeError( void ) __attribute__((error("Negative PLCtimer preset! Check instantiations!")));
    void negativePresetWarning(unsigned long number) {
      if (number < 0) {
        negativeError();
      }
    }
    /*
      ===== Access functions for timer status/controls
    */
    // Allows to start/stop a timer
    void setEN(bool en) {
      _Enable = en;
    }
    // Allows to reset a timer
    void setres(bool res) {
      _Reset = res;
    }
    // Returns enable state of timer
    byte getEN() {
      return _Enable;
    }
    // Returns reset state of timer
    bool getres() {
      return _Reset;
    }
    // Returns done status of timer
    bool getDn() {
      return _Done;
    }
    // Returns timer timing state of timer
    bool getTt() {
      return _TimerRunning;
    }
    // Returns timer timing state of timer
    bool getIntv() {
      return _TimerRunning;
    }
    // Returns state of timer done rising one-shot
    bool getOSRise() {
      return _OSRise;
    }
    // Returns state of timer done falling one-shot
    bool getOSFall() {
      return _OSFall;
    }
  private:
    /*
       Virtual timer Reset function
       Reset conditions to be determined by descendants
    */
    virtual bool Reset();

  public:

    //    Function to operate timers created under PLCtimer
    //    ----------------------------------------
    //    Update timer accumulated value & condition
    //    flags 'tt' (timer timing) and 'dn' (done) based
    //    on timer type.
    //    Function returns boolean status of done, 'dn'
    //    ===========================

    boolean update() {
      _CurrentMillis = millis(); // Get system clock ticks
      if (_Enable or _Control) { // timer is enabled to run
        _Accumulator = _Accumulator + _CurrentMillis - _LastMillis;
        if (_Accumulator >= _Preset) { // timer done?
          _Accumulator = _Preset; // Don't let accumulator run away
          _Done = true;
        }
      }
      _LastMillis = _CurrentMillis;

      // 9/25/18 - Modified the virtual function Reset() to return
      // a boolean.  The derived classes now only return a yes/no
      // to the base class to handle resetting of done and clearing
      // of accumulator.
      // This saves 50+ bytes versus resetting in the derived classes.

      if ( Reset()) { // Find out if reset needed based on derived class' criteria.
        _Done = false;
        _Accumulator = 0;
      }
     
      /*
        ----- Generate a positive going one-shot pulse on timer done f-t transition
      */
      _OSRise = (_Done and _OSRSetup);
      _OSRSetup = !_Done;
      /*
        ----- and another positive going one-shot pulse on timer done t-f transition
      */
      _OSFall = (!_Done and _OSFSetup);
      _OSFSetup = _Done;
      /*
        ----- condition the timer timing status
      */
      if ((_Enable or _Control) and !_Done and !_Reset) {
        _TimerRunning = true;
      }
      else _TimerRunning = false;
      return _Done;
    }; // end of base class update Timer operation

} ; // end of class PLCtimer

void setup() {
}

void loop() {
 
} //end of loop



What I have tried:

In lieu of a screen shot here's the command line I'm using.

>>> python make_cpp_class.py PLCtimer c:\documents\arduino\PLCtimer_python\PLCtimer_python.ino

解决方案

hello,I want to learn it too.Can we communication together?


这篇关于代码生成器是否适用于arduino文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆