Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break out firmware into multiple classes. #46

Merged
merged 8 commits into from
May 4, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: Google
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ include/
.vscode/ipch
_electronic/e-tkt-backups/
_electronic/fp-info-cache
src/optConfig.cpp
src/simulator/__pycache__/
2 changes: 1 addition & 1 deletion _3dprint/customPressWheels/source/pressWheel.scad
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//pressing carousel for DYMO label tabe
//pressing daisy wheel for DYMO label tabe

/*maybe it come in handy to calculate the deflection of the tongues (beams)
starting point: https://mechanicalc.com/reference/beam-deflection-tables
Expand Down
4 changes: 2 additions & 2 deletions data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ <h1 style="font-size: 36px; margin: 0px; transform: rotate(-2deg)">SETUP</h1>
<button
type="button"
id="test-full-button"
onclick="testCommand(true)"
onclick="testFullCommand()"
value="test"
tabindex="-1"
style="width: 75px; height: 100%; position: relative; bottom: 0px; border-radius: 21px"
Expand All @@ -435,7 +435,7 @@ <h1 style="font-size: 36px; margin: 0px; transform: rotate(-2deg)">SETUP</h1>
<input
type="button"
id="test-align-button"
onclick="testCommand(false)"
onclick="testAlignCommand()"
value="test"
tabindex="-1"
style="width: 65px; height: 32px; position: absolute; top: 5px"
Expand Down
44 changes: 25 additions & 19 deletions data/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async function labelCommand() {
if (isValidLabelText()) {
document.getElementById("text-input").blur();
setUiBusy(true);
let response = await postJson("api/task", { parameter: "tag", value: buildTreatedLabel().toLowerCase() });
let response = await postJson("api/tag", { tag: buildTreatedLabel().toLowerCase() });
if (!response.ok) {
console.error("Unable to feed");
console.error((await response.json())["error"]);
Expand Down Expand Up @@ -432,7 +432,7 @@ async function reelCommand() {
toggleSettings(false);
setUiBusy(true);
document.getElementById("submit-button").value = " reeling... ";
let response = await postJson("api/task", { parameter: "reel", value: "" });
let response = await postJson("api/reel", {});
if (!response.ok) {
console.error("Unable to reel");
console.error((await response.json())["error"]);
Expand All @@ -444,7 +444,7 @@ async function feedCommand() {
// sends feed command to the device
setUiBusy(true);
document.getElementById("submit-button").value = " feeding... ";
let response = await postJson("api/task", { parameter: "feed", value: "" });
let response = await postJson("api/feed", {});
if (!response.ok) {
console.error("Unable to feed");
console.error((await response.json())["error"]);
Expand All @@ -455,31 +455,37 @@ async function cutCommand() {
// sends cut command to the device
setUiBusy(true);
document.getElementById("submit-button").value = " cutting... ";
let response = await postJson("api/task", { parameter: "cut", value: "" });
let response = await postJson("api/cut", { });
if (!response.ok) {
console.error("Unable to cut");
console.error((await response.json())["error"]);
}
}

async function testCommand(testFull) {
async function testAlignCommand() {
// sends test command to the device
align = document.getElementById("align-field").value;
force = document.getElementById("force-field").value;
let data;
if (testFull) {
data = {
parameter: "testfull",
value: align + "," + force,
};
} else {
data = {
parameter: "testalign",
value: align + "," + 1,
};
let data = {
align: align,
};
setUiBusy(true);
let response = await postJson("api/testalign", data);
if (!response.ok) {
console.error("Unable to perform test");
console.error((await response.json())["error"]);
}
}

async function testFullCommand() {
// sends test command to the device
align = document.getElementById("align-field").value;
force = document.getElementById("force-field").value;
let data = {
align: align,
force: force,
};
setUiBusy(true);
let response = await postJson("api/task", data);
let response = await postJson("api/testfull", data);
if (!response.ok) {
console.error("Unable to perform test");
console.error((await response.json())["error"]);
Expand All @@ -497,7 +503,7 @@ async function settingsCommand() {
if (confirm("Confirm saving align [" + align + "] and force [" + force + "] settings?")) {
setUiBusy(true);
document.getElementById("submit-button").value = " saving... ";
let response = await postJson("api/task", { parameter: "save", value: align + "," + force });
let response = await postJson("api/save", { align: align, force: force });
if (!response.ok) {
console.error("Unable to save settings");
console.error((await response.json())["error"]);
Expand Down
2 changes: 1 addition & 1 deletion docs/diy/assembly/07_top.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ nav_order: 8
1. pass the flat cables for both DIP LEDs through the pathway;
2. "click" the LEDs into their slots, and you might need carefully to cut a bit of material just enough to make sure it fits firmly;
3. using a flat plier might help pressing them;
4. strech the cables and make sure no segments are falling outside the boundaries, otherwise the daisywheel might be prevented from spinning;
4. strech the cables and make sure no segments are falling outside the boundaries, otherwise the daisy wheel might be prevented from spinning;
5. crimp the dupont connectors observing the polarity: arrows shoud be ground;
6. place 2x 2-via 2.54mm caps.

Expand Down
2 changes: 1 addition & 1 deletion docs/diy/calibration.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ You will see a xray of the machine, and now we will proceed to the first part of

- the align values ranges from 1 to 9, having 5 as a default (middle).
- now click the "TEST" button to the right side of "align";
- the machine will slowly and lightly press the carousel letter;
- the machine will slowly and lightly press the daisy wheel letter;
- the goal is to have the press to be fully aligned with the character, that should also be right in the middle of the character window;
- adjust the values and test to make sure it is alright;

Expand Down
2 changes: 1 addition & 1 deletion docs/iterations/2021-10-a.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ parent: 🧬 iterations

<img src="https://user-images.githubusercontent.com/15098003/171294518-0ee089ec-255e-46a0-abe0-e298e0d07006.jpg" width="50%"><img src="https://user-images.githubusercontent.com/15098003/171293788-a3c86e39-3c88-48ff-a122-75b7ea9d374d.jpg" width="50%"><img src="https://user-images.githubusercontent.com/15098003/171293793-1dca584e-916c-40a4-add9-b05708c3230d.jpg" width="50%"><img src="https://user-images.githubusercontent.com/15098003/171293818-2b2414f0-f8f0-498c-aa39-45508902d81a.jpg" width="50%"><img src="https://user-images.githubusercontent.com/15098003/171293826-48109b19-11f2-4779-9642-5519e0dd244f.jpg" width="50%"><img src="https://user-images.githubusercontent.com/15098003/171293852-4b092ac5-6451-4703-9160-5ec2a5f6b692.jpg" width="50%"><img src="https://user-images.githubusercontent.com/15098003/171293895-25f8f618-5549-4cfc-b32f-48ae933e61ac.jpg" width="50%"><img src="https://user-images.githubusercontent.com/15098003/171294180-9392b450-8d6c-4aad-9176-0f81f5f763c9.jpg" width="50%">

- More compact device, with smaller stepper motor for the carousel.
- More compact device, with smaller stepper motor for the daisy wheel.
- Tested using NFC to open web app on smartphone, failed (security standards?).
- OLED display to help on configuration and feedback.
- QR code as an alternative to quickly open web app.
Expand Down
44 changes: 44 additions & 0 deletions src/Characters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "Characters.h"

#include <Arduino.h>
#include <U8g2lib.h>


void Characters::initialize() {
// Iterate over the keys in CHARACTERS and return the maximum
// value. This is the number of characters in the wheel.
this->characterCount = 0;
for (auto const& x : CHARACTERS) {
if (x.second > this->characterCount) {
this->characterCount = x.second;
}
}

this->characterCount++;
}

int Characters::getCharacterIndex(String character) {
auto candidate = CHARACTERS.find(character);
if (candidate == CHARACTERS.end()) {
return -1;
}
return candidate->second;
}

FontInfo Characters::getFont(String character) {
auto candidate = GLYPHS.find(character);
if (candidate == GLYPHS.end()) {
return FontInfo(u8g2_font_6x13_te, 0, 7, 0, 0);
}
return FontInfo(*(candidate->second));
}

int Characters::getCharacterFrequency(String character) {
auto index = this->getCharacterIndex(character);
if (index < 0) {
return 0;
}
return NOTES[index];
}

int Characters::getWheelCharacterCount() { return this->characterCount; }
67 changes: 67 additions & 0 deletions src/Characters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#pragma once

#include <Arduino.h>
#include <U8g2lib.h>

#include <map>

#include "pitches.h"


const std::map<String, int> CHARACTERS = {
{"$", 0}, {"-", 1}, {".", 2}, {"0", 26}, {"1", 20}, {"2", 3}, {"3", 4},
{"4", 5}, {"5", 6}, {"6", 7}, {"7", 8}, {"8", 9}, {"9", 10}, {"*", 11},
{"A", 12}, {"B", 13}, {"C", 14}, {"D", 15}, {"E", 16}, {"F", 17}, {"G", 18},
{"H", 19}, {"I", 20}, {"J", 21}, {"K", 22}, {"L", 23}, {"M", 24}, {"N", 25},
{"O", 26}, {"P", 27}, {"Q", 28}, {"R", 29}, {"S", 30}, {"T", 31}, {"U", 32},
{"V", 33}, {"W", 34}, {"X", 35}, {"Y", 36}, {"Z", 37}, {"♡", 38}, {"☆", 39},
{"♪", 40}, {"€", 41}, {"@", 42}};

const int NOTES[] = {G4, G6, A4, D4, E4, F4, G5, A5, B5, C5, D5, 0, E5, F5, C6,
D6, E6, F6, A6, B6, C4, C7, D7, E7, F7, G7, B4, A7, B7, C8,
D8, C3, D3, E3, F3, G3, A3, B3, E2, F2, G2, A2, B2, 0};

struct FontInfo {
const uint8_t* font;
int code;
int width;
int width_offset;
int height_offset;
bool isSymbol() { return font != u8g2_font_6x13_te; }

FontInfo(const uint8_t* font, int code, int width, int width_offset,
int height_offset) {
this->font = font;
this->code = code;
this->width = width;
this->width_offset = width_offset;
this->height_offset = height_offset;
}
};

/**
* For each non-ascii "glyph" character, maps it to a tuple of (font, symbol
* code, width, x offset, y offset). These values are used to align the redered
* glyph with the rest of the label text which is from a font with different
* spacing.
*/
const std::map<String, FontInfo*> GLYPHS = {
{"♡", new FontInfo(u8g2_font_6x12_t_symbols, 0x2664, 5, -1, -1)},
{"☆", new FontInfo(u8g2_font_6x12_t_symbols, 0x2605, 5, -1, -1)},
{"♪", new FontInfo(u8g2_font_siji_t_6x10, 0xE271, 5, -3, 0)},
{"€", new FontInfo(u8g2_font_6x12_t_symbols, 0x20AC, 6, -1, -1)}};
/**
* @brief Manages the characters that can be printed on the
* E-TKT.
*/
class Characters {
private:
int characterCount;

public:
void initialize();
int getCharacterIndex(String character);
FontInfo getFont(String character);
int getWheelCharacterCount();
int getCharacterFrequency(String character);
};
110 changes: 110 additions & 0 deletions src/Configuration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#pragma once

#include <Arduino.h>

/**
* Basic Configuration
*
* Depending on the hardware you've used to build your E-TKT, you might need to
* enable some of these constants to get the hardware into a working state
*/

/**
* If your hall sensor has inverted logic (eg active LOW and neutral HIGH)
* uncomment this #define to invert the logic checking it. If you're affected by
* this then you'll see the character daisy wheel move forward slightly and then
* stop when the E-TKT starts up instead of moving to the "J" position.
*
* For instance, invert if using a "3144" hall sensor but don't invert if using
* a "44E 402" hall sensor. If you're not sure if you need this, try it both
* ways and see which one works.
*/
#define INVERT_HALL_SENSOR_LOGIC false

/**
* If your feed motor moves in the wrong direction by default, uncomment the
* define below to reverse it. It should be obvious if this is happening since
* the tape gets fed in the wrong direction.
*/
#define REVERSE_FEED_STEPPER_DIRECTION false

/**
* Speed and acceleration of the stepper motor that feeds the label tape,
* measured in steps/s and steps/s^2. Use lower values if you find that the
* printer doesn't consistently feed the correct length of tape between letters.
* For calibrating these values the same advice about the character stepper
* motor above applies. 4076 steps is one full revolution of the motor.
*/
#define FEED_STEPPER_MAX_SPEED 1000000
#define FEED_STEPPER_MAX_ACCELERATION 1000

/**
* Speed and acceleration of the stepper motor that rotates the character
* daisy wheel, measured in steps/s and steps/s^2. Use lower values if you find
* that the printer sometimes prints the wrong letter. Any value above zero is
* ok but lower values will slow down printing, if you're having trouble start
* by halving them and move up from there. The speed you can reliably achieve
* depends on the quality of the motor, how much current you've set it up to
* use, and how fast the ESP-32 can talk with it. 1600 steps is a full
* revolution of the daisy wheel.
*/
#define CHARACTER_STEPPER_MAX_SPEED 320000
#define CHARACTER_STEPPER_MAX_ACCELERATION 16000

/**
* Debugging
*
* Alter these to enable/disable individual parts of the hardware while
* troubleshooting.
*/
#define ENABLE_SOUND true
#define ENABLE_FEED true
#define ENABLE_CUT true
#define ENABLE_PRESS true
#define ENABLE_DAISYWHEEL true

/**
* Development
*
* Developers of the firmware may find it useful to turn on these features
*/
#define ENABLE_SERIAL false // Enables serial output
#define ENABLE_OTA false // Enables OTA updates at http://e-tkt.local/update
#define DEBUG_WIFI false // Enables WiFi debugging

/**
* Hardware Pins
*/
#define HALL_PIN 34 // hall sensor
#define WIFI_RESET_PIN 13 // tact switch
#define SERVO_PIN 14 // Press servo
#define CHARACTER_LED_PIN 17
#define FINISH_LED_PIN 5
#define PIN_STEPPER_CHAR_STEP 32
#define PIN_STEPPER_CHAR_DIR 33
#define PIN_STEPPER_CHAR_ENABLE 25
#define BUZZER_PIN 26

/**
* Physical Characteristics
*
* Physical characteristics of the printer. These are used to calculate the
* number of steps required to move and are unlikely to ever need to be changed.
*/

#define CHAR_MICROSTEPS 16
#define CHAR_STEP_COUNT 200
// depending on the hall sensor positioning, the variable below makes sure the
// initial calibration is within tolerance use a value between -1.0 and 1.0 to
// make it roughly align during assembly
#define ASSEMBLY_CALIBRATION_ALIGN 0.5f
#define CHAR_HOME_POSITION 21

// depending on servo characteristics and P_press assembling process, the
// pressing angle might not be so precise and the value below compensates it use
// a value between 0 and 20 to make sure the press is barely touching the daisy
// wheel on test align
#define ASSEMBLY_CALIBRATION_FORCE 15
#define MICROSTEPS_FEED 8
#define FEED_MOTOR_STEPS_PER_REVOLUTION 4076
#define HALL_SENSOR_THRESHOLD 128 // between 0 and 4096