ALAA72
January 15, 2020, 7:06am
#1
hey everyone, back again!
I am trying to develop my code out of an Arduino/Adafruit libraries. but first I need to fully understand it. here is what's going on:
below you can see the .h CONSTRUCTOR, Adafriut_Thermal, which takes two parameters: *s and dtr:
// Constructor
Adafruit_Thermal::Adafruit_Thermal(Stream *s, uint8_t dtr) :
stream(s), dtrPin(dtr) {
dtrEnabled = false;
}
and in the .cpp file you can see the definition of privet variables:
private:
Stream
*stream;
uint8_t
dtrPin; // DTR handshaking pin (experimental)
now here are the questions:
1- is stream() a function? I've searches online about stream() but I got nothing...
2- if dtrPin is a variable name, then why use it like dtrPin()? like a function???
what is going on???
Hi,
What do you want your code to do that needs a library to be scrutinized?
Tom…
pert
January 15, 2020, 7:37am
#3
ALAA72:
1- is stream() a function? I've searches online about stream() but I got nothing...
It's a class that is a standardized piece of the Arduino core library:
/*
Stream.h - base class for character-based streams.
Copyright (c) 2010 David A. Mellis. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
parsing functions based on TextFinder library by Michael Margolis
*/
This file has been truncated. show original
ALAA72:
2- if dtrPin is a variable name, then why use it like dtrPin()? like a function???
That's called "member initialization". It's just an alternate way of initializing class member in a constructor:
http://www.cplusplus.com/doc/tutorial/classes/#member_initialization
Juraj
January 15, 2020, 8:17am
#4
// Constructor
Adafruit_Thermal::Adafruit_Thermal(Stream *s, uint8_t dtr) :
stream(s), dtrPin(dtr) {
dtrEnabled = false;
}
does the same as
// Constructor
Adafruit_Thermal::Adafruit_Thermal(Stream *s, uint8_t dtr) {
stream = s;
dtrPin = dtr;
dtrEnabled = false;
}
the first version would be neccessary for const Stream* stream.
Stream is a base class for hardware Serials, SoftwareSerial, networking Client, UDP etc.
the library doesn't need to be a class. you can ave standalone functions in library. they can be grouped by a name space