diff --git a/VortexEngine/src/Wireless/IRSender.cpp b/VortexEngine/src/Wireless/IRSender.cpp index c2260112b9..1d127a1978 100644 --- a/VortexEngine/src/Wireless/IRSender.cpp +++ b/VortexEngine/src/Wireless/IRSender.cpp @@ -32,8 +32,6 @@ uint32_t IRSender::m_writeCounter = 0; bool IRSender::init() { - // initialize the IR device - initPWM(); return true; } @@ -113,8 +111,6 @@ void IRSender::beginSend() m_isSending = true; DEBUG_LOGF("[%zu] Beginning send size %u (blocks: %u remainder: %u blocksize: %u)", Time::microseconds(), m_size, m_numBlocks, m_remainder, m_blockSize); - // init sender before writing, is this necessary here? I think so - initPWM(); // wakeup the other receiver with a very quick mark/space sendMark(50); sendSpace(100); @@ -148,9 +144,6 @@ void IRSender::sendMark(uint16_t time) #ifdef VORTEX_LIB // send mark timing over socket Vortex::vcallbacks()->infraredWrite(true, time); -#else - startPWM(); - Time::delayMicroseconds(time); #endif } @@ -159,23 +152,7 @@ void IRSender::sendSpace(uint16_t time) #ifdef VORTEX_LIB // send space timing over socket Vortex::vcallbacks()->infraredWrite(false, time); -#else - stopPWM(); - Time::delayMicroseconds(time); #endif } -// shamelessly stolen from IRLib2, thanks -void IRSender::initPWM() -{ -} - -void IRSender::startPWM() -{ -} - -void IRSender::stopPWM() -{ -} - #endif diff --git a/VortexEngine/src/Wireless/IRSender.h b/VortexEngine/src/Wireless/IRSender.h index d8e9df30eb..8f65fa7048 100644 --- a/VortexEngine/src/Wireless/IRSender.h +++ b/VortexEngine/src/Wireless/IRSender.h @@ -34,11 +34,6 @@ class IRSender // send a mark/space by turning PWM on/off static void sendMark(uint16_t time); static void sendSpace(uint16_t time); - // Pulse-Width Modulator (IR Transmitter) - static void initPWM(); - // turn the IR transmitter on/off in realtime - static void startPWM(); - static void stopPWM(); // the serial buffer for the data static ByteStream m_serialBuf; diff --git a/VortexEngine/src/Wireless/VLReceiver.cpp b/VortexEngine/src/Wireless/VLReceiver.cpp index d7a52c763a..8d2f12a9a1 100644 --- a/VortexEngine/src/Wireless/VLReceiver.cpp +++ b/VortexEngine/src/Wireless/VLReceiver.cpp @@ -10,62 +10,14 @@ #include "../Leds/Leds.h" #include "../Log/Log.h" -#ifdef VORTEX_EMBEDDED -#include -#include -#endif - BitStream VLReceiver::m_vlData; VLReceiver::RecvState VLReceiver::m_recvState = WAITING_HEADER_MARK; uint32_t VLReceiver::m_prevTime = 0; uint8_t VLReceiver::m_pinState = 0; uint32_t VLReceiver::m_previousBytes = 0; -#ifdef VORTEX_EMBEDDED -#define MIN_THRESHOLD 200 -#define BASE_OFFSET 100 -#define THRESHOLD_BEGIN (MIN_THRESHOLD + BASE_OFFSET) -// the sample count exponent, so 5 means 2^5 = 32 samples -// 0 NONE No accumulation > doesn't work -// 1 ACC2 2 results accumulated > doesn't work -// 2 ACC4 4 results accumulated > works okay -// 3 ACC8 8 results accumulated > works decent -// 4 ACC16 16 results accumulated > works very well -// 5 ACC32 32 results accumulated > works best -// 6 ACC64 64 results accumulated > doesn't work -#define SAMPLE_COUNT 5 -// the threshold needs to start high then it will be automatically pulled down -uint16_t threshold = THRESHOLD_BEGIN; -ISR(ADC0_WCOMP_vect) -{ - // this will store the last known state - static bool wasAboveThreshold = false; - // grab the current analog value but divide it by 8 (the number of samples) - uint16_t val = (ADC0.RES >> SAMPLE_COUNT); - // calculate a threshold by using the baseline minimum value that is above 0 - // with a static offset, this ensures whatever the baseline light level and/or - // hardware sensitivity is it will always pick a threshold just above the 'off' - if (val > MIN_THRESHOLD && val < (threshold + BASE_OFFSET)) { - threshold = val + BASE_OFFSET; - } - // compare the current analog value to the light threshold - bool isAboveThreshold = (val > threshold); - if (wasAboveThreshold != isAboveThreshold) { - VLReceiver::recvPCIHandler(); - wasAboveThreshold = isAboveThreshold; - } - // Clear the Window Comparator interrupt flag - ADC0.INTFLAGS = ADC_WCMP_bm; -} -#endif - bool VLReceiver::init() { -#ifdef VORTEX_EMBEDDED - // Disable digital input buffer on the pin to save power - PORTB.PIN1CTRL &= ~PORT_ISC_gm; - PORTB.PIN1CTRL |= PORT_ISC_INPUT_DISABLE_gc; -#endif return m_vlData.init(VL_RECV_BUF_SIZE); } @@ -131,63 +83,12 @@ bool VLReceiver::receiveMode(Mode *pMode) bool VLReceiver::beginReceiving() { -#ifdef VORTEX_EMBEDDED - // Set up the ADC - // sample campacitance, VDD reference, prescaler division - // Options are: - // 0x0 DIV2 CLK_PER divided by 2 > works - // 0x1 DIV4 CLK_PER divided by 4 > works - // 0x2 DIV8 CLK_PER divided by 8 > works - // 0x3 DIV16 CLK_PER divided by 16 > works - // 0x4 DIV32 CLK_PER divided by 32 > doesn't work - // 0x5 DIV64 CLK_PER divided by 64 > doesn't work - // 0x6 DIV128 CLK_PER divided by 128 > doesn't work - // 0x7 DIV256 CLK_PER divided by 256 > doesn't work -#if (F_CPU == 20000000) - ADC0.CTRLC = ADC_SAMPCAP_bm | ADC_REFSEL_VDDREF_gc | ADC_PRESC_DIV2_gc; -#else - ADC0.CTRLC = ADC_SAMPCAP_bm | ADC_REFSEL_VDDREF_gc | ADC_PRESC_DIV2_gc; -#endif - // no sampling delay and no delay variation - ADC0.CTRLD = 0; - // sample length - // 0 = doesn't work - // 1+ = works - ADC0.SAMPCTRL = 1; - // Select the analog pin input PB1 (AIN10) - ADC0.MUXPOS = ADC_MUXPOS_AIN10_gc; - // Initialize the Window Comparator Mode in above - ADC0.CTRLE = ADC_WINCM_ABOVE_gc; - // Set the threshold value very low - ADC0.WINHT = 0x1; - ADC0.WINLT = 0; - // set sampling amount - // 0x0 NONE No accumulation > doesn't work - // 0x1 ACC2 2 results accumulated > doesn't work - // 0x2 ACC4 4 results accumulated > works okay - // 0x3 ACC8 8 results accumulated > works decent - // 0x4 ACC16 16 results accumulated > works very well - // 0x5 ACC32 32 results accumulated > works best - // 0x6 ACC64 64 results accumulated > doesn't work - ADC0.CTRLB = SAMPLE_COUNT; - // Enable Window Comparator interrupt - ADC0.INTCTRL = ADC_WCMP_bm; - // Enable the ADC and start continuous conversions - ADC0.CTRLA = ADC_ENABLE_bm | ADC_FREERUN_bm; - // start the first conversion - ADC0.COMMAND = ADC_STCONV_bm; -#endif resetVLState(); return true; } bool VLReceiver::endReceiving() { -#ifdef VORTEX_EMBEDDED - // Stop conversions and disable the ADC - ADC0.CTRLA &= ~(ADC_ENABLE_bm | ADC_FREERUN_bm); - ADC0.INTCTRL = 0; -#endif resetVLState(); return true; } @@ -296,10 +197,6 @@ void VLReceiver::resetVLState() m_recvState = WAITING_HEADER_MARK; // zero out the receive buffer and reset bit receiver position m_vlData.reset(); -#ifdef VORTEX_EMBEDDED - // reset the threshold to a high value so that it can be pulled down again - threshold = THRESHOLD_BEGIN; -#endif DEBUG_LOG("VL State Reset"); }