diff --git a/build/app.icns b/build/app.icns new file mode 100644 index 00000000..6f6b1ce6 Binary files /dev/null and b/build/app.icns differ diff --git a/build/bf.icns b/build/bf.icns new file mode 100644 index 00000000..3e619f1f Binary files /dev/null and b/build/bf.icns differ diff --git a/build/bloc.icns b/build/bloc.icns new file mode 100644 index 00000000..7e2489a1 Binary files /dev/null and b/build/bloc.icns differ diff --git a/build/html.icns b/build/html.icns new file mode 100644 index 00000000..14adccc0 Binary files /dev/null and b/build/html.icns differ diff --git a/build/ino.icns b/build/ino.icns new file mode 100644 index 00000000..f7c0c385 Binary files /dev/null and b/build/ino.icns differ diff --git a/build/py.icns b/build/py.icns new file mode 100644 index 00000000..6cccd16d Binary files /dev/null and b/build/py.icns differ diff --git a/build/www.icns b/build/www.icns new file mode 100644 index 00000000..7192fd1e Binary files /dev/null and b/build/www.icns differ diff --git a/compilation/arduino/libraries/Esplora/Esplora.cpp b/compilation/arduino/libraries/Esplora/Esplora.cpp new file mode 100644 index 00000000..a8089444 --- /dev/null +++ b/compilation/arduino/libraries/Esplora/Esplora.cpp @@ -0,0 +1,184 @@ +/* + Esplora.cpp - Arduino Esplora board library + Written by Enrico Gueli + Copyright (c) 2012 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +#include "Esplora.h" + +_Esplora Esplora; + +/* + * The following constants tell, for each accelerometer + * axis, which values are returned when the axis measures + * zero acceleration. + */ +const int ACCEL_ZERO_X = 320; +const int ACCEL_ZERO_Y = 330; +const int ACCEL_ZERO_Z = 310; + +const byte MUX_ADDR_PINS[] = { A0, A1, A2, A3 }; +const byte MUX_COM_PIN = A4; + +const int JOYSTICK_DEAD_ZONE = 100; + +const byte RED_PIN = 5; +const byte BLUE_PIN = 9; +const byte GREEN_PIN = 10; + +const byte BUZZER_PIN = 6; + +// non-multiplexer Esplora pins: +// Accelerometer: x-A5, y-A11, z-A6 +// External outputs: D3, D11 +// Buzzer: D6 +// RGB Led: red-D5, green-D10, blue-D9 +// Led 13: D13 + +const byte ACCEL_X_PIN = A5; +const byte ACCEL_Y_PIN = A11; +const byte ACCEL_Z_PIN = A6; + +const byte LED_PIN = 13; + +_Esplora::_Esplora() { + for (byte p=0; p<4; p++) { + pinMode(MUX_ADDR_PINS[p], OUTPUT); + } + pinMode(RED_PIN, OUTPUT); + pinMode(GREEN_PIN, OUTPUT); + pinMode(BLUE_PIN, OUTPUT); +} + +unsigned int _Esplora::readChannel(byte channel) { + digitalWrite(MUX_ADDR_PINS[0], (channel & 1) ? HIGH : LOW); + digitalWrite(MUX_ADDR_PINS[1], (channel & 2) ? HIGH : LOW); + digitalWrite(MUX_ADDR_PINS[2], (channel & 4) ? HIGH : LOW); + digitalWrite(MUX_ADDR_PINS[3], (channel & 8) ? HIGH : LOW); + // workaround to cope with lack of pullup resistor on joystick switch + if (channel == CH_JOYSTICK_SW) { + pinMode(MUX_COM_PIN, INPUT_PULLUP); + unsigned int joystickSwitchState = (digitalRead(MUX_COM_PIN) == HIGH) ? 1023 : 0; + digitalWrite(MUX_COM_PIN, LOW); + return joystickSwitchState; + } + else + return analogRead(MUX_COM_PIN); +} + +boolean _Esplora::joyLowHalf(byte joyCh) { + return (readChannel(joyCh) < 512 - JOYSTICK_DEAD_ZONE) + ? LOW : HIGH; +} + +boolean _Esplora::joyHighHalf(byte joyCh) { + return (readChannel(joyCh) > 512 + JOYSTICK_DEAD_ZONE) + ? LOW : HIGH; +} + +boolean _Esplora::readButton(byte ch) { + if (ch >= SWITCH_1 && ch <= SWITCH_4) { + ch--; + } + + switch(ch) { + case JOYSTICK_RIGHT: + return joyLowHalf(CH_JOYSTICK_X); + case JOYSTICK_LEFT: + return joyHighHalf(CH_JOYSTICK_X); + case JOYSTICK_UP: + return joyLowHalf(CH_JOYSTICK_Y); + case JOYSTICK_DOWN: + return joyHighHalf(CH_JOYSTICK_Y); + } + + unsigned int val = readChannel(ch); + return (val > 512) ? HIGH : LOW; +} + +boolean _Esplora::readJoystickButton() { + if (readChannel(CH_JOYSTICK_SW) == 1023) { + return HIGH; + } else if (readChannel(CH_JOYSTICK_SW) == 0) { + return LOW; + } +} + + +void _Esplora::writeRGB(byte r, byte g, byte b) { + writeRed(r); + writeGreen(g); + writeBlue(b); +} + +#define RGB_FUNC(name, pin, lastVar) \ +void _Esplora::write##name(byte val) { \ + if (val == lastVar) \ + return; \ + analogWrite(pin, val); \ + lastVar = val; \ + delay(5); \ +} \ +\ +byte _Esplora::read##name() { \ + return lastVar; \ +} + +RGB_FUNC(Red, RED_PIN, lastRed) +RGB_FUNC(Green, GREEN_PIN, lastGreen) +RGB_FUNC(Blue, BLUE_PIN, lastBlue) + +void _Esplora::tone(unsigned int freq) { + if (freq > 0) + ::tone(BUZZER_PIN, freq); + else + ::noTone(BUZZER_PIN); +} + +void _Esplora::tone(unsigned int freq, unsigned long duration) { + if (freq > 0) + ::tone(BUZZER_PIN, freq, duration); + else + ::noTone(BUZZER_PIN); +} + +void _Esplora::noTone() { + ::noTone(BUZZER_PIN); +} + +int _Esplora::readTemperature(const byte scale) { + long rawT = readChannel(CH_TEMPERATURE); + if (scale == DEGREES_C) { + return (int)((rawT * 500 / 1024) - 50); + } + else if (scale == DEGREES_F) { + return (int)((rawT * 450 / 512 ) - 58); + } + else { + return readTemperature(DEGREES_C); + } +} + +int _Esplora::readAccelerometer(const byte axis) { + switch (axis) { + case X_AXIS: return analogRead(ACCEL_X_PIN) - ACCEL_ZERO_X; + case Y_AXIS: return analogRead(ACCEL_Y_PIN) - ACCEL_ZERO_Y; + case Z_AXIS: return analogRead(ACCEL_Z_PIN) - ACCEL_ZERO_Z; + default: return 0; + } +} diff --git a/compilation/arduino/libraries/Esplora/Esplora.h b/compilation/arduino/libraries/Esplora/Esplora.h new file mode 100644 index 00000000..4e59fbe0 --- /dev/null +++ b/compilation/arduino/libraries/Esplora/Esplora.h @@ -0,0 +1,177 @@ +/* + Esplora.h - Arduino Esplora board library + Written by Enrico Gueli + Copyright (c) 2012 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef ESPLORA_H_ +#define ESPLORA_H_ + +#include + +/* + * The following constants are used internally by the Esplora + * library code. + */ + +const byte JOYSTICK_BASE = 16; // it's a "virtual" channel: its ID won't conflict with real ones + +const byte MAX_CHANNELS = 13; + +const byte CH_SWITCH_1 = 0; +const byte CH_SWITCH_2 = 1; +const byte CH_SWITCH_3 = 2; +const byte CH_SWITCH_4 = 3; +const byte CH_SLIDER = 4; +const byte CH_LIGHT = 5; +const byte CH_TEMPERATURE = 6; +const byte CH_MIC = 7; +const byte CH_TINKERKIT_A = 8; +const byte CH_TINKERKIT_B = 9; +const byte CH_JOYSTICK_SW = 10; +const byte CH_JOYSTICK_X = 11; +const byte CH_JOYSTICK_Y = 12; + +/* + * The following constants can be used with the readButton() + * method. + */ + +const byte SWITCH_1 = 1; +const byte SWITCH_2 = 2; +const byte SWITCH_3 = 3; +const byte SWITCH_4 = 4; + +const byte SWITCH_DOWN = SWITCH_1; +const byte SWITCH_LEFT = SWITCH_2; +const byte SWITCH_UP = SWITCH_3; +const byte SWITCH_RIGHT = SWITCH_4; + +const byte JOYSTICK_DOWN = JOYSTICK_BASE; +const byte JOYSTICK_LEFT = JOYSTICK_BASE+1; +const byte JOYSTICK_UP = JOYSTICK_BASE+2; +const byte JOYSTICK_RIGHT = JOYSTICK_BASE+3; + +/* + * These constants can be use for comparison with the value returned + * by the readButton() method. + */ +const boolean PRESSED = LOW; +const boolean RELEASED = HIGH; + +/* + * The following constants can be used with the readTemperature() + * method to specify the desired scale. + */ +const byte DEGREES_C = 0; +const byte DEGREES_F = 1; + +/* + * The following constants can be used with the readAccelerometer() + * method to specify the desired axis to return. + */ +const byte X_AXIS = 0; +const byte Y_AXIS = 1; +const byte Z_AXIS = 2; + + +class _Esplora { +private: + byte lastRed; + byte lastGreen; + byte lastBlue; + + unsigned int readChannel(byte channel); + + boolean joyLowHalf(byte joyCh); + boolean joyHighHalf(byte joyCh); + +public: + _Esplora(); + + /* + * Returns a number corresponding to the position of the + * linear potentiometer. 0 means full right, 1023 means + * full left. + */ + inline unsigned int readSlider() { return readChannel(CH_SLIDER); } + + /* + * Returns a number corresponding to the amount of ambient + * light sensed by the light sensor. + */ + inline unsigned int readLightSensor() { return readChannel(CH_LIGHT); } + + /* + * Returns the current ambient temperature, expressed either in Celsius + * or Fahreneit scale. + */ + int readTemperature(const byte scale); + + /* + * Returns a number corresponding to the amount of ambient noise. + */ + inline unsigned int readMicrophone() { return readChannel(CH_MIC); } + + inline unsigned int readJoystickSwitch() { return readChannel(CH_JOYSTICK_SW); } + + inline int readJoystickX() { + return readChannel(CH_JOYSTICK_X) - 512; + } + inline int readJoystickY() { + return readChannel(CH_JOYSTICK_Y) - 512; + } + + int readAccelerometer(const byte axis); + + /* + * Reads the current state of a button. It will return + * LOW if the button is pressed, and HIGH otherwise. + */ + boolean readButton(byte channel); + + boolean readJoystickButton(); + + void writeRGB(byte red, byte green, byte blue); + void writeRed(byte red); + void writeGreen(byte green); + void writeBlue(byte blue); + + byte readRed(); + byte readGreen(); + byte readBlue(); + + void tone(unsigned int freq); + void tone(unsigned int freq, unsigned long duration); + void noTone(); + + inline unsigned int readTinkerkitInput(byte whichInput) { + return readChannel(whichInput + CH_TINKERKIT_A); + } + inline unsigned int readTinkerkitInputA() { + return readChannel(CH_TINKERKIT_A); + } + inline unsigned int readTinkerkitInputB() { + return readChannel(CH_TINKERKIT_B); + } +}; + + + +extern _Esplora Esplora; + +#endif // ESPLORA_H_ diff --git a/compilation/arduino/libraries/IRremote/IRremote.cpp b/compilation/arduino/libraries/IRremote/IRremote.cpp new file mode 100644 index 00000000..888f5e2e --- /dev/null +++ b/compilation/arduino/libraries/IRremote/IRremote.cpp @@ -0,0 +1,1154 @@ +/* + * IRremote + * Version 0.11 August, 2009 + * Copyright 2009 Ken Shirriff + * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html + * + * Modified by Paul Stoffregen to support other boards and timers + * Modified by Mitra Ardron + * Added Sanyo and Mitsubishi controllers + * Modified Sony to spot the repeat codes that some Sony's send + * + * Interrupt code based on NECIRrcv by Joe Knapp + * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 + * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ + * + * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) + * LG added by Darryl Smith (based on the JVC protocol) + */ + +#include "IRremote.h" +#include "IRremoteInt.h" + +// Provides ISR +#include + +volatile irparams_t irparams; + +// These versions of MATCH, MATCH_MARK, and MATCH_SPACE are only for debugging. +// To use them, set DEBUG in IRremoteInt.h +// Normally macros are used for efficiency +#ifdef DEBUG +int MATCH(int measured, int desired) { + Serial.print("Testing: "); + Serial.print(TICKS_LOW(desired), DEC); + Serial.print(" <= "); + Serial.print(measured, DEC); + Serial.print(" <= "); + Serial.println(TICKS_HIGH(desired), DEC); + return measured >= TICKS_LOW(desired) && measured <= TICKS_HIGH(desired); +} + +int MATCH_MARK(int measured_ticks, int desired_us) { + Serial.print("Testing mark "); + Serial.print(measured_ticks * USECPERTICK, DEC); + Serial.print(" vs "); + Serial.print(desired_us, DEC); + Serial.print(": "); + Serial.print(TICKS_LOW(desired_us + MARK_EXCESS), DEC); + Serial.print(" <= "); + Serial.print(measured_ticks, DEC); + Serial.print(" <= "); + Serial.println(TICKS_HIGH(desired_us + MARK_EXCESS), DEC); + return measured_ticks >= TICKS_LOW(desired_us + MARK_EXCESS) && measured_ticks <= TICKS_HIGH(desired_us + MARK_EXCESS); +} + +int MATCH_SPACE(int measured_ticks, int desired_us) { + Serial.print("Testing space "); + Serial.print(measured_ticks * USECPERTICK, DEC); + Serial.print(" vs "); + Serial.print(desired_us, DEC); + Serial.print(": "); + Serial.print(TICKS_LOW(desired_us - MARK_EXCESS), DEC); + Serial.print(" <= "); + Serial.print(measured_ticks, DEC); + Serial.print(" <= "); + Serial.println(TICKS_HIGH(desired_us - MARK_EXCESS), DEC); + return measured_ticks >= TICKS_LOW(desired_us - MARK_EXCESS) && measured_ticks <= TICKS_HIGH(desired_us - MARK_EXCESS); +} +#else +int MATCH(int measured, int desired) {return measured >= TICKS_LOW(desired) && measured <= TICKS_HIGH(desired);} +int MATCH_MARK(int measured_ticks, int desired_us) {return MATCH(measured_ticks, (desired_us + MARK_EXCESS));} +int MATCH_SPACE(int measured_ticks, int desired_us) {return MATCH(measured_ticks, (desired_us - MARK_EXCESS));} +// Debugging versions are in IRremote.cpp +#endif + +void IRsend::sendNEC(unsigned long data, int nbits) +{ + enableIROut(38); + mark(NEC_HDR_MARK); + space(NEC_HDR_SPACE); + for (int i = 0; i < nbits; i++) { + if (data & TOPBIT) { + mark(NEC_BIT_MARK); + space(NEC_ONE_SPACE); + } + else { + mark(NEC_BIT_MARK); + space(NEC_ZERO_SPACE); + } + data <<= 1; + } + mark(NEC_BIT_MARK); + space(0); +} + +void IRsend::sendSony(unsigned long data, int nbits) { + enableIROut(40); + mark(SONY_HDR_MARK); + space(SONY_HDR_SPACE); + data = data << (32 - nbits); + for (int i = 0; i < nbits; i++) { + if (data & TOPBIT) { + mark(SONY_ONE_MARK); + space(SONY_HDR_SPACE); + } + else { + mark(SONY_ZERO_MARK); + space(SONY_HDR_SPACE); + } + data <<= 1; + } +} + +void IRsend::sendRaw(unsigned int buf[], int len, int hz) +{ + enableIROut(hz); + for (int i = 0; i < len; i++) { + if (i & 1) { + space(buf[i]); + } + else { + mark(buf[i]); + } + } + space(0); // Just to be sure +} + +// Note: first bit must be a one (start bit) +void IRsend::sendRC5(unsigned long data, int nbits) +{ + enableIROut(36); + data = data << (32 - nbits); + mark(RC5_T1); // First start bit + space(RC5_T1); // Second start bit + mark(RC5_T1); // Second start bit + for (int i = 0; i < nbits; i++) { + if (data & TOPBIT) { + space(RC5_T1); // 1 is space, then mark + mark(RC5_T1); + } + else { + mark(RC5_T1); + space(RC5_T1); + } + data <<= 1; + } + space(0); // Turn off at end +} + +// Caller needs to take care of flipping the toggle bit +void IRsend::sendRC6(unsigned long data, int nbits) +{ + enableIROut(36); + data = data << (32 - nbits); + mark(RC6_HDR_MARK); + space(RC6_HDR_SPACE); + mark(RC6_T1); // start bit + space(RC6_T1); + int t; + for (int i = 0; i < nbits; i++) { + if (i == 3) { + // double-wide trailer bit + t = 2 * RC6_T1; + } + else { + t = RC6_T1; + } + if (data & TOPBIT) { + mark(t); + space(t); + } + else { + space(t); + mark(t); + } + + data <<= 1; + } + space(0); // Turn off at end +} +void IRsend::sendPanasonic(unsigned int address, unsigned long data) { + enableIROut(35); + mark(PANASONIC_HDR_MARK); + space(PANASONIC_HDR_SPACE); + + for(int i=0;i<16;i++) + { + mark(PANASONIC_BIT_MARK); + if (address & 0x8000) { + space(PANASONIC_ONE_SPACE); + } else { + space(PANASONIC_ZERO_SPACE); + } + address <<= 1; + } + for (int i=0; i < 32; i++) { + mark(PANASONIC_BIT_MARK); + if (data & TOPBIT) { + space(PANASONIC_ONE_SPACE); + } else { + space(PANASONIC_ZERO_SPACE); + } + data <<= 1; + } + mark(PANASONIC_BIT_MARK); + space(0); +} +void IRsend::sendJVC(unsigned long data, int nbits, int repeat) +{ + enableIROut(38); + data = data << (32 - nbits); + if (!repeat){ + mark(JVC_HDR_MARK); + space(JVC_HDR_SPACE); + } + for (int i = 0; i < nbits; i++) { + if (data & TOPBIT) { + mark(JVC_BIT_MARK); + space(JVC_ONE_SPACE); + } + else { + mark(JVC_BIT_MARK); + space(JVC_ZERO_SPACE); + } + data <<= 1; + } + mark(JVC_BIT_MARK); + space(0); +} + +void IRsend::sendSAMSUNG(unsigned long data, int nbits) +{ + enableIROut(38); + mark(SAMSUNG_HDR_MARK); + space(SAMSUNG_HDR_SPACE); + for (int i = 0; i < nbits; i++) { + if (data & TOPBIT) { + mark(SAMSUNG_BIT_MARK); + space(SAMSUNG_ONE_SPACE); + } + else { + mark(SAMSUNG_BIT_MARK); + space(SAMSUNG_ZERO_SPACE); + } + data <<= 1; + } + mark(SAMSUNG_BIT_MARK); + space(0); +} + +void IRsend::mark(int time) { + // Sends an IR mark for the specified number of microseconds. + // The mark output is modulated at the PWM frequency. + TIMER_ENABLE_PWM; // Enable pin 3 PWM output + if (time > 0) delayMicroseconds(time); +} + +/* Leave pin off for time (given in microseconds) */ +void IRsend::space(int time) { + // Sends an IR space for the specified number of microseconds. + // A space is no output, so the PWM output is disabled. + TIMER_DISABLE_PWM; // Disable pin 3 PWM output + if (time > 0) delayMicroseconds(time); +} + +void IRsend::enableIROut(int khz) { + // Enables IR output. The khz value controls the modulation frequency in kilohertz. + // The IR output will be on pin 3 (OC2B). + // This routine is designed for 36-40KHz; if you use it for other values, it's up to you + // to make sure it gives reasonable results. (Watch out for overflow / underflow / rounding.) + // TIMER2 is used in phase-correct PWM mode, with OCR2A controlling the frequency and OCR2B + // controlling the duty cycle. + // There is no prescaling, so the output frequency is 16MHz / (2 * OCR2A) + // To turn the output on and off, we leave the PWM running, but connect and disconnect the output pin. + // A few hours staring at the ATmega documentation and this will all make sense. + // See my Secrets of Arduino PWM at http://arcfn.com/2009/07/secrets-of-arduino-pwm.html for details. + + + // Disable the Timer2 Interrupt (which is used for receiving IR) + TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt + + pinMode(TIMER_PWM_PIN, OUTPUT); + digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low + + // COM2A = 00: disconnect OC2A + // COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted + // WGM2 = 101: phase-correct PWM with OCRA as top + // CS2 = 000: no prescaling + // The top value for the timer. The modulation frequency will be SYSCLOCK / 2 / OCR2A. + TIMER_CONFIG_KHZ(khz); +} + +IRrecv::IRrecv(int recvpin) +{ + irparams.recvpin = recvpin; + irparams.blinkflag = 0; +} + +// initialization +void IRrecv::enableIRIn() { + cli(); + // setup pulse clock timer interrupt + //Prescale /8 (16M/8 = 0.5 microseconds per tick) + // Therefore, the timer interval can range from 0.5 to 128 microseconds + // depending on the reset value (255 to 0) + TIMER_CONFIG_NORMAL(); + + //Timer2 Overflow Interrupt Enable + TIMER_ENABLE_INTR; + + TIMER_RESET; + + sei(); // enable interrupts + + // initialize state machine variables + irparams.rcvstate = STATE_IDLE; + irparams.rawlen = 0; + + // set pin modes + pinMode(irparams.recvpin, INPUT); +} + +// enable/disable blinking of pin 13 on IR processing +void IRrecv::blink13(int blinkflag) +{ + irparams.blinkflag = blinkflag; + if (blinkflag) + pinMode(BLINKLED, OUTPUT); +} + +// TIMER2 interrupt code to collect raw data. +// Widths of alternating SPACE, MARK are recorded in rawbuf. +// Recorded in ticks of 50 microseconds. +// rawlen counts the number of entries recorded so far. +// First entry is the SPACE between transmissions. +// As soon as a SPACE gets long, ready is set, state switches to IDLE, timing of SPACE continues. +// As soon as first MARK arrives, gap width is recorded, ready is cleared, and new logging starts +ISR(TIMER_INTR_NAME) +{ + TIMER_RESET; + + uint8_t irdata = (uint8_t)digitalRead(irparams.recvpin); + + irparams.timer++; // One more 50us tick + if (irparams.rawlen >= RAWBUF) { + // Buffer overflow + irparams.rcvstate = STATE_STOP; + } + switch(irparams.rcvstate) { + case STATE_IDLE: // In the middle of a gap + if (irdata == MARK) { + if (irparams.timer < GAP_TICKS) { + // Not big enough to be a gap. + irparams.timer = 0; + } + else { + // gap just ended, record duration and start recording transmission + irparams.rawlen = 0; + irparams.rawbuf[irparams.rawlen++] = irparams.timer; + irparams.timer = 0; + irparams.rcvstate = STATE_MARK; + } + } + break; + case STATE_MARK: // timing MARK + if (irdata == SPACE) { // MARK ended, record time + irparams.rawbuf[irparams.rawlen++] = irparams.timer; + irparams.timer = 0; + irparams.rcvstate = STATE_SPACE; + } + break; + case STATE_SPACE: // timing SPACE + if (irdata == MARK) { // SPACE just ended, record it + irparams.rawbuf[irparams.rawlen++] = irparams.timer; + irparams.timer = 0; + irparams.rcvstate = STATE_MARK; + } + else { // SPACE + if (irparams.timer > GAP_TICKS) { + // big SPACE, indicates gap between codes + // Mark current code as ready for processing + // Switch to STOP + // Don't reset timer; keep counting space width + irparams.rcvstate = STATE_STOP; + } + } + break; + case STATE_STOP: // waiting, measuring gap + if (irdata == MARK) { // reset gap timer + irparams.timer = 0; + } + break; + } + + if (irparams.blinkflag) { + if (irdata == MARK) { + BLINKLED_ON(); // turn pin 13 LED on + } + else { + BLINKLED_OFF(); // turn pin 13 LED off + } + } +} + +void IRrecv::resume() { + irparams.rcvstate = STATE_IDLE; + irparams.rawlen = 0; +} + + + +// Decodes the received IR message +// Returns 0 if no data ready, 1 if data ready. +// Results of decoding are stored in results +int IRrecv::decode(decode_results *results) { + results->rawbuf = irparams.rawbuf; + results->rawlen = irparams.rawlen; + if (irparams.rcvstate != STATE_STOP) { + return ERR; + } +#ifdef DEBUG + Serial.println("Attempting NEC decode"); +#endif + if (decodeNEC(results)) { + return DECODED; + } +#ifdef DEBUG + Serial.println("Attempting Sony decode"); +#endif + if (decodeSony(results)) { + return DECODED; + } +#ifdef DEBUG + Serial.println("Attempting Sanyo decode"); +#endif + if (decodeSanyo(results)) { + return DECODED; + } +#ifdef DEBUG + Serial.println("Attempting Mitsubishi decode"); +#endif + if (decodeMitsubishi(results)) { + return DECODED; + } +#ifdef DEBUG + Serial.println("Attempting RC5 decode"); +#endif + if (decodeRC5(results)) { + return DECODED; + } +#ifdef DEBUG + Serial.println("Attempting RC6 decode"); +#endif + if (decodeRC6(results)) { + return DECODED; + } +#ifdef DEBUG + Serial.println("Attempting Panasonic decode"); +#endif + if (decodePanasonic(results)) { + return DECODED; + } +#ifdef DEBUG + Serial.println("Attempting LG decode"); +#endif + if (decodeLG(results)) { + return DECODED; + } +#ifdef DEBUG + Serial.println("Attempting JVC decode"); +#endif + if (decodeJVC(results)) { + return DECODED; + } +#ifdef DEBUG + Serial.println("Attempting SAMSUNG decode"); +#endif + if (decodeSAMSUNG(results)) { + return DECODED; + } + // decodeHash returns a hash on any input. + // Thus, it needs to be last in the list. + // If you add any decodes, add them before this. + if (decodeHash(results)) { + return DECODED; + } + // Throw away and start over + resume(); + return ERR; +} + +// NECs have a repeat only 4 items long +long IRrecv::decodeNEC(decode_results *results) { + long data = 0; + int offset = 1; // Skip first space + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], NEC_HDR_MARK)) { + return ERR; + } + offset++; + // Check for repeat + if (irparams.rawlen == 4 && + MATCH_SPACE(results->rawbuf[offset], NEC_RPT_SPACE) && + MATCH_MARK(results->rawbuf[offset+1], NEC_BIT_MARK)) { + results->bits = 0; + results->value = REPEAT; + results->decode_type = NEC; + return DECODED; + } + if (irparams.rawlen < 2 * NEC_BITS + 4) { + return ERR; + } + // Initial space + if (!MATCH_SPACE(results->rawbuf[offset], NEC_HDR_SPACE)) { + return ERR; + } + offset++; + for (int i = 0; i < NEC_BITS; i++) { + if (!MATCH_MARK(results->rawbuf[offset], NEC_BIT_MARK)) { + return ERR; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], NEC_ONE_SPACE)) { + data = (data << 1) | 1; + } + else if (MATCH_SPACE(results->rawbuf[offset], NEC_ZERO_SPACE)) { + data <<= 1; + } + else { + return ERR; + } + offset++; + } + // Success + results->bits = NEC_BITS; + results->value = data; + results->decode_type = NEC; + return DECODED; +} + +long IRrecv::decodeSony(decode_results *results) { + long data = 0; + if (irparams.rawlen < 2 * SONY_BITS + 2) { + return ERR; + } + int offset = 0; // Dont skip first space, check its size + + // Some Sony's deliver repeats fast after first + // unfortunately can't spot difference from of repeat from two fast clicks + if (results->rawbuf[offset] < SONY_DOUBLE_SPACE_USECS) { + // Serial.print("IR Gap found: "); + results->bits = 0; + results->value = REPEAT; + results->decode_type = SANYO; + return DECODED; + } + offset++; + + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], SONY_HDR_MARK)) { + return ERR; + } + offset++; + + while (offset + 1 < irparams.rawlen) { + if (!MATCH_SPACE(results->rawbuf[offset], SONY_HDR_SPACE)) { + break; + } + offset++; + if (MATCH_MARK(results->rawbuf[offset], SONY_ONE_MARK)) { + data = (data << 1) | 1; + } + else if (MATCH_MARK(results->rawbuf[offset], SONY_ZERO_MARK)) { + data <<= 1; + } + else { + return ERR; + } + offset++; + } + + // Success + results->bits = (offset - 1) / 2; + if (results->bits < 12) { + results->bits = 0; + return ERR; + } + results->value = data; + results->decode_type = SONY; + return DECODED; +} + +// I think this is a Sanyo decoder - serial = SA 8650B +// Looks like Sony except for timings, 48 chars of data and time/space different +long IRrecv::decodeSanyo(decode_results *results) { + long data = 0; + if (irparams.rawlen < 2 * SANYO_BITS + 2) { + return ERR; + } + int offset = 0; // Skip first space + // Initial space + /* Put this back in for debugging - note can't use #DEBUG as if Debug on we don't see the repeat cos of the delay + Serial.print("IR Gap: "); + Serial.println( results->rawbuf[offset]); + Serial.println( "test against:"); + Serial.println(results->rawbuf[offset]); + */ + if (results->rawbuf[offset] < SANYO_DOUBLE_SPACE_USECS) { + // Serial.print("IR Gap found: "); + results->bits = 0; + results->value = REPEAT; + results->decode_type = SANYO; + return DECODED; + } + offset++; + + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], SANYO_HDR_MARK)) { + return ERR; + } + offset++; + + // Skip Second Mark + if (!MATCH_MARK(results->rawbuf[offset], SANYO_HDR_MARK)) { + return ERR; + } + offset++; + + while (offset + 1 < irparams.rawlen) { + if (!MATCH_SPACE(results->rawbuf[offset], SANYO_HDR_SPACE)) { + break; + } + offset++; + if (MATCH_MARK(results->rawbuf[offset], SANYO_ONE_MARK)) { + data = (data << 1) | 1; + } + else if (MATCH_MARK(results->rawbuf[offset], SANYO_ZERO_MARK)) { + data <<= 1; + } + else { + return ERR; + } + offset++; + } + + // Success + results->bits = (offset - 1) / 2; + if (results->bits < 12) { + results->bits = 0; + return ERR; + } + results->value = data; + results->decode_type = SANYO; + return DECODED; +} + +// Looks like Sony except for timings, 48 chars of data and time/space different +long IRrecv::decodeMitsubishi(decode_results *results) { + // Serial.print("?!? decoding Mitsubishi:");Serial.print(irparams.rawlen); Serial.print(" want "); Serial.println( 2 * MITSUBISHI_BITS + 2); + long data = 0; + if (irparams.rawlen < 2 * MITSUBISHI_BITS + 2) { + return ERR; + } + int offset = 0; // Skip first space + // Initial space + /* Put this back in for debugging - note can't use #DEBUG as if Debug on we don't see the repeat cos of the delay + Serial.print("IR Gap: "); + Serial.println( results->rawbuf[offset]); + Serial.println( "test against:"); + Serial.println(results->rawbuf[offset]); + */ + /* Not seeing double keys from Mitsubishi + if (results->rawbuf[offset] < MITSUBISHI_DOUBLE_SPACE_USECS) { + // Serial.print("IR Gap found: "); + results->bits = 0; + results->value = REPEAT; + results->decode_type = MITSUBISHI; + return DECODED; + } + */ + offset++; + + // Typical + // 14200 7 41 7 42 7 42 7 17 7 17 7 18 7 41 7 18 7 17 7 17 7 18 7 41 8 17 7 17 7 18 7 17 7 + + // Initial Space + if (!MATCH_MARK(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) { + return ERR; + } + offset++; + while (offset + 1 < irparams.rawlen) { + if (MATCH_MARK(results->rawbuf[offset], MITSUBISHI_ONE_MARK)) { + data = (data << 1) | 1; + } + else if (MATCH_MARK(results->rawbuf[offset], MITSUBISHI_ZERO_MARK)) { + data <<= 1; + } + else { + // Serial.println("A"); Serial.println(offset); Serial.println(results->rawbuf[offset]); + return ERR; + } + offset++; + if (!MATCH_SPACE(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) { + // Serial.println("B"); Serial.println(offset); Serial.println(results->rawbuf[offset]); + break; + } + offset++; + } + + // Success + results->bits = (offset - 1) / 2; + if (results->bits < MITSUBISHI_BITS) { + results->bits = 0; + return ERR; + } + results->value = data; + results->decode_type = MITSUBISHI; + return DECODED; +} + + +// Gets one undecoded level at a time from the raw buffer. +// The RC5/6 decoding is easier if the data is broken into time intervals. +// E.g. if the buffer has MARK for 2 time intervals and SPACE for 1, +// successive calls to getRClevel will return MARK, MARK, SPACE. +// offset and used are updated to keep track of the current position. +// t1 is the time interval for a single bit in microseconds. +// Returns -1 for error (measured time interval is not a multiple of t1). +int IRrecv::getRClevel(decode_results *results, int *offset, int *used, int t1) { + if (*offset >= results->rawlen) { + // After end of recorded buffer, assume SPACE. + return SPACE; + } + int width = results->rawbuf[*offset]; + int val = ((*offset) % 2) ? MARK : SPACE; + int correction = (val == MARK) ? MARK_EXCESS : - MARK_EXCESS; + + int avail; + if (MATCH(width, t1 + correction)) { + avail = 1; + } + else if (MATCH(width, 2*t1 + correction)) { + avail = 2; + } + else if (MATCH(width, 3*t1 + correction)) { + avail = 3; + } + else { + return -1; + } + + (*used)++; + if (*used >= avail) { + *used = 0; + (*offset)++; + } +#ifdef DEBUG + if (val == MARK) { + Serial.println("MARK"); + } + else { + Serial.println("SPACE"); + } +#endif + return val; +} + +long IRrecv::decodeRC5(decode_results *results) { + if (irparams.rawlen < MIN_RC5_SAMPLES + 2) { + return ERR; + } + int offset = 1; // Skip gap space + long data = 0; + int used = 0; + // Get start bits + if (getRClevel(results, &offset, &used, RC5_T1) != MARK) return ERR; + if (getRClevel(results, &offset, &used, RC5_T1) != SPACE) return ERR; + if (getRClevel(results, &offset, &used, RC5_T1) != MARK) return ERR; + int nbits; + for (nbits = 0; offset < irparams.rawlen; nbits++) { + int levelA = getRClevel(results, &offset, &used, RC5_T1); + int levelB = getRClevel(results, &offset, &used, RC5_T1); + if (levelA == SPACE && levelB == MARK) { + // 1 bit + data = (data << 1) | 1; + } + else if (levelA == MARK && levelB == SPACE) { + // zero bit + data <<= 1; + } + else { + return ERR; + } + } + + // Success + results->bits = nbits; + results->value = data; + results->decode_type = RC5; + return DECODED; +} + +long IRrecv::decodeRC6(decode_results *results) { + if (results->rawlen < MIN_RC6_SAMPLES) { + return ERR; + } + int offset = 1; // Skip first space + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], RC6_HDR_MARK)) { + return ERR; + } + offset++; + if (!MATCH_SPACE(results->rawbuf[offset], RC6_HDR_SPACE)) { + return ERR; + } + offset++; + long data = 0; + int used = 0; + // Get start bit (1) + if (getRClevel(results, &offset, &used, RC6_T1) != MARK) return ERR; + if (getRClevel(results, &offset, &used, RC6_T1) != SPACE) return ERR; + int nbits; + for (nbits = 0; offset < results->rawlen; nbits++) { + int levelA, levelB; // Next two levels + levelA = getRClevel(results, &offset, &used, RC6_T1); + if (nbits == 3) { + // T bit is double wide; make sure second half matches + if (levelA != getRClevel(results, &offset, &used, RC6_T1)) return ERR; + } + levelB = getRClevel(results, &offset, &used, RC6_T1); + if (nbits == 3) { + // T bit is double wide; make sure second half matches + if (levelB != getRClevel(results, &offset, &used, RC6_T1)) return ERR; + } + if (levelA == MARK && levelB == SPACE) { // reversed compared to RC5 + // 1 bit + data = (data << 1) | 1; + } + else if (levelA == SPACE && levelB == MARK) { + // zero bit + data <<= 1; + } + else { + return ERR; // Error + } + } + // Success + results->bits = nbits; + results->value = data; + results->decode_type = RC6; + return DECODED; +} +long IRrecv::decodePanasonic(decode_results *results) { + unsigned long long data = 0; + int offset = 1; + + if (!MATCH_MARK(results->rawbuf[offset], PANASONIC_HDR_MARK)) { + return ERR; + } + offset++; + if (!MATCH_MARK(results->rawbuf[offset], PANASONIC_HDR_SPACE)) { + return ERR; + } + offset++; + + // decode address + for (int i = 0; i < PANASONIC_BITS; i++) { + if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_BIT_MARK)) { + return ERR; + } + if (MATCH_SPACE(results->rawbuf[offset],PANASONIC_ONE_SPACE)) { + data = (data << 1) | 1; + } else if (MATCH_SPACE(results->rawbuf[offset],PANASONIC_ZERO_SPACE)) { + data <<= 1; + } else { + return ERR; + } + offset++; + } + results->value = (unsigned long)data; + results->panasonicAddress = (unsigned int)(data >> 32); + results->decode_type = PANASONIC; + results->bits = PANASONIC_BITS; + return DECODED; +} + +long IRrecv::decodeLG(decode_results *results) { + long data = 0; + int offset = 1; // Skip first space + + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], LG_HDR_MARK)) { + return ERR; + } + offset++; + if (irparams.rawlen < 2 * LG_BITS + 1 ) { + return ERR; + } + // Initial space + if (!MATCH_SPACE(results->rawbuf[offset], LG_HDR_SPACE)) { + return ERR; + } + offset++; + for (int i = 0; i < LG_BITS; i++) { + if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)) { + return ERR; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], LG_ONE_SPACE)) { + data = (data << 1) | 1; + } + else if (MATCH_SPACE(results->rawbuf[offset], LG_ZERO_SPACE)) { + data <<= 1; + } + else { + return ERR; + } + offset++; + } + //Stop bit + if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)){ + return ERR; + } + // Success + results->bits = LG_BITS; + results->value = data; + results->decode_type = LG; + return DECODED; +} + + +long IRrecv::decodeJVC(decode_results *results) { + long data = 0; + int offset = 1; // Skip first space + // Check for repeat + if (irparams.rawlen - 1 == 33 && + MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK) && + MATCH_MARK(results->rawbuf[irparams.rawlen-1], JVC_BIT_MARK)) { + results->bits = 0; + results->value = REPEAT; + results->decode_type = JVC; + return DECODED; + } + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], JVC_HDR_MARK)) { + return ERR; + } + offset++; + if (irparams.rawlen < 2 * JVC_BITS + 1 ) { + return ERR; + } + // Initial space + if (!MATCH_SPACE(results->rawbuf[offset], JVC_HDR_SPACE)) { + return ERR; + } + offset++; + for (int i = 0; i < JVC_BITS; i++) { + if (!MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK)) { + return ERR; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], JVC_ONE_SPACE)) { + data = (data << 1) | 1; + } + else if (MATCH_SPACE(results->rawbuf[offset], JVC_ZERO_SPACE)) { + data <<= 1; + } + else { + return ERR; + } + offset++; + } + //Stop bit + if (!MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK)){ + return ERR; + } + // Success + results->bits = JVC_BITS; + results->value = data; + results->decode_type = JVC; + return DECODED; +} + +// SAMSUNGs have a repeat only 4 items long +long IRrecv::decodeSAMSUNG(decode_results *results) { + long data = 0; + int offset = 1; // Skip first space + // Initial mark + if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_HDR_MARK)) { + return ERR; + } + offset++; + // Check for repeat + if (irparams.rawlen == 4 && + MATCH_SPACE(results->rawbuf[offset], SAMSUNG_RPT_SPACE) && + MATCH_MARK(results->rawbuf[offset+1], SAMSUNG_BIT_MARK)) { + results->bits = 0; + results->value = REPEAT; + results->decode_type = SAMSUNG; + return DECODED; + } + if (irparams.rawlen < 2 * SAMSUNG_BITS + 4) { + return ERR; + } + // Initial space + if (!MATCH_SPACE(results->rawbuf[offset], SAMSUNG_HDR_SPACE)) { + return ERR; + } + offset++; + for (int i = 0; i < SAMSUNG_BITS; i++) { + if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_BIT_MARK)) { + return ERR; + } + offset++; + if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ONE_SPACE)) { + data = (data << 1) | 1; + } + else if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ZERO_SPACE)) { + data <<= 1; + } + else { + return ERR; + } + offset++; + } + // Success + results->bits = SAMSUNG_BITS; + results->value = data; + results->decode_type = SAMSUNG; + return DECODED; +} + +/* ----------------------------------------------------------------------- + * hashdecode - decode an arbitrary IR code. + * Instead of decoding using a standard encoding scheme + * (e.g. Sony, NEC, RC5), the code is hashed to a 32-bit value. + * + * The algorithm: look at the sequence of MARK signals, and see if each one + * is shorter (0), the same length (1), or longer (2) than the previous. + * Do the same with the SPACE signals. Hszh the resulting sequence of 0's, + * 1's, and 2's to a 32-bit value. This will give a unique value for each + * different code (probably), for most code systems. + * + * http://arcfn.com/2010/01/using-arbitrary-remotes-with-arduino.html + */ + +// Compare two tick values, returning 0 if newval is shorter, +// 1 if newval is equal, and 2 if newval is longer +// Use a tolerance of 20% +int IRrecv::compare(unsigned int oldval, unsigned int newval) { + if (newval < oldval * .8) { + return 0; + } + else if (oldval < newval * .8) { + return 2; + } + else { + return 1; + } +} + +// Use FNV hash algorithm: http://isthe.com/chongo/tech/comp/fnv/#FNV-param +#define FNV_PRIME_32 16777619 +#define FNV_BASIS_32 2166136261 + +/* Converts the raw code values into a 32-bit hash code. + * Hopefully this code is unique for each button. + * This isn't a "real" decoding, just an arbitrary value. + */ +long IRrecv::decodeHash(decode_results *results) { + // Require at least 6 samples to prevent triggering on noise + if (results->rawlen < 6) { + return ERR; + } + long hash = FNV_BASIS_32; + for (int i = 1; i+2 < results->rawlen; i++) { + int value = compare(results->rawbuf[i], results->rawbuf[i+2]); + // Add value into the hash + hash = (hash * FNV_PRIME_32) ^ value; + } + results->value = hash; + results->bits = 32; + results->decode_type = UNKNOWN; + return DECODED; +} + +/* Sharp and DISH support by Todd Treece ( http://unionbridge.org/design/ircommand ) + +The Dish send function needs to be repeated 4 times, and the Sharp function +has the necessary repeat built in because of the need to invert the signal. + +Sharp protocol documentation: +http://www.sbprojects.com/knowledge/ir/sharp.htm + +Here are the LIRC files that I found that seem to match the remote codes +from the oscilloscope: + +Sharp LCD TV: +http://lirc.sourceforge.net/remotes/sharp/GA538WJSA + +DISH NETWORK (echostar 301): +http://lirc.sourceforge.net/remotes/echostar/301_501_3100_5100_58xx_59xx + +For the DISH codes, only send the last for characters of the hex. +i.e. use 0x1C10 instead of 0x0000000000001C10 which is listed in the +linked LIRC file. +*/ + +void IRsend::sendSharpRaw(unsigned long data, int nbits) { + enableIROut(38); + + // Sending codes in bursts of 3 (normal, inverted, normal) makes transmission + // much more reliable. That's the exact behaviour of CD-S6470 remote control. + for (int n = 0; n < 3; n++) { + for (int i = 1 << (nbits-1); i > 0; i>>=1) { + if (data & i) { + mark(SHARP_BIT_MARK); + space(SHARP_ONE_SPACE); + } + else { + mark(SHARP_BIT_MARK); + space(SHARP_ZERO_SPACE); + } + } + + mark(SHARP_BIT_MARK); + space(SHARP_ZERO_SPACE); + delay(40); + + data = data ^ SHARP_TOGGLE_MASK; + } +} + +// Sharp send compatible with data obtained through decodeSharp +void IRsend::sendSharp(unsigned int address, unsigned int command) { + sendSharpRaw((address << 10) | (command << 2) | 2, 15); +} + +void IRsend::sendDISH(unsigned long data, int nbits) { + enableIROut(56); + mark(DISH_HDR_MARK); + space(DISH_HDR_SPACE); + for (int i = 0; i < nbits; i++) { + if (data & DISH_TOP_BIT) { + mark(DISH_BIT_MARK); + space(DISH_ONE_SPACE); + } + else { + mark(DISH_BIT_MARK); + space(DISH_ZERO_SPACE); + } + data <<= 1; + } +} diff --git a/compilation/arduino/libraries/IRremote/IRremote.h b/compilation/arduino/libraries/IRremote/IRremote.h new file mode 100644 index 00000000..17d5e81b --- /dev/null +++ b/compilation/arduino/libraries/IRremote/IRremote.h @@ -0,0 +1,128 @@ +/* + * IRremote + * Version 0.1 July, 2009 + * Copyright 2009 Ken Shirriff + * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com + * Edited by Mitra to add new controller SANYO + * + * Interrupt code based on NECIRrcv by Joe Knapp + * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 + * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ + * + * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) +* LG added by Darryl Smith (based on the JVC protocol) + */ + +#ifndef IRremote_h +#define IRremote_h + +// The following are compile-time library options. +// If you change them, recompile the library. +// If DEBUG is defined, a lot of debugging output will be printed during decoding. +// TEST must be defined for the IRtest unittests to work. It will make some +// methods virtual, which will be slightly slower, which is why it is optional. +// #define DEBUG +// #define TEST + +// Results returned from the decoder +class decode_results { +public: + int decode_type; // NEC, SONY, RC5, UNKNOWN + union { // This is used for decoding Panasonic and Sharp data + unsigned int panasonicAddress; + unsigned int sharpAddress; + }; + unsigned long value; // Decoded value + int bits; // Number of bits in decoded value + volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks + int rawlen; // Number of records in rawbuf. +}; + +// Values for decode_type +#define NEC 1 +#define SONY 2 +#define RC5 3 +#define RC6 4 +#define DISH 5 +#define SHARP 6 +#define PANASONIC 7 +#define JVC 8 +#define SANYO 9 +#define MITSUBISHI 10 +#define SAMSUNG 11 +#define LG 12 +#define UNKNOWN -1 + +// Decoded value for NEC when a repeat code is received +#define REPEAT 0xffffffff + +// main class for receiving IR +class IRrecv +{ +public: + IRrecv(int recvpin); + void blink13(int blinkflag); + int decode(decode_results *results); + void enableIRIn(); + void resume(); +private: + // These are called by decode + int getRClevel(decode_results *results, int *offset, int *used, int t1); + long decodeNEC(decode_results *results); + long decodeSony(decode_results *results); + long decodeSanyo(decode_results *results); + long decodeMitsubishi(decode_results *results); + long decodeRC5(decode_results *results); + long decodeRC6(decode_results *results); + long decodePanasonic(decode_results *results); + long decodeLG(decode_results *results); + long decodeJVC(decode_results *results); + long decodeSAMSUNG(decode_results *results); + long decodeHash(decode_results *results); + int compare(unsigned int oldval, unsigned int newval); + +} +; + +// Only used for testing; can remove virtual for shorter code +#ifdef TEST +#define VIRTUAL virtual +#else +#define VIRTUAL +#endif + +class IRsend +{ +public: + IRsend() {} + void sendNEC(unsigned long data, int nbits); + void sendSony(unsigned long data, int nbits); + // Neither Sanyo nor Mitsubishi send is implemented yet + // void sendSanyo(unsigned long data, int nbits); + // void sendMitsubishi(unsigned long data, int nbits); + void sendRaw(unsigned int buf[], int len, int hz); + void sendRC5(unsigned long data, int nbits); + void sendRC6(unsigned long data, int nbits); + void sendDISH(unsigned long data, int nbits); + void sendSharp(unsigned int address, unsigned int command); + void sendSharpRaw(unsigned long data, int nbits); + void sendPanasonic(unsigned int address, unsigned long data); + void sendJVC(unsigned long data, int nbits, int repeat); // *Note instead of sending the REPEAT constant if you want the JVC repeat signal sent, send the original code value and change the repeat argument from 0 to 1. JVC protocol repeats by skipping the header NOT by sending a separate code value like NEC does. + // private: + void sendSAMSUNG(unsigned long data, int nbits); + void enableIROut(int khz); + VIRTUAL void mark(int usec); + VIRTUAL void space(int usec); +} +; + +// Some useful constants + +#define USECPERTICK 50 // microseconds per clock interrupt tick +#define RAWBUF 100 // Length of raw duration buffer + +// Marks tend to be 100us too long, and spaces 100us too short +// when received due to sensor lag. +#define MARK_EXCESS 100 + +#endif diff --git a/compilation/arduino/libraries/IRremote/IRremoteInt.h b/compilation/arduino/libraries/IRremote/IRremoteInt.h new file mode 100644 index 00000000..e5653277 --- /dev/null +++ b/compilation/arduino/libraries/IRremote/IRremoteInt.h @@ -0,0 +1,515 @@ +/* + * IRremote + * Version 0.1 July, 2009 + * Copyright 2009 Ken Shirriff + * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html + * + * Modified by Paul Stoffregen to support other boards and timers + * + * Interrupt code based on NECIRrcv by Joe Knapp + * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 + * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ + * + * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) + */ + +#ifndef IRremoteint_h +#define IRremoteint_h + +#if defined(ARDUINO) && ARDUINO >= 100 +#include +#else +#include +#endif + +// define which timer to use +// +// Uncomment the timer you wish to use on your board. If you +// are using another library which uses timer2, you have options +// to switch IRremote to use a different timer. + +// Arduino Mega +#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) + //#define IR_USE_TIMER1 // tx = pin 11 + #define IR_USE_TIMER2 // tx = pin 9 + //#define IR_USE_TIMER3 // tx = pin 5 + //#define IR_USE_TIMER4 // tx = pin 6 + //#define IR_USE_TIMER5 // tx = pin 46 + +// Teensy 1.0 +#elif defined(__AVR_AT90USB162__) + #define IR_USE_TIMER1 // tx = pin 17 + +// Teensy 2.0 +#elif defined(__AVR_ATmega32U4__) + //#define IR_USE_TIMER1 // tx = pin 14 + //#define IR_USE_TIMER3 // tx = pin 9 + #define IR_USE_TIMER4_HS // tx = pin 10 + +// Teensy 3.0 +#elif defined(__MK20DX128__) + #define IR_USE_TIMER_CMT // tx = pin 5 + +// Teensy++ 1.0 & 2.0 +#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) + //#define IR_USE_TIMER1 // tx = pin 25 + #define IR_USE_TIMER2 // tx = pin 1 + //#define IR_USE_TIMER3 // tx = pin 16 + +// Sanguino +#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) + //#define IR_USE_TIMER1 // tx = pin 13 + #define IR_USE_TIMER2 // tx = pin 14 + +// Atmega8 +#elif defined(__AVR_ATmega8P__) || defined(__AVR_ATmega8__) + #define IR_USE_TIMER1 // tx = pin 9 + +// Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, etc +#else + //#define IR_USE_TIMER1 // tx = pin 9 + #define IR_USE_TIMER2 // tx = pin 3 +#endif + + + +#ifdef F_CPU +#define SYSCLOCK F_CPU // main Arduino clock +#else +#define SYSCLOCK 16000000 // main Arduino clock +#endif + +#define ERR 0 +#define DECODED 1 + + +// defines for setting and clearing register bits +#ifndef cbi +#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) +#endif +#ifndef sbi +#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) +#endif + +// Pulse parms are *50-100 for the Mark and *50+100 for the space +// First MARK is the one after the long gap +// pulse parameters in usec +#define NEC_HDR_MARK 9000 +#define NEC_HDR_SPACE 4500 +#define NEC_BIT_MARK 560 +#define NEC_ONE_SPACE 1600 +#define NEC_ZERO_SPACE 560 +#define NEC_RPT_SPACE 2250 + +#define SONY_HDR_MARK 2400 +#define SONY_HDR_SPACE 600 +#define SONY_ONE_MARK 1200 +#define SONY_ZERO_MARK 600 +#define SONY_RPT_LENGTH 45000 +#define SONY_DOUBLE_SPACE_USECS 500 // usually ssee 713 - not using ticks as get number wrapround + +// SA 8650B +#define SANYO_HDR_MARK 3500 // seen range 3500 +#define SANYO_HDR_SPACE 950 // seen 950 +#define SANYO_ONE_MARK 2400 // seen 2400 +#define SANYO_ZERO_MARK 700 // seen 700 +#define SANYO_DOUBLE_SPACE_USECS 800 // usually ssee 713 - not using ticks as get number wrapround +#define SANYO_RPT_LENGTH 45000 + +// Mitsubishi RM 75501 +// 14200 7 41 7 42 7 42 7 17 7 17 7 18 7 41 7 18 7 17 7 17 7 18 7 41 8 17 7 17 7 18 7 17 7 + +// #define MITSUBISHI_HDR_MARK 250 // seen range 3500 +#define MITSUBISHI_HDR_SPACE 350 // 7*50+100 +#define MITSUBISHI_ONE_MARK 1950 // 41*50-100 +#define MITSUBISHI_ZERO_MARK 750 // 17*50-100 +// #define MITSUBISHI_DOUBLE_SPACE_USECS 800 // usually ssee 713 - not using ticks as get number wrapround +// #define MITSUBISHI_RPT_LENGTH 45000 + + +#define RC5_T1 889 +#define RC5_RPT_LENGTH 46000 + +#define RC6_HDR_MARK 2666 +#define RC6_HDR_SPACE 889 +#define RC6_T1 444 +#define RC6_RPT_LENGTH 46000 + +#define SHARP_BIT_MARK 245 +#define SHARP_ONE_SPACE 1805 +#define SHARP_ZERO_SPACE 795 +#define SHARP_GAP 600000 +#define SHARP_TOGGLE_MASK 0x3FF +#define SHARP_RPT_SPACE 3000 + +#define DISH_HDR_MARK 400 +#define DISH_HDR_SPACE 6100 +#define DISH_BIT_MARK 400 +#define DISH_ONE_SPACE 1700 +#define DISH_ZERO_SPACE 2800 +#define DISH_RPT_SPACE 6200 +#define DISH_TOP_BIT 0x8000 + +#define PANASONIC_HDR_MARK 3502 +#define PANASONIC_HDR_SPACE 1750 +#define PANASONIC_BIT_MARK 502 +#define PANASONIC_ONE_SPACE 1244 +#define PANASONIC_ZERO_SPACE 400 + +#define JVC_HDR_MARK 8000 +#define JVC_HDR_SPACE 4000 +#define JVC_BIT_MARK 600 +#define JVC_ONE_SPACE 1600 +#define JVC_ZERO_SPACE 550 +#define JVC_RPT_LENGTH 60000 + +#define LG_HDR_MARK 8000 +#define LG_HDR_SPACE 4000 +#define LG_BIT_MARK 600 +#define LG_ONE_SPACE 1600 +#define LG_ZERO_SPACE 550 +#define LG_RPT_LENGTH 60000 + +#define SAMSUNG_HDR_MARK 5000 +#define SAMSUNG_HDR_SPACE 5000 +#define SAMSUNG_BIT_MARK 560 +#define SAMSUNG_ONE_SPACE 1600 +#define SAMSUNG_ZERO_SPACE 560 +#define SAMSUNG_RPT_SPACE 2250 + + +#define SHARP_BITS 15 +#define DISH_BITS 16 + +#define TOLERANCE 25 // percent tolerance in measurements +#define LTOL (1.0 - TOLERANCE/100.) +#define UTOL (1.0 + TOLERANCE/100.) + +#define _GAP 5000 // Minimum map between transmissions +#define GAP_TICKS (_GAP/USECPERTICK) + +#define TICKS_LOW(us) (int) (((us)*LTOL/USECPERTICK)) +#define TICKS_HIGH(us) (int) (((us)*UTOL/USECPERTICK + 1)) + +// receiver states +#define STATE_IDLE 2 +#define STATE_MARK 3 +#define STATE_SPACE 4 +#define STATE_STOP 5 + +// information for the interrupt handler +typedef struct { + uint8_t recvpin; // pin for IR data from detector + uint8_t rcvstate; // state machine + uint8_t blinkflag; // TRUE to enable blinking of pin 13 on IR processing + unsigned int timer; // state timer, counts 50uS ticks. + unsigned int rawbuf[RAWBUF]; // raw data + uint8_t rawlen; // counter of entries in rawbuf +} +irparams_t; + +// Defined in IRremote.cpp +extern volatile irparams_t irparams; + +// IR detector output is active low +#define MARK 0 +#define SPACE 1 + +#define TOPBIT 0x80000000 + +#define NEC_BITS 32 +#define SONY_BITS 12 +#define SANYO_BITS 12 +#define MITSUBISHI_BITS 16 +#define MIN_RC5_SAMPLES 11 +#define MIN_RC6_SAMPLES 1 +#define PANASONIC_BITS 48 +#define JVC_BITS 16 +#define LG_BITS 28 +#define SAMSUNG_BITS 32 + + + + +// defines for timer2 (8 bits) +#if defined(IR_USE_TIMER2) +#define TIMER_RESET +#define TIMER_ENABLE_PWM (TCCR2A |= _BV(COM2B1)) +#define TIMER_DISABLE_PWM (TCCR2A &= ~(_BV(COM2B1))) +#define TIMER_ENABLE_INTR (TIMSK2 = _BV(OCIE2A)) +#define TIMER_DISABLE_INTR (TIMSK2 = 0) +#define TIMER_INTR_NAME TIMER2_COMPA_vect +#define TIMER_CONFIG_KHZ(val) ({ \ + const uint8_t pwmval = SYSCLOCK / 2000 / (val); \ + TCCR2A = _BV(WGM20); \ + TCCR2B = _BV(WGM22) | _BV(CS20); \ + OCR2A = pwmval; \ + OCR2B = pwmval / 3; \ +}) +#define TIMER_COUNT_TOP (SYSCLOCK * USECPERTICK / 1000000) +#if (TIMER_COUNT_TOP < 256) +#define TIMER_CONFIG_NORMAL() ({ \ + TCCR2A = _BV(WGM21); \ + TCCR2B = _BV(CS20); \ + OCR2A = TIMER_COUNT_TOP; \ + TCNT2 = 0; \ +}) +#else +#define TIMER_CONFIG_NORMAL() ({ \ + TCCR2A = _BV(WGM21); \ + TCCR2B = _BV(CS21); \ + OCR2A = TIMER_COUNT_TOP / 8; \ + TCNT2 = 0; \ +}) +#endif +#if defined(CORE_OC2B_PIN) +#define TIMER_PWM_PIN CORE_OC2B_PIN /* Teensy */ +#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#define TIMER_PWM_PIN 9 /* Arduino Mega */ +#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) +#define TIMER_PWM_PIN 14 /* Sanguino */ +#else +#define TIMER_PWM_PIN 3 /* Arduino Duemilanove, Diecimila, LilyPad, etc */ +#endif + + +// defines for timer1 (16 bits) +#elif defined(IR_USE_TIMER1) +#define TIMER_RESET +#define TIMER_ENABLE_PWM (TCCR1A |= _BV(COM1A1)) +#define TIMER_DISABLE_PWM (TCCR1A &= ~(_BV(COM1A1))) +#if defined(__AVR_ATmega8P__) || defined(__AVR_ATmega8__) + #define TIMER_ENABLE_INTR (TIMSK = _BV(OCIE1A)) + #define TIMER_DISABLE_INTR (TIMSK = 0) +#else + #define TIMER_ENABLE_INTR (TIMSK1 = _BV(OCIE1A)) + #define TIMER_DISABLE_INTR (TIMSK1 = 0) +#endif +#define TIMER_INTR_NAME TIMER1_COMPA_vect +#define TIMER_CONFIG_KHZ(val) ({ \ + const uint16_t pwmval = SYSCLOCK / 2000 / (val); \ + TCCR1A = _BV(WGM11); \ + TCCR1B = _BV(WGM13) | _BV(CS10); \ + ICR1 = pwmval; \ + OCR1A = pwmval / 3; \ +}) +#define TIMER_CONFIG_NORMAL() ({ \ + TCCR1A = 0; \ + TCCR1B = _BV(WGM12) | _BV(CS10); \ + OCR1A = SYSCLOCK * USECPERTICK / 1000000; \ + TCNT1 = 0; \ +}) +#if defined(CORE_OC1A_PIN) +#define TIMER_PWM_PIN CORE_OC1A_PIN /* Teensy */ +#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#define TIMER_PWM_PIN 11 /* Arduino Mega */ +#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) +#define TIMER_PWM_PIN 13 /* Sanguino */ +#else +#define TIMER_PWM_PIN 9 /* Arduino Duemilanove, Diecimila, LilyPad, etc */ +#endif + + +// defines for timer3 (16 bits) +#elif defined(IR_USE_TIMER3) +#define TIMER_RESET +#define TIMER_ENABLE_PWM (TCCR3A |= _BV(COM3A1)) +#define TIMER_DISABLE_PWM (TCCR3A &= ~(_BV(COM3A1))) +#define TIMER_ENABLE_INTR (TIMSK3 = _BV(OCIE3A)) +#define TIMER_DISABLE_INTR (TIMSK3 = 0) +#define TIMER_INTR_NAME TIMER3_COMPA_vect +#define TIMER_CONFIG_KHZ(val) ({ \ + const uint16_t pwmval = SYSCLOCK / 2000 / (val); \ + TCCR3A = _BV(WGM31); \ + TCCR3B = _BV(WGM33) | _BV(CS30); \ + ICR3 = pwmval; \ + OCR3A = pwmval / 3; \ +}) +#define TIMER_CONFIG_NORMAL() ({ \ + TCCR3A = 0; \ + TCCR3B = _BV(WGM32) | _BV(CS30); \ + OCR3A = SYSCLOCK * USECPERTICK / 1000000; \ + TCNT3 = 0; \ +}) +#if defined(CORE_OC3A_PIN) +#define TIMER_PWM_PIN CORE_OC3A_PIN /* Teensy */ +#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#define TIMER_PWM_PIN 5 /* Arduino Mega */ +#else +#error "Please add OC3A pin number here\n" +#endif + + +// defines for timer4 (10 bits, high speed option) +#elif defined(IR_USE_TIMER4_HS) +#define TIMER_RESET +#define TIMER_ENABLE_PWM (TCCR4A |= _BV(COM4A1)) +#define TIMER_DISABLE_PWM (TCCR4A &= ~(_BV(COM4A1))) +#define TIMER_ENABLE_INTR (TIMSK4 = _BV(TOIE4)) +#define TIMER_DISABLE_INTR (TIMSK4 = 0) +#define TIMER_INTR_NAME TIMER4_OVF_vect +#define TIMER_CONFIG_KHZ(val) ({ \ + const uint16_t pwmval = SYSCLOCK / 2000 / (val); \ + TCCR4A = (1<> 8; \ + OCR4C = pwmval; \ + TC4H = (pwmval / 3) >> 8; \ + OCR4A = (pwmval / 3) & 255; \ +}) +#define TIMER_CONFIG_NORMAL() ({ \ + TCCR4A = 0; \ + TCCR4B = _BV(CS40); \ + TCCR4C = 0; \ + TCCR4D = 0; \ + TCCR4E = 0; \ + TC4H = (SYSCLOCK * USECPERTICK / 1000000) >> 8; \ + OCR4C = (SYSCLOCK * USECPERTICK / 1000000) & 255; \ + TC4H = 0; \ + TCNT4 = 0; \ +}) +#if defined(CORE_OC4A_PIN) +#define TIMER_PWM_PIN CORE_OC4A_PIN /* Teensy */ +#elif defined(__AVR_ATmega32U4__) +#define TIMER_PWM_PIN 13 /* Leonardo */ +#else +#error "Please add OC4A pin number here\n" +#endif + + +// defines for timer4 (16 bits) +#elif defined(IR_USE_TIMER4) +#define TIMER_RESET +#define TIMER_ENABLE_PWM (TCCR4A |= _BV(COM4A1)) +#define TIMER_DISABLE_PWM (TCCR4A &= ~(_BV(COM4A1))) +#define TIMER_ENABLE_INTR (TIMSK4 = _BV(OCIE4A)) +#define TIMER_DISABLE_INTR (TIMSK4 = 0) +#define TIMER_INTR_NAME TIMER4_COMPA_vect +#define TIMER_CONFIG_KHZ(val) ({ \ + const uint16_t pwmval = SYSCLOCK / 2000 / (val); \ + TCCR4A = _BV(WGM41); \ + TCCR4B = _BV(WGM43) | _BV(CS40); \ + ICR4 = pwmval; \ + OCR4A = pwmval / 3; \ +}) +#define TIMER_CONFIG_NORMAL() ({ \ + TCCR4A = 0; \ + TCCR4B = _BV(WGM42) | _BV(CS40); \ + OCR4A = SYSCLOCK * USECPERTICK / 1000000; \ + TCNT4 = 0; \ +}) +#if defined(CORE_OC4A_PIN) +#define TIMER_PWM_PIN CORE_OC4A_PIN +#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#define TIMER_PWM_PIN 6 /* Arduino Mega */ +#else +#error "Please add OC4A pin number here\n" +#endif + + +// defines for timer5 (16 bits) +#elif defined(IR_USE_TIMER5) +#define TIMER_RESET +#define TIMER_ENABLE_PWM (TCCR5A |= _BV(COM5A1)) +#define TIMER_DISABLE_PWM (TCCR5A &= ~(_BV(COM5A1))) +#define TIMER_ENABLE_INTR (TIMSK5 = _BV(OCIE5A)) +#define TIMER_DISABLE_INTR (TIMSK5 = 0) +#define TIMER_INTR_NAME TIMER5_COMPA_vect +#define TIMER_CONFIG_KHZ(val) ({ \ + const uint16_t pwmval = SYSCLOCK / 2000 / (val); \ + TCCR5A = _BV(WGM51); \ + TCCR5B = _BV(WGM53) | _BV(CS50); \ + ICR5 = pwmval; \ + OCR5A = pwmval / 3; \ +}) +#define TIMER_CONFIG_NORMAL() ({ \ + TCCR5A = 0; \ + TCCR5B = _BV(WGM52) | _BV(CS50); \ + OCR5A = SYSCLOCK * USECPERTICK / 1000000; \ + TCNT5 = 0; \ +}) +#if defined(CORE_OC5A_PIN) +#define TIMER_PWM_PIN CORE_OC5A_PIN +#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#define TIMER_PWM_PIN 46 /* Arduino Mega */ +#else +#error "Please add OC5A pin number here\n" +#endif + + +// defines for special carrier modulator timer +#elif defined(IR_USE_TIMER_CMT) +#define TIMER_RESET ({ \ + uint8_t tmp = CMT_MSC; \ + CMT_CMD2 = 30; \ +}) +#define TIMER_ENABLE_PWM CORE_PIN5_CONFIG = PORT_PCR_MUX(2)|PORT_PCR_DSE|PORT_PCR_SRE +#define TIMER_DISABLE_PWM CORE_PIN5_CONFIG = PORT_PCR_MUX(1)|PORT_PCR_DSE|PORT_PCR_SRE +#define TIMER_ENABLE_INTR NVIC_ENABLE_IRQ(IRQ_CMT) +#define TIMER_DISABLE_INTR NVIC_DISABLE_IRQ(IRQ_CMT) +#define TIMER_INTR_NAME cmt_isr +#ifdef ISR +#undef ISR +#endif +#define ISR(f) void f(void) +#if F_BUS == 48000000 +#define CMT_PPS_VAL 5 +#else +#define CMT_PPS_VAL 2 +#endif +#define TIMER_CONFIG_KHZ(val) ({ \ + SIM_SCGC4 |= SIM_SCGC4_CMT; \ + SIM_SOPT2 |= SIM_SOPT2_PTD7PAD; \ + CMT_PPS = CMT_PPS_VAL; \ + CMT_CGH1 = 2667 / val; \ + CMT_CGL1 = 5333 / val; \ + CMT_CMD1 = 0; \ + CMT_CMD2 = 30; \ + CMT_CMD3 = 0; \ + CMT_CMD4 = 0; \ + CMT_OC = 0x60; \ + CMT_MSC = 0x01; \ +}) +#define TIMER_CONFIG_NORMAL() ({ \ + SIM_SCGC4 |= SIM_SCGC4_CMT; \ + CMT_PPS = CMT_PPS_VAL; \ + CMT_CGH1 = 1; \ + CMT_CGL1 = 1; \ + CMT_CMD1 = 0; \ + CMT_CMD2 = 30; \ + CMT_CMD3 = 0; \ + CMT_CMD4 = 19; \ + CMT_OC = 0; \ + CMT_MSC = 0x03; \ +}) +#define TIMER_PWM_PIN 5 + + +#else // unknown timer +#error "Internal code configuration error, no known IR_USE_TIMER# defined\n" +#endif + + +// defines for blinking the LED +#if defined(CORE_LED0_PIN) +#define BLINKLED CORE_LED0_PIN +#define BLINKLED_ON() (digitalWrite(CORE_LED0_PIN, HIGH)) +#define BLINKLED_OFF() (digitalWrite(CORE_LED0_PIN, LOW)) +#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) +#define BLINKLED 13 +#define BLINKLED_ON() (PORTB |= B10000000) +#define BLINKLED_OFF() (PORTB &= B01111111) +#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__) +#define BLINKLED 0 +#define BLINKLED_ON() (PORTD |= B00000001) +#define BLINKLED_OFF() (PORTD &= B11111110) +#else +#define BLINKLED 13 +#define BLINKLED_ON() (PORTB |= B00100000) +#define BLINKLED_OFF() (PORTB &= B11011111) +#endif + +#endif diff --git a/compilation/arduino/libraries/extension/extension.cpp b/compilation/arduino/libraries/extension/extension.cpp index ef7535be..ec3b9349 100644 --- a/compilation/arduino/libraries/extension/extension.cpp +++ b/compilation/arduino/libraries/extension/extension.cpp @@ -1,9 +1,9 @@ #include #include "extension.h" -extension::extension(){} +Extension::Extension(){} -void extension::ultrason(byte trig, byte echo){ +void Extension::ultrason(byte trig, byte echo){ pinMode(trig, OUTPUT); digitalWrite(trig, LOW); pinMode(echo, INPUT); @@ -11,117 +11,55 @@ void extension::ultrason(byte trig, byte echo){ echo_pin = echo; } -float extension::ultrason_distance(){ +float Extension::mesure_distance(){ digitalWrite(trig_pin, HIGH); delayMicroseconds(10); digitalWrite(trig_pin, LOW); return pulseIn(echo_pin, HIGH)/58; } -void extension::bargraphe(byte dcki, byte di){ +void Extension::bargraphe(byte dcki, byte di){ pinMode(dcki, OUTPUT); pinMode(di, OUTPUT); dcki_pin = dcki; di_pin = di; } -void extension::bargraphe_allumer(byte del){ - unsigned char _state[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - void sendData(unsigned int data) { - for (unsigned char i=0; i < 16; i++){ - unsigned int state=(data&0x8000) ? HIGH : LOW; - digitalWrite(di_pin, state); - state=digitalRead(dcki_pin) ? LOW : HIGH; - digitalWrite(dcki_pin, state); - data <<= 1; - } - } - void setData(unsigned char _state[]) { - sendData(0x00); - for (unsigned char i=0; i<10; i++) sendData(_state[10-i-1]); - sendData(0x00); - sendData(0x00); - digitalWrite(di_pin, LOW); - delayMicroseconds(10); - for (unsigned char i=0; i<4; i++){ +void Extension::sendData(unsigned int data){ + for (byte i=0; i < 16; i++){ + unsigned int state=(data&0x8000) ? HIGH : LOW; + digitalWrite(di_pin, state); + state=digitalRead(dcki_pin) ? LOW : HIGH; + digitalWrite(dcki_pin, state); + data <<= 1; + } +} + +void Extension::setData(unsigned char _state[]){ + sendData(0x00); + for (byte i=0; i<10; i++) sendData(_state[10-i-1]); + sendData(0x00); + sendData(0x00); + digitalWrite(di_pin, LOW); + delayMicroseconds(10); + for (byte i=0; i<4; i++){ digitalWrite(di_pin, HIGH); digitalWrite(di_pin, LOW); - } } +} + +void Extension::bargraphe_allumer(float del){ + unsigned char _state[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; del=max(0, min(10, del)); del *= 8; for (byte i=0; i<10; i++) { _state[i]=(del>8) ? ~0 : (del>0) ? ~(~0 << byte(del)) : 0; del -= 8; - }; - setData(_state); -} - -void extension::matrice16(){ - pinMode(A4,OUTPUT); - pinMode(A5,OUTPUT); - digitalWrite(A4,LOW); - digitalWrite(A5,LOW); - sda_pin = A4; - scl_pin = A5; -} - -void extension::matrice16_afficher(byte s[]){ - void IIC_start() { - digitalWrite(scl_pin,LOW); - delayMicroseconds(3); - digitalWrite(sda_pin,HIGH); - delayMicroseconds(3); - digitalWrite(scl_pin,HIGH); - delayMicroseconds(3); - digitalWrite(sda_pin,LOW); - delayMicroseconds(3); - } - void IIC_end() { - digitalWrite(scl_pin,LOW); - delayMicroseconds(3); - digitalWrite(sda_pin,LOW); - delayMicroseconds(3); - digitalWrite(scl_pin,HIGH); - delayMicroseconds(3); - digitalWrite(sda_pin,HIGH); - delayMicroseconds(3); - } - void IIC_send(unsigned char send_data) { - for(char i = 0;i < 8;i++) { - digitalWrite(scl_pin,LOW); - delayMicroseconds(3); - if(send_data & 0x01) { - digitalWrite(sda_pin,HIGH); - } else { - digitalWrite(sda_pin,LOW); - } - delayMicroseconds(3); - digitalWrite(scl_pin,HIGH); - delayMicroseconds(3); - send_data = send_data >> 1; - } } - IIC_start(); - IIC_send(0x40); - IIC_end(); - IIC_start(); - IIC_send(0xC0); - for(char i=0; i<16; i++) { - IIC_send(s[i]); - } - IIC_end(); - IIC_start(); - IIC_send(0x8F); - IIC_end(); -} - -void extension::matrice16_effacer(){ - byte t[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; - matrice16_afficher (t); + setData(_state); } -void extension::rvb(byte pinR, byte pinV, byte pinB){ +void Extension::rvb(byte pinR, byte pinV, byte pinB){ pinMode(pinR, OUTPUT); pinMode(pinV, OUTPUT); pinMode(pinB, OUTPUT); @@ -130,12 +68,64 @@ void extension::rvb(byte pinR, byte pinV, byte pinB){ Bleu_pin = pinB; } -void extension::rvb_afficher_couleur(byte red, byte green, byte blue){ +void Extension::rvb_afficher_couleur(byte red, byte green, byte blue){ analogWrite(Rouge_pin, red); analogWrite(Vert_pin, green); analogWrite(Bleu_pin, blue); } -void extension::mp3(){ - -} \ No newline at end of file +void Extension::exe_cmd(byte CMD, byte Par1, byte Par2){ + word check=-(0xFF + 0x06 + CMD + 0x00 + Par1 + Par2); + byte Command[10]={0x7E,0xFF,0x06,CMD,0x00,Par1,Par2,highByte(check),lowByte(check),0xEF}; + for (byte i=0; i<10; i++) Serial.write(Command[i]); +} + +void Extension::mp3(byte volume_hex){ + Serial.begin(9600); + delay(1000); + exe_cmd(0x3F,0,0); + delay(500); + exe_cmd(0x06,0,volume_hex); + delay(500); +} + +void Extension::mp3_lecture_auto(byte volume_hex){ + Serial.begin(9600); + delay(1000); + exe_cmd(0x3F,0,0); + delay(500); + exe_cmd(0x06,0,volume_hex); + delay(500); + exe_cmd(0x11,0,1); + delay(500); +} + +void Extension::mp3_lecture(){ + exe_cmd(0x0D,0,1); + delay(500); +} + +void Extension::mp3_pause(){ + exe_cmd(0x0E,0,0); + delay(500); +} + +void Extension::mp3_suivant(){ + exe_cmd(0x01,0,1); + delay(500); +} + +void Extension::mp3_precedent(){ + exe_cmd(0x02,0,1); + delay(500); +} + +void Extension::mp3_volume(byte volume_hex){ + exe_cmd(0x06,0,volume_hex); + delay(500); +} + +void Extension::mp3_lecture_piste(byte piste){ + exe_cmd(0x03,0,piste); + delay(500); +} diff --git a/compilation/arduino/libraries/extension/extension.h b/compilation/arduino/libraries/extension/extension.h index 18f091fd..f984c1ec 100644 --- a/compilation/arduino/libraries/extension/extension.h +++ b/compilation/arduino/libraries/extension/extension.h @@ -1,18 +1,23 @@ #ifndef extension_h #define extension_h -class extension { +class Extension { public: - extension(); + Extension(); void ultrason(byte trig, byte echo); - float ultrason_distance(); + float mesure_distance(); void bargraphe(byte dcki, byte di); - void bargraphe_allumer(byte del); - void matrice16(byte sda, byte scl); - void matrice32(byte sda, byte scl); + void bargraphe_allumer(float del); void rvb(byte pinR, byte pinV, byte pinB); void rvb_afficher_couleur(byte red, byte green, byte blue); - void mp3(); + void mp3(byte volume_hex); + void mp3_lecture_auto(byte volume_hex); + void mp3_lecture(); + void mp3_lecture_piste(byte piste); + void mp3_suivant(); + void mp3_precedent(); + void mp3_pause(); + void mp3_volume(byte volume_hex); private: byte Rouge_pin; byte Vert_pin; @@ -21,8 +26,9 @@ class extension { byte echo_pin; byte dcki_pin; byte di_pin; - byte sda_pin; - byte scl_pin; + void setData(unsigned char _state[]); + void sendData(unsigned int data); + void exe_cmd(byte CMD, byte Par1, byte Par2); }; #endif \ No newline at end of file diff --git a/package.json b/package.json index d1ec3d76..2dd8c094 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,10 @@ { "name": "Blocklino", - "version": "1.8.0", + "version": "1.9.0", "description": "environnement de développement pour langage graphique", "author": "Fontaine Jean Philippe", "license": "CC0-1.0", + "homepage": "https://fontainejp.github.io/", "main": "electronApp.js", "keywords": [ "blockly", @@ -31,7 +32,9 @@ "postinstall": "electron-builder install-app-deps", "start": "electron .", "compiler": "build --win --ia32", - "publier": "build --win --ia32 -p always" + "publier": "build --win --ia32 -p always", + "comp-mac": "build --mac", + "pub-mac": "build --mac -p always" }, "build": { "appId": "com.electron.blocklino", @@ -58,6 +61,10 @@ ], "icon": "build/app.ico" }, + "mac": { + "target": "dmg", + "icon": "build/app.icns" + }, "fileAssociations": [ { "ext": "bloc", diff --git a/www/accueil.html b/www/accueil.html deleted file mode 100644 index 7b3060b4..00000000 --- a/www/accueil.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - - BLOCKLY-TOOLS - - - - - - - - - -
-
- -
-
-
-
-
-

BLOCKLY-TOOLS

-

environnement de développement pour langage graphique libre et open source.

-


-
-
- -

BLOCKLINO

- Programmation de carte à microcontrôlleur.

- Démarrer -
-
-
-

BLOCKLY-WEB

- Le HTML et CSS en temps réel.


- Démarrer -
-
- -

BLOCKLY-FACTORY

- Fabriquer vos propres blocs.


- Démarrer -
-
-
-
-
- - - \ No newline at end of file diff --git a/www/blocs&generateurs/_actionneur.js b/www/blocs&generateurs/_actionneur.js index 143fa7bb..b8acd749 100644 --- a/www/blocs&generateurs/_actionneur.js +++ b/www/blocs&generateurs/_actionneur.js @@ -730,7 +730,7 @@ Blockly.Arduino["pixel_setcolor"]=function(block){ var color=block.getFieldValue("color"); var colorR=color[1] + color[2], colorG=color[3] + color[4], colorB=color[5] + color[6]; var red=parseInt(colorR,16), green=parseInt(colorG,16), blue=parseInt(colorB,16); - return "pixel.setPixelColor(" + pin + ", " + red + ", " + green + ", " + blue + ");\n" + return "pixel.setPixelColor(" + pin + ", " + red + ", " + green + ", " + blue + ");\npixel.show();\n" }; Blockly.Python["pixel_setcolor"]=function(block){ var pin=Blockly.Python.valueToCode(block, "broche", Blockly.Python.ORDER_ASSIGNMENT); @@ -771,7 +771,7 @@ Blockly.Blocks["pixel_clear"]={init:function(){ this.setHelpUrl("http://")} }; Blockly.Arduino["pixel_clear"]=function(block){ - return "pixel.show();\n" + return "pixel.clear();\npixel.show();\n" }; Blockly.Python["pixel_clear"]=function(block){ var carte = localStorage.getItem('card') @@ -781,7 +781,6 @@ Blockly.Python["pixel_clear"]=function(block){ } else { return "np.clear()\n" } - }; ////////////// Blockly.Blocks["pixel_setbrightness"]={init:function(){ @@ -797,6 +796,25 @@ Blockly.Arduino["pixel_setbrightness"]=function(block){ return "pixel.setBrightness(" + value + ");\n" }; Blockly.Python["pixel_setbrightness"]=function(){return""}; +////////////// +Blockly.Blocks["pixel_setcolor_random"]={init:function(){ + this.appendValueInput("broche").setCheck("Number").appendField(Blockly.Msg.pixel6); + this.appendDummyInput().appendField(Blockly.Msg.pixel8); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setColour("#00929F"); + this.setTooltip(Blockly.Msg.pixel6_tooltip); + this.setHelpUrl("http://")} +}; +Blockly.Arduino["pixel_setcolor_random"]=function(block){ + var pin=Blockly.Arduino.valueToCode(block, "broche", Blockly.Arduino.ORDER_ASSIGNMENT); + Blockly.Arduino.setups_["randomSeed"]="randomSeed(analogRead(0));"; + return "pixel.setPixelColor(" + pin + ", random(0,256), random(0,256), random(0,256));\npixel.show();\n" +}; +Blockly.Python["pixel_setcolor_random"]=function(block){ + return "" +}; ////////////// /* moteur */ ////////////// diff --git a/www/blocs&generateurs/_microbit.js b/www/blocs&generateurs/_microbit.js index d68af558..04ec869d 100644 --- a/www/blocs&generateurs/_microbit.js +++ b/www/blocs&generateurs/_microbit.js @@ -554,7 +554,7 @@ Blockly.Blocks["plays"]={init:function(){ Blockly.Python["plays"]=function(block){ var value_note=block.getFieldValue("note"); var value_tempo=block.getFieldValue("tempo"); - Blockly.Python.imports_["time"]="import time"; + Blockly.Python.imports_["music"]="import music"; return 'music.play(["' + value_note + ':' + value_tempo +'"])\n' }; ////////////// @@ -873,7 +873,7 @@ Blockly.Arduino['print'] = function(block) { return "Serial.println(" + str + ");\n" }; ///////////////// -/* bluetooth */ +/* bluetooth /////////////// Blockly.Blocks["bluetooth_a"]={init:function(){ this.appendValueInput("data_s").setCheck("Number").appendField(Blockly.Msg.bluetooth2); @@ -1036,4 +1036,5 @@ Blockly.Blocks["bluetooth_create_container"]={init:function(){ this.contextMenu = false } }; -////////////// \ No newline at end of file +////////////// +*/ \ No newline at end of file diff --git a/www/blocs&generateurs/arduino_generateurs_cpp.js b/www/blocs&generateurs/arduino_generateurs_cpp.js index 1e7d779b..04862987 100644 --- a/www/blocs&generateurs/arduino_generateurs_cpp.js +++ b/www/blocs&generateurs/arduino_generateurs_cpp.js @@ -131,7 +131,7 @@ Blockly.Arduino["bluetooth_init"]=function(block){ var dropdown_pin2=Blockly.Arduino.valueToCode(block,"PIN2", Blockly.Arduino.ORDER_NONE); var dropdown_speed=block.getFieldValue("SPEED"); var n=0; - Blockly.Arduino.includes_["bluetooth"]="#include "; + Blockly.Arduino.includes_["define_ss"]="#include "; Blockly.Arduino.definitions_["bluetooth"]="SoftwareSerial bluetooth("+dropdown_pin1+","+dropdown_pin2+");"; Blockly.Arduino.setups_["bluetooth"]="bluetooth.begin(" + dropdown_speed + ");"; return "" diff --git a/www/blocs&generateurs/factory/add.js b/www/blocs&generateurs/factory/add.js deleted file mode 100644 index 811bd888..00000000 --- a/www/blocs&generateurs/factory/add.js +++ /dev/null @@ -1,13 +0,0 @@ -Blockly.Blocks['monbloc']={init:function(){ - this.appendDummyInput() - .setAlign(Blockly.ALIGN_CENTRE) - .appendField("code()"); - this.setInputsInline(false); - this.setOutput(true); - this.setColour('#00929f')} -}; -Blockly.Python['monbloc']=function(block){ - Blockly.Python.userFunctions_['func'] = 'def code():\n return 0'; - var code = 'code()'; - return [code, Blockly.Python.ORDER_ATOMIC]; -}; \ No newline at end of file diff --git a/www/blocs&generateurs/factory/append.js b/www/blocs&generateurs/factory/append.js index bd144996..35ce40f3 100644 --- a/www/blocs&generateurs/factory/append.js +++ b/www/blocs&generateurs/factory/append.js @@ -1 +1,2 @@ // Blocs réalisés avec BLOCKLY-FACTORY + diff --git a/www/blocs&generateurs/factory/generator.js b/www/blocs&generateurs/factory/generator.js index 836a8f36..d22f88c9 100644 --- a/www/blocs&generateurs/factory/generator.js +++ b/www/blocs&generateurs/factory/generator.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict'; var blockType = ''; var mainWorkspace = null; @@ -250,14 +250,14 @@ function updateGenerator() { } } if (language_generator=="Arduino") { - code.push(" Blockly." + language_generator + ".includes_['lib'] = '#include <lib.h> ;';"); - code.push(" Blockly." + language_generator + ".variables_['var'] = 'int var;';"); - code.push(" Blockly." + language_generator + ".definitions_['inst'] = 'inst instance;';"); - code.push(" Blockly." + language_generator + ".userFunctions_['func'] = 'void func(){return 0};';"); - code.push(" Blockly." + language_generator + ".setups_['setup'] = 'code du setup();';"); - code.push(" var code = 'code du loop()';"); + code.push(" Blockly." + language_generator + ".includes_['lib'] = '#include \"lib.h\" ;'; // à supprimer si inutile"); + code.push(" Blockly." + language_generator + ".variables_['var'] = 'int var;'; // à supprimer si inutile"); + code.push(" Blockly." + language_generator + ".definitions_['inst'] = 'inst instance;'; // à supprimer si inutile"); + code.push(" Blockly." + language_generator + ".userFunctions_['func'] = 'void func(){return 0};'; // à supprimer si inutile"); + code.push(" Blockly." + language_generator + ".setups_['setup'] = 'code_setup();'; // à supprimer si inutile"); + code.push(" var code = 'code_loop();\\n';"); if (rootBlock.getFieldValue('CONNECTIONS') == 'LEFT') { - code.push(" return [code, Blockly." + language_generator + ".ORDER_ATOMIC];"); + code.push(" return [code, Blockly." + language_generator + ".ORDER_ATOMIC]"); } else { code.push(" return code"); } @@ -266,9 +266,9 @@ function updateGenerator() { code.push(" Blockly." + language_generator + ".imports_['lib'] = 'import lib';"); code.push(" Blockly." + language_generator + ".definitions_['inst'] = 'inst instance';"); code.push(" Blockly." + language_generator + ".userFunctions_['func'] = 'def func():\\n return 0';"); - code.push(" var code = 'placer ici le reste du code';"); + code.push(" var code = 'code';"); if (rootBlock.getFieldValue('CONNECTIONS') == 'LEFT') { - code.push(" return [code, Blockly." + language_generator + ".ORDER_ATOMIC];"); + code.push(" return [code, Blockly." + language_generator + ".ORDER_ATOMIC]"); } else { code.push(" return code"); } @@ -276,7 +276,7 @@ function updateGenerator() { if (language_generator=="html") { code.push(" var code = 'placer votre code ici'"); if (rootBlock.getFieldValue('CONNECTIONS') == 'LEFT') { - code.push(" return [code, Blockly." + language_generator + ".ORDER_ATOMIC];"); + code.push(" return [code, Blockly." + language_generator + ".ORDER_ATOMIC]"); } else { code.push(" return code"); } @@ -285,9 +285,17 @@ function updateGenerator() { code.push("};"); editor.setValue(code.join('\n'),1); } +var oldDir = null; function updatePreview() { - if (previewWorkspace) previewWorkspace.dispose(); - previewWorkspace = Blockly.inject('preview',{scrollbars:true,grid:{snap:true},media:'media/',sounds:false,zoom:{controls:true,wheel:true}}); + var newDir = document.getElementById('direction').value; + if (oldDir != newDir) { + if (previewWorkspace) { + previewWorkspace.dispose(); + } + var rtl = newDir == 'rtl'; + previewWorkspace = Blockly.inject('preview',{rtl: rtl, media: 'media/', sounds: false, scrollbars: true}); + oldDir = newDir; + } previewWorkspace.clear(); if (Blockly.Blocks[blockType]) throw 'Block name collides with existing property: ' + blockType; var code = document.getElementById('languagePre').textContent.trim(); @@ -342,22 +350,9 @@ function init() { rootBlock.initSvg(); rootBlock.render(); rootBlock.setDeletable(false); - /*var urlFile = getStringParamFromUrl('url', '') - if (urlFile) { - $.get( urlFile, function(data){ - if (data){ - var xml = Blockly.Xml.textToDom(data); - mainWorkspace.clear(); - Blockly.Xml.domToWorkspace(xml, mainWorkspace); - mainWorkspace.render(); - var elem = xml.getElementsByTagName("language")[0]; - var node = elem.childNodes[0]; - localStorage.code_bf = node.nodeValue; - } - }, 'text') - }*/ mainWorkspace.addChangeListener(onchange); if (window.localStorage.prog == "python") $("#language_generator").val("Python"); + document.getElementById('direction').addEventListener('change', updatePreview); document.getElementById('language_generator').addEventListener('change', updateGenerator); $('[data-toggle="tooltip"]').tooltip(); } diff --git a/www/factory.html b/www/factory.html index 2b981a29..8556fa91 100644 --- a/www/factory.html +++ b/www/factory.html @@ -64,6 +64,10 @@
+
Prévisualisation :
diff --git a/www/index.html b/www/index.html index 1a44fdfb..d02654f9 100644 --- a/www/index.html +++ b/www/index.html @@ -519,39 +519,66 @@
diff --git a/www/js/blocklino.js b/www/js/blocklino.js index 82c75e2c..9d60b6a1 100644 --- a/www/js/blocklino.js +++ b/www/js/blocklino.js @@ -1,11 +1,13 @@ 'use strict'; var BlocklyDuino = {}; +var option_scratch = {}; BlocklyDuino.selectedToolbox = "toolbox_arduino_all"; BlocklyDuino.selectedCard = "uno"; BlocklyDuino.content = "on"; BlocklyDuino.contentHTML = "on"; BlocklyDuino.theme = "sqlserver"; +BlocklyDuino.renderer = "blockly"; BlocklyDuino.size = "14px"; BlocklyDuino.workspace = null; BlocklyDuino.loadOnce = ""; @@ -16,7 +18,11 @@ BlocklyDuino.prog_microbit = "# Python\n\nfrom microbit import *\n\nwhile True:\ BlocklyDuino.init = function() { Code.initLanguage(); BlocklyDuino.loadConfig(); - BlocklyDuino.workspace = Blockly.inject('content_blocks',{grid:{snap:true},sounds:false,media:'media/',toolbox:BlocklyDuino.buildToolbox(),zoom:{controls:true,wheel:true}}); + if (window.localStorage.renderer == "blockly") { + BlocklyDuino.workspace = Blockly.inject('content_blocks',{grid:{snap:true},sounds:false,media:'media/',toolbox:BlocklyDuino.buildToolbox(),zoom:{controls:true,wheel:true}}); + } else { + BlocklyDuino.workspace = Blockly.inject('content_blocks',option_scratch); + } var bTD = document.getElementsByClassName('blocklyToolboxDiv'); if ($("#toolboxes").val()=="toolbox_fresnel_all") { bTD[0].style.width = "290px" @@ -151,6 +157,7 @@ BlocklyDuino.loadConfig = function() { var content = window.localStorage.content; var prog = window.localStorage.prog; var theme = window.localStorage.theme; + var renderer = window.localStorage.renderer; var size = window.localStorage.size; if (card===undefined) { window.localStorage.card = BlocklyDuino.selectedCard; @@ -200,6 +207,9 @@ BlocklyDuino.loadConfig = function() { $('#fontsize').val(size); document.getElementById('content_code').style.fontSize = size } + if (renderer === undefined) { + window.localStorage.renderer = BlocklyDuino.renderer + } } BlocklyDuino.change_card = function() { //BlocklyDuino.backupBlocks(); @@ -322,6 +332,7 @@ BlocklyDuino.bindFunctions = function() { window.localStorage.size = $(this).val() }); $('#theme').on("change", BlocklyDuino.apply_theme); + $('#renderer').on("change", BlocklyDuino.apply_renderer); $('.modal-child').on('show.bs.modal', function () { var modalParent = $(this).attr('data-modal-parent'); $(modalParent).css('opacity', 0) @@ -459,6 +470,15 @@ BlocklyDuino.apply_theme = function () { BlocklyDuino.theme_sqlserver() } } +BlocklyDuino.apply_renderer = function () { + var new_renderer = $('#renderer').val(); + window.localStorage.renderer = new_renderer + if (new_renderer == "blockly") { + + } else { + + } +} BlocklyDuino.checkAll = function () { if(this.checked) { $('#modal-body-config input:checkbox[id^=checkbox_]').each(function() { diff --git a/www/lang/Arduino_en.js b/www/lang/Arduino_en.js index 6ccdbdb4..307cbbd9 100644 --- a/www/lang/Arduino_en.js +++ b/www/lang/Arduino_en.js @@ -215,11 +215,13 @@ Blockly.Msg.pixel4 = "number"; Blockly.Msg.pixel5 = "set pixel brightness to"; Blockly.Msg.pixel6 = "set the pixel"; Blockly.Msg.pixel7 = "turn off pixels"; +Blockly.Msg.pixel8="with random color"; Blockly.Msg.pixel1_tooltip="neopixel RGB module indicate the pin to be connected and the number of pixels"; Blockly.Msg.pixel2_tooltip="show changes made"; Blockly.Msg.pixel3_tooltip="choose the pixel to light and its color \nCaution the numbering starts at 0"; Blockly.Msg.pixel4_tooltip="turn off all the pixels"; Blockly.Msg.pixel5_tooltip="adjusts pixel brightness (from 0 to 255)"; +Blockly.Msg.pixel6_tooltip="choose the pixel to light and its random color\nCaution the numbering starts at 0"; // output Blockly.Msg.ARDUINO_INOUT_DIGITAL_WRITE_INPUT1 = "put the DIGITAL pin"; Blockly.Msg.ARDUINO_INOUT_DIGITAL_WRITE_TOOLTIP = "write a 0 or 1 logical state to a specific output"; diff --git a/www/lang/Arduino_fr.js b/www/lang/Arduino_fr.js index a13d9928..a3f7d84a 100644 --- a/www/lang/Arduino_fr.js +++ b/www/lang/Arduino_fr.js @@ -213,13 +213,15 @@ Blockly.Msg.pixel2="mettre à jour les pixels"; Blockly.Msg.pixel3="avec la couleur"; Blockly.Msg.pixel4="nombre"; Blockly.Msg.pixel5="régler la luminosité des pixels à"; -Blockly.Msg.pixel6="régler la pixel"; +Blockly.Msg.pixel6="allumer la pixel"; Blockly.Msg.pixel7="éteindre les pixels"; +Blockly.Msg.pixel8="avec une couleur aléatoire"; Blockly.Msg.pixel1_tooltip="module neopixel RVB\nindiquer la broche à connecter et le nombre de pixels"; Blockly.Msg.pixel2_tooltip="affiche les modifications apportées"; Blockly.Msg.pixel3_tooltip="choisir la pixel à allumer ainsi que sa couleur\nAttention la numérotation commence à 0"; Blockly.Msg.pixel4_tooltip="éteint toutes les pixels"; Blockly.Msg.pixel5_tooltip="règle la luminosité des pixels (de 0 à 255)"; +Blockly.Msg.pixel6_tooltip="choisir la pixel à allumer ainsi qu'une couleur aléatoire\nAttention la numérotation commence à 0"; //sortie Blockly.Msg.ARDUINO_INOUT_DIGITAL_WRITE_INPUT1="mettre la broche NUMERIQUE"; Blockly.Msg.ARDUINO_INOUT_DIGITAL_WRITE_TOOLTIP="écrire un état logique (0 ou 1) sur la broche indiquée"; diff --git a/www/lang/code.js b/www/lang/code.js index 8c6dd223..a2dab6e3 100644 --- a/www/lang/code.js +++ b/www/lang/code.js @@ -42,6 +42,8 @@ Code.initLanguage = function() { languageMenu.append(option); } $('#span_theme').text(Blockly.Msg['span_theme']); + $('#span_renderer').text(Blockly.Msg['span_renderer']); + $('#span_library').text(Blockly.Msg['span_library']); $('#span_fontsize').text(Blockly.Msg['span_fontsize']); $('#span_card_connect').text(Blockly.Msg['span_card_connect']); $('#span_card_cpu').text(Blockly.Msg['span_card_cpu']); diff --git a/www/lang/msg_en.js b/www/lang/msg_en.js index d3c7acff..7be69b0a 100644 --- a/www/lang/msg_en.js +++ b/www/lang/msg_en.js @@ -68,7 +68,9 @@ Blockly.Msg.btn_add= " Add to workspace "; Blockly.Msg.btn_tint= " Colors "; Blockly.Msg.btn_games= " BLOCKLY-GAMES "; Blockly.Msg.span_fontsize= "Font size = "; -Blockly.Msg.span_theme= "Theme = "; +Blockly.Msg.span_theme= "Theme : "; +Blockly.Msg.span_renderer= "Renderer : "; +Blockly.Msg.span_library= "Library"; Blockly.Msg.span_card_connect= "Connector = "; Blockly.Msg.span_card_cpu= "CPU = "; Blockly.Msg.span_card_voltage= "Supply voltage = "; diff --git a/www/lang/msg_fr.js b/www/lang/msg_fr.js index 2b3b76d5..f1a9a424 100644 --- a/www/lang/msg_fr.js +++ b/www/lang/msg_fr.js @@ -69,6 +69,8 @@ Blockly.Msg.btn_tint= " couleurs "; Blockly.Msg.btn_games= " BLOCKLY-GAMES "; Blockly.Msg.span_fontsize= "Taille de police : "; Blockly.Msg.span_theme= "Thème : "; +Blockly.Msg.span_renderer= "Rendu : "; +Blockly.Msg.span_library= "Bibliothèque"; Blockly.Msg.span_card_connect= "Connecteur : "; Blockly.Msg.span_card_cpu= "CPU : "; Blockly.Msg.span_card_voltage= "Tension d'alimentation : "; diff --git a/www/modalVar.html b/www/modalVar.html index 81bc80bd..a03e2bea 100644 --- a/www/modalVar.html +++ b/www/modalVar.html @@ -16,7 +16,6 @@
-

diff --git a/www/splash.html b/www/splash.html deleted file mode 100644 index 0dd1fb61..00000000 --- a/www/splash.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - BLOCKLINO - - - - - - \ No newline at end of file diff --git a/www/toolbox/toolbox_arduino_all.xml b/www/toolbox/toolbox_arduino_all.xml index fc37c1f8..6fcc2d31 100644 --- a/www/toolbox/toolbox_arduino_all.xml +++ b/www/toolbox/toolbox_arduino_all.xml @@ -1,7 +1,7 @@ CAT_LOGIC,CAT_MATH,CAT_TEXT,CAT_TAB,CAT_VARIABLES,CAT_FUNCTIONS,CAT_ARDUINO,CAT_ARDUINO_IN,CAT_ARDUINO_TIME,CAT_actionneur,CAT_ultrason,CAT_com,CAT_STOCKAGE - + @@ -13,7 +13,7 @@ - + @@ -27,23 +27,23 @@ - + - + - - - + + + @@ -52,7 +52,7 @@ - + @@ -61,27 +61,28 @@ - + - - + + - - - + + + + - + @@ -89,7 +90,7 @@ - + @@ -98,7 +99,7 @@ - + @@ -107,11 +108,11 @@ - + - + @@ -124,8 +125,8 @@ - - + + @@ -135,7 +136,7 @@ - + @@ -150,8 +151,8 @@ - - + + @@ -159,7 +160,7 @@ - + @@ -167,13 +168,13 @@ - + - +