-
Notifications
You must be signed in to change notification settings - Fork 19
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
EOL refactor prototype #183
base: ayab-esp32
Are you sure you want to change the base?
Changes from all commits
ada1981
b9c4d6f
0fae84e
5fcf606
74d7c7a
b46fc2d
d240b15
a195b96
a069382
a058a7e
8d993f8
aa76597
b702457
18fedbe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"build": { | ||
"arduino":{ | ||
"ldscript": "esp32s3_out.ld", | ||
"partitions": "default.csv" | ||
}, | ||
"core": "esp32", | ||
"extra_flags": [ | ||
"-DARDUINO_USB_CDC_ON_BOOT=1", | ||
"-DARDUINO_RUNNING_CORE=1", | ||
"-DARDUINO_EVENT_RUNNING_CORE=1", | ||
"-DBOARD_HAS_PSRAM" | ||
], | ||
"f_cpu": "240000000L", | ||
"f_flash": "80000000L", | ||
"flash_mode": "qio", | ||
"hwids": [ | ||
[ | ||
"0x239A", | ||
"0x811B" | ||
], | ||
[ | ||
"0x239A", | ||
"0x011B" | ||
], | ||
[ | ||
"0x239A", | ||
"0x811C" | ||
] | ||
], | ||
"mcu": "esp32s3", | ||
"variant": "esp32s3" | ||
}, | ||
"connectivity": [ | ||
"bluetooth", | ||
"wifi" | ||
], | ||
"debug": { | ||
"openocd_target": "esp32s3.cfg" | ||
}, | ||
"frameworks": [ | ||
"arduino", | ||
"espidf" | ||
], | ||
"name": "AYAB-ESP32", | ||
"upload": { | ||
"flash_size": "4MB", | ||
"maximum_ram_size": 327680, | ||
"maximum_size": 4194304, | ||
"use_1200bps_touch": true, | ||
"wait_for_upload_port": true, | ||
"require_upload_port": true, | ||
"speed": 460800 | ||
}, | ||
"url": "https://ayab-knitting.com", | ||
"vendor": "AllYarnsAreBeautiful" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,8 @@ | |
* http://ayab-knitting.com | ||
*/ | ||
|
||
#include "board.h" | ||
#include <Arduino.h> | ||
|
||
#include "board.h" | ||
#include "encoders.h" | ||
|
||
|
||
|
@@ -52,15 +51,72 @@ void Encoders::encA_interrupt() { | |
* \brief Read hall sensor on left and right. | ||
* \param pSensor Which sensor to read (left or right). | ||
*/ | ||
uint16_t Encoders::getHallValue(Direction_t pSensor) { | ||
HallState_t Encoders::getHallValue(Direction_t pSensor) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a HallState is return from now on, we could rename the method to getHallState instead of getHallValue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I think that makes sense. |
||
#if defined(EOL_ANALOG) | ||
// Need to check if the polarity matches with the correct voltage swing. | ||
uint16_t sensorValue; | ||
|
||
switch (pSensor) { | ||
case Direction_t::Left: | ||
|
||
sensorValue = analogRead(EOL_PIN_L); | ||
if(sensorValue < FILTER_L_MIN[static_cast<uint8_t>(m_machineType)]) { | ||
return HallState_t::North; | ||
} | ||
else if (sensorValue > FILTER_L_MAX[static_cast<uint8_t>(m_machineType)]) { | ||
return HallState_t::South; | ||
} | ||
else { | ||
return HallState_t::None; | ||
} | ||
|
||
case Direction_t::Right: | ||
|
||
sensorValue = analogRead(EOL_PIN_R); | ||
if(sensorValue < FILTER_R_MIN[static_cast<uint8_t>(m_machineType)]) { | ||
return HallState_t::North; | ||
} | ||
else if (sensorValue > FILTER_R_MAX[static_cast<uint8_t>(m_machineType)]) { | ||
return HallState_t::South; | ||
} | ||
else { | ||
return HallState_t::None; | ||
} | ||
|
||
default: | ||
return HallState_t::Error; | ||
} | ||
|
||
#elif defined(EOL_COMPARATOR) | ||
|
||
switch (pSensor) { | ||
case Direction_t::Left: | ||
return analogRead(EOL_PIN_L); | ||
if(digitalRead(EOL_PIN_L_N)) { | ||
return HallState_t::North; | ||
} | ||
else if(digitalRead(EOL_PIN_L_S)){ | ||
return HallState_t::South; | ||
} | ||
else { | ||
return HallState::None; | ||
} | ||
|
||
case Direction_t::Right: | ||
return analogRead(EOL_PIN_R); | ||
if(digitalRead(EOL_PIN_R_N)) { | ||
return HallState_t::North; | ||
} | ||
else if(digitalRead(EOL_PIN_R_S)){ | ||
return HallState_t::South; | ||
} | ||
else { | ||
return HallState::None; | ||
} | ||
|
||
default: | ||
return 0; | ||
return HallState_t::Error; | ||
} | ||
|
||
#endif | ||
} | ||
|
||
/*! | ||
|
@@ -150,15 +206,14 @@ void Encoders::encA_rising() { | |
} | ||
|
||
// In front of Left Hall Sensor? | ||
uint16_t hallValue = analogRead(EOL_PIN_L); | ||
if ((hallValue < FILTER_L_MIN[static_cast<uint8_t>(m_machineType)]) || | ||
(hallValue > FILTER_L_MAX[static_cast<uint8_t>(m_machineType)])) { | ||
HallState_t hallValue = getHallValue(Direction_t::Left); | ||
if (hallValue == HallState_t::North || hallValue == HallState_t::South) { | ||
m_hallActive = Direction_t::Left; | ||
|
||
Carriage detected_carriage = Carriage_t::NoCarriage; | ||
uint8_t start_position = END_LEFT_PLUS_OFFSET[static_cast<uint8_t>(m_machineType)]; | ||
|
||
if (hallValue >= FILTER_L_MIN[static_cast<uint8_t>(m_machineType)]) { | ||
if (hallValue == HallState_t::North) { | ||
detected_carriage = Carriage_t::Knit; | ||
} else { | ||
detected_carriage = Carriage_t::Lace; | ||
|
@@ -208,21 +263,15 @@ void Encoders::encA_falling() { | |
} | ||
|
||
// In front of Right Hall Sensor? | ||
uint16_t hallValue = analogRead(EOL_PIN_R); | ||
|
||
// Avoid 'comparison of unsigned expression < 0 is always false' | ||
// by being explicit about that behaviour being expected. | ||
bool hallValueSmall = false; | ||
|
||
hallValueSmall = (hallValue < FILTER_R_MIN[static_cast<uint8_t>(m_machineType)]); | ||
HallState_t hallValue = getHallValue(Direction_t::Right); | ||
|
||
if (hallValueSmall || hallValue > FILTER_R_MAX[static_cast<uint8_t>(m_machineType)]) { | ||
if (hallValue == HallState_t::North || hallValue == HallState_t::South) { | ||
m_hallActive = Direction_t::Right; | ||
|
||
// The garter carriage has a second set of magnets that are going to | ||
// pass the sensor and will reset state incorrectly if allowed to | ||
// continue. | ||
if (hallValueSmall && (m_carriage != Carriage_t::Garter)) { | ||
if ((hallValue == HallState_t::North) && (m_carriage != Carriage_t::Garter)) { | ||
m_carriage = Carriage_t::Knit; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes are also required in the documentation of the API https://github.com/AllYarnsAreBeautiful/ayab-manual/blob/1.0.0-dev/docs/API.md