basic magnetic encoder support (untested)

main
radex 2024-02-21 22:54:14 +01:00
parent 1914c026d2
commit d478fe34ea
Signed by: radex
SSH Key Fingerprint: SHA256:hvqRXAGG1h89yqnS+cyFTLKQbzjWD4uXIqw7Y+0ws30
3 changed files with 36 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include "stepper.h"
#include "memes.h"
#include "input.h"
#include "spindle.h"
void setup() {
setupDebug();
@ -27,6 +28,9 @@ void setup() {
if (!setupKeyboard()) {
fatal();
}
if (!setupSpindle()) {
fatal();
}
splashScreen();
}

27
firmware/src/spindle.cpp Normal file
View File

@ -0,0 +1,27 @@
#include <AS5600.h>
#include <Wire.h>
#include "spindle.h"
AS5600 spindle(&Wire);
bool setupSpindle() {
if (!spindle.begin()) {
Serial.println("Could not initialize spindle encoder");
return false;
} else if (!spindle.detectMagnet()) {
Serial.println("Could not detect magnet");
return false;
} else if (spindle.magnetTooWeak()) {
Serial.println("Magnet too weak");
return false;
} else if (spindle.magnetTooStrong()) {
Serial.println("Magnet too strong");
return false;
}
return true;
}
uint16_t getSpindlePosition() {
return spindle.readAngle();
}

5
firmware/src/spindle.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
bool setupSpindle();
/** 0..4095 (12-bit) */
uint16_t getSpindlePosition();