basic magnetic encoder support (untested)
parent
1914c026d2
commit
d478fe34ea
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
bool setupSpindle();
|
||||
/** 0..4095 (12-bit) */
|
||||
uint16_t getSpindlePosition();
|
Loading…
Reference in New Issue