Advertisement
CarlosDelfino

ZFM20 Header

Oct 5th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. /*
  2.  * ZFM20.h
  3.  *
  4.  *  Created on: 04/10/2014
  5.  *      Author: Carlos Delfino <consultoria@carlosdelfino.eti.br>
  6.  */
  7.  
  8. /**
  9.  * Classe de controle do Scanner ZFM20Series
  10.  */
  11. class ZFM20Series {
  12. public:
  13.     ZFM20Series(Stream *serial);
  14.     void begin(ZFM20Address p_add = ZFM20_DEFAULT_ADDRESS);
  15.     void sendPacket(ZFM20BasePackage p_pac);
  16. };
  17.  
  18. ZFM20Series::ZFM20Series(Stream * p_serial) {
  19.     ok = false;
  20.     scanner = p_serial;
  21.     address = ZFM20_DEFAULT_ADDRESS;
  22. }
  23.  
  24. void ZFM20Series::begin(ZFM20Address p_add) {
  25.     ZFM20Address old_add;
  26.     if (p_add != getAddress()) {
  27.         old_add = setAddress(p_add);
  28.     }
  29.     delay(500);
  30.     ok = doHandshake();
  31.     if (!ok && old_add) {
  32.         if (ZFM20SERIES_DEBUG) {
  33.             Serial.print(F("Begin Fail, return old add"));
  34.             Serial.println(old_add, HEX);
  35.         }
  36.         setAddress(old_add);
  37.     }
  38. }
  39. void ZFM20Series::sendPacket(ZFM20BasePackage p_pac) {
  40.  
  41.     (*scanner).write(1);
  42.     uint16_t sizedata = p_pac.size - 0x02; // menos dois bytes do checksum
  43. ..... // here have more code, similar, which send more others numbers.
  44.     scanner->flush();
  45.  
  46.     if (ZFM20SERIES_DEBUG) {
  47.         Serial.println(F("sendPacket()"));
  48.         Serial.println(F("************"));
  49.         Serial.flush();
  50.     }
  51.  
  52. }
  53.  
  54.  
  55. ////// ZFMTest.ino
  56. #define ZFM20SERIES_DEBUG true
  57.  
  58. #include "ZFM20Series.h"
  59.  
  60. ZFM20Series scanner(&Serial3);
  61.  
  62. void setup() {
  63.   Serial.begin(57600);
  64.  
  65.   Serial.println(F("\n\nInicializando o Scanner"));
  66.  
  67.   Serial.print(F("Address: 0x"));
  68.   Serial.println(scanner.getAddress(),HEX);
  69.  
  70.   Serial3.begin(57600);
  71.   Serial3.write(0xFF); // here send correct value
  72.   scanner.begin(); // here not send correct value
  73.  
  74. }
  75.  
  76. void loop() {
  77.   // put your main code here, to run repeatedly:
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement