Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Misc fixes. #46

Merged
merged 4 commits into from
Apr 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 17 additions & 24 deletions Adafruit_Thermal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ void Adafruit_Thermal::timeoutSet(unsigned long x) {
// This function waits (if necessary) for the prior task to complete.
void Adafruit_Thermal::timeoutWait() {
if (dtrEnabled) {
while (digitalRead(dtrPin) == HIGH)
;
while (digitalRead(dtrPin) == HIGH) {
yield();
};
} else {
while ((long)(micros() - resumeTime) < 0L)
; // (syntax is rollover-proof)
while ((long)(micros() - resumeTime) < 0L) {
yield();
}; // (syntax is rollover-proof)
}
}

Expand Down Expand Up @@ -163,12 +165,6 @@ size_t Adafruit_Thermal::write(uint8_t c) {
return 1;
}

/*!
@def printDensity
Printing density, default: 100% (? can go higher, text is darker but fuzzy)
@def printBreakTime
Printing break time. Default: 500 uS
*/
void Adafruit_Thermal::begin(uint16_t version) {

firmware = version;
Expand All @@ -183,20 +179,6 @@ void Adafruit_Thermal::begin(uint16_t version) {

setHeatConfig();

// Print density description from manual:
// DC2 # n Set printing density
// D4..D0 of n is used to set the printing density. Density is
// 50% + 5% * n(D4-D0) printing density.
// D7..D5 of n is used to set the printing break time. Break time
// is n(D7-D5)*250us.
// (Unsure of the default value for either -- not documented)

#define printDensity 10

#define printBreakTime 2

writeBytes(ASCII_DC2, '#', (printBreakTime << 5) | printDensity);

// Enable DTR pin if requested
if (dtrPin < 255) {
pinMode(dtrPin, INPUT_PULLUP);
Expand Down Expand Up @@ -456,6 +438,17 @@ void Adafruit_Thermal::setHeatConfig(uint8_t dots, uint8_t time,
writeBytes(dots, time, interval); // Heating dots, heat time, heat interval
}

// Print density description from manual:
// DC2 # n Set printing density
// D4..D0 of n is used to set the printing density. Density is
// 50% + 5% * n(D4-D0) printing density.
// D7..D5 of n is used to set the printing break time. Break time
// is n(D7-D5)*250us.
// (Unsure of the default value for either -- not documented)
void Adafruit_Thermal::setPrintDensity(uint8_t density, uint8_t breakTime) {
writeBytes(ASCII_DC2, '#', (density << 5) | breakTime);
}

// Underlines of different weights can be produced:
// 0 - no underline
// 1 - normal underline
Expand Down
6 changes: 6 additions & 0 deletions Adafruit_Thermal.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ class Adafruit_Thermal : public Print {
* @param interval heating interval, 10 us per increment
*/
setHeatConfig(uint8_t dots=11, uint8_t time=120, uint8_t interval=40),
/*!
* @brief Sets print density
* @param density printing density
* @param breakTime printing break time
*/
setPrintDensity(uint8_t density=10, uint8_t breakTime=2),
/*!
* @brief Puts the printer into a low-energy state immediately
*/
Expand Down