Changeset 8189 for lang/cplusplus

Show
Ignore:
Timestamp:
03/20/08 17:23:11 (5 years ago)
Author:
mootoh
Message:

lang/cplusplus/gainer++: add continuos analog input example.

Location:
lang/cplusplus/gainer++
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • lang/cplusplus/gainer++/Makefile

    r8183 r8189  
    2020        $(CXX) -o $@ $^ $(LIBS) 
    2121 
     22gainer-cain: gainer-cain.o $(TARGET_LIB) 
     23        $(CXX) -o $@ $^ $(LIBS) 
    2224 
    2325clean: 
  • lang/cplusplus/gainer++/gainer.cc

    r8185 r8189  
    3131 
    3232  while (not self->end_) { 
    33     DEBUG_PRINT("next_event..."); 
     33    //DEBUG_PRINT("next_event..."); 
    3434 
    3535    fd_set fds; 
     
    4242      const size_t SIZE(80); 
    4343      char buf[SIZE]; 
    44       read(self->io_, buf, SIZE); 
     44      char ch(' '); 
     45      size_t i(0); 
     46      while ('*' != ch and i<SIZE) { 
     47        read(self->io_, &ch, 1); 
     48        buf[i++] = ch; 
     49      } 
     50      //read(self->io_, buf, SIZE); 
     51      //DEBUG_PRINT(buf); 
    4552      std::string s(buf); 
    4653 
     
    5360namespace Gainer { 
    5461  Gainer::Gainer(const std::string &path, int config) : 
    55     led_(false) 
     62      led_(false) 
    5663    , config_(config) 
    5764    , end_(false) 
     
    6875 
    6976  Gainer::~Gainer() { 
     77    reboot(); 
    7078    end_ = true; 
    7179    pthread_join(thread_, NULL); 
     
    101109 
    102110  void Gainer::set_led(bool flag)          { command(flag ? "h" : "l"); } 
    103   void Gainer::reboot()                    { command("Q", 1); } 
     111  void Gainer::reboot()                    { command("Q", 2); } 
    104112  void Gainer::peek_digital_inputs()       { command("R"); } 
    105113  void Gainer::peek_analog_inputs()        { command("I"); } 
     
    110118  void Gainer::set_digital_output(int n) { 
    111119    std::stringstream ss("D"); 
    112     for (int i(0); i< CONFIG[config_][DOUT]-1; i++) { 
     120    for (int i(0); i< CONFIG[config_][DOUT]-1; i++) 
    113121      ss << ' '; 
    114     } 
    115122    ss << n; 
    116123    command(ss.str()); 
     
    127134 
    128135  void Gainer::process_event(std::string &event) { 
    129     DEBUG_PRINT("event: " << event); 
     136    //DEBUG_PRINT("event: " << event); 
    130137    switch(event[0]) { 
    131138      case '!': // something wrong