Skip to content

Instantly share code, notes, and snippets.

@basilfx
Created September 16, 2017 22:03
Show Gist options
  • Save basilfx/befee5f344edef2699e841f83f70429d to your computer and use it in GitHub Desktop.
Save basilfx/befee5f344edef2699e841f83f70429d to your computer and use it in GitHub Desktop.
Repetier Firmware and WS2812B using events
#ifndef CUSTOM_EVENTS_H_INCLUDED
#define CUSTOM_EVENTS_H_INCLUDED
extern void Custom_Initialize();
extern void Custom_Timer100MS();
extern void Custom_SetBedTemp(float temp, bool beep);
extern void Custom_Kill(bool only_steppers);
extern void Custom_JamDetected(int8_t id);
extern void Custom_HeaterDecoupled(int8_t id);
extern void Custom_HeaterDefect(int8_t id);
extern void Custom_FatalErrorOccured();
extern void Custom_ContinueFromFatalError();
#define EVENT_INITIALIZE {Custom_Initialize();}
#define EVENT_TIMER_100MS {Custom_Timer100MS();}
#define EVENT_SET_BED_TEMP(temp,beep) {Custom_SetBedTemp(temp,beep);}
#define EVENT_KILL(only_steppers) {Custom_Kill(only_steppers);}
#define EVENT_JAM_DETECTED {Custom_JamDetected(id);}
#define EVENT_HEATER_DECOUPLED(id) {Custom_HeaterDecoupled(id);}
#define EVENT_HEATER_DEFECT(id) {Custom_HeaterDefect(id);}
#define EVENT_FATAL_ERROR_OCCURED {Custom_FatalErrorOccured();}
#define EVENT_CONTINUE_FROM_FATAL_ERROR {Custom_ContinueFromFatalError();}
#endif // CUSTOM_EVENTS_H_INCLUDED
#include <Adafruit_NeoPixel.h>
#define LEDS_PIN 52
#define NUMBER_OF_LEDS 8
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMBER_OF_LEDS, LEDS_PIN, NEO_GRB + NEO_KHZ800);
bool errorMode = false;
int errorTimer = 0;
int errorDirection = 1;
float targetTemperatureC = 0.0;
void Custom_Initialize()
{
pixels.begin();
// Set to green.
for (int i = 0; i < NUMBER_OF_LEDS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 255, 0));
}
pixels.show();
}
void Custom_Timer100MS()
{
if (errorMode) {
if (errorTimer >= 10) {
errorDirection = -1;
}
else if (errorTimer <= 0) {
errorDirection = 1;
}
errorTimer = errorTimer + errorDirection;
for (int i = 0; i < NUMBER_OF_LEDS; i++) {
pixels.setPixelColor(i, pixels.Color(5 + (errorTimer * 10), 0, 0));
}
}
else {
if (targetTemperatureC == 0.0) {
for (int i = 0; i < NUMBER_OF_LEDS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 255, 0));
}
}
else {
int red = map(Extruder::getHeatedBedTemperature(), 0, (int) targetTemperatureC, 0, 255);
for (int i = 0; i < NUMBER_OF_LEDS; i++) {
pixels.setPixelColor(i, pixels.Color(red, 0, 255 - red));
}
}
}
pixels.show();
}
void Custom_SetBedTemp(float temp, bool beep)
{
targetTemperatureC = temp;
}
void Custom_Kill(bool only_steppers)
{
errorMode = true;
}
void Custom_JamDetected(int8_t id)
{
errorMode = true;
}
void Custom_HeaterDecoupled(int8_t id)
{
errorMode = true;
}
void Custom_HeaterDefect(int8_t id)
{
errorMode = true;
}
void Custom_FatalErrorOccured()
{
errorMode = true;
}
void Custom_ContinueFromFatalError()
{
errorMode = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment