This repository has been archived by the owner on Mar 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from camrein/protocol_v3
Protocol v3
- Loading branch information
Showing
10 changed files
with
202 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "ezgraver_v3.h" | ||
|
||
#include <QDebug> | ||
#include <QByteArray> | ||
#include <QBuffer> | ||
|
||
#include "specifications.h" | ||
|
||
namespace Ez { | ||
|
||
void EzGraverV3::start(unsigned char const& burnTime) { | ||
_setBurnTime(burnTime); | ||
qDebug() << "starting engrave process"; | ||
_transmit(QByteArray::fromRawData("\xFF\x01\x01\x00", 4)); | ||
} | ||
|
||
void EzGraverV3::_setBurnTime(unsigned char const& burnTime) { | ||
if(burnTime < 0x01 || burnTime > 0xF0) { | ||
throw new std::out_of_range("burntime out of range"); | ||
} | ||
qDebug() << "setting burn time to:" << static_cast<int>(burnTime); | ||
|
||
QByteArray payload{"\xFF\x05?\x00", 4}; | ||
payload[2] = burnTime; | ||
_transmit(payload); | ||
} | ||
|
||
void EzGraverV3::pause() { | ||
qDebug() << "pausing engrave process"; | ||
_transmit(QByteArray::fromRawData("\xFF\x01\x02\x00", 4)); | ||
} | ||
|
||
void EzGraverV3::reset() { | ||
qDebug() << "resetting"; | ||
_transmit(QByteArray::fromRawData("\xFF\x04\x01\x00", 4)); | ||
} | ||
|
||
void EzGraverV3::home() { | ||
qDebug() << "moving to home"; | ||
_transmit(0xF3); | ||
} | ||
|
||
void EzGraverV3::center() { | ||
qDebug() << "moving to center"; | ||
_transmit(QByteArray::fromRawData("\xFF\x02\x01\x00", 4)); | ||
} | ||
|
||
void EzGraverV3::preview() { | ||
qDebug() << "drawing image preview"; | ||
_transmit(QByteArray::fromRawData("\xFF\x02\x02\x00", 4)); | ||
} | ||
|
||
void EzGraverV3::up() { | ||
qDebug() << "moving up"; | ||
_transmit(QByteArray::fromRawData("\xFF\x03\x01\x00", 4)); | ||
} | ||
|
||
void EzGraverV3::down() { | ||
qDebug() << "moving down"; | ||
_transmit(QByteArray::fromRawData("\xFF\x03\x02\x00", 4)); | ||
} | ||
|
||
void EzGraverV3::left() { | ||
qDebug() << "moving left"; | ||
_transmit(QByteArray::fromRawData("\xFF\x03\x03\x00", 4)); | ||
} | ||
|
||
void EzGraverV3::right() { | ||
qDebug() << "moving right"; | ||
_transmit(QByteArray::fromRawData("\xFF\x03\x04\x00", 4)); | ||
} | ||
|
||
int EzGraverV3::erase() { | ||
qDebug() << "erasing EEPROM"; | ||
_transmit(QByteArray::fromRawData("\xFF\x06\x01\x00", 4)); | ||
return 50; | ||
} | ||
|
||
int EzGraverV3::uploadImage(QImage const& originalImage) { | ||
qDebug() << "converting image to bitmap"; | ||
QImage image{originalImage | ||
.scaled(Ez::Specifications::ImageWidth, Ez::Specifications::ImageHeight) | ||
.mirrored() | ||
.convertToFormat(QImage::Format_Mono)}; | ||
QByteArray bytes{}; | ||
QBuffer buffer{&bytes}; | ||
image.save(&buffer, "BMP"); | ||
|
||
// protocol v3 neither needs the BMP header nor the invertion of the pixels. | ||
return EzGraver::uploadImage(bytes.mid(62)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#ifndef EZGRAVERV3_H | ||
#define EZGRAVERV3_H | ||
|
||
#include <QSerialPort> | ||
|
||
#include <memory> | ||
|
||
#include "ezgraver.h" | ||
|
||
namespace Ez { | ||
|
||
struct EzGraverV3 : EzGraver { | ||
using EzGraver::EzGraver; | ||
|
||
/*! | ||
* Starts the engraving process with the given \a burnTime. | ||
* | ||
* \param burnTime The burn time to use in milliseconds. | ||
*/ | ||
void start(unsigned char const& burnTime) override; | ||
|
||
/*! | ||
* Pauses the engraving process at the given location. The process | ||
* can be continued by invoking start. | ||
*/ | ||
void pause() override; | ||
|
||
/*! Resets the engraver. */ | ||
void reset() override; | ||
|
||
/*! Moves the engraver to the home position. */ | ||
void home() override; | ||
|
||
/*! Moves the engraver to the center. */ | ||
void center() override; | ||
|
||
/*! Draws a preview of the currently loaded image. */ | ||
void preview() override; | ||
|
||
/*! Moves the engraver up. */ | ||
void up() override; | ||
|
||
/*! Moves the engraver down. */ | ||
void down() override; | ||
|
||
/*! Moves the engraver left. */ | ||
void left() override; | ||
|
||
/*! Moves the engraver right. */ | ||
void right() override; | ||
|
||
/*! | ||
* Erases the EEPROM of the engraver. This is necessary before uploading | ||
* any new image to it. | ||
* Erasing the EEPROM takes a while. Sending image data to early causes | ||
* that some of the leading pixels are lost. Waiting for about 5 seconds | ||
* seems to be sufficient. | ||
* | ||
* \return The recommended time in ms to wait until uploading the image. | ||
*/ | ||
int erase() override; | ||
|
||
/*! | ||
* Uploads the given \a image to the EEPROM. It is mandatory to use \a erase() | ||
* it prior uploading an image. The image will automatically be scaled, inverted, | ||
* mirrored and converted to a monochrome bitmap. | ||
* | ||
* \param image The image to upload to the EEPROM for engraving. | ||
* \return The number of bytes being sent to the device. | ||
*/ | ||
int uploadImage(QImage const& image) override; | ||
|
||
private: | ||
void _setBurnTime(unsigned char const& burnTime); | ||
}; | ||
|
||
} | ||
|
||
#endif // EZGRAVERV3_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters