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

Teensy fixes #9

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
16 changes: 15 additions & 1 deletion Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@
#define RGB_LEDS
//#define RGBW_LEDS
//#define MATRIX_XXL
#define LPD_ALTLAYOUT
#endif

/*
* Welche Uhr soll benutzt werden?
*/
#define DS1307
//#define DS1307
// #define DS3231
#define TEENSYRTC

/*
* Welche IR-Fernbedienung soll benutzt werden?
Expand Down Expand Up @@ -178,6 +180,18 @@
*/
#define BUTTON_TRESHOLD 300

// Buttons sind kapazitive Button (Teensy)
#define TOUCHBUTTONS

//! Wie viele samples gesammelt werden, bis der Durchschnitt als stabil erachtet wird
#define TOUCHSAMPLES 1500

//! Minimal Erhöhung des Wertes, um mal als berüht zu gelten
#define TOUCHTHRESHOLD 30

//! Nummer der Samples die über dem Durchschnitt liegen müssen, vermeidet spontanes Rauschen
#define NUMTOUCHSAMPLES 3

// ------------------ DCF77-Empfaenger ---------------------
/*
* Fuer wieviele DCF77-Samples muessen die Zeitabstaende stimmen, damit das DCF77-Telegramm als gueltig zaehlt?
Expand Down
5 changes: 5 additions & 0 deletions LedDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "Settings.h"
#include "MyRTC.h"
#include "TeensyRTC.h"
#include "Transitions.h"
#include "Modes.h"
#include "Configuration.h"
Expand All @@ -32,7 +33,11 @@
extern volatile byte helperSeconds;
extern Mode mode;
extern Settings settings;
#ifdef TEENSYRTC
extern TeensyRTC rtc;
#else
extern MyRTC rtc;
#endif
extern bool evtActive;

/* Treiberkonfiguration */
Expand Down
53 changes: 53 additions & 0 deletions LedDriverLPD8806.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,59 @@ void LedDriverLPD8806::clearData() {
_strip->show();
}


#if defined(LDP_ALT_LAYOUT)
void LedDriverLPD8806::_setEcke(uint8_t ecke, uint32_t c) {
switch(ecke) {
case 0:
_strip->setPixelColor(1, c);
break;
case 1:
// led unten links + zeile + 1. led
_strip->setPixelColor(2 + 12 + 1 , c);
break;
case 2:
// 2 * leds + 9 zeilen + 1. led
_strip->setPixelColor(2*2 + 9 *12 + 1, c);
break;
case 3:
// 10 zeilen + 3 * leds
_strip->setPixelColor(10 *12 + (3 * 2) + 1, c);
break;
}
}

/**
* Einen X/Y-koordinierten Pixel in der Matrix setzen.
*/
void LedDriverLPD8806::_setPixel(byte x, byte y, uint32_t c) {
y = 9-y;
if (y % 2==1) {
// Gegenläufige Reiche
x = 11 -x;
} else {
// Ganz links freilassen
x = x;
}
if (y == 0) {
_strip->setPixelColor(2+x, c);
} else if (y <=8) {
_strip->setPixelColor(y*12 +4 + x, c);
} else {
// oberste reihe
_strip->setPixelColor(y*12 +6 + x, c);
}


}
#else
/**
Einen X/Y-koordinierten Pixel in der Matrix setzen.
*/
void LedDriverLPD8806::_setPixel(byte x, byte y, uint32_t c) {
_setPixel(x + (y * 11), c);
}
#endif

/**
Einen Pixel im Streifen setzten (die Eck-LEDs sind am Ende).
Expand Down Expand Up @@ -376,6 +423,12 @@ void LedDriverLPD8806::_setPixel(byte num, uint32_t c) {
;
}
}
#elif defined(LDP_ALT_LAYOUT)
if (num < 110) {
_setPixel(num, c);
} else {
_setEcke(num-110,c);
}
#else
if (num < 110) {
if ((num / 11) % 2 == 0) {
Expand Down
4 changes: 4 additions & 0 deletions LedDriverLPD8806.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class LedDriverLPD8806 : public LedDriver {
void _setPixel(byte x, byte y, uint32_t c);
void _setPixel(byte num, uint32_t c);

#ifdef LDP_ALT_LAYOUT
void _setEcke(uint8_t ecke, uint32_t c);
#endif

uint32_t _wheel(byte brightness, byte wheelPos);

void _clear();
Expand Down
3 changes: 3 additions & 0 deletions MyIRremote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "MyIRremote.h"
#include "MyIRremoteInt.h"

#ifndef __arm__

// Provides ISR
#include <avr/interrupt.h>

Expand Down Expand Up @@ -1160,3 +1162,4 @@ void IRsend::sendDISH(unsigned long data, int nbits) {
data <<= 1;
}
}
#endif
4 changes: 4 additions & 0 deletions MyIRremote.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#ifndef My_IRremote_h
#define My_IRremote_h
// ARM benutzt die normale IRremote Bibliothek
#ifndef __arm__

// The following are compile-time library options.
// If you change them, recompile the library.
Expand Down Expand Up @@ -126,3 +128,5 @@ class IRsend
#define MARK_EXCESS 100

#endif

#endif
2 changes: 2 additions & 0 deletions MyIRremoteInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#ifndef My_IRremoteint_h
#define My_IRremoteint_h
#ifndef __arm__

#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
Expand Down Expand Up @@ -515,3 +516,4 @@ extern volatile irparams_t irparams;
#endif

#endif
#endif
4 changes: 3 additions & 1 deletion MyRTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ class MyRTC : public TimeStamp {

byte getSeconds();

private:

int _address;
byte _statusLedPin;

protected:
byte _seconds;

byte decToBcd(byte val);
byte bcdToDec(byte val);
uint8_t conv2d(const char* p);

};

#endif
Expand Down
80 changes: 74 additions & 6 deletions Qlockthree.ino
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,18 @@
#include "IRTranslatorMooncandles.h"
#include "IRTranslatorLunartec.h"
#include "IRTranslatorCLT.h"
// Der Teenys hat 256k Flash und kein Problem mit der großen Orginal Bibliothek
#ifdef __arm__
#include <IRremote.h>
#endif

#include "MyIRremote.h"
#include "MyRTC.h"
#include "TeensyRTC.h"
#include "MyDCF77.h"
#include "Button.h"
#include "AnalogButton.h"
#include "TouchButton.h"
#include "LDR.h"
#include "DCF77Helper.h"
#include "Renderer.h"
Expand All @@ -207,7 +214,7 @@
Serial-Monitor muss mit der hier angegeben uebereinstimmen.
Default: ausgeschaltet
*/
// #define DEBUG
#define DEBUG
#include "Debug.h"
// Die Geschwindigkeit der seriellen Schnittstelle. Default: 57600. Die Geschwindigkeit brauchen wir immer,
// da auch ohne DEBUG Meldungen ausgegeben werden!
Expand Down Expand Up @@ -492,6 +499,30 @@ LedDriverLPD8806 ledDriver(13, 11);
#define PIN_DCF77_LED 8

#define PIN_SPEAKER -1
#elif defined(BOARD_TEENSY)
LedDriverLPD8806 ledDriver(7, 14);
#define PIN_MODE 16
#define PIN_M_PLUS 15
#define PIN_H_PLUS 17

#define BUTTONS_PRESSING_AGAINST LOW

#define PIN_IR_RECEIVER 10

#define PIN_LDR A6
#define IS_INVERTED true

#define PIN_SQW_SIGNAL -1
#define PIN_DCF77_SIGNAL 2

#define PIN_DCF77_PON -1

#define PIN_SQW_LED -1
#define PIN_DCF77_LED 13

#define PIN_SPEAKER -1
#else
#error Kein passendes Board für LPD8806 Treiber definiert
#endif

#endif
Expand Down Expand Up @@ -523,9 +554,15 @@ IRTranslatorCLT irTranslatorBT;
// Werden zur Kommunikation mit der
// RTC verwendet.
/**
Die Real-Time-Clock mit der Status-LED fuer das SQW-Signal.
*/
* Die Real-Time-Clock mit der Status-LED fuer das SQW-Signal.
*/
#ifdef TEENSYRTC
TeensyRTC rtc(PIN_SQW_LED);
IntervalTimer rtcTimer;
#else
MyRTC rtc(0x68, PIN_SQW_LED);
#endif

volatile byte helperSeconds;

/**
Expand Down Expand Up @@ -555,13 +592,21 @@ byte brightnessToDisplay;
/**
Die Tasten.
*/
#ifdef TOUCHBUTTONS
TouchButton minutesPlusButton(PIN_M_PLUS);
TouchButton hoursPlusButton(PIN_H_PLUS);
DoubleTouchButton extModeDoubleButton(minutesPlusButton, hoursPlusButton);
TouchButton modeChangeButton(PIN_MODE);
#else
Button minutesPlusButton(PIN_M_PLUS, BUTTONS_PRESSING_AGAINST);
Button hoursPlusButton(PIN_H_PLUS, BUTTONS_PRESSING_AGAINST);
Button extModeDoubleButton(PIN_M_PLUS, PIN_H_PLUS, BUTTONS_PRESSING_AGAINST);
Button modeChangeButton(PIN_MODE, BUTTONS_PRESSING_AGAINST);
#endif

// Startmode...
Mode mode = STD_MODE_NORMAL;
//Mode mode = EXT_MODE_TEST;
// Merker fuer den Modus vor der Abschaltung...
Mode lastMode = mode;

Expand Down Expand Up @@ -609,14 +654,25 @@ void updateFromRtc() {
}
}

#ifdef __arm__
/* unistd.h inkludieren definiert auch alarm, was Problem mit Alarm Klasse macht.
* deshalb prototype fur sbrk einzeln definieren*/
extern "C" char* sbrk(int incr);
#endif

/**
Den freien Specher abschaetzen.
Kopiert von: http://playground.arduino.cc/Code/AvailableMemory
*/
int freeRam() {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
#ifdef __arm__
char top;
return &top - reinterpret_cast<char*>(sbrk(0));
#else
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
#endif
}

/**
Expand Down Expand Up @@ -698,6 +754,8 @@ void setup() {
#elif defined DS3231
DEBUG_PRINTLN(F("Uhrentyp ist DS3231."));
rtc.enableSQWOnDS3231();
#elif defined TEENSYRTC
DEBUG_PRINTLN(F("Uhrentyp ist Teensy RTC (Freescale MK20)"));
#else
Definition_des_Uhrtyps_fehlt!
In der Configuration.h muss der Uhrentyp angegeben werden!
Expand Down Expand Up @@ -729,6 +787,16 @@ void setup() {
for (int i = 0; i < 1000; i++) {
analogRead(PIN_LDR);
}
#ifdef TEENSYRTC
// Bei der internen RTC vom Teensy wird kein Rechtecksignal
// an einem externen pin geniert. Deshalb normaler Software Timer
// IntervalTimer ist hochpräziser Timer, eigentlich unnötig
rtcTimer.priority(255);
if(!rtcTimer.begin(updateFromRtc, 1*1000*1000))
Serial.printf("Failed to set teensy timer\n");
#else
attachInterrupt(0, updateFromRtc, FALLING);
#endif

// rtcSQWLed-LED drei Mal als 'Hello' blinken lassen
// und Speaker piepsen kassen, falls ENABLE_ALARM eingeschaltet ist.
Expand Down
4 changes: 2 additions & 2 deletions Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void Settings::setDcfSignalIsInverted(boolean dcfSignalIsInverted) {
/**
* Zeitverschiebung
*/
char Settings::getTimeShift() {
signed char Settings::getTimeShift() {
return _timeShift;
}

Expand All @@ -166,7 +166,7 @@ void Settings::setJumpToNormalTimeout(byte jumpToNormalTimeout) {
_jumpToNormalTimeout = jumpToNormalTimeout;
}

void Settings::setTimeShift(char timeShift) {
void Settings::setTimeShift(signed char timeShift) {
_timeShift = timeShift;
}

Expand Down
6 changes: 3 additions & 3 deletions Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class Settings {
boolean getDcfSignalIsInverted();
void setDcfSignalIsInverted(boolean dcfSignalIsInverted);

char getTimeShift();
void setTimeShift(char timeShift);
signed char getTimeShift();
void setTimeShift(signed char timeShift);

byte getJumpToNormalTimeout();
void setJumpToNormalTimeout(byte jumpToNormalTimeout);
Expand All @@ -88,7 +88,7 @@ class Settings {
byte _brightness;
boolean _enableAlarm;
boolean _dcfSignalIsInverted;
char _timeShift;
signed char _timeShift;
eColors _color;
byte _transitionMode;
byte _event;
Expand Down
Loading