Automatic Cronjob Checkin: 20150208-002231

This commit is contained in:
2015-02-07 23:22:32 +00:00
parent 8624842bbb
commit debb3e7ed0
15 changed files with 2413 additions and 1043 deletions
+108
View File
@@ -0,0 +1,108 @@
/*
* Interrupt.hpp
*
* Created: 18.11.2014 00:27:52
* Author: netz
*/
#ifndef INTERRUPT_H_
#define INTERRUPT_H_
#include <util/delay.h>
template <typename Port, int pin_int, typename Led>
class IR {
public:
IR() {
this->init();
}
int read() {
if(intpin::value()) { //Is High, Abbort
return 254;
}
_delay_ms(4); //Wait 4ms
if(intpin::value()) { //Is High, Abbort
return 254;
}
intpin::wait_is_set(); //Wait for the rest of the init.
intpin::wait_is_clear(); // Init Complete, wait for first Byte
//Read First Byte must be 0!
if(this->read8bit() != 0) { //Is first Byte not 0 Abbort;
return 255;
}
//Read Second Byte must be 239!
if(this->read8bit() != 239) {
return 255;
}
//Read Byte 3 and 4 (Data Byte and Checksum Byte!
uint8_t a = this->read8bit();
uint8_t b = this->read8bit();
//Make Checksum Byte 3 + 4 must be 255!
if(a+b != 255) {
return 255;
}
return a; //Return Byte 3
}
//The Interrupt Function
void interrupt() {
led.red(1);
uint8_t code = this->read();
if(code == 255) {
_delay_ms(500);
} else if(code == 254) {
_delay_ms(1);
} else {
this->_code = code;
}
led.red(0);
EIFR |= (1<<INTF0);
}
uint8_t getCode() {
uint8_t ret = this->_code;
this->_code = 255;
return ret;
}
private:
Led led;
uint8_t _code;
void init() {
intpin::make_input();
this->_code = 255;
this->init_int();
}
void init_int() {
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Falling Edge
// INT1: Off
// Interrupt on any change on pins PCINT0-7: Off
// Interrupt on any change on pins PCINT8-14: Off
// Interrupt on any change on pins PCINT16-23: Off
EICRA=(0<<ISC11) | (0<<ISC10) | (1<<ISC01) | (0<<ISC00);
EIMSK=(0<<INT1) | (1<<INT0);
EIFR=(0<<INTF1) | (0<<INTF0);
}
uint8_t read8bit() {
uint8_t r = 0;
for (uint8_t i=0;i<8;i++) {
intpin::wait_is_set();
_delay_us(800);
if(intpin::read()) {
r |= (1<<i);
}
for(uint8_t j=0;j<50;j++) {
if(!intpin::value()) {
break;
}
_delay_us(20);
}
}
return r;
}
const typedef avrlib::pin<Port, pin_int> intpin;
};
#endif /* INTERRUPT_H_ */
-42
View File
@@ -1,42 +0,0 @@
/*
* Interrupt.hpp
*
* Created: 18.11.2014 00:27:52
* Author: netz
*/
#ifndef INTERRUPT_H_
#define INTERRUPT_H_
template <typename Port, int pin_int>
class Interrupt {
public:
Interrupt() {
init();
}
uint8_t is_active() {
return intpin::read();
}
private:
void init() {
intpin::make_input();
intpin::pullup();
init_int();
}
void init_int() {
// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// INT1: Off
// Interrupt on any change on pins PCINT0-7: Off
// Interrupt on any change on pins PCINT8-14: Off
// Interrupt on any change on pins PCINT16-23: Off
EICRA=(0<<ISC11) | (0<<ISC10) | (0<<ISC01) | (1<<ISC00);
EIMSK=(0<<INT1) | (1<<INT0);
EIFR=(0<<INTF1) | (1<<INTF0);
}
const typedef avrlib::pin<Port, pin_int> intpin;
};
#endif /* INTERRUPT_H_ */
+67 -10
View File
@@ -10,11 +10,13 @@
#include "hardware/pin.hpp"
#include <util/delay.h>
template <typename PortR, int pin_red, typename PortG, int pin_green, typename PortB, int pin_blue>
class Stripe {
public:
Stripe() {
init();
this->init();
}
void color(uint8_t r, uint8_t g, uint8_t b) {
OCR0B=r; //ROT
@@ -34,13 +36,70 @@ class Stripe {
static const uint8_t MAGENTA = 5;
static const uint8_t YELLOW = 6;
static const uint8_t WHITE = 7;
void off() {
this->timerOff();
stripered::make_low();
stripegreen::make_low();
stripeblue::make_low();
}
void on() {
this->timerOn();
}
void lower() {
if(OCR0B >= 5) {
OCR0B = OCR0B - 5;
} else {
OCR0B = 0;
}
if(OCR2B >= 5) {
OCR2B = OCR2B - 5;
} else {
OCR2B = 0;
}
if(OCR2A >= 5) {
OCR2A = OCR2A - 5;
} else {
OCR2A = 0;
}
}
void higher() {
if(OCR0B <= 250) {
OCR0B = OCR0B + 5;
} else {
OCR0B = 0;
}
if(OCR2B <= 250) {
OCR2B = OCR2B + 5;
} else {
OCR2B = 0;
}
if(OCR2A <= 250) {
OCR2A = OCR2A + 5;
} else {
OCR2A = 0;
}
}
private:
void init() {
stripered::make_output();
stripegreen::make_output();
stripeblue::make_output();
initTimer();
color(0, 0, 0);
this->initTimer();
this->color(0, 0, 0);
}
void timerOff() {
// OC0B output: Disconnected
// OC2A output: Disconnected
// OC2B output: Disconnected
TCCR0A &= ~(1<<COM0B1);
TCCR2A &= ~((1<<COM2A1) | (1<<COM2B1));
}
void timerOn() {
// OC0B output: Non-Inverted PWM
// OC2A output: Non-Inverted PWM
// OC2B output: Non-Inverted PWM
TCCR0A |= (1<<COM0B1);
TCCR2A |= (1<<COM2A1) | (1<<COM2B1);
}
void uninit();
void initTimer() {
@@ -49,31 +108,29 @@ class Stripe {
// Clock value: 8000,000 kHz
// Mode: Phase correct PWM top=0xFF
// OC0A output: Disconnected
// OC0B output: Non-Inverted PWM
// Timer Period: 0,06375 ms
// Output Pulse(s):
// OC0B Period: 0,06375 ms Width: 0 us
TCCR0A=(0<<COM0A1) | (0<<COM0A0) | (1<<COM0B1) | (0<<COM0B0) | (0<<WGM01) | (1<<WGM00);
TCCR0B=(0<<WGM02) | (0<<CS02) | (0<<CS01) | (1<<CS00);
TCCR0A=(0<<COM0A1) | (0<<COM0A0) | (0<<COM0B0) | (0<<WGM01) | (1<<WGM00);
TCCR0B=(0<<WGM02) | (1<<CS02) | (0<<CS01) | (0<<CS00);
TCNT0=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: 8000,000 kHz
// Mode: Phase correct PWM top=0xFF
// OC2A output: Non-Inverted PWM
// OC2B output: Non-Inverted PWM
// Timer Period: 0,06375 ms
// Output Pulse(s):
// OC2A Period: 0,06375 ms Width: 0 us
// OC2B Period: 0,06375 ms Width: 0 us
ASSR=(0<<EXCLK) | (0<<AS2);
TCCR2A=(1<<COM2A1) | (0<<COM2A0) | (1<<COM2B1) | (0<<COM2B0) | (0<<WGM21) | (1<<WGM20);
TCCR2B=(0<<WGM22) | (0<<CS22) | (0<<CS21) | (1<<CS20);
TCCR2A=(0<<COM2A0) | (0<<COM2B0) | (0<<WGM21) | (1<<WGM20);
TCCR2B=(0<<WGM22) | (1<<CS22) | (0<<CS21) | (1<<CS20);
TCNT2=0x00;
// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=(0<<OCIE0B) | (0<<OCIE0A) | (0<<TOIE0);
// Timer/Counter 2 Interrupt(s) initialization
TIMSK2=(0<<OCIE2B) | (0<<OCIE2A) | (0<<TOIE2);
this->timerOn();
}
const typedef avrlib::pin<PortR, pin_red> stripered;
const typedef avrlib::pin<PortG, pin_green> stripegreen;
+3
View File
@@ -43,6 +43,9 @@ namespace avrlib {
static void set_low() { set(false); }
static bool read() { return value(); }
static void pullup() { set_high(); }
static void wait_is_set() { do { } while (!(Port::pin() & (1<<Pin))); }
static void wait_is_clear() { do {} while ((Port::pin() & (1<<Pin))); }
};
}