├── .gitignore ├── Documents ├── ODROID-GO_REV0.1_20180518.pdf ├── esp32-wrover_datasheet_en-1223875.pdf └── esp32_datasheet_en.pdf ├── Launchers └── README.md ├── README.md ├── component.mk ├── examples ├── Applications │ ├── Colorview │ │ └── Colorview.ino │ ├── FlappyBird │ │ └── FlappyBird.ino │ ├── IR_Receiver │ │ └── IR_Receiver.ino │ ├── PIR_Motion_Detector │ │ └── PIR_Motion_Detector.ino │ ├── Qwerty │ │ └── Qwerty.ino │ ├── RTC │ │ └── RTC.ino │ ├── Servo_Motor │ │ └── Servo_Motor.ino │ ├── Tetris │ │ ├── Tetris.ino │ │ ├── tetris.jpg │ │ └── tetris_img.c │ ├── Ultrasonic_Distance_Meter │ │ └── Ultrasonic_Distance_Meter.ino │ └── Weather_Station │ │ ├── WeatherBoard.cpp │ │ ├── WeatherBoard.h │ │ ├── Weather_Station.ino │ │ └── data │ │ ├── css │ │ ├── images │ │ │ └── ajax-loader.gif │ │ ├── jquerymobile145.css │ │ └── ws_style.css │ │ ├── index.html │ │ └── js │ │ ├── jquery.mask.js │ │ ├── jquery.mobile-1.4.5.min.js │ │ ├── sevenSeg.js │ │ ├── ws_page_setup.js │ │ └── ws_websocket.js ├── BT_Serial │ └── BT_Serial.ino ├── Battery │ └── Battery.ino ├── Buttons │ └── Buttons.ino ├── Hello_World │ └── Hello_World.ino ├── I2C_16x2_LCD │ └── I2C_16x2_LCD.ino ├── LED │ └── LED.ino ├── LED_PWM │ └── LED_PWM.ino ├── Sensors │ ├── MMA8451_ODROID │ │ └── MMA8451_ODROID.ino │ └── MMA8451demo │ │ └── MMA8451demo.ino ├── Speaker │ └── Speaker.ino ├── TFT_Image │ └── TFT_Image.ino └── Wifi_AP │ └── Wifi_AP.ino ├── library.json ├── library.properties ├── prebuilt ├── BT_Serial.ino.bin ├── Battery.ino.bin ├── Buttons.ino.bin ├── Colorview.ino.bin ├── FlappyBird.ino.bin ├── Hello_World.ino.bin ├── I2C_16x2_LCD.ino.bin ├── IR_Receiver.ino.bin ├── LED.ino.bin ├── LED_PWM.ino.bin ├── PIR_Motion_Detector.ino.bin ├── README.md ├── Servo_Motor.ino.bin ├── Speaker.ino.bin ├── Tetris.ino.bin ├── Ultrasonic_Distance_Meter.ino.bin ├── Weather_Station.ino.bin ├── Wifi_AP.ino.bin └── tft_demo.bin └── src ├── Fonts ├── ASC16 ├── ASC16.h ├── Custom │ ├── Orbitron_Light_24.h │ ├── Orbitron_Light_32.h │ ├── Roboto_Thin_24.h │ ├── Satisfy_24.h │ └── Yellowtail_32.h ├── Font16.c ├── Font16.h ├── Font32rle.c ├── Font32rle.h ├── Font64rle.c ├── Font64rle.h ├── Font72rle.c ├── Font72rle.h ├── Font7srle.c ├── Font7srle.h ├── GFXFF │ ├── FreeMono12pt7b.h │ ├── FreeMono18pt7b.h │ ├── FreeMono24pt7b.h │ ├── FreeMono9pt7b.h │ ├── FreeMonoBold12pt7b.h │ ├── FreeMonoBold18pt7b.h │ ├── FreeMonoBold24pt7b.h │ ├── FreeMonoBold9pt7b.h │ ├── FreeMonoBoldOblique12pt7b.h │ ├── FreeMonoBoldOblique18pt7b.h │ ├── FreeMonoBoldOblique24pt7b.h │ ├── FreeMonoBoldOblique9pt7b.h │ ├── FreeMonoOblique12pt7b.h │ ├── FreeMonoOblique18pt7b.h │ ├── FreeMonoOblique24pt7b.h │ ├── FreeMonoOblique9pt7b.h │ ├── FreeSans12pt7b.h │ ├── FreeSans18pt7b.h │ ├── FreeSans24pt7b.h │ ├── FreeSans9pt7b.h │ ├── FreeSansBold12pt7b.h │ ├── FreeSansBold18pt7b.h │ ├── FreeSansBold24pt7b.h │ ├── FreeSansBold9pt7b.h │ ├── FreeSansBoldOblique12pt7b.h │ ├── FreeSansBoldOblique18pt7b.h │ ├── FreeSansBoldOblique24pt7b.h │ ├── FreeSansBoldOblique9pt7b.h │ ├── FreeSansOblique12pt7b.h │ ├── FreeSansOblique18pt7b.h │ ├── FreeSansOblique24pt7b.h │ ├── FreeSansOblique9pt7b.h │ ├── FreeSerif12pt7b.h │ ├── FreeSerif18pt7b.h │ ├── FreeSerif24pt7b.h │ ├── FreeSerif9pt7b.h │ ├── FreeSerifBold12pt7b.h │ ├── FreeSerifBold18pt7b.h │ ├── FreeSerifBold24pt7b.h │ ├── FreeSerifBold9pt7b.h │ ├── FreeSerifBoldItalic12pt7b.h │ ├── FreeSerifBoldItalic18pt7b.h │ ├── FreeSerifBoldItalic24pt7b.h │ ├── FreeSerifBoldItalic9pt7b.h │ ├── FreeSerifItalic12pt7b.h │ ├── FreeSerifItalic18pt7b.h │ ├── FreeSerifItalic24pt7b.h │ ├── FreeSerifItalic9pt7b.h │ ├── TomThumb.h │ ├── gfxfont.h │ ├── license.txt │ └── print.txt ├── HZK16 ├── HZK16.h ├── TrueType │ └── Not_yet_supported.txt └── glcdfont.c ├── odroid_go.cpp ├── odroid_go.h ├── sensors ├── Adafruit_BME280.cpp ├── Adafruit_BME280.h ├── Adafruit_BME280.md ├── Adafruit_BMP085_U.cpp ├── Adafruit_BMP085_U.h ├── Adafruit_MMA8451.cpp ├── Adafruit_MMA8451.h ├── Adafruit_Sensor.h ├── Adafruit_TCS34725.cpp ├── Adafruit_TCS34725.h ├── ODROID_Si1132.cpp ├── ODROID_Si1132.h ├── ODROID_Si70xx.cpp ├── ODROID_Si70xx.h ├── RTClib.cpp ├── RTClib.h ├── Rtc_Pcf8563.cpp ├── Rtc_Pcf8563.h ├── Ultrasonic.cpp ├── Ultrasonic.h ├── Wire.cpp ├── Wire.h ├── esp32-hal-gpio.c ├── esp32-hal-gpio.h ├── esp32-hal-i2c.c ├── esp32-hal-i2c.h ├── esp32-hal-log.h ├── ir │ ├── IRremote.cpp │ ├── IRremote.h │ ├── IRremoteInt.h │ ├── boarddefs.h │ ├── irPronto.cpp │ ├── irRecv.cpp │ ├── irSend.cpp │ ├── ir_Aiwa.cpp │ ├── ir_Denon.cpp │ ├── ir_Dish.cpp │ ├── ir_JVC.cpp │ ├── ir_LG.cpp │ ├── ir_Lego_PF.cpp │ ├── ir_Lego_PF_BitStreamEncoder.h │ ├── ir_Mitsubishi.cpp │ ├── ir_NEC.cpp │ ├── ir_Panasonic.cpp │ ├── ir_RC5_RC6.cpp │ ├── ir_Samsung.cpp │ ├── ir_Sanyo.cpp │ ├── ir_Sharp.cpp │ ├── ir_Sony.cpp │ ├── ir_Template.cpp │ └── ir_Whynter.cpp ├── tca8418.cpp └── tca8418.h ├── utility ├── Button.cpp ├── Button.h ├── Config.h ├── Display.cpp ├── Display.h ├── Display.txt ├── Speaker.cpp ├── Speaker.h ├── battery.cpp ├── battery.h ├── bmp_map.c ├── bmp_map.h ├── glcdfont.c ├── music_8bit.h ├── qrcode.c ├── qrcode.h └── startup_music.c └── web ├── ESP8266WebServer.h ├── Parsing.cpp ├── SimpleTimer.cpp ├── SimpleTimer.h ├── WebServer.cpp ├── WebServer.h ├── WebSockets.cpp ├── WebSockets.h ├── WebSocketsClient.cpp ├── WebSocketsClient.h ├── WebSocketsServer.cpp ├── WebSocketsServer.h ├── detail ├── RequestHandler.h └── RequestHandlersImpl.h ├── libb64 ├── AUTHORS ├── LICENSE ├── cdecode.c ├── cdecode_inc.h ├── cencode.c └── cencode_inc.h └── libsha1 ├── libsha1.c └── libsha1.h /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /Documents/ODROID-GO_REV0.1_20180518.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/Documents/ODROID-GO_REV0.1_20180518.pdf -------------------------------------------------------------------------------- /Documents/esp32-wrover_datasheet_en-1223875.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/Documents/esp32-wrover_datasheet_en-1223875.pdf -------------------------------------------------------------------------------- /Documents/esp32_datasheet_en.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/Documents/esp32_datasheet_en.pdf -------------------------------------------------------------------------------- /Launchers/README.md: -------------------------------------------------------------------------------- 1 | # Launchers 2 | 3 | > Available Emulator Launchers 4 | 5 | ## Go Play 6 | > Factory 7 | 8 | [Go Play](https://github.com/OtherCrashOverride/go-play) from [@OtherCrashOverride](https://github.com/OtherCrashOverride) is the factory distribution launcher for retro video game emulation. 9 | 10 | ### Support 11 | > Emulator Count - **6** 12 | 13 | - [x] Nintendo Entertainment System 14 | - [x] Nintendo Game Boy 15 | - [x] Nintendo Game Boy Color 16 | - [x] Sega Master System 17 | - [x] Sega Game Gear 18 | - [x] Colecovision 19 | 20 | ![Downloads](https://img.shields.io/github/downloads/OtherCrashOverride/go-play/total?style=for-the-badge) 21 | 22 | ## Go Play 23 | > @Pelle7 Enhancements 24 | 25 | [Go Play](https://github.com/pelle7/go-play) from [@pelle7](https://github.com/pelle7) is the factory distribution launcher with enhancements. 26 | 27 | ### Support 28 | > Emulator Count - **6** 29 | 30 | - [x] Nintendo Entertainment System 31 | - [x] Nintendo Game Boy 32 | - [x] Nintendo Game Boy Color 33 | - [x] Sega Master System 34 | - [x] Sega Game Gear 35 | - [x] Colecovision 36 | 37 | ![Downloads](https://img.shields.io/github/downloads/pelle7/go-play/total?style=for-the-badge) 38 | 39 | ## Super Go Play 40 | > Enhanced Go Play 41 | 42 | [Super Go Play](https://github.com/mattkj/super-go-play) from [@mattkj](https://github.com/mattkj) is an enhancement of the factory distribution launcher. 43 | 44 | This version includes color pallete selection for Game Boy *(gnuboy-go)* emulator. 45 | 46 | ### Support 47 | > Emulator Count - **6** 48 | 49 | - [x] Nintendo Entertainment System 50 | - [x] Nintendo Game Boy 51 | - [x] Nintendo Game Boy Color 52 | - [x] Sega Master System 53 | - [x] Sega Game Gear 54 | - [x] Colecovision 55 | 56 | ![Downlaods](https://img.shields.io/github/downloads/mattkj/super-go-play/total?style=for-the-badge) 57 | 58 | ## Retro ESP32 59 | > Retro ESP32 is a turbo charged Odroid Go Launcher, Emulator and ROM Manager 60 | 61 | [Retro ESP32](https://github.com/retro-esp32/RetroESP32) from [@retro-esp32](https://github.com/retro-esp32) is a **community collaboration** with support 62 | 63 | Retro ESP32 is the ultimate feature packed Odroid Go Launcher. 64 | 65 | Drawing inspiration from the popular RetroArch emulator front end of choice. 66 | We packed 11 (current count) prebundled emulators including ROM / Game manager. 67 | Additionally each emulator includes an in game menu for further management. 68 | 69 | ### Support 70 | > Emulator Count - **11** 71 | 72 | - [x] Nintendo Entertainment System 73 | - [x] Nintendo Game Boy 74 | - [x] Nintendo Game Boy Color 75 | - [x] Sega Master System 76 | - [x] Sega Game Gear 77 | - [x] Colecovision 78 | - [x] Sinclair Zx Spectrum 48k 79 | - [x] Atari 2600 80 | - [x] Atari 7800 81 | - [x] Atari Lynx 82 | - [x] PC Engine 83 | 84 | ![Downloads](https://img.shields.io/github/downloads/retro-esp32/RetroESP32/total?style=for-the-badge) 85 | 86 | ## ESPlay Retro Emulation 87 | > Retro-EMU 88 | 89 | [Go Play](https://github.com/pebri86/esplay-retro-emulation) from [@pebri86](https://github.com/pebri86) 90 | 91 | This projects is a set of firmware for playing second and third generation gaming platform and to be runs on esplay-micro-hardware, an ESP32 Devices with WROVER Module (4MB PSRAM) 92 | 93 | ### Support 94 | > Emulator Count - **6** 95 | 96 | - [x] Nintendo Entertainment System 97 | - [x] Nintendo Game Boy 98 | - [x] Nintendo Game Boy Color 99 | - [x] Sega Master System 100 | - [x] Sega Game Gear 101 | - [x] Colecovision 102 | 103 | ![Downloads](https://img.shields.io/github/downloads/pebri86/esplay-retro-emulation/total?style=for-the-badge) -------------------------------------------------------------------------------- /component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | #COMPONENT_SRCDIRS := . src 7 | #COMPONENT_ADD_INCLUDEDIRS := . src 8 | 9 | COMPONENT_SRCDIRS := src src/utility src/sensors src/sensors/ir src/web src/web/libb64 src/web/detail src/web/libsha1 src/Fonts src/Fonts/GFXFF src/Fonts/Custom src/Fonts/TrueType 10 | COMPONENT_ADD_INCLUDEDIRS := src src/utility src/sensors src/sensors/ir src/web src/web/libb64 src/web/detail src/web/libsha1 src/Fonts src/Fonts/GFXFF src/Fonts/Custom src/Fonts/TrueType 11 | -------------------------------------------------------------------------------- /examples/Applications/Colorview/Colorview.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sensors/Adafruit_TCS34725.h" 3 | 4 | //- #define CALI_ENABLE 5 | //- #define PROCESSING_ENABLE 6 | #define LCD_ENABLE 7 | 8 | #if defined(PROCESSING_ENABLE) 9 | #undef LCD_ENABLE 10 | #endif 11 | 12 | Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_1X); 13 | 14 | unsigned long preMillis = 0; 15 | unsigned long curMillis = 0; 16 | int rCal, gCal, bCal; 17 | uint16_t clear, red, green, blue; 18 | unsigned char step = 0; 19 | int cali(void); 20 | 21 | int cali(void) { 22 | 23 | uint32_t sum; 24 | float r, g, b; 25 | 26 | switch (step) { 27 | 28 | case 0: 29 | 30 | curMillis = millis(); 31 | if (curMillis - preMillis >= 5000) { 32 | 33 | step = 1; 34 | 35 | tcs.setInterrupt(false); // turn on LED 36 | tcs.getRawData(&red, &green, &blue, &clear); 37 | tcs.setInterrupt(true); // turn off LED 38 | 39 | GO.lcd.clearDisplay(); 40 | GO.lcd.setCursor(30, 50); 41 | GO.lcd.println("Put on GREEN"); 42 | 43 | sum = clear; 44 | r = red; r /= sum; 45 | g = green; g /= sum; 46 | b = blue; b /= sum; 47 | r *= 256; g *= 256; b *= 256; 48 | 49 | rCal = r; 50 | 51 | preMillis = millis(); 52 | } 53 | break; 54 | 55 | case 1: 56 | 57 | curMillis = millis(); 58 | if (curMillis - preMillis >= 5000) { 59 | 60 | step = 2; 61 | 62 | tcs.setInterrupt(false); // turn on LED 63 | //- delay(60); // takes 50ms to read 64 | tcs.getRawData(&red, &green, &blue, &clear); 65 | tcs.setInterrupt(true); // turn off LED 66 | 67 | GO.lcd.clearDisplay(); 68 | GO.lcd.setCursor(30, 50); 69 | GO.lcd.println("Put on BLUE"); 70 | 71 | sum = clear; 72 | r = red; r /= sum; 73 | g = green; g /= sum; 74 | b = blue; b /= sum; 75 | r *= 256; g *= 256; b *= 256; 76 | 77 | gCal = g; 78 | 79 | preMillis = millis(); 80 | } 81 | break; 82 | 83 | case 2: 84 | 85 | curMillis = millis(); 86 | if (curMillis - preMillis >= 5000) { 87 | step = 3; 88 | 89 | tcs.setInterrupt(false); // turn on LED 90 | tcs.getRawData(&red, &green, &blue, &clear); 91 | tcs.setInterrupt(true); // turn off LED 92 | 93 | sum = clear; 94 | r = red; r /= sum; 95 | g = green; g /= sum; 96 | b = blue; b /= sum; 97 | r *= 256; g *= 256; b *= 256; 98 | 99 | GO.lcd.clearDisplay(); 100 | 101 | bCal = b; 102 | } 103 | break; 104 | 105 | case 3: 106 | 107 | return 0; 108 | 109 | default:; 110 | } 111 | 112 | return 1; 113 | } 114 | 115 | void setup() { 116 | GO.begin(); 117 | Serial.println("Color View Test!"); 118 | 119 | if (tcs.begin()) { 120 | Serial.println("Found sensor"); 121 | } else { 122 | Serial.println("No TCS34725 found ... check your connections"); 123 | while (1); // halt! 124 | } 125 | 126 | GO.lcd.setCursor(30, 50); 127 | GO.lcd.setTextSize(2); 128 | GO.lcd.println("Hello, ODROID-GO"); 129 | 130 | #if defined(CALI_ENABLE) 131 | delay(1000); 132 | 133 | GO.lcd.clearDisplay(); 134 | GO.lcd.setCursor(30, 50); 135 | GO.lcd.print("Put on RED"); 136 | preMillis = millis(); 137 | 138 | while (cali()); 139 | 140 | GO.lcd.clearDisplay(); 141 | GO.lcd.setTextColor(WHITE); 142 | GO.lcd.setCursor(0, 40); 143 | GO.lcd.setTextSize(2); 144 | GO.lcd.print("Cali:R("); GO.lcd.print(int(rCal), DEC); 145 | GO.lcd.print(") G("); GO.lcd.print(gCal, DEC); 146 | GO.lcd.print(") B("); GO.lcd.print(bCal, DEC); 147 | GO.lcd.println(")"); 148 | #endif 149 | 150 | delay(2000); 151 | } 152 | 153 | void loop() { 154 | 155 | //- uint16_t clear, red, green, blue; 156 | 157 | tcs.setInterrupt(false); // turn on LED 158 | //- delay(60); // takes 50ms to read 159 | tcs.getRawData(&red, &green, &blue, &clear); 160 | tcs.setInterrupt(true); // turn off LED 161 | 162 | #if !defined(LCD_ENABLE) 163 | Serial.print("C:\t"); Serial.print(clear); 164 | Serial.print("\tR:\t"); Serial.print(red); 165 | Serial.print("\tG:\t"); Serial.print(green); 166 | Serial.print("\tB:\t"); Serial.print(blue); 167 | #endif 168 | 169 | // Figure out some basic hex code for visualization 170 | uint32_t sum = clear; 171 | float r, g, b; 172 | r = red; r /= sum; 173 | g = green; g /= sum; 174 | b = blue; b /= sum; 175 | r *= 256; g *= 256; b *= 256; 176 | 177 | #if defined(CALI_ENABLE) 178 | r = r - rCal + 256; 179 | g = g - gCal + 256; 180 | b = b - bCal + 256; 181 | #endif 182 | 183 | #if !defined(LCD_ENABLE) 184 | Serial.print("\t"); 185 | Serial.print((int)r, HEX); Serial.print((int)g, HEX); Serial.print((int)b, HEX); 186 | Serial.println(); 187 | #endif 188 | 189 | //Serial.print((int)r ); Serial.print(" "); Serial.print((int)g);Serial.print(" "); Serial.println((int)b ); 190 | 191 | #if defined(LCD_ENABLE) 192 | 193 | uint16_t colorTemp, lux, rgb565; 194 | 195 | colorTemp = tcs.calculateColorTemperature(r, g, b); 196 | lux = tcs.calculateLux(r, g, b); 197 | rgb565 = (((int)r) & 0xF8) << 8 | (((int)g) & 0xFC) << 3 | ((int)b) >> 3; 198 | 199 | //- GO.lcd.clearDisplay(); 200 | GO.lcd.fillScreen(rgb565); 201 | GO.lcd.setTextColor(WHITE); 202 | GO.lcd.setCursor(0, 40); 203 | GO.lcd.setTextSize(2); 204 | GO.lcd.print("* RGB565(Hex) : 0x"); 205 | GO.lcd.println(rgb565, HEX); 206 | GO.lcd.println(" "); 207 | 208 | GO.lcd.print("* Color Temp : "); GO.lcd.println(colorTemp, DEC); 209 | GO.lcd.print("* Lux : "); GO.lcd.println(lux, DEC); 210 | GO.lcd.println(" "); 211 | 212 | GO.lcd.print("* R - raw : "); GO.lcd.print(int(r), DEC); GO.lcd.print(" - "); GO.lcd.println(red, DEC); 213 | GO.lcd.print("* G - raw : "); GO.lcd.print(int(g), DEC); GO.lcd.print(" - "); GO.lcd.println(green, DEC); 214 | GO.lcd.print("* B - raw : "); GO.lcd.print(int(b), DEC); GO.lcd.print(" - "); GO.lcd.println(blue, DEC); 215 | GO.lcd.print("* Clear : "); GO.lcd.print(int(clear), DEC); 216 | 217 | delay(1000); 218 | 219 | #endif 220 | } 221 | 222 | -------------------------------------------------------------------------------- /examples/Applications/IR_Receiver/IR_Receiver.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "sensors/ir/IRremote.h" 3 | 4 | const int RECV_PIN = 4; 5 | 6 | IRrecv irrecv(RECV_PIN); 7 | decode_results results; 8 | 9 | void setup() { 10 | // put your setup code here, to run once: 11 | GO.begin(); 12 | 13 | GO.lcd.setTextDatum(MC_DATUM); 14 | GO.lcd.setTextFont(4); 15 | GO.lcd.setTextSize(1); 16 | GO.lcd.setTextColor(WHITE); 17 | GO.lcd.drawString("====== IR Receiver Test ======", 120, 0); 18 | 19 | Serial.println("Enabling IRin"); 20 | irrecv.enableIRIn(); // Start the receiver 21 | Serial.println("Enabled IRin"); 22 | 23 | GO.lcd.setTextSize(2); 24 | GO.lcd.setTextColor(RED); 25 | displayStatusUpdate("NO SIGNAL"); 26 | } 27 | 28 | void decodeSignal() { 29 | GO.lcd.setTextColor(GREEN); 30 | switch (results.value) { 31 | case 0x4DB23BC4: 32 | displayStatusUpdate("POWER"); 33 | break; 34 | case 0x4DB211EE: 35 | displayStatusUpdate("MUTE"); 36 | break; 37 | case 0x4DB241BE: 38 | displayStatusUpdate("HOME"); 39 | break; 40 | case 0x4DB2738C: 41 | displayStatusUpdate("OK"); 42 | break; 43 | case 0x4DB253AC: 44 | displayStatusUpdate("UP"); 45 | break; 46 | case 0x4DB29966: 47 | displayStatusUpdate("LEFT"); 48 | break; 49 | case 0x4DB2837C: 50 | displayStatusUpdate("RIGHT"); 51 | break; 52 | case 0x4DB24BB4: 53 | displayStatusUpdate("DOWN"); 54 | break; 55 | case 0x4DB2A35C: 56 | displayStatusUpdate("MENU"); 57 | break; 58 | case 0x4DB259A6: 59 | displayStatusUpdate("BACK"); 60 | break; 61 | case 0x4DB2817E: 62 | displayStatusUpdate("VOL DOWN"); 63 | break; 64 | case 0x4DB201FE: 65 | displayStatusUpdate("VOL UP"); 66 | break; 67 | case 0xFFFFFFFF: 68 | GO.lcd.setTextColor(BLUE); 69 | displayStatusUpdate("REFEATED"); 70 | break; 71 | case 0x4DB2: 72 | GO.lcd.setTextColor(RED); 73 | displayStatusUpdate("BROKEN"); 74 | break; 75 | default: 76 | GO.lcd.setTextColor(RED); 77 | displayStatusUpdate("UNKNOWN"); 78 | break; 79 | } 80 | } 81 | 82 | void displayStatusUpdate(String result) { 83 | GO.lcd.fillRect(0, 92, 320, 48, BLACK); 84 | GO.lcd.drawString(result, 160, 122); 85 | } 86 | 87 | void loop() { 88 | // put your main code here, to run repeatedly: 89 | if (irrecv.decode(&results)) { 90 | Serial.print("received: "); 91 | Serial.println(results.value, HEX); 92 | 93 | decodeSignal(); 94 | irrecv.resume(); // Receive the next value 95 | } 96 | delay(100); 97 | } 98 | -------------------------------------------------------------------------------- /examples/Applications/PIR_Motion_Detector/PIR_Motion_Detector.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define PIN_BLUE_LED 2 4 | #define PIN_PIR_INPUT 4 5 | 6 | int prePirValue; 7 | int pirValue; 8 | int sensorBlockingTimeout; 9 | 10 | void setup() { 11 | // put your setup code here, to run once: 12 | GO.begin(); 13 | 14 | GO.lcd.setTextFont(4); 15 | GO.lcd.setTextSize(1); 16 | GO.lcd.setTextColor(WHITE); 17 | GO.lcd.setCursor(0, 0); 18 | GO.lcd.print("= PIR Motion Detector Test ="); 19 | 20 | pinMode(PIN_BLUE_LED, OUTPUT); 21 | pinMode(PIN_PIR_INPUT, INPUT); 22 | digitalWrite(PIN_BLUE_LED, LOW); 23 | 24 | GO.lcd.setTextSize(2); 25 | GO.lcd.setTextColor(BLUE); 26 | for (int i = 60; i > 0; i--) { 27 | GO.lcd.fillRect(0, 100, 320, 48, BLACK); 28 | GO.lcd.setCursor(6, 100); 29 | GO.lcd.printf("Initilizing... %2d", i); 30 | delay(1000); 31 | } 32 | 33 | displayStatusUpdate(); 34 | } 35 | 36 | void displayStatusUpdate() { 37 | GO.lcd.fillRect(0, 100, 320, 56, BLACK); 38 | GO.lcd.setTextSize(2); 39 | 40 | if (pirValue) { 41 | GO.lcd.setTextColor(GREEN); 42 | GO.lcd.setCursor(58, 100); 43 | GO.lcd.print("Detected"); 44 | 45 | sensorBlockingTimeout = 3; 46 | } else { 47 | GO.lcd.setTextColor(RED); 48 | GO.lcd.setCursor(14, 100); 49 | GO.lcd.print("Not Detected"); 50 | 51 | while (prePirValue) { 52 | GO.lcd.fillRect(0, 170, 320, 32, BLACK); 53 | GO.lcd.setTextSize(2); 54 | 55 | if (sensorBlockingTimeout == 0) { 56 | break; 57 | } else { 58 | GO.lcd.setTextSize(1); 59 | GO.lcd.setCursor(100, 170); 60 | GO.lcd.printf("Timeout: %d", sensorBlockingTimeout); 61 | 62 | delay(1000); 63 | sensorBlockingTimeout--; 64 | } 65 | } 66 | } 67 | } 68 | 69 | void loop() { 70 | // put your main code here, to run repeatedly: 71 | pirValue = digitalRead(PIN_PIR_INPUT); 72 | if (prePirValue != pirValue) { 73 | displayStatusUpdate(); 74 | prePirValue = pirValue; 75 | } 76 | 77 | digitalWrite(PIN_BLUE_LED, pirValue); 78 | } -------------------------------------------------------------------------------- /examples/Applications/Tetris/tetris.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/examples/Applications/Tetris/tetris.jpg -------------------------------------------------------------------------------- /examples/Applications/Ultrasonic_Distance_Meter/Ultrasonic_Distance_Meter.ino: -------------------------------------------------------------------------------- 1 | /* ODROID-GO with Ultrasonic Sensor */ 2 | #include 3 | #include 4 | 5 | /* Header 10 : P2-4 */ 6 | #define TRIG_IO_PORT 15 7 | /* Header 10 : P2-5 */ 8 | #define ECHO_IO_PORT 4 9 | 10 | Ultrasonic ultrasonic(TRIG_IO_PORT, ECHO_IO_PORT); 11 | float distance = 0; 12 | 13 | void setup() { 14 | // put your setup code here, to run once: 15 | GO.begin(); 16 | GO.lcd.setTextFont(4); 17 | GO.lcd.setCursor(0, 0); 18 | GO.lcd.setTextColor(WHITE); 19 | GO.lcd.print("===== Ultrasonic Sensor ====="); 20 | } 21 | 22 | void display_distance() { 23 | float distance_new = ultrasonic.distanceRead(CM); 24 | 25 | GO.lcd.setCursor(0, 32); 26 | GO.lcd.setTextSize(1); 27 | GO.lcd.setTextColor(YELLOW); 28 | GO.lcd.print("Distance [unit : inch]"); 29 | GO.lcd.setCursor(0, 128); 30 | GO.lcd.print("Distance [unit : cm]"); 31 | 32 | if (!distance_new) 33 | GO.lcd.setTextColor(RED); 34 | else { 35 | GO.lcd.setTextColor(GREEN); 36 | GO.lcd.fillRect(0, 64, 320, 64, 0x0000); 37 | GO.lcd.fillRect(0, 160, 320, 64, 0x0000); 38 | distance = distance_new; 39 | } 40 | GO.lcd.setTextSize(2); 41 | GO.lcd.setCursor(0, 64); 42 | /* unit convert cm to inch : 1 cm = 0.3937 inch */ 43 | GO.lcd.print(distance * 0.3937); 44 | GO.lcd.print(" inch "); 45 | 46 | GO.lcd.setCursor(0, 160); 47 | GO.lcd.print(distance); 48 | GO.lcd.print(" cm "); 49 | } 50 | 51 | void loop() { 52 | // put your main code here, to run repeatedly: 53 | display_distance(); 54 | delay(1000); 55 | } 56 | -------------------------------------------------------------------------------- /examples/Applications/Weather_Station/WeatherBoard.cpp: -------------------------------------------------------------------------------- 1 | #include "WeatherBoard.h" 2 | 3 | uint8_t WeatherBoard::begin(void) 4 | { 5 | revision = 0; 6 | // Check board version 7 | Wire.beginTransmission(96); 8 | if (Wire.endTransmission() == 0) { 9 | revision = 2; 10 | bme.begin(); 11 | si1132.begin(); 12 | } 13 | 14 | //Wire.beginTransmission((byte)BMP085_REGISTER_CHIPID); 15 | Wire.beginTransmission(119); 16 | if (Wire.endTransmission() == 0) { 17 | revision = 1; 18 | bmp.begin(); 19 | sensor_t sensor; 20 | bmp.getSensor(&sensor); 21 | si1132.begin(); 22 | } 23 | return revision; 24 | } 25 | 26 | uint8_t WeatherBoard::read8(byte _i2caddr, byte reg) 27 | { 28 | byte value; 29 | Wire.beginTransmission((uint8_t)_i2caddr); 30 | Wire.write((uint8_t)reg); 31 | Wire.endTransmission(); 32 | Wire.requestFrom((uint8_t)_i2caddr, (byte)1); 33 | value = Wire.read(); 34 | Wire.endTransmission(); 35 | 36 | return value; 37 | } 38 | void WeatherBoard::getBMP180() 39 | { 40 | sensors_event_t event; 41 | bmp.getEvent(&event); 42 | 43 | if (event.pressure) { 44 | bmp.getTemperature(&BMP180Temperature); 45 | BMP180Pressure = event.pressure; 46 | BMP180Altitude = bmp.pressureToAltitude(1025, event.pressure); 47 | } 48 | } 49 | 50 | void WeatherBoard::getSi1132() 51 | { 52 | Si1132UVIndex = 0; 53 | Si1132Visible = 0; 54 | Si1132IR = 0; 55 | for (int i = 0; i < 10; i++) { 56 | Si1132Visible += si1132.readVisible(); 57 | Si1132IR += si1132.readIR(); 58 | Si1132UVIndex += si1132.readUV(); 59 | } 60 | Si1132UVIndex /= 10; 61 | Si1132UVIndex /= 100; 62 | Si1132Visible /= 10; 63 | Si1132IR /= 10; 64 | } 65 | 66 | void WeatherBoard::getSi7020() 67 | { 68 | Si7020Temperature = si7020.readTemperature(); 69 | Si7020Humidity = si7020.readHumidity(); 70 | } 71 | 72 | void WeatherBoard::getBME280(void) 73 | { 74 | BME280Temperature = bme.readTemperature(); 75 | BME280Pressure = (bme.readPressure() / 100); 76 | BME280Humidity = bme.readHumidity(); 77 | BME280Altitude = bme.readAltitude(SEALEVELPRESSURE_HPA); 78 | } 79 | 80 | void WeatherBoard::errorCheck() 81 | { 82 | if ((read8(BME280_ADDRESS, BME280_REGISTER_CHIPID) != 0x60) && 83 | (read8(BMP085_ADDRESS, BMP085_REGISTER_CHIPID) != 0x55)) { 84 | if (!errorState) { 85 | // GO.lcd.fillScreen(backgroundColor); 86 | // displayLabel(); 87 | } 88 | errorState = 1; 89 | } else if (errorState) { 90 | if (read8(BME280_ADDRESS, BME280_REGISTER_CHIPID) != 0x60) { 91 | revision = 1; 92 | } else { 93 | revision = 2; 94 | } 95 | //si1132.begin(); 96 | 97 | if (revision == 1) { 98 | bmp.begin(); 99 | sensor_t sensor; 100 | bmp.getSensor(&sensor); 101 | } else { 102 | if (!bme.begin()) { 103 | } 104 | } 105 | //GO.lcd.fillScreen(backgroundColor); 106 | // displayLabel(); 107 | errorState = 0; 108 | } 109 | if (errorState) { 110 | BMP180Temperature = 0; 111 | BMP180Pressure = 0; 112 | BMP180Altitude = 0; 113 | 114 | Si7020Temperature = 0; 115 | Si7020Humidity = 0; 116 | 117 | BME280Temperature = 0; 118 | BME280Pressure = 0; 119 | BME280Humidity = 0; 120 | BME280Altitude = 0; 121 | 122 | Si1132UVIndex = 0; 123 | Si1132Visible = 0; 124 | Si1132IR = 0; 125 | } 126 | } 127 | 128 | -------------------------------------------------------------------------------- /examples/Applications/Weather_Station/WeatherBoard.h: -------------------------------------------------------------------------------- 1 | #include "sensors/Adafruit_BMP085_U.h" 2 | #include "sensors/Adafruit_BME280.h" 3 | #include "sensors/Adafruit_Sensor.h" 4 | #include "sensors/ODROID_Si1132.h" 5 | #include "sensors/ODROID_Si70xx.h" 6 | 7 | #include "Arduino.h" 8 | 9 | #define SEALEVELPRESSURE_HPA (1024.25) 10 | 11 | class WeatherBoard { 12 | public: 13 | Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(SEALEVELPRESSURE_HPA); 14 | Adafruit_BME280 bme; // I2C 15 | ODROID_Si70xx si7020; 16 | ODROID_Si1132 si1132; 17 | uint8_t revision = 0; 18 | uint8_t errorState = 0; 19 | 20 | float BMP180Temperature = 0; 21 | float BMP180Pressure = 0; 22 | float BMP180Altitude = 0; 23 | 24 | float BME280Temperature = 0; 25 | float BME280Pressure = 0; 26 | float BME280Humidity = 0; 27 | float BME280Altitude = 0; 28 | 29 | float Si7020Temperature = 0; 30 | float Si7020Humidity = 0; 31 | 32 | float Si1132UVIndex = 0; 33 | uint32_t Si1132Visible = 0; 34 | uint32_t Si1132IR = 0; 35 | 36 | uint8_t begin(); 37 | uint8_t read8(byte _i2caddr, byte reg); 38 | void getBMP180(); 39 | void getBME280(); 40 | void getSi7020(); 41 | void getSi1132(); 42 | void errorCheck(); 43 | }; 44 | -------------------------------------------------------------------------------- /examples/Applications/Weather_Station/data/css/images/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/examples/Applications/Weather_Station/data/css/images/ajax-loader.gif -------------------------------------------------------------------------------- /examples/Applications/Weather_Station/data/css/ws_style.css: -------------------------------------------------------------------------------- 1 | .sevenseg_item { 2 | display: inline-block; 3 | } 4 | 5 | .sevenseg_label { 6 | float: left; 7 | 8 | font-family: 'Courier New', Courier, monospace; 9 | font-size: 4vw; 10 | } 11 | 12 | .sevenseg_label_unit { 13 | float: right; 14 | 15 | font-family: 'Courier New', Courier, monospace; 16 | font-size: 3vw; 17 | } 18 | 19 | .custom-corners .ui-bar { 20 | -webkit-border-top-left-radius: inherit; 21 | border-top-left-radius: inherit; 22 | -webkit-border-top-right-radius: inherit; 23 | border-top-right-radius: inherit; 24 | } 25 | 26 | .custom-corners .ui-body { 27 | border-top-width: 0; 28 | -webkit-border-bottom-left-radius: inherit; 29 | border-bottom-left-radius: inherit; 30 | -webkit-border-bottom-right-radius: inherit; 31 | border-bottom-right-radius: inherit; 32 | } -------------------------------------------------------------------------------- /examples/Applications/Weather_Station/data/js/ws_page_setup.js: -------------------------------------------------------------------------------- 1 | $(document).bind('mobileinit', function() { 2 | $.mobile.pushStateEnabled = false; 3 | }); 4 | 5 | $(function() { 6 | $('#tf_ipv4').ipAddress(); 7 | 8 | $("#sevenseg_temperature").sevenSeg({ 9 | digits: 5, 10 | decimalPlaces: 2 11 | }); 12 | $("#sevenseg_pressure").sevenSeg({ 13 | digits: 5, 14 | decimalPlaces: 1 15 | }); 16 | $("#sevenseg_humidity").sevenSeg({ 17 | digits: 5, 18 | decimalPlaces: 2 19 | }); 20 | $("#sevenseg_altitude").sevenSeg({ 21 | digits: 5, 22 | decimalPlaces: 1 23 | }); 24 | $("#sevenseg_uvindex").sevenSeg({ 25 | digits: 5, 26 | decimalPlaces: 2 27 | }); 28 | $("#sevenseg_visible").sevenSeg({ 29 | digits: 5, 30 | decimalPlaces: 0 31 | }); 32 | $("#sevenseg_ir").sevenSeg({ 33 | digits: 5, 34 | decimalPlaces: 0 35 | }); 36 | 37 | $("#navbar_home").on("pagebeforeshow", function() { 38 | pageState = 0; 39 | if (connected) { 40 | ws.send(PAGE_STATE + pageState); 41 | } 42 | }); 43 | 44 | $("#navbar_settings").on("pagebeforeshow", function() { 45 | pageState = 1; 46 | if (connected) { 47 | ws.send(PAGE_STATE + pageState); 48 | } 49 | }); 50 | 51 | $("#text_net_ipv4").prop("disabled", true); 52 | 53 | $("#text_net_ipv4").mask('0ZZ.0ZZ.0ZZ.0ZZ', { 54 | translation: { 55 | 'Z': { 56 | pattern: /[0-9]/, optional: true 57 | } 58 | } 59 | });; 60 | 61 | $("#btn_save_network").click(function() { 62 | ssid = $("#text_net_ssid").val(); 63 | ipaddr = $("#text_net_ipv4").val(); 64 | passwd = $("#text_net_passwd").val(); 65 | 66 | if (ipaddr.length == 0 || ssid.length == 0 || passwd.length == 0) { 67 | alert("All fields are required."); 68 | } else if (passwd.length < 8) { 69 | alert("Password length must be at least 8 characters long."); 70 | } else { 71 | ws.send(SAVE_NETWORKS + ssid + "," + ipaddr + "," + passwd); 72 | alert("ODROID GO will reboot."); 73 | } 74 | }); 75 | 76 | $("#btn_reset_network").click(function() { 77 | $("#text_net_ipv4").val("192.168.4.1").textinput("refresh"); 78 | $("#text_net_ssid").val("ODROID_GO").textinput("refresh"); 79 | $("#text_net_passwd").val("12345678").textinput("refresh"); 80 | }); 81 | }); 82 | -------------------------------------------------------------------------------- /examples/Applications/Weather_Station/data/js/ws_websocket.js: -------------------------------------------------------------------------------- 1 | var SET_DEFAULT_VOLTAGE = 'v'; 2 | var SET_VOLTAGE = 'w'; 3 | var SET_AUTORUN = 'a'; 4 | var SAVE_NETWORKS = 'n'; 5 | var MEASUREWATTHOUR = 'm'; 6 | var CMD_ONOFF = 'o'; 7 | var PAGE_STATE = 'p'; 8 | var DATA_PVI = 'd'; 9 | var SAVE_SSID = 's'; 10 | var SAVE_IPADDR = 'i'; 11 | var SAVE_PASSWD = 'x'; 12 | var FW_VERSION = 'f'; 13 | 14 | var wsUriC = "ws://" + ipaddr + ":81"; 15 | var ws; 16 | var pageState = 0; 17 | var connected = 0; 18 | var onoff = 1; 19 | var setVolt; 20 | var temperature = 0; 21 | var humidity = 0; 22 | var pressure = 0; 23 | var altitude = 0; 24 | var ssid = 0; 25 | var ipaddr = 0; 26 | var passwd = 0; 27 | 28 | function wsConnectC() { 29 | console.log("WebSocket", wsUriC); 30 | 31 | ws = new WebSocket(wsUriC); 32 | ws.onmessage = function(msg) { 33 | var data = msg.data; 34 | console.log(msg.data); 35 | 36 | switch (data.charAt(0)) { 37 | case SAVE_NETWORKS: 38 | networkInfo = data.substring(1).split(","); 39 | ssid = networkInfo[0]; 40 | ipaddr = networkInfo[1]; 41 | passwd = networkInfo[2]; 42 | $("#text_net_ssid").val(ssid).textinput("refresh"); 43 | $("#text_net_ipv4").val(ipaddr).textinput("refresh"); 44 | $("#text_net_passwd").val(passwd).textinput("refresh"); 45 | break; 46 | case DATA_PVI: 47 | dataInfo = data.substring(1).split(","); 48 | if (temperature != dataInfo[0]) { 49 | temperature = dataInfo[0]; 50 | $("#sevenseg_temperature").sevenSeg({ 51 | value: dataInfo[0] 52 | }); 53 | } 54 | if (pressure != dataInfo[1]) { 55 | pressure = dataInfo[1]; 56 | $("#sevenseg_pressure").sevenSeg({ 57 | value: dataInfo[1] 58 | }); 59 | } 60 | if (humidity != dataInfo[2]) { 61 | humidity = dataInfo[2]; 62 | $("#sevenseg_humidity").sevenSeg({ 63 | value: dataInfo[2] 64 | }); 65 | } 66 | if (altitude != dataInfo[3]) { 67 | altitude = dataInfo[3]; 68 | $("#sevenseg_altitude").sevenSeg({ 69 | value: altitude 70 | }); 71 | } 72 | if (humidity != dataInfo[4]) { 73 | humidity = dataInfo[4]; 74 | $("#sevenseg_uvindex").sevenSeg({ 75 | value: dataInfo[4] 76 | }); 77 | } 78 | if (humidity != dataInfo[5]) { 79 | humidity = dataInfo[5]; 80 | $("#sevenseg_visible").sevenSeg({ 81 | value: dataInfo[5] 82 | }); 83 | } 84 | if (humidity != dataInfo[6]) { 85 | humidity = dataInfo[6]; 86 | $("#sevenseg_ir").sevenSeg({ 87 | value: dataInfo[6] 88 | }); 89 | } 90 | break; 91 | case FW_VERSION: 92 | $("#fwversion").html(data.substring(1)); 93 | break; 94 | } 95 | } 96 | 97 | ws.onopen = function() { 98 | $("#label_connect").html("Connected"); 99 | ws.send(PAGE_STATE + pageState); 100 | 101 | connected = 1; 102 | } 103 | 104 | ws.onclose = function() { 105 | $("#label_connect").html("Not Connected"); 106 | 107 | connected = 0; 108 | setTimeout(wsConnectC, 1000); 109 | } 110 | } -------------------------------------------------------------------------------- /examples/BT_Serial/BT_Serial.ino: -------------------------------------------------------------------------------- 1 | #include "BluetoothSerial.h" 2 | 3 | BluetoothSerial serialBT; 4 | 5 | void setup() { 6 | Serial.begin(115200); 7 | 8 | serialBT.begin("ODROID-GO"); 9 | Serial.println("The device started, now you can pair it with bluetooth!"); 10 | } 11 | 12 | void loop() { 13 | if (Serial.available()) { 14 | serialBT.write(Serial.read()); 15 | } 16 | if (serialBT.available()) { 17 | Serial.write(serialBT.read()); 18 | } 19 | delay(20); 20 | } 21 | -------------------------------------------------------------------------------- /examples/Battery/Battery.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RESISTANCE_NUM 2 6 | #define DEFAULT_VREF 1100 7 | #define NO_OF_SAMPLES 64 8 | 9 | static esp_adc_cal_characteristics_t adc_chars; 10 | 11 | void setup() { 12 | // put your setup code here, to run once: 13 | GO.begin(); 14 | 15 | GO.lcd.setTextSize(2); 16 | 17 | adc1_config_width(ADC_WIDTH_BIT_12); 18 | adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11); 19 | esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, DEFAULT_VREF, &adc_chars); 20 | } 21 | 22 | double readBatteryVoltage() { 23 | uint32_t adc_reading = 0; 24 | for (int i = 0; i < NO_OF_SAMPLES; i++) { 25 | adc_reading += adc1_get_raw((adc1_channel_t) ADC1_CHANNEL_0); 26 | } 27 | adc_reading /= NO_OF_SAMPLES; 28 | 29 | return (double) esp_adc_cal_raw_to_voltage(adc_reading, &adc_chars) * RESISTANCE_NUM / 1000; 30 | } 31 | 32 | void showBatteryVoltage(double voltage) { 33 | GO.lcd.clear(); 34 | GO.lcd.setCursor(0, 0); 35 | 36 | GO.lcd.printf("Current Voltage: %1.3lf V \n", voltage); 37 | } 38 | 39 | void loop() { 40 | // put your main code here, to run repeatedly: 41 | showBatteryVoltage(readBatteryVoltage()); 42 | delay(1000); 43 | } 44 | -------------------------------------------------------------------------------- /examples/Buttons/Buttons.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() { 4 | // put your setup code here, to run once: 5 | GO.begin(); 6 | GO.lcd.setTextSize(2); 7 | } 8 | 9 | void displayButtons() { 10 | GO.lcd.clear(); 11 | GO.lcd.setCursor(0, 0); 12 | 13 | GO.lcd.println("/* Direction pad */"); 14 | GO.lcd.printf("Joy-Y-Up: %s \n", (GO.JOY_Y.isAxisPressed() == 2) ? "Pressed" : " "); 15 | GO.lcd.printf("Joy-Y-Down: %s \n", (GO.JOY_Y.isAxisPressed() == 1) ? "Pressed" : " "); 16 | GO.lcd.printf("Joy-X-Left: %s \n", (GO.JOY_X.isAxisPressed() == 2) ? "Pressed" : " "); 17 | GO.lcd.printf("Joy-X-Right: %s \n", (GO.JOY_X.isAxisPressed() == 1) ? "Pressed" : " "); 18 | GO.lcd.println(""); 19 | GO.lcd.println("/* Function key */"); 20 | GO.lcd.printf("Menu: %s \n", (GO.BtnMenu.isPressed() == 1) ? "Pressed" : " "); 21 | GO.lcd.printf("Volume: %s \n", (GO.BtnVolume.isPressed() == 1) ? "Pressed" : " "); 22 | GO.lcd.printf("Select: %s \n", (GO.BtnSelect.isPressed() == 1) ? "Pressed" : " "); 23 | GO.lcd.printf("Start: %s \n", (GO.BtnStart.isPressed() == 1) ? "Pressed" : " "); 24 | GO.lcd.println(""); 25 | GO.lcd.println("/* Actions */"); 26 | GO.lcd.printf("B: %s \n", (GO.BtnB.isPressed() == 1) ? "Pressed" : " "); 27 | GO.lcd.printf("A: %s \n", (GO.BtnA.isPressed() == 1) ? "Pressed" : " "); 28 | } 29 | 30 | void loop() { 31 | // put your main code here, to run repeatedly: 32 | GO.update(); 33 | displayButtons(); 34 | delay(1000); 35 | } 36 | -------------------------------------------------------------------------------- /examples/Hello_World/Hello_World.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | uint8_t idx; 4 | uint8_t rotate; 5 | 6 | void setup() { 7 | // put your setup code here, to run once: 8 | GO.begin(); 9 | 10 | GO.lcd.println("Hello, ODROID-GO"); 11 | 12 | delay(1000); 13 | } 14 | 15 | void displayGO() { 16 | GO.lcd.clearDisplay(); 17 | GO.lcd.setRotation(rotate); 18 | GO.lcd.setCursor(30, 40); 19 | 20 | if (idx) { 21 | GO.lcd.setTextSize(1); 22 | GO.lcd.setTextFont(4); 23 | GO.lcd.setTextColor(MAGENTA); 24 | } else { 25 | GO.lcd.setTextSize(2); 26 | GO.lcd.setTextFont(1); 27 | GO.lcd.setTextColor(GREEN); 28 | } 29 | GO.lcd.print("Hello, ODROID-GO"); 30 | 31 | idx = !idx; 32 | rotate++; 33 | rotate = rotate % 4; 34 | 35 | delay(1000); 36 | } 37 | 38 | void loop() { 39 | // put your main code here, to run repeatedly: 40 | displayGO(); 41 | } 42 | -------------------------------------------------------------------------------- /examples/I2C_16x2_LCD/I2C_16x2_LCD.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define RESISTANCE_NUM 2 6 | #define DEFAULT_VREF 1100 7 | #define NO_OF_SAMPLES 64 8 | 9 | static esp_adc_cal_characteristics_t adc_chars; 10 | 11 | LiquidCrystal_I2C *lcd = NULL; 12 | 13 | void setup() { 14 | // put your setup code here, to run once: 15 | uint8_t lcd_addr = 0; 16 | uint8_t cnt = 0; 17 | 18 | Wire.begin(15, 4); 19 | Serial.begin(115200); 20 | 21 | adc1_config_width(ADC_WIDTH_BIT_12); 22 | adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11); 23 | esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, DEFAULT_VREF, &adc_chars); 24 | 25 | while (cnt < 4) { 26 | lcd_addr = getAddress(); 27 | if (lcd_addr > 0) 28 | break; 29 | Serial.println("Does not find any slave address of the LCD"); 30 | delay(1000); 31 | cnt++; 32 | } 33 | 34 | Serial.print("Slave address : 0x"); 35 | Serial.println(lcd_addr, HEX); 36 | 37 | if (lcd_addr) 38 | lcd = new LiquidCrystal_I2C(lcd_addr, 16, 2); 39 | 40 | if (lcd) { 41 | lcd->init(); 42 | lcd->backlight(); 43 | lcd->setCursor(0, 0); 44 | lcd->print("Hello, ODROID-GO"); 45 | } 46 | } 47 | 48 | uint8_t getAddress() { 49 | Wire.beginTransmission(0x27); 50 | uint8_t lcd_addr = 0; 51 | if (!Wire.endTransmission()) { 52 | lcd_addr = 0x27; 53 | } else { 54 | Wire.beginTransmission(0x3f); 55 | if (!Wire.endTransmission()) { 56 | lcd_addr = 0x3f; 57 | } 58 | } 59 | return lcd_addr; 60 | } 61 | 62 | double readBatteryVoltage() { 63 | uint32_t adc_reading = 0; 64 | for (int i = 0; i < NO_OF_SAMPLES; i++) { 65 | adc_reading += adc1_get_raw((adc1_channel_t) ADC1_CHANNEL_0); 66 | } 67 | adc_reading /= NO_OF_SAMPLES; 68 | 69 | return (double) esp_adc_cal_raw_to_voltage(adc_reading, &adc_chars) * RESISTANCE_NUM / 1000; 70 | } 71 | 72 | void showBatteryVoltage(double voltage) { 73 | if (lcd) { 74 | lcd->setCursor(0, 1); 75 | lcd->printf("Battery: %1.2lf V \n", voltage); 76 | } 77 | } 78 | 79 | void loop() { 80 | // put your main code here, to run repeatedly: 81 | showBatteryVoltage(readBatteryVoltage()); 82 | delay(1000); 83 | } 84 | -------------------------------------------------------------------------------- /examples/LED/LED.ino: -------------------------------------------------------------------------------- 1 | #define PIN_BLUE_LED 2 2 | 3 | void setup() { 4 | // put your setup code here, to run once: 5 | 6 | pinMode(PIN_BLUE_LED, OUTPUT); 7 | } 8 | 9 | void loop() { 10 | // put your main code here, to run repeatedly: 11 | 12 | digitalWrite(PIN_BLUE_LED, HIGH); 13 | delay(500); 14 | digitalWrite(PIN_BLUE_LED, LOW); 15 | delay(500); 16 | } 17 | -------------------------------------------------------------------------------- /examples/LED_PWM/LED_PWM.ino: -------------------------------------------------------------------------------- 1 | #define PIN_BLUE_LED 2 2 | #define PWM_CHANNEL 1 3 | 4 | int dutyCycle = 0; 5 | 6 | void setup() { 7 | // put your setup code here, to run once: 8 | 9 | pinMode(PIN_BLUE_LED, OUTPUT); 10 | digitalWrite(PIN_BLUE_LED, HIGH); 11 | 12 | ledcAttachPin(PIN_BLUE_LED, PWM_CHANNEL); 13 | ledcSetup(PWM_CHANNEL, 12000, 8); // 12 kHz PWM, 8-bit resolution 14 | } 15 | 16 | void loop() { 17 | // put your main code here, to run repeatedly: 18 | 19 | for (dutyCycle = 0; dutyCycle < 255; dutyCycle++) { 20 | ledcWrite(PWM_CHANNEL, dutyCycle); 21 | delay(3); 22 | } 23 | for (dutyCycle = 255; dutyCycle > 0; dutyCycle--) { 24 | ledcWrite(PWM_CHANNEL, dutyCycle); 25 | delay(3); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/Sensors/MMA8451demo/MMA8451demo.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************************/ 2 | /*! 3 | @file Adafruit_MMA8451.h 4 | @author K. Townsend (Adafruit Industries) 5 | @license BSD (see license.txt) 6 | 7 | This is an example for the Adafruit MMA8451 Accel breakout board 8 | ----> https://www.adafruit.com/products/2019 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | @section HISTORY 15 | 16 | v1.0 - First release 17 | */ 18 | /**************************************************************************/ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | Adafruit_MMA8451 mma = Adafruit_MMA8451(); 25 | 26 | void setup(void) { 27 | Serial.begin(9600); 28 | 29 | Serial.println("Adafruit MMA8451 test!"); 30 | 31 | 32 | if (! mma.begin()) { 33 | Serial.println("Couldnt start"); 34 | while (1); 35 | } 36 | Serial.println("MMA8451 found!"); 37 | 38 | mma.setRange(MMA8451_RANGE_2_G); 39 | 40 | Serial.print("Range = "); Serial.print(2 << mma.getRange()); 41 | Serial.println("G"); 42 | 43 | } 44 | 45 | void loop() { 46 | // Read the 'raw' data in 14-bit counts 47 | mma.read(); 48 | Serial.print("X:\t"); Serial.print(mma.x); 49 | Serial.print("\tY:\t"); Serial.print(mma.y); 50 | Serial.print("\tZ:\t"); Serial.print(mma.z); 51 | Serial.println(); 52 | 53 | /* Get a new sensor event */ 54 | sensors_event_t event; 55 | mma.getEvent(&event); 56 | 57 | /* Display the results (acceleration is measured in m/s^2) */ 58 | Serial.print("X: \t"); Serial.print(event.acceleration.x); Serial.print("\t"); 59 | Serial.print("Y: \t"); Serial.print(event.acceleration.y); Serial.print("\t"); 60 | Serial.print("Z: \t"); Serial.print(event.acceleration.z); Serial.print("\t"); 61 | Serial.println("m/s^2 "); 62 | 63 | /* Get the orientation of the sensor */ 64 | uint8_t o = mma.getOrientation(); 65 | 66 | switch (o) { 67 | case MMA8451_PL_PUF: 68 | Serial.println("Portrait Up Front"); 69 | break; 70 | case MMA8451_PL_PUB: 71 | Serial.println("Portrait Up Back"); 72 | break; 73 | case MMA8451_PL_PDF: 74 | Serial.println("Portrait Down Front"); 75 | break; 76 | case MMA8451_PL_PDB: 77 | Serial.println("Portrait Down Back"); 78 | break; 79 | case MMA8451_PL_LRF: 80 | Serial.println("Landscape Right Front"); 81 | break; 82 | case MMA8451_PL_LRB: 83 | Serial.println("Landscape Right Back"); 84 | break; 85 | case MMA8451_PL_LLF: 86 | Serial.println("Landscape Left Front"); 87 | break; 88 | case MMA8451_PL_LLB: 89 | Serial.println("Landscape Left Back"); 90 | break; 91 | } 92 | Serial.println(); 93 | delay(500); 94 | 95 | } -------------------------------------------------------------------------------- /examples/Speaker/Speaker.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void setup() { 5 | // put your setup code here, to run once: 6 | GO.begin(); 7 | 8 | GO.lcd.printf("ODROID-GO Speaker test:\r\n"); 9 | GO.Speaker.setVolume(8); 10 | GO.Speaker.playMusic(m5stack_startup_music, 25000); 11 | } 12 | 13 | void loop() { 14 | // put your main code here, to run repeatedly: 15 | 16 | if (GO.BtnA.wasPressed()) { 17 | GO.lcd.printf("wasPressed: A \r\n"); 18 | GO.Speaker.beep(); 19 | } 20 | 21 | if (GO.BtnB.wasPressed()) { 22 | GO.lcd.printf("wasPressed: B \r\n"); 23 | GO.Speaker.tone(3000, 200); 24 | } 25 | 26 | if (GO.BtnStart.wasPressed()) { 27 | GO.lcd.printf("wasPressed: Start \r\n"); 28 | GO.Speaker.playMusic(m5stack_startup_music, 25000); 29 | } 30 | 31 | GO.update(); 32 | } 33 | -------------------------------------------------------------------------------- /examples/TFT_Image/TFT_Image.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Show M5STACK logo from bmp_map.h (rgb565 format) 5 | 6 | void setup() { 7 | GO.begin(); 8 | uint16_t *img = (uint16_t *)((void *)gImage_logoM5); 9 | GO.lcd.pushRect(0,0,320,240,img); 10 | } 11 | 12 | void loop() { 13 | } 14 | -------------------------------------------------------------------------------- /examples/Wifi_AP/Wifi_AP.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define PIN_STATUS_LED 2 4 | 5 | const char *apSsid = "ODROID_GO_AP"; 6 | const char *apPasswd = "12345678"; 7 | 8 | WiFiServer server(80); 9 | 10 | void setup() { 11 | Serial.begin(115200); 12 | 13 | pinMode(PIN_STATUS_LED, OUTPUT); 14 | digitalWrite(PIN_STATUS_LED, LOW); 15 | 16 | IPAddress gateway(192, 168, 4, 1); 17 | IPAddress subnet(255, 255, 255, 0); 18 | 19 | if (WiFi.softAP(apSsid, apPasswd)) { 20 | Serial.println("Wifi AP established."); 21 | Serial.print("Wifi AP IP: "); 22 | Serial.println(WiFi.softAPIP()); 23 | Serial.print("AP SSID: "); 24 | Serial.println(apSsid); 25 | Serial.print("AP Password: "); 26 | Serial.println(apPasswd); 27 | 28 | server.begin(); 29 | } else { 30 | Serial.println("Wifi AP establishing failed."); 31 | } 32 | } 33 | 34 | void loop() { 35 | WiFiClient client = server.available(); 36 | 37 | if (client) { 38 | Serial.println("New Client."); 39 | String currentLine = ""; 40 | while (client.connected()) { 41 | if (client.available()) { 42 | char c = client.read(); 43 | Serial.write(c); 44 | if (c == '\n') { 45 | if (currentLine.length() == 0) { 46 | client.println("HTTP/1.1 200 OK"); 47 | client.println("Content-type:text/html"); 48 | client.println(); 49 | 50 | client.print("Click here to turn the blue status LED on.
"); 51 | client.print("Click here to turn the blue status LED off.
"); 52 | 53 | client.println(); 54 | break; 55 | } else { 56 | currentLine = ""; 57 | } 58 | } else if (c != '\r') { 59 | currentLine += c; 60 | } 61 | 62 | if (currentLine.endsWith("GET /H")) { 63 | digitalWrite(PIN_STATUS_LED, HIGH); 64 | } 65 | if (currentLine.endsWith("GET /L")) { 66 | digitalWrite(PIN_STATUS_LED, LOW); 67 | } 68 | } 69 | } 70 | client.stop(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ODROID-GO", 3 | "keywords": "esp32,odroid", 4 | "description": "A library for ODROID-GO development kit", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/hardkernel/ODROID-GO" 8 | }, 9 | "version": "1.0.0", 10 | "license": "MIT", 11 | "frameworks": "arduino", 12 | "platforms": "espressif32", 13 | "authors": { 14 | "name": "Seungchul Lee", 15 | "email": "john.lee@hardkernel.com", 16 | "maintainer": true 17 | }, 18 | "examples": [ 19 | "examples/*/*.ino" 20 | ] 21 | } 22 | 23 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ODROID-GO 2 | version=1.0.0 3 | author=Seungchul Lee , Joshua Yang 4 | maintainer=SeungChul Lee , Joshua Yang 5 | sentence=A library for ODROID-GO development kit 6 | paragraph=http://www.hardkernel.com 7 | category=Device Control 8 | url=https://github.com/hardkernel/ODROID-GO.git 9 | architectures=esp32 10 | includes=odroid_go.h 11 | -------------------------------------------------------------------------------- /prebuilt/BT_Serial.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/BT_Serial.ino.bin -------------------------------------------------------------------------------- /prebuilt/Battery.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/Battery.ino.bin -------------------------------------------------------------------------------- /prebuilt/Buttons.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/Buttons.ino.bin -------------------------------------------------------------------------------- /prebuilt/Colorview.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/Colorview.ino.bin -------------------------------------------------------------------------------- /prebuilt/FlappyBird.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/FlappyBird.ino.bin -------------------------------------------------------------------------------- /prebuilt/Hello_World.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/Hello_World.ino.bin -------------------------------------------------------------------------------- /prebuilt/I2C_16x2_LCD.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/I2C_16x2_LCD.ino.bin -------------------------------------------------------------------------------- /prebuilt/IR_Receiver.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/IR_Receiver.ino.bin -------------------------------------------------------------------------------- /prebuilt/LED.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/LED.ino.bin -------------------------------------------------------------------------------- /prebuilt/LED_PWM.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/LED_PWM.ino.bin -------------------------------------------------------------------------------- /prebuilt/PIR_Motion_Detector.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/PIR_Motion_Detector.ino.bin -------------------------------------------------------------------------------- /prebuilt/README.md: -------------------------------------------------------------------------------- 1 | # ODROID-GO 2 | 3 | These files are binaries pre-built from the Arduino sketches. You can upload them to the ODROID-GO with the ESP32 upload tool, but the upload will overwrite the standard firmware loader. 4 | 5 | Better is to convert these `.ino.bin` files into `.fw` files, and copy them onto the SD card. Then you can select them with the firmware selector when you power-on the ODROID-GO while pressing the 'B' button. 6 | 7 | Copy .fw files to your SD card "odroid/firmware/" folder 8 | 9 | - [How to make Arduino Applications for ODROID-GO](https://wiki.odroid.com/odroid_go/arduino_app#make_arduino_applications_for_odroid-go) 10 | 11 | -------------------------------------------------------------------------------- /prebuilt/Servo_Motor.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/Servo_Motor.ino.bin -------------------------------------------------------------------------------- /prebuilt/Speaker.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/Speaker.ino.bin -------------------------------------------------------------------------------- /prebuilt/Tetris.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/Tetris.ino.bin -------------------------------------------------------------------------------- /prebuilt/Ultrasonic_Distance_Meter.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/Ultrasonic_Distance_Meter.ino.bin -------------------------------------------------------------------------------- /prebuilt/Weather_Station.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/Weather_Station.ino.bin -------------------------------------------------------------------------------- /prebuilt/Wifi_AP.ino.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/Wifi_AP.ino.bin -------------------------------------------------------------------------------- /prebuilt/tft_demo.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/prebuilt/tft_demo.bin -------------------------------------------------------------------------------- /src/Fonts/ASC16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/src/Fonts/ASC16 -------------------------------------------------------------------------------- /src/Fonts/Font16.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define nr_chrs_f16 96 4 | #define chr_hgt_f16 16 5 | #define baseline_f16 13 6 | #define data_size_f16 8 7 | #define firstchr_f16 32 8 | 9 | extern const unsigned char widtbl_f16[96]; 10 | extern const unsigned char* const chrtbl_f16[96]; 11 | -------------------------------------------------------------------------------- /src/Fonts/Font32rle.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define nr_chrs_f32 96 4 | #define chr_hgt_f32 26 5 | #define baseline_f32 19 6 | #define data_size_f32 8 7 | #define firstchr_f32 32 8 | 9 | extern const unsigned char widtbl_f32[96]; 10 | extern const unsigned char* const chrtbl_f32[96]; 11 | -------------------------------------------------------------------------------- /src/Fonts/Font64rle.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define nr_chrs_f64 96 4 | #define chr_hgt_f64 48 5 | #define baseline_f64 36 6 | #define data_size_f64 8 7 | #define firstchr_f64 32 8 | 9 | extern const unsigned char widtbl_f64[96]; 10 | extern const unsigned char* const chrtbl_f64[96]; 11 | -------------------------------------------------------------------------------- /src/Fonts/Font72rle.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define nr_chrs_f72 96 4 | #define chr_hgt_f72 75 5 | #define baseline_f72 73 6 | #define data_size_f72 8 7 | #define firstchr_f72 32 8 | 9 | extern const unsigned char widtbl_f72[96]; 10 | extern const unsigned char* const chrtbl_f72[96]; 11 | -------------------------------------------------------------------------------- /src/Fonts/Font7srle.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define nr_chrs_f7s 96 4 | #define chr_hgt_f7s 48 5 | #define baseline_f7s 47 6 | #define data_size_f7s 8 7 | #define firstchr_f7s 32 8 | 9 | extern const unsigned char widtbl_f7s[96]; 10 | extern const unsigned char* const chrtbl_f7s[96]; 11 | -------------------------------------------------------------------------------- /src/Fonts/GFXFF/gfxfont.h: -------------------------------------------------------------------------------- 1 | // Adopted by Bodmer to support TFT_HX8357_Due library. 2 | 3 | // Font structures for newer Adafruit_GFX (1.1 and later). 4 | // Example fonts are included in 'Fonts' directory. 5 | // To use a font in your Arduino sketch, #include the corresponding .h 6 | // file and pass address of GFXfont struct to setFont(). Pass NULL to 7 | // revert to 'classic' fixed-space bitmap font. 8 | 9 | #ifndef _GFXFONT_H_ 10 | #define _GFXFONT_H_ 11 | 12 | #ifdef LOAD_GFXFF 13 | 14 | typedef struct { // Data stored PER GLYPH 15 | uint16_t bitmapOffset; // Pointer into GFXfont->bitmap 16 | uint8_t width, height; // Bitmap dimensions in pixels 17 | uint8_t xAdvance; // Distance to advance cursor (x axis) 18 | int8_t xOffset, yOffset; // Dist from cursor pos to UL corner 19 | } GFXglyph; 20 | 21 | typedef struct { // Data stored for FONT AS A WHOLE: 22 | uint8_t *bitmap; // Glyph bitmaps, concatenated 23 | GFXglyph *glyph; // Glyph array 24 | uint8_t first, last; // ASCII extents 25 | uint8_t yAdvance; // Newline distance (y axis) 26 | } GFXfont; 27 | 28 | #endif // LOAD_GFXFF 29 | 30 | #endif // _GFXFONT_H_ 31 | -------------------------------------------------------------------------------- /src/Fonts/GFXFF/license.txt: -------------------------------------------------------------------------------- 1 | This TFT_eSPI library has been developed from the Adafruit_GFX library: 2 | 3 | https://github.com/adafruit/Adafruit-GFX-Library 4 | 5 | It has been modified extensively to improve rendering speed on 6 | ESP8266 processors. There follows the original library license text. 7 | 8 | 9 | Original text follows: 10 | 11 | Software License Agreement (BSD License) 12 | 13 | Copyright (c) 2012 Adafruit Industries. All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without 16 | modification, are permitted provided that the following conditions are met: 17 | 18 | - Redistributions of source code must retain the above copyright notice, 19 | this list of conditions and the following disclaimer. 20 | - Redistributions in binary form must reproduce the above copyright notice, 21 | this list of conditions and the following disclaimer in the documentation 22 | and/or other materials provided with the distribution. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | POSSIBILITY OF SUCH DAMAGE. 35 | -------------------------------------------------------------------------------- /src/Fonts/GFXFF/print.txt: -------------------------------------------------------------------------------- 1 | #define TT1 TomThumb 2 | 3 | #define FF1 FreeMono9pt7b 4 | #define FF2 FreeMono12pt7b 5 | #define FF3 FreeMono18pt7b 6 | #define FF4 FreeMono24pt7b 7 | 8 | #define FF5 FreeMonoBold9pt7b 9 | #define FF6 FreeMonoBold12pt7b 10 | #define FF7 FreeMonoBold18pt7b 11 | #define FF8 FreeMonoBold24pt7b 12 | 13 | #define FF9 FreeMonoBoldOblique9pt7b 14 | #define FF10 FreeMonoBoldOblique12pt7b 15 | #define FF11 FreeMonoBoldOblique18pt7b 16 | #define FF12 FreeMonoBoldOblique24pt7b 17 | 18 | #define FF13 FreeMonoOblique9pt7b 19 | #define FF14 FreeMonoOblique12pt7b 20 | #define FF15 FreeMonoOblique18pt7b 21 | #define FF16 FreeMonoOblique24pt7b 22 | 23 | #define FF17 FreeSans9pt7b 24 | #define FF18 FreeSans12pt7b 25 | #define FF19 FreeSans18pt7b 26 | #define FF20 FreeSans24pt7b 27 | 28 | #define FF21 FreeSansBold9pt7b 29 | #define FF22 FreeSansBold12pt7b 30 | #define FF23 FreeSansBold18pt7b 31 | #define FF24 FreeSansBold24pt7b 32 | 33 | #define FF25 FreeSansBoldOblique9pt7b 34 | #define FF26 FreeSansBoldOblique12pt7b 35 | #define FF27 FreeSansBoldOblique18pt7b 36 | #define FF28 FreeSansBoldOblique24pt7b 37 | 38 | #define FF29 FreeSansOblique9pt7b 39 | #define FF30 FreeSansOblique12pt7b 40 | #define FF31 FreeSansOblique18pt7b 41 | #define FF32 FreeSansOblique24pt7b 42 | 43 | #define FF33 FreeSerif9pt7b 44 | #define FF34 FreeSerif12pt7b 45 | #define FF35 FreeSerif18pt7b 46 | #define FF36 FreeSerif24pt7b 47 | 48 | #define FF37 FreeSerifBold9pt7b 49 | #define FF38 FreeSerifBold12pt7b 50 | #define FF39 FreeSerifBold18pt7b 51 | #define FF40 FreeSerifBold24pt7b 52 | 53 | #define FF41 FreeSerifBoldItalic9pt7b 54 | #define FF42 FreeSerifBoldItalic12pt7b 55 | #define FF43 FreeSerifBoldItalic18pt7b 56 | #define FF44 FreeSerifBoldItalic24pt7b 57 | 58 | #define FF45 FreeSerifItalic9pt7b 59 | #define FF46 FreeSerifItalic12pt7b 60 | #define FF47 FreeSerifItalic18pt7b 61 | #define FF48 FreeSerifItalic24pt7b 62 | -------------------------------------------------------------------------------- /src/Fonts/HZK16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/src/Fonts/HZK16 -------------------------------------------------------------------------------- /src/Fonts/TrueType/Not_yet_supported.txt: -------------------------------------------------------------------------------- 1 | TO DO: Add support for converted True Type fonts in an RLE format. -------------------------------------------------------------------------------- /src/odroid_go.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) M5Stack. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "odroid_go.h" 5 | 6 | void ODROID_GO::begin(unsigned long baud) { 7 | 8 | // UART 9 | Serial.begin(baud); 10 | 11 | Serial.flush(); 12 | Serial.print("ODROID_GO initializing..."); 13 | 14 | Speaker.begin(); 15 | 16 | pinMode(BUTTON_A_PIN, INPUT_PULLUP); 17 | pinMode(BUTTON_B_PIN, INPUT_PULLUP); 18 | pinMode(BUTTON_MENU, INPUT_PULLUP); 19 | pinMode(BUTTON_SELECT, INPUT_PULLUP); 20 | pinMode(BUTTON_START, INPUT_PULLUP); 21 | pinMode(BUTTON_VOLUME, INPUT_PULLUP); 22 | pinMode(BUTTON_JOY_Y, INPUT_PULLDOWN); 23 | pinMode(BUTTON_JOY_X, INPUT_PULLDOWN); 24 | 25 | // ODROID_GO LCD INIT 26 | lcd.begin(); 27 | lcd.setRotation(1); 28 | lcd.fillScreen(BLACK); 29 | lcd.setCursor(0, 0); 30 | lcd.setTextColor(WHITE); 31 | lcd.setTextSize(1); 32 | lcd.setBrightness(255); 33 | 34 | // Battery 35 | battery.begin(); 36 | 37 | Serial.println("OK"); 38 | } 39 | 40 | void ODROID_GO::update() { 41 | 42 | //Button update 43 | BtnA.read(); 44 | BtnB.read(); 45 | BtnMenu.read(); 46 | BtnVolume.read(); 47 | BtnSelect.read(); 48 | BtnStart.read(); 49 | JOY_Y.readAxis(); 50 | JOY_X.readAxis(); 51 | 52 | //Speaker update 53 | Speaker.update(); 54 | battery.update(); 55 | } 56 | ODROID_GO GO; 57 | -------------------------------------------------------------------------------- /src/odroid_go.h: -------------------------------------------------------------------------------- 1 | #ifndef _ODROID_GO_H_ 2 | #define _ODROID_GO_H_ 3 | 4 | #if defined(ESP32) 5 | 6 | #include 7 | #include 8 | #include "utility/Config.h" 9 | 10 | #include "utility/Display.h" 11 | #include "utility/Speaker.h" 12 | #include "utility/Button.h" 13 | #include "utility/battery.h" 14 | 15 | extern "C" { 16 | #include "esp_sleep.h" 17 | } 18 | 19 | class ODROID_GO { 20 | 21 | public: 22 | void begin(unsigned long baud = 115200); 23 | void update(); 24 | 25 | #define DEBOUNCE_MS 5 26 | Button JOY_Y = Button(BUTTON_JOY_Y, true, DEBOUNCE_MS); 27 | Button JOY_X = Button(BUTTON_JOY_X, true, DEBOUNCE_MS); 28 | Button BtnA = Button(BUTTON_A_PIN, true, DEBOUNCE_MS); 29 | Button BtnB = Button(BUTTON_B_PIN, true, DEBOUNCE_MS); 30 | Button BtnMenu = Button(BUTTON_MENU, true, DEBOUNCE_MS); 31 | Button BtnVolume = Button(BUTTON_VOLUME, true, DEBOUNCE_MS); 32 | Button BtnSelect = Button(BUTTON_SELECT, true, DEBOUNCE_MS); 33 | Button BtnStart = Button(BUTTON_START, true, DEBOUNCE_MS); 34 | 35 | ILI9341 lcd = ILI9341(); 36 | SPEAKER Speaker; 37 | Battery battery; 38 | 39 | }; 40 | 41 | extern ODROID_GO GO; 42 | #define go GO 43 | 44 | #else 45 | #error “This library only supports boards with ESP32 processor.” 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/sensors/Adafruit_BME280.md: -------------------------------------------------------------------------------- 1 | This is a library for the Adafruit BME280 Humidity, Barometric Pressure + Temp sensor 2 | 3 | Designed specifically to work with the Adafruit BME280 Breakout 4 | * http://www.adafruit.com/products/2652 5 | 6 | These sensors use I2C or SPI to communicate, up to 4 pins are required to interface 7 | 8 | Adafruit invests time and resources providing this open source code, 9 | please support Adafruit and open-source hardware by purchasing 10 | products from Adafruit! 11 | 12 | Check out the links above for our tutorials and wiring diagrams 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | 17 | To download. click the DOWNLOAD ZIP button, rename the uncompressed folder Adafruit_BME280. 18 | Check that the Adafruit_BME280 folder contains Adafruit_BME280.cpp and Adafruit_BME280.h 19 | 20 | Place the Adafruit_BME280 library folder your arduinosketchfolder/libraries/ folder. 21 | You may need to create the libraries subfolder if its your first library. Restart the IDE. 22 | 23 | We also have a great tutorial on Arduino library installation at: 24 | http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use -------------------------------------------------------------------------------- /src/sensors/Adafruit_BMP085_U.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | This is a library for the BMP085 pressure sensor 3 | 4 | Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout 5 | ----> http://www.adafruit.com/products/391 6 | ----> http://www.adafruit.com/products/1603 7 | 8 | These displays use I2C to communicate, 2 pins are required to interface. 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit andopen-source hardware by purchasing products 12 | from Adafruit! 13 | 14 | Written by Kevin Townsend for Adafruit Industries. 15 | BSD license, all text above must be included in any redistribution 16 | ***************************************************************************/ 17 | #ifndef __BMP085_H__ 18 | #define __BMP085_H__ 19 | 20 | #if (ARDUINO >= 100) 21 | #include "Arduino.h" 22 | #else 23 | #include "WProgram.h" 24 | #endif 25 | 26 | #include "Adafruit_Sensor.h" 27 | 28 | #ifdef __AVR_ATtiny85__ 29 | #include "TinyWireM.h" 30 | #define Wire TinyWireM 31 | #else 32 | #include "sensors/Wire.h" 33 | #endif 34 | 35 | /*========================================================================= 36 | I2C ADDRESS/BITS 37 | -----------------------------------------------------------------------*/ 38 | #define BMP085_ADDRESS (0x77) 39 | /*=========================================================================*/ 40 | 41 | /*========================================================================= 42 | REGISTERS 43 | -----------------------------------------------------------------------*/ 44 | enum 45 | { 46 | BMP085_REGISTER_CAL_AC1 = 0xAA, // R Calibration data (16 bits) 47 | BMP085_REGISTER_CAL_AC2 = 0xAC, // R Calibration data (16 bits) 48 | BMP085_REGISTER_CAL_AC3 = 0xAE, // R Calibration data (16 bits) 49 | BMP085_REGISTER_CAL_AC4 = 0xB0, // R Calibration data (16 bits) 50 | BMP085_REGISTER_CAL_AC5 = 0xB2, // R Calibration data (16 bits) 51 | BMP085_REGISTER_CAL_AC6 = 0xB4, // R Calibration data (16 bits) 52 | BMP085_REGISTER_CAL_B1 = 0xB6, // R Calibration data (16 bits) 53 | BMP085_REGISTER_CAL_B2 = 0xB8, // R Calibration data (16 bits) 54 | BMP085_REGISTER_CAL_MB = 0xBA, // R Calibration data (16 bits) 55 | BMP085_REGISTER_CAL_MC = 0xBC, // R Calibration data (16 bits) 56 | BMP085_REGISTER_CAL_MD = 0xBE, // R Calibration data (16 bits) 57 | BMP085_REGISTER_CHIPID = 0xD0, 58 | BMP085_REGISTER_VERSION = 0xD1, 59 | BMP085_REGISTER_SOFTRESET = 0xE0, 60 | BMP085_REGISTER_CONTROL = 0xF4, 61 | BMP085_REGISTER_TEMPDATA = 0xF6, 62 | BMP085_REGISTER_PRESSUREDATA = 0xF6, 63 | BMP085_REGISTER_READTEMPCMD = 0x2E, 64 | BMP085_REGISTER_READPRESSURECMD = 0x34 65 | }; 66 | /*=========================================================================*/ 67 | 68 | /*========================================================================= 69 | MODE SETTINGS 70 | -----------------------------------------------------------------------*/ 71 | typedef enum 72 | { 73 | BMP085_MODE_ULTRALOWPOWER = 0, 74 | BMP085_MODE_STANDARD = 1, 75 | BMP085_MODE_HIGHRES = 2, 76 | BMP085_MODE_ULTRAHIGHRES = 3 77 | } bmp085_mode_t; 78 | /*=========================================================================*/ 79 | 80 | /*========================================================================= 81 | CALIBRATION DATA 82 | -----------------------------------------------------------------------*/ 83 | typedef struct 84 | { 85 | int16_t ac1; 86 | int16_t ac2; 87 | int16_t ac3; 88 | uint16_t ac4; 89 | uint16_t ac5; 90 | uint16_t ac6; 91 | int16_t b1; 92 | int16_t b2; 93 | int16_t mb; 94 | int16_t mc; 95 | int16_t md; 96 | } bmp085_calib_data; 97 | /*=========================================================================*/ 98 | 99 | class Adafruit_BMP085_Unified : public Adafruit_Sensor 100 | { 101 | public: 102 | Adafruit_BMP085_Unified(int32_t sensorID = -1); 103 | 104 | bool begin(bmp085_mode_t mode = BMP085_MODE_ULTRAHIGHRES); 105 | void getTemperature(float *temp); 106 | void getPressure(float *pressure); 107 | float pressureToAltitude(float seaLevel, float atmospheric); 108 | float seaLevelForAltitude(float altitude, float atmospheric); 109 | // Note that the next two functions are just for compatibility with old 110 | // code that passed the temperature as a third parameter. A newer 111 | // calculation is used which does not need temperature. 112 | float pressureToAltitude(float seaLevel, float atmospheric, float temp); 113 | float seaLevelForAltitude(float altitude, float atmospheric, float temp); 114 | bool getEvent(sensors_event_t*); 115 | void getSensor(sensor_t*); 116 | 117 | private: 118 | int32_t computeB5(int32_t ut); 119 | int32_t _sensorID; 120 | }; 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /src/sensors/Adafruit_MMA8451.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************/ 2 | /*! 3 | @file Adafruit_MMA8451.h 4 | @author K. Townsend (Adafruit Industries) 5 | @license BSD (see license.txt) 6 | 7 | This is a library for the Adafruit MMA8451 Accel breakout board 8 | ----> https://www.adafruit.com/products/2019 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | @section HISTORY 15 | 16 | v1.0 - First release 17 | */ 18 | /**************************************************************************/ 19 | 20 | #ifndef _ADAFRUIT_MMA8451_H_ 21 | #define _ADAFRUIT_MMA8451_H_ 22 | 23 | #if ARDUINO >= 100 24 | #include "Arduino.h" 25 | #else 26 | #include "WProgram.h" 27 | #endif 28 | 29 | 30 | #include "sensors/Wire.h" 31 | 32 | #define USE_SENSOR // Support the sesor library; comment out to compile/run without sensor library. 33 | #ifdef USE_SENSOR 34 | #include "Adafruit_Sensor.h" 35 | #endif 36 | 37 | /*========================================================================= 38 | I2C ADDRESS/BITS 39 | -----------------------------------------------------------------------*/ 40 | #define MMA8451_DEFAULT_ADDRESS (0x1D) // if A is GND, its 0x1C 41 | /*=========================================================================*/ 42 | 43 | #define MMA8451_REG_OUT_X_MSB 0x01 44 | #define MMA8451_REG_SYSMOD 0x0B 45 | #define MMA8451_REG_WHOAMI 0x0D 46 | #define MMA8451_REG_XYZ_DATA_CFG 0x0E 47 | #define MMA8451_REG_PL_STATUS 0x10 48 | #define MMA8451_REG_PL_CFG 0x11 49 | #define MMA8451_REG_CTRL_REG1 0x2A 50 | #define MMA8451_REG_CTRL_REG2 0x2B 51 | #define MMA8451_REG_CTRL_REG4 0x2D 52 | #define MMA8451_REG_CTRL_REG5 0x2E 53 | 54 | 55 | 56 | #define MMA8451_PL_PUF 0 57 | #define MMA8451_PL_PUB 1 58 | #define MMA8451_PL_PDF 2 59 | #define MMA8451_PL_PDB 3 60 | #define MMA8451_PL_LRF 4 61 | #define MMA8451_PL_LRB 5 62 | #define MMA8451_PL_LLF 6 63 | #define MMA8451_PL_LLB 7 64 | 65 | typedef enum 66 | { 67 | MMA8451_RANGE_8_G = 0b10, // +/- 8g 68 | MMA8451_RANGE_4_G = 0b01, // +/- 4g 69 | MMA8451_RANGE_2_G = 0b00 // +/- 2g (default value) 70 | } mma8451_range_t; 71 | 72 | 73 | /* Used with register 0x2A (MMA8451_REG_CTRL_REG1) to set bandwidth */ 74 | typedef enum 75 | { 76 | MMA8451_DATARATE_800_HZ = 0b000, // 800Hz 77 | MMA8451_DATARATE_400_HZ = 0b001, // 400Hz 78 | MMA8451_DATARATE_200_HZ = 0b010, // 200Hz 79 | MMA8451_DATARATE_100_HZ = 0b011, // 100Hz 80 | MMA8451_DATARATE_50_HZ = 0b100, // 50Hz 81 | MMA8451_DATARATE_12_5_HZ = 0b101, // 12.5Hz 82 | MMA8451_DATARATE_6_25HZ = 0b110, // 6.25Hz 83 | MMA8451_DATARATE_1_56_HZ = 0b111, // 1.56Hz 84 | 85 | MMA8451_DATARATE_MASK = 0b111 86 | } mma8451_dataRate_t; 87 | 88 | 89 | 90 | class Adafruit_MMA8451 91 | #ifdef USE_SENSOR 92 | : public Adafruit_Sensor 93 | #endif 94 | { 95 | public: 96 | Adafruit_MMA8451(int32_t id = -1); 97 | 98 | 99 | bool begin(uint8_t addr = MMA8451_DEFAULT_ADDRESS); 100 | 101 | void read(); 102 | 103 | void setRange(mma8451_range_t range); 104 | mma8451_range_t getRange(void); 105 | 106 | void setDataRate(mma8451_dataRate_t dataRate); 107 | mma8451_dataRate_t getDataRate(void); 108 | 109 | #ifdef USE_SENSOR 110 | bool getEvent(sensors_event_t *event); 111 | void getSensor(sensor_t *sensor); 112 | #endif 113 | 114 | uint8_t getOrientation(void); 115 | 116 | int16_t x, y, z; 117 | float x_g, y_g, z_g; 118 | 119 | void writeRegister8(uint8_t reg, uint8_t value); 120 | protected: 121 | uint8_t readRegister8(uint8_t reg); 122 | private: 123 | int32_t _sensorID; 124 | int8_t _i2caddr; 125 | }; 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /src/sensors/Adafruit_Sensor.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardkernel/ODROID-GO/4a496e337d16bca4ddedbeca3486d7b60662d017/src/sensors/Adafruit_Sensor.h -------------------------------------------------------------------------------- /src/sensors/ODROID_Si1132.cpp: -------------------------------------------------------------------------------- 1 | #include "ODROID_Si1132.h" 2 | #include "sensors/Wire.h" 3 | 4 | ODROID_Si1132::ODROID_Si1132() 5 | { 6 | _addr = Si1132_ADDR; 7 | } 8 | 9 | boolean ODROID_Si1132::begin(void) 10 | { 11 | //if (read8(Si1132_REG_CHIPID) != 0x60) 12 | // return false; 13 | reset(); 14 | configRegister(); 15 | 16 | return true; 17 | } 18 | 19 | uint16_t ODROID_Si1132::readUV() 20 | { 21 | delay(10); 22 | return read16(0x2c); 23 | } 24 | 25 | float ODROID_Si1132::readIR() 26 | { 27 | delay(10); 28 | return ((read16(0x24) - 250)/2.44)*14.5; 29 | } 30 | 31 | float ODROID_Si1132::readVisible() 32 | { 33 | delay(10); 34 | return ((read16(0x22) - 256)/0.282)*14.5; 35 | } 36 | 37 | void ODROID_Si1132::reset() 38 | { 39 | write8(Si1132_REG_MEASRATE0, 0); 40 | write8(Si1132_REG_MEASRATE1, 0); 41 | write8(Si1132_REG_IRQEN, 0); 42 | write8(Si1132_REG_IRQMODE1, 0); 43 | write8(Si1132_REG_IRQMODE2, 0); 44 | write8(Si1132_REG_INTCFG, 0); 45 | write8(Si1132_REG_IRQSTAT, 0xFF); 46 | 47 | write8(Si1132_REG_COMMAND, Si1132_RESET); 48 | delay(10); 49 | write8(Si1132_REG_HWKEY, 0x17); 50 | 51 | delay(10); 52 | } 53 | 54 | void ODROID_Si1132::configRegister() 55 | { 56 | // enable UVindex measurement coefficients! 57 | write8(Si1132_REG_UCOEF0, 0x7B); 58 | write8(Si1132_REG_UCOEF1, 0x6B); 59 | write8(Si1132_REG_UCOEF2, 0x01); 60 | write8(Si1132_REG_UCOEF3, 0x00); 61 | 62 | // enable UV sensor 63 | writeParam(Si1132_PARAM_CHLIST, Si1132_PARAM_CHLIST_ENUV | 64 | Si1132_PARAM_CHLIST_ENALSIR | Si1132_PARAM_CHLIST_ENALSVIS); 65 | write8(Si1132_REG_INTCFG, Si1132_REG_INTCFG_INTOE); 66 | write8(Si1132_REG_IRQEN, Si1132_REG_IRQEN_ALSEVERYSAMPLE); 67 | 68 | writeParam(Si1132_PARAM_ALSIRADCMUX, Si1132_PARAM_ADCMUX_SMALLIR); 69 | // fastest clocks, clock div 1 70 | writeParam(Si1132_PARAM_ALSIRADCGAIN, 0); 71 | // take 511 clocks to measure 72 | writeParam(Si1132_PARAM_ALSIRADCCOUNTER, Si1132_PARAM_ADCCOUNTER_511CLK); 73 | // in high range mode 74 | writeParam(Si1132_PARAM_ALSIRADCMISC, Si1132_PARAM_ALSIRADCMISC_RANGE); 75 | 76 | // fastest clocks 77 | writeParam(Si1132_PARAM_ALSVISADCGAIN, 0); 78 | // take 511 clocks to measure 79 | writeParam(Si1132_PARAM_ALSVISADCCOUNTER, Si1132_PARAM_ADCCOUNTER_511CLK); 80 | // in high range mode (not normal signal) 81 | writeParam(Si1132_PARAM_ALSVISADCMISC, Si1132_PARAM_ALSVISADCMISC_VISRANGE); 82 | 83 | write8(Si1132_REG_MEASRATE0, 0xFF); 84 | write8(Si1132_REG_COMMAND, Si1132_ALS_AUTO); 85 | } 86 | 87 | uint8_t ODROID_Si1132::read8(uint8_t reg) 88 | { 89 | uint16_t val; 90 | Wire.beginTransmission(_addr); 91 | Wire.write((uint8_t)reg); 92 | Wire.endTransmission(); 93 | 94 | Wire.requestFrom((uint8_t)_addr, (uint8_t)1); 95 | return Wire.read(); 96 | } 97 | 98 | uint16_t ODROID_Si1132::read16(uint8_t reg) 99 | { 100 | uint16_t ret; 101 | 102 | Wire.beginTransmission(_addr); 103 | Wire.write(reg); 104 | Wire.endTransmission(); 105 | 106 | Wire.requestFrom(_addr, (uint8_t)2); 107 | ret = Wire.read(); 108 | ret |= (uint16_t)Wire.read() << 8; 109 | 110 | return ret; 111 | } 112 | 113 | void ODROID_Si1132::write8(uint8_t reg, uint8_t val) 114 | { 115 | Wire.beginTransmission(_addr); 116 | Wire.write(reg); 117 | Wire.write(val); 118 | Wire.endTransmission(); 119 | } 120 | 121 | uint8_t ODROID_Si1132::writeParam(uint8_t p, uint8_t v) 122 | { 123 | write8(Si1132_REG_PARAMWR, v); 124 | write8(Si1132_REG_COMMAND, p | Si1132_PARAM_SET); 125 | return read8(Si1132_REG_PARAMRD); 126 | } 127 | -------------------------------------------------------------------------------- /src/sensors/ODROID_Si1132.h: -------------------------------------------------------------------------------- 1 | #ifndef ODROID_Si1132_H 2 | #define ODROID_Si1132_H 3 | 4 | #if (ARDUINO >= 100) 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | /* COMMANDS */ 11 | #define Si1132_PARAM_QUERY 0x80 12 | #define Si1132_PARAM_SET 0xA0 13 | #define Si1132_NOP 0x00 14 | #define Si1132_RESET 0x01 15 | #define Si1132_BUSADDR 0x02 16 | #define Si1132_GET_CAL 0x12 17 | #define Si1132_ALS_FORCE 0x06 18 | #define Si1132_ALS_PAUSE 0x0A 19 | #define Si1132_ALS_AUTO 0x0E 20 | 21 | /* Parameters */ 22 | #define Si1132_PARAM_I2CADDR 0x00 23 | #define Si1132_PARAM_CHLIST 0x01 24 | #define Si1132_PARAM_CHLIST_ENUV 0x80 25 | #define Si1132_PARAM_CHLIST_ENAUX 0x40 26 | #define Si1132_PARAM_CHLIST_ENALSIR 0x20 27 | #define Si1132_PARAM_CHLIST_ENALSVIS 0x10 28 | 29 | #define Si1132_PARAM_ALSENCODING 0x06 30 | 31 | #define Si1132_PARAM_ALSIRADCMUX 0x0E 32 | #define Si1132_PARAM_AUXADCMUX 0x0F 33 | 34 | #define Si1132_PARAM_ALSVISADCCOUNTER 0x10 35 | #define Si1132_PARAM_ALSVISADCGAIN 0x11 36 | #define Si1132_PARAM_ALSVISADCMISC 0x12 37 | #define Si1132_PARAM_ALSVISADCMISC_VISRANGE 0x20 38 | 39 | #define Si1132_PARAM_ALSIRADCCOUNTER 0x1D 40 | #define Si1132_PARAM_ALSIRADCGAIN 0x1E 41 | #define Si1132_PARAM_ALSIRADCMISC 0x1F 42 | #define Si1132_PARAM_ALSIRADCMISC_RANGE 0x20 43 | 44 | #define Si1132_PARAM_ADCCOUNTER_511CLK 0x70 45 | 46 | #define Si1132_PARAM_ADCMUX_SMALLIR 0x00 47 | #define Si1132_PARAM_ADCMUX_LARGEIR 0x03 48 | 49 | /* REGISTERS */ 50 | #define Si1132_REG_PARTID 0x00 51 | #define Si1132_REG_REVID 0x01 52 | #define Si1132_REG_SEQID 0x02 53 | 54 | #define Si1132_REG_INTCFG 0x03 55 | #define Si1132_REG_INTCFG_INTOE 0x01 56 | 57 | #define Si1132_REG_IRQEN 0x04 58 | #define Si1132_REG_IRQEN_ALSEVERYSAMPLE 0x01 59 | 60 | #define Si1132_REG_IRQMODE1 0x05 61 | #define Si1132_REG_IRQMODE2 0x06 62 | 63 | #define Si1132_REG_HWKEY 0x07 64 | #define Si1132_REG_MEASRATE0 0x08 65 | #define Si1132_REG_MEASRATE1 0x09 66 | #define Si1132_REG_UCOEF0 0x13 67 | #define Si1132_REG_UCOEF1 0x14 68 | #define Si1132_REG_UCOEF2 0x15 69 | #define Si1132_REG_UCOEF3 0x16 70 | #define Si1132_REG_PARAMWR 0x17 71 | #define Si1132_REG_COMMAND 0x18 72 | #define Si1132_REG_RESPONSE 0x20 73 | #define Si1132_REG_IRQSTAT 0x21 74 | 75 | #define Si1132_REG_ALSVISDATA0 0x22 76 | #define Si1132_REG_ALSVISDATA1 0x23 77 | #define Si1132_REG_ALSIRDATA0 0x24 78 | #define Si1132_REG_ALSIRDATA1 0x25 79 | #define Si1132_REG_UVINDEX0 0x2C 80 | #define Si1132_REG_UVINDEX1 0x2D 81 | #define Si1132_REG_PARAMRD 0x2E 82 | #define Si1132_REG_CHIPSTAT 0x30 83 | 84 | #define Si1132_ADDR 0x60 85 | 86 | class ODROID_Si1132 { 87 | public : 88 | ODROID_Si1132(void); 89 | boolean begin(void); 90 | void reset(void); 91 | void configRegister(void); 92 | uint16_t readTemperature(void); 93 | uint16_t readUV(void); 94 | float readVisible(void); 95 | float readIR(void); 96 | private : 97 | uint16_t read16(uint8_t addr); 98 | uint8_t read8(uint8_t addr); 99 | void write8(uint8_t reg, uint8_t val); 100 | uint8_t readParam(uint8_t p); 101 | uint8_t writeParam(uint8_t p, uint8_t v); 102 | uint8_t _addr; 103 | }; 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /src/sensors/ODROID_Si70xx.cpp: -------------------------------------------------------------------------------- 1 | #include "ODROID_Si70xx.h" 2 | #include "sensors/Wire.h" 3 | 4 | ODROID_Si70xx::ODROID_Si70xx() 5 | { 6 | Wire.begin(15, 4); 7 | //if (read8(Si1132_REG_CHIPID) != 0x60) 8 | // return false; 9 | } 10 | 11 | float ODROID_Si70xx::readTemperature(void) 12 | { 13 | float temp; 14 | int32_t rawTemp; 15 | write8(CMD_MEASURE_TEMPERATURE_HOLD); 16 | 17 | rawTemp = read16(CMD_MEASURE_TEMPERATURE_HOLD); 18 | temp = (rawTemp*175.72/65536) - 46.85; 19 | 20 | return temp; 21 | } 22 | 23 | float ODROID_Si70xx::readHumidity(void) 24 | { 25 | float humi; 26 | int32_t rawHumi; 27 | write8(CMD_MEASURE_HUMIDITY_HOLD); 28 | delay(10); 29 | rawHumi = read16(CMD_MEASURE_HUMIDITY_HOLD); 30 | delay(10); 31 | humi = (rawHumi*125.0/65536) - 6; 32 | 33 | return humi; 34 | } 35 | 36 | uint16_t ODROID_Si70xx::read16(uint8_t addr) 37 | { 38 | uint16_t ret; 39 | Wire.beginTransmission(ID_SI7020); 40 | Wire.write(addr); 41 | Wire.endTransmission(); 42 | 43 | Wire.beginTransmission(ID_SI7020); 44 | Wire.requestFrom(ID_SI7020, 2); 45 | ret = Wire.read(); 46 | ret <<= 8; 47 | ret |= Wire.read(); 48 | Wire.endTransmission(); 49 | 50 | return ret; 51 | } 52 | 53 | void ODROID_Si70xx::write8(uint8_t addr) 54 | { 55 | Wire.beginTransmission(ID_SI7020); 56 | Wire.write(addr); 57 | Wire.endTransmission(); 58 | } 59 | -------------------------------------------------------------------------------- /src/sensors/ODROID_Si70xx.h: -------------------------------------------------------------------------------- 1 | #ifndef ODROID_Si70xx_H 2 | #define ODROID_Si70xx_H 3 | 4 | #if (ARDUINO >= 100) 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | /* Commands */ 11 | #define CMD_MEASURE_HUMIDITY_HOLD 0xE5 12 | #define CMD_MEASURE_HUMIDITY_NO_HOLD 0xF5 13 | #define CMD_MEASURE_TEMPERATURE_HOLD 0xE3 14 | #define CMD_MEASURE_TEMPERATURE_NO_HOLD 0xF3 15 | #define CMD_MEASURE_THERMISTOR_HOLD 0xEE 16 | #define CMD_READ_PREVIOUS_TEMPERATURE 0xE0 17 | #define CMD_RESET 0xFE 18 | #define CMD_WRITE_REGISTER_1 0xE6 19 | #define CMD_READ_REGISTER_1 0xE7 20 | #define CMD_WRITE_REGISTER_2 0x50 21 | #define CMD_READ_REGISTER_2 0x10 22 | #define CMD_WRITE_REGISTER_3 0x51 23 | #define CMD_READ_REGISTER_3 0x11 24 | #define CMD_WRITE_COEFFICIENT 0xC5 25 | #define CMD_READ_COEFFICIENT 0x84 26 | 27 | /* User Register 1 */ 28 | #define REG1_RESOLUTION_MASK 0x81 29 | #define REG1_RESOLUTION_H12_T14 0x00 30 | #define REG1_RESOLUTION_H08_T12 0x01 31 | #define REG1_RESOLUTION_H10_T13 0x80 32 | #define REG1_RESOLUTION_H11_T11 0x81 33 | #define REG1_LOW_VOLTAGE 0x40 34 | #define REG1_ENABLE_HEATER 0x04 35 | 36 | /* User Register 2 */ 37 | #define REG2_VOUT 0x01 38 | #define REG2_VREF_VDD 0x02 39 | #define REG2_VIN_BUFFERED 0x04 40 | #define REG2_RESERVED 0x08 41 | #define REG2_FAST_CONVERSION 0x10 42 | #define REG2_MODE_CORRECTION 0x20 43 | #define REG2_MODE_NO_HOLD 0x40 44 | 45 | /* Device Identification */ 46 | #define ID_SAMPLE 0xFF 47 | #define ID_SI7013 0x0D 48 | #define ID_SI7020 0x40 49 | #define ID_SI7021 0x15 50 | 51 | /* Coefficients */ 52 | #define COEFFICIENT_BASE 0x82 53 | #define COEFFICIENT_COUNT 9 54 | 55 | class ODROID_Si70xx { 56 | public : 57 | ODROID_Si70xx(); 58 | float readTemperature(void); 59 | float readHumidity(void); 60 | private : 61 | uint8_t read8(uint8_t addr); 62 | uint16_t read16(uint8_t addr); 63 | void write8(uint8_t addr); 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/sensors/RTClib.h: -------------------------------------------------------------------------------- 1 | // Code by JeeLabs http://news.jeelabs.org/code/ 2 | // Released to the public domain! Enjoy! 3 | 4 | #ifndef _RTCLIB_H_ 5 | #define _RTCLIB_H_ 6 | 7 | struct alarm_flags { 8 | char minute; 9 | char hour; 10 | char day; 11 | char wday; 12 | }; 13 | 14 | #define AE_M 1 15 | #define AE_H 1 16 | #define AE_D 1 17 | #define AE_W 1 18 | 19 | // TimeDelta which can represent changes in time with seconds accuracy. 20 | class TimeDelta { 21 | public: 22 | TimeDelta (uint32_t seconds =0); 23 | TimeDelta (uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds); 24 | TimeDelta (const TimeDelta& copy); 25 | uint16_t days() const { return _sec / 86400L; } 26 | uint8_t hours() const { return _sec/ 3600 % 24; } 27 | uint8_t minutes() const { return _sec / 60 % 60; } 28 | uint8_t seconds() const { return _sec % 60; } 29 | uint32_t totalseconds() const { return _sec; } 30 | 31 | TimeDelta operator+(const TimeDelta& right); 32 | TimeDelta operator-(const TimeDelta& right); 33 | 34 | protected: 35 | uint32_t _sec; 36 | }; 37 | 38 | // Simple general-purpose date/time class (no TZ / DST / leap second handling!) 39 | class DateTime { 40 | public: 41 | char* format(char* ret); 42 | DateTime (uint32_t t =0); 43 | DateTime (uint16_t year, uint8_t month, uint8_t day, 44 | uint8_t hour =0, uint8_t min =0, uint8_t sec =0); 45 | DateTime (const char* date, const char* time); 46 | DateTime (const __FlashStringHelper* date, const __FlashStringHelper* time); 47 | DateTime (const char* sdate); 48 | uint16_t year() const { return 2000 + yOff; } 49 | uint8_t month() const { return m; } 50 | uint8_t day() const { return d; } 51 | uint8_t hour() const { return hh; } 52 | uint8_t minute() const { return mm; } 53 | uint8_t second() const { return ss; } 54 | uint8_t dayOfWeek() const; 55 | void setyear(uint16_t year) { yOff = year - 2000; } 56 | void setmonth(uint8_t month) { m = month; } 57 | void setday(uint8_t day) { d = day; } 58 | void sethour(uint8_t hour) { hh = hour%24; } 59 | void setminute(uint8_t minute) { mm = minute%60; } 60 | void setsecond(uint8_t second) { ss = second%60; } 61 | // 32-bit times as seconds since 1/1/2000 62 | long secondstime() const; 63 | // 32-bit times as seconds since 1/1/1970 64 | uint32_t unixtime(void) const; 65 | unsigned char equals(const char* sdate) const;//DD-MM-YYYY hh:mm:ss 66 | unsigned char equals(const DateTime &date) const; 67 | unsigned char operator == (const char *sdate) const {return equals(sdate);} 68 | unsigned char operator == (const DateTime &date) const {return equals(date);} 69 | unsigned char operator != (const char *sdate) const {return !equals(sdate);} 70 | unsigned char operator != (const DateTime &date) const {return !equals(date);} 71 | unsigned char operator < (const DateTime &date) const; 72 | unsigned char operator > (const DateTime &date) const; 73 | unsigned char operator <= (const DateTime &date) const; 74 | unsigned char operator >= (const DateTime &date) const; 75 | 76 | DateTime operator + (const TimeDelta& delta); 77 | DateTime operator - (const TimeDelta& delta); 78 | TimeDelta operator - (const DateTime& right); 79 | 80 | protected: 81 | uint8_t yOff, m, d, hh, mm, ss; 82 | }; 83 | 84 | // RTC based on the DS1302 chip connected via pins 85 | class DS1302 { 86 | private: 87 | uint8_t read(); 88 | void write(const uint8_t val); 89 | public: 90 | DS1302 (uint8_t ce_pin = 4, uint8_t sck_pin = 5, uint8_t io_pin = 6); 91 | uint8_t begin(void); 92 | void adjust(const DateTime& dt); 93 | uint8_t isrunning(void); 94 | DateTime now(); 95 | uint8_t read(const uint8_t addr); 96 | void write(const uint8_t addr, const uint8_t val); 97 | protected: 98 | uint8_t ce, sck, io; 99 | }; 100 | 101 | // RTC based on the DS1307 chip connected via I2C and the Wire library 102 | class DS1307 { 103 | public: 104 | uint8_t begin(void); 105 | void adjust(const DateTime& dt); 106 | uint8_t isrunning(void); 107 | DateTime now(); 108 | uint8_t read(const uint8_t addr); 109 | void write(const uint8_t addr, const uint8_t val); 110 | }; 111 | 112 | class DS3231 { 113 | public: 114 | uint8_t begin(void); 115 | void adjust(const DateTime& dt); 116 | uint8_t isrunning(void); 117 | double getTemp(void); 118 | DateTime now(); 119 | uint8_t read(const uint8_t addr); 120 | void write(const uint8_t addr, const uint8_t val); 121 | }; 122 | 123 | 124 | class PCF8583 { 125 | int address; 126 | public: 127 | PCF8583(); 128 | PCF8583(int device_address); 129 | uint8_t begin(void); 130 | DateTime now(); 131 | uint8_t isrunning(void); 132 | void adjust(const DateTime& dt); 133 | void off_alarm(void); 134 | DateTime get_alarm(); 135 | void set_alarm(const DateTime& dt); 136 | }; 137 | 138 | class PCF8563 { 139 | int address; 140 | int status1; 141 | int status2; 142 | public: 143 | PCF8563(); 144 | PCF8563(int device_address); 145 | uint8_t begin(void); 146 | DateTime now(); 147 | uint8_t isrunning(void); 148 | void adjust(const DateTime& dt); 149 | void off_alarm(void); 150 | void on_alarm(void); 151 | DateTime get_alarm(); 152 | void set_alarm(const DateTime& dt, struct alarm_flags flags); 153 | }; 154 | 155 | // RTC using the internal millis() clock, has to be initialized before use 156 | // NOTE: this clock won't be correct once the millis() timer rolls over (>49d?) 157 | class RTC_Millis { 158 | private: 159 | uint8_t ok; 160 | public: 161 | void begin(const DateTime& dt) { adjust(dt);ok = 1; } 162 | void adjust(const DateTime& dt); 163 | DateTime now(); 164 | uint8_t begin(void); 165 | uint8_t isrunning(void); 166 | 167 | protected: 168 | static long offset; 169 | 170 | }; 171 | 172 | #endif // _RTCLIB_H_ 173 | -------------------------------------------------------------------------------- /src/sensors/Rtc_Pcf8563.h: -------------------------------------------------------------------------------- 1 | /***** 2 | * NAME 3 | * External Real Time Clock support routines 4 | * AUTHOR 5 | * Joe Robertson, jmr 6 | * orbitalair@bellsouth.net 7 | * 8 | * CREATION DATE 9 | * 1/2/10, init - built off of pic rtc code 10 | * NOTES 11 | * HISTORY 12 | * 1/2/10 ported to arduino compiler, jmr 13 | * 2/14/10 added 3 world date formats, jmr 14 | * 28/02/2012 A. Pasotti 15 | * fixed a bug in RTCC_ALARM_AF, 16 | * added a few (not really useful) methods 17 | * 12/26/12 added version method to be able to track builds. jmr 18 | * fix for arduino 1.0.1. Wire. 19 | * 20 | * TODO 21 | * 22 | ****** 23 | * Robodoc embedded documentation. 24 | * http://www.xs4all.nl/~rfsber/Robo/robodoc.html 25 | */ 26 | 27 | #ifndef Rtc_Pcf8563_H 28 | #define Rtc_Pcf8563_H 29 | 30 | #include "Arduino.h" 31 | #include "Wire.h" 32 | 33 | #define RTCC_VERSION "Pcf8563 v1.0.3" 34 | 35 | /* the read and write values for pcf8563 rtcc */ 36 | /* these are adjusted for arduino */ 37 | #define RTCC_R 0xa3 38 | #define RTCC_W 0xa2 39 | 40 | #define RTCC_SEC 1 41 | #define RTCC_MIN 2 42 | #define RTCC_HR 3 43 | #define RTCC_DAY 4 44 | #define RTCC_WEEKDAY 5 45 | #define RTCC_MONTH 6 46 | #define RTCC_YEAR 7 47 | #define RTCC_CENTURY 8 48 | 49 | /* register addresses in the rtc */ 50 | #define RTCC_STAT1_ADDR 0x0 51 | #define RTCC_STAT2_ADDR 0x01 52 | #define RTCC_SEC_ADDR 0x02 53 | #define RTCC_MIN_ADDR 0x03 54 | #define RTCC_HR_ADDR 0x04 55 | #define RTCC_DAY_ADDR 0x05 56 | #define RTCC_WEEKDAY_ADDR 0x06 57 | #define RTCC_MONTH_ADDR 0x07 58 | #define RTCC_YEAR_ADDR 0x08 59 | #define RTCC_ALRM_MIN_ADDR 0x09 60 | #define RTCC_SQW_ADDR 0x0D 61 | 62 | /* setting the alarm flag to 0 enables the alarm. 63 | * set it to 1 to disable the alarm for that value. 64 | */ 65 | #define RTCC_ALARM 0x80 66 | #define RTCC_ALARM_AIE 0x02 67 | #define RTCC_ALARM_AF 0x08 // 0x08 : not 0x04!!!! 68 | /* optional val for no alarm setting */ 69 | #define RTCC_NO_ALARM 99 70 | 71 | #define RTCC_CENTURY_MASK 0x80 72 | 73 | /* date format flags */ 74 | #define RTCC_DATE_WORLD 0x01 75 | #define RTCC_DATE_ASIA 0x02 76 | #define RTCC_DATE_US 0x04 77 | /* time format flags */ 78 | #define RTCC_TIME_HMS 0x01 79 | #define RTCC_TIME_HM 0x02 80 | 81 | /* square wave contants */ 82 | #define SQW_DISABLE B00000000 83 | #define SQW_32KHZ B10000000 84 | #define SQW_1024HZ B10000001 85 | #define SQW_32HZ B10000010 86 | #define SQW_1HZ B10000011 87 | 88 | 89 | /* arduino class */ 90 | class Rtc_Pcf8563 { 91 | public: 92 | Rtc_Pcf8563(); 93 | 94 | void initClock(); /* zero out all values, disable all alarms */ 95 | void clearStatus(); /* set both status bytes to zero */ 96 | 97 | void getDate(); /* get date vals to local vars */ 98 | void setDate(byte day, byte weekday, byte month, byte century, byte year); 99 | void getTime(); /* get time vars + 2 status bytes to local vars */ 100 | void getAlarm(); 101 | void setTime(byte sec, byte minute, byte hour); 102 | byte readStatus2(); 103 | boolean alarmEnabled(); 104 | boolean alarmActive(); 105 | 106 | void enableAlarm(); /* activate alarm flag and interrupt */ 107 | void setAlarm(byte min, byte hour, byte day, byte weekday); /* set alarm vals, 99=ignore */ 108 | void clearAlarm(); /* clear alarm flag and interrupt */ 109 | void resetAlarm(); /* clear alarm flag but leave interrupt unchanged */ 110 | void setSquareWave(byte frequency); 111 | void clearSquareWave(); 112 | 113 | byte getSecond(); 114 | byte getMinute(); 115 | byte getHour(); 116 | byte getDay(); 117 | byte getMonth(); 118 | byte getYear(); 119 | byte getWeekday(); 120 | byte getStatus1(); 121 | byte getStatus2(); 122 | 123 | byte getAlarmMinute(); 124 | byte getAlarmHour(); 125 | byte getAlarmDay(); 126 | byte getAlarmWeekday(); 127 | 128 | /*get a output string, these call getTime/getDate for latest vals */ 129 | char *formatTime(byte style=RTCC_TIME_HMS); 130 | /* date supports 3 styles as listed in the wikipedia page about world date/time. */ 131 | char *formatDate(byte style=RTCC_DATE_US); 132 | 133 | char *version(); 134 | 135 | private: 136 | /* methods */ 137 | byte decToBcd(byte value); 138 | byte bcdToDec(byte value); 139 | /* time variables */ 140 | byte hour; 141 | byte minute; 142 | byte sec; 143 | byte day; 144 | byte weekday; 145 | byte month; 146 | byte year; 147 | /* alarm */ 148 | byte alarm_hour; 149 | byte alarm_minute; 150 | byte alarm_weekday; 151 | byte alarm_day; 152 | /* support */ 153 | byte status1; 154 | byte status2; 155 | byte century; 156 | 157 | char strOut[9]; 158 | char strDate[11]; 159 | 160 | int Rtcc_Addr; 161 | }; 162 | 163 | #endif 164 | -------------------------------------------------------------------------------- /src/sensors/Ultrasonic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultrasonic.cpp 3 | * 4 | * Library for Ultrasonic Ranging Module in a minimalist way 5 | * 6 | * created 3 Apr 2014 7 | * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes) 8 | * modified 23 Jan 2017 9 | * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes) 10 | * modified 04 Mar 2017 11 | * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes) 12 | * modified 15 May 2017 13 | * by Eliot Lim (github: @eliotlim) 14 | * 15 | * Released into the MIT License. 16 | */ 17 | 18 | #include 19 | #include "Ultrasonic.h" 20 | 21 | Ultrasonic::Ultrasonic(uint8_t trigPin, uint8_t echoPin, unsigned long timeOut) { 22 | trig = trigPin; 23 | echo = echoPin; 24 | threePins = trig == echo ? true : false; 25 | pinMode(trig, OUTPUT); 26 | pinMode(echo, INPUT); 27 | timeout = timeOut; 28 | } 29 | 30 | unsigned int Ultrasonic::timing() { 31 | if (threePins) 32 | pinMode(trig, OUTPUT); 33 | 34 | digitalWrite(trig, LOW); 35 | delayMicroseconds(2); 36 | digitalWrite(trig, HIGH); 37 | delayMicroseconds(10); 38 | digitalWrite(trig, LOW); 39 | 40 | if (threePins) 41 | pinMode(trig, INPUT); 42 | 43 | return pulseIn(echo, HIGH, timeout); // duration 44 | } 45 | 46 | unsigned int Ultrasonic::distanceRead() { 47 | /* 48 | * If the unit of measure is not passed as a parameter, 49 | * by default, it will return the distance in centimeters. 50 | * To change the default, replace CM by INC. 51 | */ 52 | return distanceRead(CM); 53 | } 54 | 55 | unsigned int Ultrasonic::distanceRead(uint8_t und) { 56 | return timing() / und / 2; //distance by divisor 57 | } 58 | -------------------------------------------------------------------------------- /src/sensors/Ultrasonic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Ultrasonic.h 3 | * 4 | * Library for Ultrasonic Ranging Module in a minimalist way 5 | * 6 | * created 3 Apr 2014 7 | * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes) 8 | * modified 23 Jan 2017 9 | * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes) 10 | * modified 04 Mar 2017 11 | * by Erick Simões (github: @ErickSimoes | twitter: @AloErickSimoes) 12 | * modified 15 May 2017 13 | * by Eliot Lim (github: @eliotlim) 14 | * 15 | * Released into the MIT License. 16 | */ 17 | 18 | #ifndef Ultrasonic_h 19 | #define Ultrasonic_h 20 | 21 | /* 22 | * Values of divisors 23 | */ 24 | #define CM 28 25 | #define INC 71 26 | 27 | class Ultrasonic { 28 | public: 29 | Ultrasonic(uint8_t sigPin) : Ultrasonic(sigPin, sigPin) {}; 30 | Ultrasonic(uint8_t trigPin, uint8_t echoPin, unsigned long timeOut = 20000UL); 31 | unsigned int distanceRead(); 32 | unsigned int distanceRead(uint8_t und); 33 | void setTimeout(unsigned long timeOut) {timeout = timeOut;} 34 | 35 | private: 36 | uint8_t trig; 37 | uint8_t echo; 38 | boolean threePins = false; 39 | unsigned long timeout; 40 | unsigned int timing(); 41 | }; 42 | 43 | #endif // Ultrasonic_h 44 | -------------------------------------------------------------------------------- /src/sensors/Wire.h: -------------------------------------------------------------------------------- 1 | /* 2 | TwoWire.h - TWI/I2C library for Arduino & Wiring 3 | Copyright (c) 2006 Nicholas Zambetti. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts 20 | Modified December 2014 by Ivan Grokhotkov (ivan@esp8266.com) - esp8266 support 21 | Modified April 2015 by Hrsto Gochkov (ficeto@ficeto.com) - alternative esp8266 support 22 | Modified November 2017 by Chuck Todd to use ISR and increase stability. 23 | */ 24 | 25 | #ifndef TwoWire_h 26 | #define TwoWire_h 27 | 28 | #include 29 | #include "freertos/FreeRTOS.h" 30 | #include "freertos/queue.h" 31 | #include "Stream.h" 32 | 33 | #define STICKBREAKER V0.2.2 34 | #define I2C_BUFFER_LENGTH 128 35 | typedef void(*user_onRequest)(void); 36 | typedef void(*user_onReceive)(uint8_t*, int); 37 | 38 | class TwoWire: public Stream 39 | { 40 | protected: 41 | uint8_t num; 42 | int8_t sda; 43 | int8_t scl; 44 | i2c_t * i2c; 45 | 46 | uint8_t rxBuffer[I2C_BUFFER_LENGTH]; 47 | uint16_t rxIndex; 48 | uint16_t rxLength; 49 | uint16_t rxQueued; //@stickBreaker 50 | 51 | uint8_t txBuffer[I2C_BUFFER_LENGTH]; 52 | uint16_t txIndex; 53 | uint16_t txLength; 54 | uint16_t txAddress; 55 | uint16_t txQueued; //@stickbreaker 56 | 57 | uint8_t transmitting; 58 | /* slave Mode, not yet Stickbreaker 59 | static user_onRequest uReq[2]; 60 | static user_onReceive uRcv[2]; 61 | void onRequestService(void); 62 | void onReceiveService(uint8_t*, int); 63 | */ 64 | i2c_err_t last_error; // @stickBreaker from esp32-hal-i2c.h 65 | uint16_t _timeOutMillis; 66 | 67 | public: 68 | TwoWire(uint8_t bus_num); 69 | ~TwoWire(); 70 | void begin(int sda=-1, int scl=-1, uint32_t frequency=0); 71 | 72 | void setClock(uint32_t frequency); // change bus clock without initing hardware 73 | size_t getClock(); // current bus clock rate in hz 74 | 75 | void setTimeOut(uint16_t timeOutMillis); 76 | uint16_t getTimeOut(); 77 | 78 | uint8_t lastError(); 79 | char * getErrorText(uint8_t err); 80 | 81 | //@stickBreaker for big blocks and ISR model 82 | i2c_err_t writeTransmission(uint16_t address, uint8_t* buff, uint16_t size, bool sendStop=true); 83 | i2c_err_t readTransmission(uint16_t address, uint8_t* buff, uint16_t size, bool sendStop=true, uint32_t *readCount=NULL); 84 | 85 | void beginTransmission(uint16_t address); 86 | void beginTransmission(uint8_t address); 87 | void beginTransmission(int address); 88 | 89 | uint8_t endTransmission(bool sendStop); 90 | uint8_t endTransmission(uint8_t sendStop); 91 | uint8_t endTransmission(void); 92 | 93 | uint8_t requestFrom(uint16_t address, uint8_t size, bool sendStop); 94 | uint8_t requestFrom(uint16_t address, uint8_t size, uint8_t sendStop); 95 | uint8_t requestFrom(uint16_t address, uint8_t size); 96 | uint8_t requestFrom(uint8_t address, uint8_t size, uint8_t sendStop); 97 | uint8_t requestFrom(uint8_t address, uint8_t size); 98 | uint8_t requestFrom(int address, int size, int sendStop); 99 | uint8_t requestFrom(int address, int size); 100 | 101 | size_t write(uint8_t); 102 | size_t write(const uint8_t *, size_t); 103 | int available(void); 104 | int read(void); 105 | int peek(void); 106 | void flush(void); 107 | 108 | inline size_t write(const char * s) 109 | { 110 | return write((uint8_t*) s, strlen(s)); 111 | } 112 | inline size_t write(unsigned long n) 113 | { 114 | return write((uint8_t)n); 115 | } 116 | inline size_t write(long n) 117 | { 118 | return write((uint8_t)n); 119 | } 120 | inline size_t write(unsigned int n) 121 | { 122 | return write((uint8_t)n); 123 | } 124 | inline size_t write(int n) 125 | { 126 | return write((uint8_t)n); 127 | } 128 | 129 | void onReceive( void (*)(int) ); 130 | void onRequest( void (*)(void) ); 131 | 132 | void dumpInts(); 133 | void dumpI2C(); 134 | }; 135 | 136 | extern TwoWire Wire; 137 | 138 | 139 | /* 140 | V0.2.2 13APR2018 preserve custom SCL,SDA,Frequency when no parameters passed to begin() 141 | V0.2.1 15MAR2018 Hardware reset, Glitch prevention, adding destructor for second i2c testing 142 | */ 143 | #endif 144 | -------------------------------------------------------------------------------- /src/sensors/esp32-hal-gpio.h: -------------------------------------------------------------------------------- 1 | /* 2 | Arduino.h - Main include file for the Arduino SDK 3 | Copyright (c) 2005-2013 Arduino Team. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef MAIN_ESP32_HAL_GPIO_H_ 21 | #define MAIN_ESP32_HAL_GPIO_H_ 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | #include "esp32-hal.h" 28 | 29 | #define LOW 0x0 30 | #define HIGH 0x1 31 | 32 | //GPIO FUNCTIONS 33 | #define INPUT 0x01 34 | #define OUTPUT 0x02 35 | #define PULLUP 0x04 36 | #define INPUT_PULLUP 0x05 37 | #define PULLDOWN 0x08 38 | #define INPUT_PULLDOWN 0x09 39 | #define OPEN_DRAIN 0x10 40 | #define OUTPUT_OPEN_DRAIN 0x12 41 | #define SPECIAL 0xF0 42 | #define FUNCTION_1 0x00 43 | #define FUNCTION_2 0x20 44 | #define FUNCTION_3 0x40 45 | #define FUNCTION_4 0x60 46 | #define FUNCTION_5 0x80 47 | #define FUNCTION_6 0xA0 48 | #define ANALOG 0xC0 49 | 50 | //Interrupt Modes 51 | #define DISABLED 0x00 52 | #define RISING 0x01 53 | #define FALLING 0x02 54 | #define CHANGE 0x03 55 | #define ONLOW 0x04 56 | #define ONHIGH 0x05 57 | #define ONLOW_WE 0x0C 58 | #define ONHIGH_WE 0x0D 59 | 60 | typedef struct { 61 | uint8_t reg; /*!< GPIO register offset from DR_REG_IO_MUX_BASE */ 62 | int8_t rtc; /*!< RTC GPIO number (-1 if not RTC GPIO pin) */ 63 | int8_t adc; /*!< ADC Channel number (-1 if not ADC pin) */ 64 | int8_t touch; /*!< Touch Channel number (-1 if not Touch pin) */ 65 | } esp32_gpioMux_t; 66 | 67 | extern const esp32_gpioMux_t esp32_gpioMux[40]; 68 | extern const int8_t esp32_adc2gpio[20]; 69 | 70 | #define digitalPinIsValid(pin) ((pin) < 40 && esp32_gpioMux[(pin)].reg) 71 | #define digitalPinCanOutput(pin) ((pin) < 34 && esp32_gpioMux[(pin)].reg) 72 | #define digitalPinToRtcPin(pin) (((pin) < 40)?esp32_gpioMux[(pin)].rtc:-1) 73 | #define digitalPinToAnalogChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].adc:-1) 74 | #define digitalPinToTouchChannel(pin) (((pin) < 40)?esp32_gpioMux[(pin)].touch:-1) 75 | #define digitalPinToDacChannel(pin) (((pin) == 25)?0:((pin) == 26)?1:-1) 76 | 77 | void pinMode(uint8_t pin, uint8_t mode); 78 | void digitalWrite(uint8_t pin, uint8_t val); 79 | int digitalRead(uint8_t pin); 80 | 81 | void attachInterrupt(uint8_t pin, void (*)(void), int mode); 82 | void detachInterrupt(uint8_t pin); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* MAIN_ESP32_HAL_GPIO_H_ */ 89 | -------------------------------------------------------------------------------- /src/sensors/esp32-hal-i2c.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // modified Nov 2017 by Chuck Todd to support Interrupt Driven I/O 15 | 16 | #ifndef _ESP32_HAL_I2C_H_ 17 | #define _ESP32_HAL_I2C_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | #include 25 | #include "freertos/FreeRTOS.h" 26 | #include "freertos/event_groups.h" 27 | 28 | // External Wire.h equivalent error Codes 29 | typedef enum { 30 | I2C_ERROR_OK=0, 31 | I2C_ERROR_DEV, 32 | I2C_ERROR_ACK, 33 | I2C_ERROR_TIMEOUT, 34 | I2C_ERROR_BUS, 35 | I2C_ERROR_BUSY, 36 | I2C_ERROR_MEMORY, 37 | I2C_ERROR_CONTINUE, 38 | I2C_ERROR_NO_BEGIN 39 | } i2c_err_t; 40 | 41 | struct i2c_struct_t; 42 | typedef struct i2c_struct_t i2c_t; 43 | 44 | i2c_t * i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t clk_speed); 45 | void i2cRelease(i2c_t *i2c); // free ISR, Free DQ, Power off peripheral clock. Must call i2cInit() to recover 46 | i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, uint8_t* buff, uint16_t size, bool sendStop, uint16_t timeOutMillis); 47 | i2c_err_t i2cRead(i2c_t * i2c, uint16_t address, uint8_t* buff, uint16_t size, bool sendStop, uint16_t timeOutMillis, uint32_t *readCount); 48 | i2c_err_t i2cFlush(i2c_t *i2c); 49 | i2c_err_t i2cSetFrequency(i2c_t * i2c, uint32_t clk_speed); 50 | uint32_t i2cGetFrequency(i2c_t * i2c); 51 | 52 | //Functions below should be used only if well understood 53 | //Might be deprecated and removed in future 54 | i2c_err_t i2cAttachSCL(i2c_t * i2c, int8_t scl); 55 | i2c_err_t i2cDetachSCL(i2c_t * i2c, int8_t scl); 56 | i2c_err_t i2cAttachSDA(i2c_t * i2c, int8_t sda); 57 | i2c_err_t i2cDetachSDA(i2c_t * i2c, int8_t sda); 58 | 59 | //Stickbreakers ISR Support 60 | i2c_err_t i2cProcQueue(i2c_t *i2c, uint32_t *readCount, uint16_t timeOutMillis); 61 | i2c_err_t i2cAddQueueWrite(i2c_t *i2c, uint16_t i2cDeviceAddr, uint8_t *dataPtr, uint16_t dataLen, bool SendStop, EventGroupHandle_t event); 62 | i2c_err_t i2cAddQueueRead(i2c_t *i2c, uint16_t i2cDeviceAddr, uint8_t *dataPtr, uint16_t dataLen, bool SendStop, EventGroupHandle_t event); 63 | 64 | //stickbreaker debug support 65 | void i2cDumpInts(uint8_t num); 66 | void i2cDumpI2c(i2c_t *i2c); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* _ESP32_HAL_I2C_H_ */ 73 | -------------------------------------------------------------------------------- /src/sensors/esp32-hal-log.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | #ifndef __ARDUHAL_LOG_H__ 15 | #define __ARDUHAL_LOG_H__ 16 | 17 | #ifdef __cplusplus 18 | extern "C" 19 | { 20 | #endif 21 | 22 | #include "sdkconfig.h" 23 | 24 | #define ARDUHAL_LOG_LEVEL_NONE (0) 25 | #define ARDUHAL_LOG_LEVEL_ERROR (1) 26 | #define ARDUHAL_LOG_LEVEL_WARN (2) 27 | #define ARDUHAL_LOG_LEVEL_INFO (3) 28 | #define ARDUHAL_LOG_LEVEL_DEBUG (4) 29 | #define ARDUHAL_LOG_LEVEL_VERBOSE (5) 30 | 31 | #ifndef CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL 32 | #define CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL ARDUHAL_LOG_LEVEL_NONE 33 | #endif 34 | 35 | #ifndef CORE_DEBUG_LEVEL 36 | #define ARDUHAL_LOG_LEVEL CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL 37 | #else 38 | #define ARDUHAL_LOG_LEVEL CORE_DEBUG_LEVEL 39 | #endif 40 | 41 | #ifndef CONFIG_ARDUHAL_LOG_COLORS 42 | #define CONFIG_ARDUHAL_LOG_COLORS 0 43 | #endif 44 | 45 | #if CONFIG_ARDUHAL_LOG_COLORS 46 | #define ARDUHAL_LOG_COLOR_BLACK "30" 47 | #define ARDUHAL_LOG_COLOR_RED "31" //ERROR 48 | #define ARDUHAL_LOG_COLOR_GREEN "32" //INFO 49 | #define ARDUHAL_LOG_COLOR_YELLOW "33" //WARNING 50 | #define ARDUHAL_LOG_COLOR_BLUE "34" 51 | #define ARDUHAL_LOG_COLOR_MAGENTA "35" 52 | #define ARDUHAL_LOG_COLOR_CYAN "36" //DEBUG 53 | #define ARDUHAL_LOG_COLOR_GRAY "37" //VERBOSE 54 | #define ARDUHAL_LOG_COLOR_WHITE "38" 55 | 56 | #define ARDUHAL_LOG_COLOR(COLOR) "\033[0;" COLOR "m" 57 | #define ARDUHAL_LOG_BOLD(COLOR) "\033[1;" COLOR "m" 58 | #define ARDUHAL_LOG_RESET_COLOR "\033[0m" 59 | 60 | #define ARDUHAL_LOG_COLOR_E ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_RED) 61 | #define ARDUHAL_LOG_COLOR_W ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_YELLOW) 62 | #define ARDUHAL_LOG_COLOR_I ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_GREEN) 63 | #define ARDUHAL_LOG_COLOR_D ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_CYAN) 64 | #define ARDUHAL_LOG_COLOR_V ARDUHAL_LOG_COLOR(ARDUHAL_LOG_COLOR_GRAY) 65 | #else 66 | #define ARDUHAL_LOG_COLOR_E 67 | #define ARDUHAL_LOG_COLOR_W 68 | #define ARDUHAL_LOG_COLOR_I 69 | #define ARDUHAL_LOG_COLOR_D 70 | #define ARDUHAL_LOG_COLOR_V 71 | #define ARDUHAL_LOG_RESET_COLOR 72 | #endif 73 | 74 | const char * pathToFileName(const char * path); 75 | int log_printf(const char *fmt, ...); 76 | 77 | #define ARDUHAL_SHORT_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_ ## letter format ARDUHAL_LOG_RESET_COLOR "\r\n" 78 | #define ARDUHAL_LOG_FORMAT(letter, format) ARDUHAL_LOG_COLOR_ ## letter "[" #letter "][%s:%u] %s(): " format ARDUHAL_LOG_RESET_COLOR "\r\n", pathToFileName(__FILE__), __LINE__, __FUNCTION__ 79 | 80 | #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_VERBOSE 81 | #define log_v(format, ...) log_printf(ARDUHAL_LOG_FORMAT(V, format), ##__VA_ARGS__) 82 | #else 83 | #define log_v(format, ...) 84 | #endif 85 | 86 | #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG 87 | #define log_d(format, ...) log_printf(ARDUHAL_LOG_FORMAT(D, format), ##__VA_ARGS__) 88 | #else 89 | #define log_d(format, ...) 90 | #endif 91 | 92 | #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO 93 | #define log_i(format, ...) log_printf(ARDUHAL_LOG_FORMAT(I, format), ##__VA_ARGS__) 94 | #else 95 | #define log_i(format, ...) 96 | #endif 97 | 98 | #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN 99 | #define log_w(format, ...) log_printf(ARDUHAL_LOG_FORMAT(W, format), ##__VA_ARGS__) 100 | #else 101 | #define log_w(format, ...) 102 | #endif 103 | 104 | #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR 105 | #define log_e(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) 106 | #else 107 | #define log_e(format, ...) 108 | #endif 109 | 110 | #if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_NONE 111 | #define log_n(format, ...) log_printf(ARDUHAL_LOG_FORMAT(E, format), ##__VA_ARGS__) 112 | #else 113 | #define log_n(format, ...) 114 | #endif 115 | 116 | #include "esp_log.h" 117 | 118 | #ifdef CONFIG_ARDUHAL_ESP_LOG 119 | #undef ESP_LOGE 120 | #undef ESP_LOGW 121 | #undef ESP_LOGI 122 | #undef ESP_LOGD 123 | #undef ESP_LOGV 124 | 125 | #define ESP_LOGE(tag, ...) log_e(__VA_ARGS__) 126 | #define ESP_LOGW(tag, ...) log_w(__VA_ARGS__) 127 | #define ESP_LOGI(tag, ...) log_i(__VA_ARGS__) 128 | #define ESP_LOGD(tag, ...) log_d(__VA_ARGS__) 129 | #define ESP_LOGV(tag, ...) log_v(__VA_ARGS__) 130 | #endif 131 | 132 | #ifdef __cplusplus 133 | } 134 | #endif 135 | 136 | #endif /* __ESP_LOGGING_H__ */ 137 | -------------------------------------------------------------------------------- /src/sensors/ir/IRremoteInt.h: -------------------------------------------------------------------------------- 1 | //****************************************************************************** 2 | // IRremote 3 | // Version 2.0.1 June, 2015 4 | // Copyright 2009 Ken Shirriff 5 | // For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html 6 | // 7 | // Modified by Paul Stoffregen to support other boards and timers 8 | // 9 | // Interrupt code based on NECIRrcv by Joe Knapp 10 | // http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 11 | // Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ 12 | // 13 | // JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post) 14 | // Whynter A/C ARC-110WD added by Francesco Meschia 15 | //****************************************************************************** 16 | 17 | #ifndef IRremoteint_h 18 | #define IRremoteint_h 19 | 20 | //------------------------------------------------------------------------------ 21 | // Include the right Arduino header 22 | // 23 | #if defined(ARDUINO) && (ARDUINO >= 100) 24 | # include 25 | #else 26 | # if !defined(IRPRONTO) 27 | # include 28 | # endif 29 | #endif 30 | 31 | //------------------------------------------------------------------------------ 32 | // This handles definition and access to global variables 33 | // 34 | #ifdef IR_GLOBAL 35 | # define EXTERN 36 | #else 37 | # define EXTERN extern 38 | #endif 39 | 40 | //------------------------------------------------------------------------------ 41 | // Information for the Interrupt Service Routine 42 | // 43 | #define RAWBUF 101 // Maximum length of raw duration buffer 44 | 45 | typedef 46 | struct { 47 | // The fields are ordered to reduce memory over caused by struct-padding 48 | uint8_t rcvstate; // State Machine state 49 | uint8_t recvpin; // Pin connected to IR data from detector 50 | uint8_t blinkpin; 51 | uint8_t blinkflag; // true -> enable blinking of pin on IR processing 52 | uint8_t rawlen; // counter of entries in rawbuf 53 | unsigned int timer; // State timer, counts 50uS ticks. 54 | unsigned int rawbuf[RAWBUF]; // raw data 55 | uint8_t overflow; // Raw buffer overflow occurred 56 | } 57 | irparams_t; 58 | 59 | // ISR State-Machine : Receiver States 60 | #define STATE_IDLE 2 61 | #define STATE_MARK 3 62 | #define STATE_SPACE 4 63 | #define STATE_STOP 5 64 | #define STATE_OVERFLOW 6 65 | 66 | // Allow all parts of the code access to the ISR data 67 | // NB. The data can be changed by the ISR at any time, even mid-function 68 | // Therefore we declare it as "volatile" to stop the compiler/CPU caching it 69 | EXTERN volatile irparams_t irparams; 70 | 71 | //------------------------------------------------------------------------------ 72 | // Defines for setting and clearing register bits 73 | // 74 | #ifndef cbi 75 | # define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) 76 | #endif 77 | 78 | #ifndef sbi 79 | # define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) 80 | #endif 81 | 82 | //------------------------------------------------------------------------------ 83 | // Pulse parms are ((X*50)-100) for the Mark and ((X*50)+100) for the Space. 84 | // First MARK is the one after the long gap 85 | // Pulse parameters in uSec 86 | // 87 | 88 | // Due to sensor lag, when received, Marks tend to be 100us too long and 89 | // Spaces tend to be 100us too short 90 | #define MARK_EXCESS 100 91 | 92 | // Upper and Lower percentage tolerances in measurements 93 | #define TOLERANCE 25 94 | #define LTOL (1.0 - (TOLERANCE/100.)) 95 | #define UTOL (1.0 + (TOLERANCE/100.)) 96 | 97 | // Minimum gap between IR transmissions 98 | #define _GAP 5000 99 | #define GAP_TICKS (_GAP/USECPERTICK) 100 | 101 | #define TICKS_LOW(us) ((int)(((us)*LTOL/USECPERTICK))) 102 | #define TICKS_HIGH(us) ((int)(((us)*UTOL/USECPERTICK + 1))) 103 | 104 | //------------------------------------------------------------------------------ 105 | // IR detector output is active low 106 | // 107 | #define MARK 0 108 | #define SPACE 1 109 | 110 | // All board specific stuff has been moved to its own file, included here. 111 | #include "boarddefs.h" 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /src/sensors/ir/irSend.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //+============================================================================= 5 | void IRsend::sendRaw (const unsigned int buf[], unsigned int len, unsigned int hz) 6 | { 7 | // Set IR carrier frequency 8 | enableIROut(hz); 9 | 10 | for (unsigned int i = 0; i < len; i++) { 11 | if (i & 1) space(buf[i]) ; 12 | else mark (buf[i]) ; 13 | } 14 | 15 | space(0); // Always end with the LED off 16 | } 17 | 18 | //+============================================================================= 19 | // Sends an IR mark for the specified number of microseconds. 20 | // The mark output is modulated at the PWM frequency. 21 | // 22 | void IRsend::mark (unsigned int time) 23 | { 24 | #ifdef ESP32 25 | ledcWrite(LEDCHANNEL, 50); 26 | #else 27 | TIMER_ENABLE_PWM; // Enable pin 3 PWM output 28 | #endif 29 | if (time > 0) custom_delay_usec(time); 30 | } 31 | 32 | //+============================================================================= 33 | // Leave pin off for time (given in microseconds) 34 | // Sends an IR space for the specified number of microseconds. 35 | // A space is no output, so the PWM output is disabled. 36 | // 37 | void IRsend::space (unsigned int time) 38 | { 39 | #ifdef ESP32 40 | ledcWrite(LEDCHANNEL, 0); 41 | #else 42 | TIMER_DISABLE_PWM; // Disable pin 3 PWM output 43 | #endif 44 | if (time > 0) IRsend::custom_delay_usec(time); 45 | 46 | } 47 | 48 | 49 | 50 | 51 | 52 | //+============================================================================= 53 | // Enables IR output. The khz value controls the modulation frequency in kilohertz. 54 | // The IR output will be on pin 3 (OC2B). 55 | // This routine is designed for 36-40KHz; if you use it for other values, it's up to you 56 | // to make sure it gives reasonable results. (Watch out for overflow / underflow / rounding.) 57 | // TIMER2 is used in phase-correct PWM mode, with OCR2A controlling the frequency and OCR2B 58 | // controlling the duty cycle. 59 | // There is no prescaling, so the output frequency is 16MHz / (2 * OCR2A) 60 | // To turn the output on and off, we leave the PWM running, but connect and disconnect the output pin. 61 | // A few hours staring at the ATmega documentation and this will all make sense. 62 | // See my Secrets of Arduino PWM at http://arcfn.com/2009/07/secrets-of-arduino-pwm.html for details. 63 | // 64 | void IRsend::enableIROut (int khz) 65 | { 66 | // FIXME: implement ESP32 support, see IR_TIMER_USE_ESP32 in boarddefs.h 67 | #ifndef ESP32 68 | // Disable the Timer2 Interrupt (which is used for receiving IR) 69 | TIMER_DISABLE_INTR; //Timer2 Overflow Interrupt 70 | 71 | pinMode(TIMER_PWM_PIN, OUTPUT); 72 | digitalWrite(TIMER_PWM_PIN, LOW); // When not sending PWM, we want it low 73 | 74 | // COM2A = 00: disconnect OC2A 75 | // COM2B = 00: disconnect OC2B; to send signal set to 10: OC2B non-inverted 76 | // WGM2 = 101: phase-correct PWM with OCRA as top 77 | // CS2 = 000: no prescaling 78 | // The top value for the timer. The modulation frequency will be SYSCLOCK / 2 / OCR2A. 79 | TIMER_CONFIG_KHZ(khz); 80 | #else 81 | ledcSetup(LEDCHANNEL, khz*1000, 8); 82 | ledcAttachPin(timerPwmPin, LEDCHANNEL); 83 | #endif 84 | } 85 | 86 | //+============================================================================= 87 | // Custom delay function that circumvents Arduino's delayMicroseconds limit 88 | 89 | void IRsend::custom_delay_usec(unsigned long uSecs) { 90 | if (uSecs > 4) { 91 | unsigned long start = micros(); 92 | unsigned long endMicros = start + uSecs - 4; 93 | if (endMicros < start) { // Check if overflow 94 | while ( micros() > start ) {} // wait until overflow 95 | } 96 | while ( micros() < endMicros ) {} // normal wait 97 | } 98 | //else { 99 | // __asm__("nop\n\t"); // must have or compiler optimizes out 100 | //} 101 | } 102 | 103 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Aiwa.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // AAA IIIII W W AAA 6 | // A A I W W A A 7 | // AAAAA I W W W AAAAA 8 | // A A I W W W A A 9 | // A A IIIII WWW A A 10 | //============================================================================== 11 | 12 | // Based off the RC-T501 RCU 13 | // Lirc file http://lirc.sourceforge.net/remotes/aiwa/RC-T501 14 | 15 | #define AIWA_RC_T501_HZ 38 16 | #define AIWA_RC_T501_BITS 15 17 | #define AIWA_RC_T501_PRE_BITS 26 18 | #define AIWA_RC_T501_POST_BITS 1 19 | #define AIWA_RC_T501_SUM_BITS (AIWA_RC_T501_PRE_BITS + AIWA_RC_T501_BITS + AIWA_RC_T501_POST_BITS) 20 | #define AIWA_RC_T501_HDR_MARK 8800 21 | #define AIWA_RC_T501_HDR_SPACE 4500 22 | #define AIWA_RC_T501_BIT_MARK 500 23 | #define AIWA_RC_T501_ONE_SPACE 600 24 | #define AIWA_RC_T501_ZERO_SPACE 1700 25 | 26 | //+============================================================================= 27 | #if SEND_AIWA_RC_T501 28 | void IRsend::sendAiwaRCT501 (int code) 29 | { 30 | unsigned long pre = 0x0227EEC0; // 26-bits 31 | 32 | // Set IR carrier frequency 33 | enableIROut(AIWA_RC_T501_HZ); 34 | 35 | // Header 36 | mark(AIWA_RC_T501_HDR_MARK); 37 | space(AIWA_RC_T501_HDR_SPACE); 38 | 39 | // Send "pre" data 40 | for (unsigned long mask = 1UL << (26 - 1); mask; mask >>= 1) { 41 | mark(AIWA_RC_T501_BIT_MARK); 42 | if (pre & mask) space(AIWA_RC_T501_ONE_SPACE) ; 43 | else space(AIWA_RC_T501_ZERO_SPACE) ; 44 | } 45 | 46 | //-v- THIS CODE LOOKS LIKE IT MIGHT BE WRONG - CHECK! 47 | // it only send 15bits and ignores the top bit 48 | // then uses TOPBIT which is 0x80000000 to check the bit code 49 | // I suspect TOPBIT should be changed to 0x00008000 50 | 51 | // Skip first code bit 52 | code <<= 1; 53 | // Send code 54 | for (int i = 0; i < 15; i++) { 55 | mark(AIWA_RC_T501_BIT_MARK); 56 | if (code & 0x80000000) space(AIWA_RC_T501_ONE_SPACE) ; 57 | else space(AIWA_RC_T501_ZERO_SPACE) ; 58 | code <<= 1; 59 | } 60 | 61 | //-^- THIS CODE LOOKS LIKE IT MIGHT BE WRONG - CHECK! 62 | 63 | // POST-DATA, 1 bit, 0x0 64 | mark(AIWA_RC_T501_BIT_MARK); 65 | space(AIWA_RC_T501_ZERO_SPACE); 66 | 67 | mark(AIWA_RC_T501_BIT_MARK); 68 | space(0); 69 | } 70 | #endif 71 | 72 | //+============================================================================= 73 | #if DECODE_AIWA_RC_T501 74 | bool IRrecv::decodeAiwaRCT501 (decode_results *results) 75 | { 76 | int data = 0; 77 | int offset = 1; 78 | 79 | // Check SIZE 80 | if (irparams.rawlen < 2 * (AIWA_RC_T501_SUM_BITS) + 4) return false ; 81 | 82 | // Check HDR Mark/Space 83 | if (!MATCH_MARK (results->rawbuf[offset++], AIWA_RC_T501_HDR_MARK )) return false ; 84 | if (!MATCH_SPACE(results->rawbuf[offset++], AIWA_RC_T501_HDR_SPACE)) return false ; 85 | 86 | offset += 26; // skip pre-data - optional 87 | while(offset < irparams.rawlen - 4) { 88 | if (MATCH_MARK(results->rawbuf[offset], AIWA_RC_T501_BIT_MARK)) offset++ ; 89 | else return false ; 90 | 91 | // ONE & ZERO 92 | if (MATCH_SPACE(results->rawbuf[offset], AIWA_RC_T501_ONE_SPACE)) data = (data << 1) | 1 ; 93 | else if (MATCH_SPACE(results->rawbuf[offset], AIWA_RC_T501_ZERO_SPACE)) data = (data << 1) | 0 ; 94 | else break ; // End of one & zero detected 95 | offset++; 96 | } 97 | 98 | results->bits = (offset - 1) / 2; 99 | if (results->bits < 42) return false ; 100 | 101 | results->value = data; 102 | results->decode_type = AIWA_RC_T501; 103 | return true; 104 | } 105 | #endif 106 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Denon.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | // Reverse Engineered by looking at RAW dumps generated by IRremote 5 | 6 | // I have since discovered that Denon publish all their IR codes: 7 | // https://www.google.co.uk/search?q=DENON+MASTER+IR+Hex+Command+Sheet 8 | // -> http://assets.denon.com/documentmaster/us/denon%20master%20ir%20hex.xls 9 | 10 | // Having looked at the official Denon Pronto sheet and reverse engineered 11 | // the timing values from it, it is obvious that Denon have a range of 12 | // different timings and protocols ...the values here work for my AVR-3801 Amp! 13 | 14 | //============================================================================== 15 | // DDDD EEEEE N N OOO N N 16 | // D D E NN N O O NN N 17 | // D D EEE N N N O O N N N 18 | // D D E N NN O O N NN 19 | // DDDD EEEEE N N OOO N N 20 | //============================================================================== 21 | 22 | #define BITS 14 // The number of bits in the command 23 | 24 | #define HDR_MARK 300 // The length of the Header:Mark 25 | #define HDR_SPACE 750 // The lenght of the Header:Space 26 | 27 | #define BIT_MARK 300 // The length of a Bit:Mark 28 | #define ONE_SPACE 1800 // The length of a Bit:Space for 1's 29 | #define ZERO_SPACE 750 // The length of a Bit:Space for 0's 30 | 31 | //+============================================================================= 32 | // 33 | #if SEND_DENON 34 | void IRsend::sendDenon (unsigned long data, int nbits) 35 | { 36 | // Set IR carrier frequency 37 | enableIROut(38); 38 | 39 | // Header 40 | mark (HDR_MARK); 41 | space(HDR_SPACE); 42 | 43 | // Data 44 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 45 | if (data & mask) { 46 | mark (BIT_MARK); 47 | space(ONE_SPACE); 48 | } else { 49 | mark (BIT_MARK); 50 | space(ZERO_SPACE); 51 | } 52 | } 53 | 54 | // Footer 55 | mark(BIT_MARK); 56 | space(0); // Always end with the LED off 57 | } 58 | #endif 59 | 60 | //+============================================================================= 61 | // 62 | #if DECODE_DENON 63 | bool IRrecv::decodeDenon (decode_results *results) 64 | { 65 | unsigned long data = 0; // Somewhere to build our code 66 | int offset = 1; // Skip the Gap reading 67 | 68 | // Check we have the right amount of data 69 | if (irparams.rawlen != 1 + 2 + (2 * BITS) + 1) return false ; 70 | 71 | // Check initial Mark+Space match 72 | if (!MATCH_MARK (results->rawbuf[offset++], HDR_MARK )) return false ; 73 | if (!MATCH_SPACE(results->rawbuf[offset++], HDR_SPACE)) return false ; 74 | 75 | // Read the bits in 76 | for (int i = 0; i < BITS; i++) { 77 | // Each bit looks like: MARK + SPACE_1 -> 1 78 | // or : MARK + SPACE_0 -> 0 79 | if (!MATCH_MARK(results->rawbuf[offset++], BIT_MARK)) return false ; 80 | 81 | // IR data is big-endian, so we shuffle it in from the right: 82 | if (MATCH_SPACE(results->rawbuf[offset], ONE_SPACE)) data = (data << 1) | 1 ; 83 | else if (MATCH_SPACE(results->rawbuf[offset], ZERO_SPACE)) data = (data << 1) | 0 ; 84 | else return false ; 85 | offset++; 86 | } 87 | 88 | // Success 89 | results->bits = BITS; 90 | results->value = data; 91 | results->decode_type = DENON; 92 | return true; 93 | } 94 | #endif 95 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Dish.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // DDDD IIIII SSSS H H 6 | // D D I S H H 7 | // D D I SSS HHHHH 8 | // D D I S H H 9 | // DDDD IIIII SSSS H H 10 | //============================================================================== 11 | 12 | // Sharp and DISH support by Todd Treece ( http://unionbridge.org/design/ircommand ) 13 | // 14 | // The sned function needs to be repeated 4 times 15 | // 16 | // Only send the last for characters of the hex. 17 | // I.E. Use 0x1C10 instead of 0x0000000000001C10 as listed in the LIRC file. 18 | // 19 | // Here is the LIRC file I found that seems to match the remote codes from the 20 | // oscilloscope: 21 | // DISH NETWORK (echostar 301): 22 | // http://lirc.sourceforge.net/remotes/echostar/301_501_3100_5100_58xx_59xx 23 | 24 | #define DISH_BITS 16 25 | #define DISH_HDR_MARK 400 26 | #define DISH_HDR_SPACE 6100 27 | #define DISH_BIT_MARK 400 28 | #define DISH_ONE_SPACE 1700 29 | #define DISH_ZERO_SPACE 2800 30 | #define DISH_RPT_SPACE 6200 31 | 32 | //+============================================================================= 33 | #if SEND_DISH 34 | void IRsend::sendDISH (unsigned long data, int nbits) 35 | { 36 | // Set IR carrier frequency 37 | enableIROut(56); 38 | 39 | mark(DISH_HDR_MARK); 40 | space(DISH_HDR_SPACE); 41 | 42 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 43 | if (data & mask) { 44 | mark(DISH_BIT_MARK); 45 | space(DISH_ONE_SPACE); 46 | } else { 47 | mark(DISH_BIT_MARK); 48 | space(DISH_ZERO_SPACE); 49 | } 50 | } 51 | mark(DISH_HDR_MARK); //added 26th March 2016, by AnalysIR ( https://www.AnalysIR.com ) 52 | } 53 | #endif 54 | 55 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_JVC.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // JJJJJ V V CCCC 6 | // J V V C 7 | // J V V C 8 | // J J V V C 9 | // J V CCCC 10 | //============================================================================== 11 | 12 | #define JVC_BITS 16 13 | #define JVC_HDR_MARK 8000 14 | #define JVC_HDR_SPACE 4000 15 | #define JVC_BIT_MARK 600 16 | #define JVC_ONE_SPACE 1600 17 | #define JVC_ZERO_SPACE 550 18 | #define JVC_RPT_LENGTH 60000 19 | 20 | //+============================================================================= 21 | // JVC does NOT repeat by sending a separate code (like NEC does). 22 | // The JVC protocol repeats by skipping the header. 23 | // To send a JVC repeat signal, send the original code value 24 | // and set 'repeat' to true 25 | // 26 | #if SEND_JVC 27 | void IRsend::sendJVC (unsigned long data, int nbits, bool repeat) 28 | { 29 | // Set IR carrier frequency 30 | enableIROut(38); 31 | 32 | // Only send the Header if this is NOT a repeat command 33 | if (!repeat){ 34 | mark(JVC_HDR_MARK); 35 | space(JVC_HDR_SPACE); 36 | } 37 | 38 | // Data 39 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 40 | if (data & mask) { 41 | mark(JVC_BIT_MARK); 42 | space(JVC_ONE_SPACE); 43 | } else { 44 | mark(JVC_BIT_MARK); 45 | space(JVC_ZERO_SPACE); 46 | } 47 | } 48 | 49 | // Footer 50 | mark(JVC_BIT_MARK); 51 | space(0); // Always end with the LED off 52 | } 53 | #endif 54 | 55 | //+============================================================================= 56 | #if DECODE_JVC 57 | bool IRrecv::decodeJVC (decode_results *results) 58 | { 59 | long data = 0; 60 | int offset = 1; // Skip first space 61 | 62 | // Check for repeat 63 | if ( (irparams.rawlen - 1 == 33) 64 | && MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK) 65 | && MATCH_MARK(results->rawbuf[irparams.rawlen-1], JVC_BIT_MARK) 66 | ) { 67 | results->bits = 0; 68 | results->value = REPEAT; 69 | results->decode_type = JVC; 70 | return true; 71 | } 72 | 73 | // Initial mark 74 | if (!MATCH_MARK(results->rawbuf[offset++], JVC_HDR_MARK)) return false ; 75 | 76 | if (irparams.rawlen < (2 * JVC_BITS) + 1 ) return false ; 77 | 78 | // Initial space 79 | if (!MATCH_SPACE(results->rawbuf[offset++], JVC_HDR_SPACE)) return false ; 80 | 81 | for (int i = 0; i < JVC_BITS; i++) { 82 | if (!MATCH_MARK(results->rawbuf[offset++], JVC_BIT_MARK)) return false ; 83 | 84 | if (MATCH_SPACE(results->rawbuf[offset], JVC_ONE_SPACE)) data = (data << 1) | 1 ; 85 | else if (MATCH_SPACE(results->rawbuf[offset], JVC_ZERO_SPACE)) data = (data << 1) | 0 ; 86 | else return false ; 87 | offset++; 88 | } 89 | 90 | // Stop bit 91 | if (!MATCH_MARK(results->rawbuf[offset], JVC_BIT_MARK)) return false ; 92 | 93 | // Success 94 | results->bits = JVC_BITS; 95 | results->value = data; 96 | results->decode_type = JVC; 97 | 98 | return true; 99 | } 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_LG.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // L GGGG 6 | // L G 7 | // L G GG 8 | // L G G 9 | // LLLLL GGG 10 | //============================================================================== 11 | 12 | #define LG_BITS 28 13 | 14 | #define LG_HDR_MARK 8000 15 | #define LG_HDR_SPACE 4000 16 | #define LG_BIT_MARK 600 17 | #define LG_ONE_SPACE 1600 18 | #define LG_ZERO_SPACE 550 19 | #define LG_RPT_LENGTH 60000 20 | 21 | //+============================================================================= 22 | #if DECODE_LG 23 | bool IRrecv::decodeLG (decode_results *results) 24 | { 25 | long data = 0; 26 | int offset = 1; // Skip first space 27 | 28 | // Check we have the right amount of data 29 | if (irparams.rawlen < (2 * LG_BITS) + 1 ) return false ; 30 | 31 | // Initial mark/space 32 | if (!MATCH_MARK(results->rawbuf[offset++], LG_HDR_MARK)) return false ; 33 | if (!MATCH_SPACE(results->rawbuf[offset++], LG_HDR_SPACE)) return false ; 34 | 35 | for (int i = 0; i < LG_BITS; i++) { 36 | if (!MATCH_MARK(results->rawbuf[offset++], LG_BIT_MARK)) return false ; 37 | 38 | if (MATCH_SPACE(results->rawbuf[offset], LG_ONE_SPACE)) data = (data << 1) | 1 ; 39 | else if (MATCH_SPACE(results->rawbuf[offset], LG_ZERO_SPACE)) data = (data << 1) | 0 ; 40 | else return false ; 41 | offset++; 42 | } 43 | 44 | // Stop bit 45 | if (!MATCH_MARK(results->rawbuf[offset], LG_BIT_MARK)) return false ; 46 | 47 | // Success 48 | results->bits = LG_BITS; 49 | results->value = data; 50 | results->decode_type = LG; 51 | return true; 52 | } 53 | #endif 54 | 55 | //+============================================================================= 56 | #if SEND_LG 57 | void IRsend::sendLG (unsigned long data, int nbits) 58 | { 59 | // Set IR carrier frequency 60 | enableIROut(38); 61 | 62 | // Header 63 | mark(LG_HDR_MARK); 64 | space(LG_HDR_SPACE); 65 | mark(LG_BIT_MARK); 66 | 67 | // Data 68 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 69 | if (data & mask) { 70 | space(LG_ONE_SPACE); 71 | mark(LG_BIT_MARK); 72 | } else { 73 | space(LG_ZERO_SPACE); 74 | mark(LG_BIT_MARK); 75 | } 76 | } 77 | space(0); // Always end with the LED off 78 | } 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Lego_PF.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | #include "ir_Lego_PF_BitStreamEncoder.h" 4 | 5 | //============================================================================== 6 | // L EEEEEE EEEE OOOO 7 | // L E E O O 8 | // L EEEE E EEE O O 9 | // L E E E O O LEGO Power Functions 10 | // LLLLLL EEEEEE EEEE OOOO Copyright (c) 2016 Philipp Henkel 11 | //============================================================================== 12 | 13 | // Supported Devices 14 | // LEGO® Power Functions IR Receiver 8884 15 | 16 | //+============================================================================= 17 | // 18 | #if SEND_LEGO_PF 19 | 20 | #if DEBUG 21 | namespace { 22 | void logFunctionParameters(uint16_t data, bool repeat) { 23 | DBG_PRINT("sendLegoPowerFunctions(data="); 24 | DBG_PRINT(data); 25 | DBG_PRINT(", repeat="); 26 | DBG_PRINTLN(repeat?"true)" : "false)"); 27 | } 28 | } // anonymous namespace 29 | #endif // DEBUG 30 | 31 | void IRsend::sendLegoPowerFunctions(uint16_t data, bool repeat) 32 | { 33 | #if DEBUG 34 | ::logFunctionParameters(data, repeat); 35 | #endif // DEBUG 36 | 37 | enableIROut(38); 38 | static LegoPfBitStreamEncoder bitStreamEncoder; 39 | bitStreamEncoder.reset(data, repeat); 40 | do { 41 | mark(bitStreamEncoder.getMarkDuration()); 42 | space(bitStreamEncoder.getPauseDuration()); 43 | } while (bitStreamEncoder.next()); 44 | } 45 | 46 | #endif // SEND_LEGO_PF 47 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Lego_PF_BitStreamEncoder.h: -------------------------------------------------------------------------------- 1 | 2 | //============================================================================== 3 | // L EEEEEE EEEE OOOO 4 | // L E E O O 5 | // L EEEE E EEE O O 6 | // L E E E O O LEGO Power Functions 7 | // LLLLLL EEEEEE EEEE OOOO Copyright (c) 2016, 2017 Philipp Henkel 8 | //============================================================================== 9 | 10 | //+============================================================================= 11 | // 12 | 13 | class LegoPfBitStreamEncoder { 14 | private: 15 | uint16_t data; 16 | bool repeatMessage; 17 | uint8_t messageBitIdx; 18 | uint8_t repeatCount; 19 | uint16_t messageLength; 20 | 21 | public: 22 | // HIGH data bit = IR mark + high pause 23 | // LOW data bit = IR mark + low pause 24 | static const uint16_t LOW_BIT_DURATION = 421; 25 | static const uint16_t HIGH_BIT_DURATION = 711; 26 | static const uint16_t START_BIT_DURATION = 1184; 27 | static const uint16_t STOP_BIT_DURATION = 1184; 28 | static const uint8_t IR_MARK_DURATION = 158; 29 | static const uint16_t HIGH_PAUSE_DURATION = HIGH_BIT_DURATION - IR_MARK_DURATION; 30 | static const uint16_t LOW_PAUSE_DURATION = LOW_BIT_DURATION - IR_MARK_DURATION; 31 | static const uint16_t START_PAUSE_DURATION = START_BIT_DURATION - IR_MARK_DURATION; 32 | static const uint16_t STOP_PAUSE_DURATION = STOP_BIT_DURATION - IR_MARK_DURATION; 33 | static const uint8_t MESSAGE_BITS = 18; 34 | static const uint16_t MAX_MESSAGE_LENGTH = 16000; 35 | 36 | void reset(uint16_t data, bool repeatMessage) { 37 | this->data = data; 38 | this->repeatMessage = repeatMessage; 39 | messageBitIdx = 0; 40 | repeatCount = 0; 41 | messageLength = getMessageLength(); 42 | } 43 | 44 | int getChannelId() const { return 1 + ((data >> 12) & 0x3); } 45 | 46 | uint16_t getMessageLength() const { 47 | // Sum up all marks 48 | uint16_t length = MESSAGE_BITS * IR_MARK_DURATION; 49 | 50 | // Sum up all pauses 51 | length += START_PAUSE_DURATION; 52 | for (unsigned long mask = 1UL << 15; mask; mask >>= 1) { 53 | if (data & mask) { 54 | length += HIGH_PAUSE_DURATION; 55 | } else { 56 | length += LOW_PAUSE_DURATION; 57 | } 58 | } 59 | length += STOP_PAUSE_DURATION; 60 | return length; 61 | } 62 | 63 | boolean next() { 64 | messageBitIdx++; 65 | if (messageBitIdx >= MESSAGE_BITS) { 66 | repeatCount++; 67 | messageBitIdx = 0; 68 | } 69 | if (repeatCount >= 1 && !repeatMessage) { 70 | return false; 71 | } else if (repeatCount >= 5) { 72 | return false; 73 | } else { 74 | return true; 75 | } 76 | } 77 | 78 | uint8_t getMarkDuration() const { return IR_MARK_DURATION; } 79 | 80 | uint32_t getPauseDuration() const { 81 | if (messageBitIdx == 0) 82 | return START_PAUSE_DURATION; 83 | else if (messageBitIdx < MESSAGE_BITS - 1) { 84 | return getDataBitPause(); 85 | } else { 86 | return getStopPause(); 87 | } 88 | } 89 | 90 | private: 91 | uint16_t getDataBitPause() const { 92 | const int pos = MESSAGE_BITS - 2 - messageBitIdx; 93 | const bool isHigh = data & (1 << pos); 94 | return isHigh ? HIGH_PAUSE_DURATION : LOW_PAUSE_DURATION; 95 | } 96 | 97 | uint32_t getStopPause() const { 98 | if (repeatMessage) { 99 | return getRepeatStopPause(); 100 | } else { 101 | return STOP_PAUSE_DURATION; 102 | } 103 | } 104 | 105 | uint32_t getRepeatStopPause() const { 106 | if (repeatCount == 0 || repeatCount == 1) { 107 | return STOP_PAUSE_DURATION + (uint32_t)5 * MAX_MESSAGE_LENGTH - messageLength; 108 | } else if (repeatCount == 2 || repeatCount == 3) { 109 | return STOP_PAUSE_DURATION 110 | + (uint32_t)(6 + 2 * getChannelId()) * MAX_MESSAGE_LENGTH - messageLength; 111 | } else { 112 | return STOP_PAUSE_DURATION; 113 | } 114 | } 115 | }; 116 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Mitsubishi.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // MMMMM IIIII TTTTT SSSS U U BBBB IIIII SSSS H H IIIII 6 | // M M M I T S U U B B I S H H I 7 | // M M M I T SSS U U BBBB I SSS HHHHH I 8 | // M M I T S U U B B I S H H I 9 | // M M IIIII T SSSS UUU BBBBB IIIII SSSS H H IIIII 10 | //============================================================================== 11 | 12 | // Looks like Sony except for timings, 48 chars of data and time/space different 13 | 14 | #define MITSUBISHI_BITS 16 15 | 16 | // Mitsubishi RM 75501 17 | // 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 18 | // #define MITSUBISHI_HDR_MARK 250 // seen range 3500 19 | #define MITSUBISHI_HDR_SPACE 350 // 7*50+100 20 | #define MITSUBISHI_ONE_MARK 1950 // 41*50-100 21 | #define MITSUBISHI_ZERO_MARK 750 // 17*50-100 22 | // #define MITSUBISHI_DOUBLE_SPACE_USECS 800 // usually ssee 713 - not using ticks as get number wrapround 23 | // #define MITSUBISHI_RPT_LENGTH 45000 24 | 25 | //+============================================================================= 26 | #if DECODE_MITSUBISHI 27 | bool IRrecv::decodeMitsubishi (decode_results *results) 28 | { 29 | // Serial.print("?!? decoding Mitsubishi:");Serial.print(irparams.rawlen); Serial.print(" want "); Serial.println( 2 * MITSUBISHI_BITS + 2); 30 | long data = 0; 31 | if (irparams.rawlen < 2 * MITSUBISHI_BITS + 2) return false ; 32 | int offset = 0; // Skip first space 33 | // Initial space 34 | 35 | #if 0 36 | // 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 37 | Serial.print("IR Gap: "); 38 | Serial.println( results->rawbuf[offset]); 39 | Serial.println( "test against:"); 40 | Serial.println(results->rawbuf[offset]); 41 | #endif 42 | 43 | #if 0 44 | // Not seeing double keys from Mitsubishi 45 | if (results->rawbuf[offset] < MITSUBISHI_DOUBLE_SPACE_USECS) { 46 | // Serial.print("IR Gap found: "); 47 | results->bits = 0; 48 | results->value = REPEAT; 49 | results->decode_type = MITSUBISHI; 50 | return true; 51 | } 52 | #endif 53 | 54 | offset++; 55 | 56 | // Typical 57 | // 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 58 | 59 | // Initial Space 60 | if (!MATCH_MARK(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) return false ; 61 | offset++; 62 | 63 | while (offset + 1 < irparams.rawlen) { 64 | if (MATCH_MARK(results->rawbuf[offset], MITSUBISHI_ONE_MARK)) data = (data << 1) | 1 ; 65 | else if (MATCH_MARK(results->rawbuf[offset], MITSUBISHI_ZERO_MARK)) data <<= 1 ; 66 | else return false ; 67 | offset++; 68 | 69 | if (!MATCH_SPACE(results->rawbuf[offset], MITSUBISHI_HDR_SPACE)) break ; 70 | offset++; 71 | } 72 | 73 | // Success 74 | results->bits = (offset - 1) / 2; 75 | if (results->bits < MITSUBISHI_BITS) { 76 | results->bits = 0; 77 | return false; 78 | } 79 | 80 | results->value = data; 81 | results->decode_type = MITSUBISHI; 82 | return true; 83 | } 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_NEC.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // N N EEEEE CCCC 6 | // NN N E C 7 | // N N N EEE C 8 | // N NN E C 9 | // N N EEEEE CCCC 10 | //============================================================================== 11 | 12 | #define NEC_BITS 32 13 | #define NEC_HDR_MARK 9000 14 | #define NEC_HDR_SPACE 4500 15 | #define NEC_BIT_MARK 560 16 | #define NEC_ONE_SPACE 1690 17 | #define NEC_ZERO_SPACE 560 18 | #define NEC_RPT_SPACE 2250 19 | 20 | //+============================================================================= 21 | #if SEND_NEC 22 | void IRsend::sendNEC (unsigned long data, int nbits) 23 | { 24 | // Set IR carrier frequency 25 | enableIROut(38); 26 | 27 | // Header 28 | mark(NEC_HDR_MARK); 29 | space(NEC_HDR_SPACE); 30 | 31 | // Data 32 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 33 | if (data & mask) { 34 | mark(NEC_BIT_MARK); 35 | space(NEC_ONE_SPACE); 36 | } else { 37 | mark(NEC_BIT_MARK); 38 | space(NEC_ZERO_SPACE); 39 | } 40 | } 41 | 42 | // Footer 43 | mark(NEC_BIT_MARK); 44 | space(0); // Always end with the LED off 45 | } 46 | #endif 47 | 48 | //+============================================================================= 49 | // NECs have a repeat only 4 items long 50 | // 51 | #if DECODE_NEC 52 | bool IRrecv::decodeNEC (decode_results *results) 53 | { 54 | long data = 0; // We decode in to here; Start with nothing 55 | int offset = 1; // Index in to results; Skip first entry!? 56 | 57 | // Check header "mark" 58 | if (!MATCH_MARK(results->rawbuf[offset], NEC_HDR_MARK)) return false ; 59 | offset++; 60 | 61 | // Check for repeat 62 | if ( (irparams.rawlen == 4) 63 | && MATCH_SPACE(results->rawbuf[offset ], NEC_RPT_SPACE) 64 | && MATCH_MARK (results->rawbuf[offset+1], NEC_BIT_MARK ) 65 | ) { 66 | results->bits = 0; 67 | results->value = REPEAT; 68 | results->decode_type = NEC; 69 | return true; 70 | } 71 | 72 | // Check we have enough data 73 | if (irparams.rawlen < (2 * NEC_BITS) + 4) return false ; 74 | 75 | // Check header "space" 76 | if (!MATCH_SPACE(results->rawbuf[offset], NEC_HDR_SPACE)) return false ; 77 | offset++; 78 | 79 | // Build the data 80 | for (int i = 0; i < NEC_BITS; i++) { 81 | // Check data "mark" 82 | if (!MATCH_MARK(results->rawbuf[offset], NEC_BIT_MARK)) return false ; 83 | offset++; 84 | // Suppend this bit 85 | if (MATCH_SPACE(results->rawbuf[offset], NEC_ONE_SPACE )) data = (data << 1) | 1 ; 86 | else if (MATCH_SPACE(results->rawbuf[offset], NEC_ZERO_SPACE)) data = (data << 1) | 0 ; 87 | else return false ; 88 | offset++; 89 | } 90 | 91 | // Success 92 | results->bits = NEC_BITS; 93 | results->value = data; 94 | results->decode_type = NEC; 95 | 96 | return true; 97 | } 98 | #endif 99 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Panasonic.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // PPPP AAA N N AAA SSSS OOO N N IIIII CCCC 6 | // P P A A NN N A A S O O NN N I C 7 | // PPPP AAAAA N N N AAAAA SSS O O N N N I C 8 | // P A A N NN A A S O O N NN I C 9 | // P A A N N A A SSSS OOO N N IIIII CCCC 10 | //============================================================================== 11 | 12 | #define PANASONIC_BITS 48 13 | #define PANASONIC_HDR_MARK 3502 14 | #define PANASONIC_HDR_SPACE 1750 15 | #define PANASONIC_BIT_MARK 502 16 | #define PANASONIC_ONE_SPACE 1244 17 | #define PANASONIC_ZERO_SPACE 400 18 | 19 | //+============================================================================= 20 | #if SEND_PANASONIC 21 | void IRsend::sendPanasonic (unsigned int address, unsigned long data) 22 | { 23 | // Set IR carrier frequency 24 | enableIROut(35); 25 | 26 | // Header 27 | mark(PANASONIC_HDR_MARK); 28 | space(PANASONIC_HDR_SPACE); 29 | 30 | // Address 31 | for (unsigned long mask = 1UL << (16 - 1); mask; mask >>= 1) { 32 | mark(PANASONIC_BIT_MARK); 33 | if (address & mask) space(PANASONIC_ONE_SPACE) ; 34 | else space(PANASONIC_ZERO_SPACE) ; 35 | } 36 | 37 | // Data 38 | for (unsigned long mask = 1UL << (32 - 1); mask; mask >>= 1) { 39 | mark(PANASONIC_BIT_MARK); 40 | if (data & mask) space(PANASONIC_ONE_SPACE) ; 41 | else space(PANASONIC_ZERO_SPACE) ; 42 | } 43 | 44 | // Footer 45 | mark(PANASONIC_BIT_MARK); 46 | space(0); // Always end with the LED off 47 | } 48 | #endif 49 | 50 | //+============================================================================= 51 | #if DECODE_PANASONIC 52 | bool IRrecv::decodePanasonic (decode_results *results) 53 | { 54 | unsigned long long data = 0; 55 | int offset = 1; 56 | 57 | if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_HDR_MARK )) return false ; 58 | if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_HDR_SPACE)) return false ; 59 | 60 | // decode address 61 | for (int i = 0; i < PANASONIC_BITS; i++) { 62 | if (!MATCH_MARK(results->rawbuf[offset++], PANASONIC_BIT_MARK)) return false ; 63 | 64 | if (MATCH_SPACE(results->rawbuf[offset],PANASONIC_ONE_SPACE )) data = (data << 1) | 1 ; 65 | else if (MATCH_SPACE(results->rawbuf[offset],PANASONIC_ZERO_SPACE)) data = (data << 1) | 0 ; 66 | else return false ; 67 | offset++; 68 | } 69 | 70 | results->value = (unsigned long)data; 71 | results->address = (unsigned int)(data >> 32); 72 | results->decode_type = PANASONIC; 73 | results->bits = PANASONIC_BITS; 74 | 75 | return true; 76 | } 77 | #endif 78 | 79 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Samsung.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // SSSS AAA MMM SSSS U U N N GGGG 6 | // S A A M M M S U U NN N G 7 | // SSS AAAAA M M M SSS U U N N N G GG 8 | // S A A M M S U U N NN G G 9 | // SSSS A A M M SSSS UUU N N GGG 10 | //============================================================================== 11 | 12 | #define SAMSUNG_BITS 32 13 | #define SAMSUNG_HDR_MARK 5000 14 | #define SAMSUNG_HDR_SPACE 5000 15 | #define SAMSUNG_BIT_MARK 560 16 | #define SAMSUNG_ONE_SPACE 1600 17 | #define SAMSUNG_ZERO_SPACE 560 18 | #define SAMSUNG_RPT_SPACE 2250 19 | 20 | //+============================================================================= 21 | #if SEND_SAMSUNG 22 | void IRsend::sendSAMSUNG (unsigned long data, int nbits) 23 | { 24 | // Set IR carrier frequency 25 | enableIROut(38); 26 | 27 | // Header 28 | mark(SAMSUNG_HDR_MARK); 29 | space(SAMSUNG_HDR_SPACE); 30 | 31 | // Data 32 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 33 | if (data & mask) { 34 | mark(SAMSUNG_BIT_MARK); 35 | space(SAMSUNG_ONE_SPACE); 36 | } else { 37 | mark(SAMSUNG_BIT_MARK); 38 | space(SAMSUNG_ZERO_SPACE); 39 | } 40 | } 41 | 42 | // Footer 43 | mark(SAMSUNG_BIT_MARK); 44 | space(0); // Always end with the LED off 45 | } 46 | #endif 47 | 48 | //+============================================================================= 49 | // SAMSUNGs have a repeat only 4 items long 50 | // 51 | #if DECODE_SAMSUNG 52 | bool IRrecv::decodeSAMSUNG (decode_results *results) 53 | { 54 | long data = 0; 55 | int offset = 1; // Skip first space 56 | 57 | // Initial mark 58 | if (!MATCH_MARK(results->rawbuf[offset], SAMSUNG_HDR_MARK)) return false ; 59 | offset++; 60 | 61 | // Check for repeat 62 | if ( (irparams.rawlen == 4) 63 | && MATCH_SPACE(results->rawbuf[offset], SAMSUNG_RPT_SPACE) 64 | && MATCH_MARK(results->rawbuf[offset+1], SAMSUNG_BIT_MARK) 65 | ) { 66 | results->bits = 0; 67 | results->value = REPEAT; 68 | results->decode_type = SAMSUNG; 69 | return true; 70 | } 71 | if (irparams.rawlen < (2 * SAMSUNG_BITS) + 4) return false ; 72 | 73 | // Initial space 74 | if (!MATCH_SPACE(results->rawbuf[offset++], SAMSUNG_HDR_SPACE)) return false ; 75 | 76 | for (int i = 0; i < SAMSUNG_BITS; i++) { 77 | if (!MATCH_MARK(results->rawbuf[offset++], SAMSUNG_BIT_MARK)) return false ; 78 | 79 | if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ONE_SPACE)) data = (data << 1) | 1 ; 80 | else if (MATCH_SPACE(results->rawbuf[offset], SAMSUNG_ZERO_SPACE)) data = (data << 1) | 0 ; 81 | else return false ; 82 | offset++; 83 | } 84 | 85 | // Success 86 | results->bits = SAMSUNG_BITS; 87 | results->value = data; 88 | results->decode_type = SAMSUNG; 89 | return true; 90 | } 91 | #endif 92 | 93 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Sanyo.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // SSSS AAA N N Y Y OOO 6 | // S A A NN N Y Y O O 7 | // SSS AAAAA N N N Y O O 8 | // S A A N NN Y O O 9 | // SSSS A A N N Y OOO 10 | //============================================================================== 11 | 12 | // I think this is a Sanyo decoder: Serial = SA 8650B 13 | // Looks like Sony except for timings, 48 chars of data and time/space different 14 | 15 | #define SANYO_BITS 12 16 | #define SANYO_HDR_MARK 3500 // seen range 3500 17 | #define SANYO_HDR_SPACE 950 // seen 950 18 | #define SANYO_ONE_MARK 2400 // seen 2400 19 | #define SANYO_ZERO_MARK 700 // seen 700 20 | #define SANYO_DOUBLE_SPACE_USECS 800 // usually ssee 713 - not using ticks as get number wrapround 21 | #define SANYO_RPT_LENGTH 45000 22 | 23 | //+============================================================================= 24 | #if DECODE_SANYO 25 | bool IRrecv::decodeSanyo (decode_results *results) 26 | { 27 | long data = 0; 28 | int offset = 0; // Skip first space <-- CHECK THIS! 29 | 30 | if (irparams.rawlen < (2 * SANYO_BITS) + 2) return false ; 31 | 32 | #if 0 33 | // 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 34 | Serial.print("IR Gap: "); 35 | Serial.println( results->rawbuf[offset]); 36 | Serial.println( "test against:"); 37 | Serial.println(results->rawbuf[offset]); 38 | #endif 39 | 40 | // Initial space 41 | if (results->rawbuf[offset] < SANYO_DOUBLE_SPACE_USECS) { 42 | //Serial.print("IR Gap found: "); 43 | results->bits = 0; 44 | results->value = REPEAT; 45 | results->decode_type = SANYO; 46 | return true; 47 | } 48 | offset++; 49 | 50 | // Initial mark 51 | if (!MATCH_MARK(results->rawbuf[offset++], SANYO_HDR_MARK)) return false ; 52 | 53 | // Skip Second Mark 54 | if (!MATCH_MARK(results->rawbuf[offset++], SANYO_HDR_MARK)) return false ; 55 | 56 | while (offset + 1 < irparams.rawlen) { 57 | if (!MATCH_SPACE(results->rawbuf[offset++], SANYO_HDR_SPACE)) break ; 58 | 59 | if (MATCH_MARK(results->rawbuf[offset], SANYO_ONE_MARK)) data = (data << 1) | 1 ; 60 | else if (MATCH_MARK(results->rawbuf[offset], SANYO_ZERO_MARK)) data = (data << 1) | 0 ; 61 | else return false ; 62 | offset++; 63 | } 64 | 65 | // Success 66 | results->bits = (offset - 1) / 2; 67 | if (results->bits < 12) { 68 | results->bits = 0; 69 | return false; 70 | } 71 | 72 | results->value = data; 73 | results->decode_type = SANYO; 74 | return true; 75 | } 76 | #endif 77 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Sharp.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // SSSS H H AAA RRRR PPPP 6 | // S H H A A R R P P 7 | // SSS HHHHH AAAAA RRRR PPPP 8 | // S H H A A R R P 9 | // SSSS H H A A R R P 10 | //============================================================================== 11 | 12 | // Sharp and DISH support by Todd Treece: http://unionbridge.org/design/ircommand 13 | // 14 | // The send function has the necessary repeat built in because of the need to 15 | // invert the signal. 16 | // 17 | // Sharp protocol documentation: 18 | // http://www.sbprojects.com/knowledge/ir/sharp.htm 19 | // 20 | // Here is the LIRC file I found that seems to match the remote codes from the 21 | // oscilloscope: 22 | // Sharp LCD TV: 23 | // http://lirc.sourceforge.net/remotes/sharp/GA538WJSA 24 | 25 | #define SHARP_BITS 15 26 | #define SHARP_BIT_MARK 245 27 | #define SHARP_ONE_SPACE 1805 28 | #define SHARP_ZERO_SPACE 795 29 | #define SHARP_GAP 600000 30 | #define SHARP_RPT_SPACE 3000 31 | 32 | #define SHARP_TOGGLE_MASK 0x3FF 33 | 34 | //+============================================================================= 35 | #if SEND_SHARP 36 | void IRsend::sendSharpRaw (unsigned long data, int nbits) 37 | { 38 | enableIROut(38); 39 | 40 | // Sending codes in bursts of 3 (normal, inverted, normal) makes transmission 41 | // much more reliable. That's the exact behaviour of CD-S6470 remote control. 42 | for (int n = 0; n < 3; n++) { 43 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 44 | if (data & mask) { 45 | mark(SHARP_BIT_MARK); 46 | space(SHARP_ONE_SPACE); 47 | } else { 48 | mark(SHARP_BIT_MARK); 49 | space(SHARP_ZERO_SPACE); 50 | } 51 | } 52 | 53 | mark(SHARP_BIT_MARK); 54 | space(SHARP_ZERO_SPACE); 55 | delay(40); 56 | 57 | data = data ^ SHARP_TOGGLE_MASK; 58 | } 59 | } 60 | #endif 61 | 62 | //+============================================================================= 63 | // Sharp send compatible with data obtained through decodeSharp() 64 | // ^^^^^^^^^^^^^ FUNCTION MISSING! 65 | // 66 | #if SEND_SHARP 67 | void IRsend::sendSharp (unsigned int address, unsigned int command) 68 | { 69 | sendSharpRaw((address << 10) | (command << 2) | 2, SHARP_BITS); 70 | } 71 | #endif 72 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Sony.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // SSSS OOO N N Y Y 6 | // S O O NN N Y Y 7 | // SSS O O N N N Y 8 | // S O O N NN Y 9 | // SSSS OOO N N Y 10 | //============================================================================== 11 | 12 | #define SONY_BITS 12 13 | #define SONY_HDR_MARK 2400 14 | #define SONY_HDR_SPACE 600 15 | #define SONY_ONE_MARK 1200 16 | #define SONY_ZERO_MARK 600 17 | #define SONY_RPT_LENGTH 45000 18 | #define SONY_DOUBLE_SPACE_USECS 500 // usually ssee 713 - not using ticks as get number wrapround 19 | 20 | //+============================================================================= 21 | #if SEND_SONY 22 | void IRsend::sendSony (unsigned long data, int nbits) 23 | { 24 | // Set IR carrier frequency 25 | enableIROut(40); 26 | 27 | // Header 28 | mark(SONY_HDR_MARK); 29 | space(SONY_HDR_SPACE); 30 | 31 | // Data 32 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 33 | if (data & mask) { 34 | mark(SONY_ONE_MARK); 35 | space(SONY_HDR_SPACE); 36 | } else { 37 | mark(SONY_ZERO_MARK); 38 | space(SONY_HDR_SPACE); 39 | } 40 | } 41 | 42 | // We will have ended with LED off 43 | } 44 | #endif 45 | 46 | //+============================================================================= 47 | #if DECODE_SONY 48 | bool IRrecv::decodeSony (decode_results *results) 49 | { 50 | long data = 0; 51 | int offset = 0; // Dont skip first space, check its size 52 | 53 | if (irparams.rawlen < (2 * SONY_BITS) + 2) return false ; 54 | 55 | // Some Sony's deliver repeats fast after first 56 | // unfortunately can't spot difference from of repeat from two fast clicks 57 | if (results->rawbuf[offset] < SONY_DOUBLE_SPACE_USECS) { 58 | // Serial.print("IR Gap found: "); 59 | results->bits = 0; 60 | results->value = REPEAT; 61 | 62 | # ifdef DECODE_SANYO 63 | results->decode_type = SANYO; 64 | # else 65 | results->decode_type = UNKNOWN; 66 | # endif 67 | 68 | return true; 69 | } 70 | offset++; 71 | 72 | // Initial mark 73 | if (!MATCH_MARK(results->rawbuf[offset++], SONY_HDR_MARK)) return false ; 74 | 75 | while (offset + 1 < irparams.rawlen) { 76 | if (!MATCH_SPACE(results->rawbuf[offset++], SONY_HDR_SPACE)) break ; 77 | 78 | if (MATCH_MARK(results->rawbuf[offset], SONY_ONE_MARK)) data = (data << 1) | 1 ; 79 | else if (MATCH_MARK(results->rawbuf[offset], SONY_ZERO_MARK)) data = (data << 1) | 0 ; 80 | else return false ; 81 | offset++; 82 | } 83 | 84 | // Success 85 | results->bits = (offset - 1) / 2; 86 | if (results->bits < 12) { 87 | results->bits = 0; 88 | return false; 89 | } 90 | results->value = data; 91 | results->decode_type = SONY; 92 | return true; 93 | } 94 | #endif 95 | 96 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Template.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Assuming the protocol we are adding is for the (imaginary) manufacturer: Shuzu 3 | 4 | Our fantasy protocol is a standard protocol, so we can use this standard 5 | template without too much work. Some protocols are quite unique and will require 6 | considerably more work in this file! It is way beyond the scope of this text to 7 | explain how to reverse engineer "unusual" IR protocols. But, unless you own an 8 | oscilloscope, the starting point is probably to use the rawDump.ino sketch and 9 | try to spot the pattern! 10 | 11 | Before you start, make sure the IR library is working OK: 12 | # Open up the Arduino IDE 13 | # Load up the rawDump.ino example sketch 14 | # Run it 15 | 16 | Now we can start to add our new protocol... 17 | 18 | 1. Copy this file to : ir_Shuzu.cpp 19 | 20 | 2. Replace all occurrences of "Shuzu" with the name of your protocol. 21 | 22 | 3. Tweak the #defines to suit your protocol. 23 | 24 | 4. If you're lucky, tweaking the #defines will make the default send() function 25 | work. 26 | 27 | 5. Again, if you're lucky, tweaking the #defines will have made the default 28 | decode() function work. 29 | 30 | You have written the code to support your new protocol! 31 | 32 | Now you must do a few things to add it to the IRremote system: 33 | 34 | 1. Open IRremote.h and make the following changes: 35 | REMEMEBER to change occurences of "SHUZU" with the name of your protocol 36 | 37 | A. At the top, in the section "Supported Protocols", add: 38 | #define DECODE_SHUZU 1 39 | #define SEND_SHUZU 1 40 | 41 | B. In the section "enumerated list of all supported formats", add: 42 | SHUZU, 43 | to the end of the list (notice there is a comma after the protocol name) 44 | 45 | C. Further down in "Main class for receiving IR", add: 46 | //...................................................................... 47 | #if DECODE_SHUZU 48 | bool decodeShuzu (decode_results *results) ; 49 | #endif 50 | 51 | D. Further down in "Main class for sending IR", add: 52 | //...................................................................... 53 | #if SEND_SHUZU 54 | void sendShuzu (unsigned long data, int nbits) ; 55 | #endif 56 | 57 | E. Save your changes and close the file 58 | 59 | 2. Now open irRecv.cpp and make the following change: 60 | 61 | A. In the function IRrecv::decode(), add: 62 | #ifdef DECODE_NEC 63 | DBG_PRINTLN("Attempting Shuzu decode"); 64 | if (decodeShuzu(results)) return true ; 65 | #endif 66 | 67 | B. Save your changes and close the file 68 | 69 | You will probably want to add your new protocol to the example sketch 70 | 71 | 3. Open MyDocuments\Arduino\libraries\IRremote\examples\IRrecvDumpV2.ino 72 | 73 | A. In the encoding() function, add: 74 | case SHUZU: Serial.print("SHUZU"); break ; 75 | 76 | Now open the Arduino IDE, load up the rawDump.ino sketch, and run it. 77 | Hopefully it will compile and upload. 78 | If it doesn't, you've done something wrong. Check your work. 79 | If you can't get it to work - seek help from somewhere. 80 | 81 | If you get this far, I will assume you have successfully added your new protocol 82 | There is one last thing to do. 83 | 84 | 1. Delete this giant instructional comment. 85 | 86 | 2. Send a copy of your work to us so we can include it in the library and 87 | others may benefit from your hard work and maybe even write a song about how 88 | great you are for helping them! :) 89 | 90 | Regards, 91 | BlueChip 92 | */ 93 | 94 | #include "IRremote.h" 95 | #include "IRremoteInt.h" 96 | 97 | //============================================================================== 98 | // 99 | // 100 | // S H U Z U 101 | // 102 | // 103 | //============================================================================== 104 | 105 | #define BITS 32 // The number of bits in the command 106 | 107 | #define HDR_MARK 1000 // The length of the Header:Mark 108 | #define HDR_SPACE 2000 // The lenght of the Header:Space 109 | 110 | #define BIT_MARK 3000 // The length of a Bit:Mark 111 | #define ONE_SPACE 4000 // The length of a Bit:Space for 1's 112 | #define ZERO_SPACE 5000 // The length of a Bit:Space for 0's 113 | 114 | #define OTHER 1234 // Other things you may need to define 115 | 116 | //+============================================================================= 117 | // 118 | #if SEND_SHUZU 119 | void IRsend::sendShuzu (unsigned long data, int nbits) 120 | { 121 | // Set IR carrier frequency 122 | enableIROut(38); 123 | 124 | // Header 125 | mark (HDR_MARK); 126 | space(HDR_SPACE); 127 | 128 | // Data 129 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 130 | if (data & mask) { 131 | mark (BIT_MARK); 132 | space(ONE_SPACE); 133 | } else { 134 | mark (BIT_MARK); 135 | space(ZERO_SPACE); 136 | } 137 | } 138 | 139 | // Footer 140 | mark(BIT_MARK); 141 | space(0); // Always end with the LED off 142 | } 143 | #endif 144 | 145 | //+============================================================================= 146 | // 147 | #if DECODE_SHUZU 148 | bool IRrecv::decodeShuzu (decode_results *results) 149 | { 150 | unsigned long data = 0; // Somewhere to build our code 151 | int offset = 1; // Skip the Gap reading 152 | 153 | // Check we have the right amount of data 154 | if (irparams.rawlen != 1 + 2 + (2 * BITS) + 1) return false ; 155 | 156 | // Check initial Mark+Space match 157 | if (!MATCH_MARK (results->rawbuf[offset++], HDR_MARK )) return false ; 158 | if (!MATCH_SPACE(results->rawbuf[offset++], HDR_SPACE)) return false ; 159 | 160 | // Read the bits in 161 | for (int i = 0; i < SHUZU_BITS; i++) { 162 | // Each bit looks like: MARK + SPACE_1 -> 1 163 | // or : MARK + SPACE_0 -> 0 164 | if (!MATCH_MARK(results->rawbuf[offset++], BIT_MARK)) return false ; 165 | 166 | // IR data is big-endian, so we shuffle it in from the right: 167 | if (MATCH_SPACE(results->rawbuf[offset], ONE_SPACE)) data = (data << 1) | 1 ; 168 | else if (MATCH_SPACE(results->rawbuf[offset], ZERO_SPACE)) data = (data << 1) | 0 ; 169 | else return false ; 170 | offset++; 171 | } 172 | 173 | // Success 174 | results->bits = BITS; 175 | results->value = data; 176 | results->decode_type = SHUZU; 177 | return true; 178 | } 179 | #endif 180 | -------------------------------------------------------------------------------- /src/sensors/ir/ir_Whynter.cpp: -------------------------------------------------------------------------------- 1 | #include "IRremote.h" 2 | #include "IRremoteInt.h" 3 | 4 | //============================================================================== 5 | // W W H H Y Y N N TTTTT EEEEE RRRRR 6 | // W W H H Y Y NN N T E R R 7 | // W W W HHHHH Y N N N T EEE RRRR 8 | // W W W H H Y N NN T E R R 9 | // WWW H H Y N N T EEEEE R R 10 | //============================================================================== 11 | 12 | #define WHYNTER_BITS 32 13 | #define WHYNTER_HDR_MARK 2850 14 | #define WHYNTER_HDR_SPACE 2850 15 | #define WHYNTER_BIT_MARK 750 16 | #define WHYNTER_ONE_MARK 750 17 | #define WHYNTER_ONE_SPACE 2150 18 | #define WHYNTER_ZERO_MARK 750 19 | #define WHYNTER_ZERO_SPACE 750 20 | 21 | //+============================================================================= 22 | #if SEND_WHYNTER 23 | void IRsend::sendWhynter (unsigned long data, int nbits) 24 | { 25 | // Set IR carrier frequency 26 | enableIROut(38); 27 | 28 | // Start 29 | mark(WHYNTER_ZERO_MARK); 30 | space(WHYNTER_ZERO_SPACE); 31 | 32 | // Header 33 | mark(WHYNTER_HDR_MARK); 34 | space(WHYNTER_HDR_SPACE); 35 | 36 | // Data 37 | for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) { 38 | if (data & mask) { 39 | mark(WHYNTER_ONE_MARK); 40 | space(WHYNTER_ONE_SPACE); 41 | } else { 42 | mark(WHYNTER_ZERO_MARK); 43 | space(WHYNTER_ZERO_SPACE); 44 | } 45 | } 46 | 47 | // Footer 48 | mark(WHYNTER_ZERO_MARK); 49 | space(WHYNTER_ZERO_SPACE); // Always end with the LED off 50 | } 51 | #endif 52 | 53 | //+============================================================================= 54 | #if DECODE_WHYNTER 55 | bool IRrecv::decodeWhynter (decode_results *results) 56 | { 57 | long data = 0; 58 | int offset = 1; // skip initial space 59 | 60 | // Check we have the right amount of data 61 | if (irparams.rawlen < (2 * WHYNTER_BITS) + 6) return false ; 62 | 63 | // Sequence begins with a bit mark and a zero space 64 | if (!MATCH_MARK (results->rawbuf[offset++], WHYNTER_BIT_MARK )) return false ; 65 | if (!MATCH_SPACE(results->rawbuf[offset++], WHYNTER_ZERO_SPACE)) return false ; 66 | 67 | // header mark and space 68 | if (!MATCH_MARK (results->rawbuf[offset++], WHYNTER_HDR_MARK )) return false ; 69 | if (!MATCH_SPACE(results->rawbuf[offset++], WHYNTER_HDR_SPACE)) return false ; 70 | 71 | // data bits 72 | for (int i = 0; i < WHYNTER_BITS; i++) { 73 | if (!MATCH_MARK(results->rawbuf[offset++], WHYNTER_BIT_MARK)) return false ; 74 | 75 | if (MATCH_SPACE(results->rawbuf[offset], WHYNTER_ONE_SPACE )) data = (data << 1) | 1 ; 76 | else if (MATCH_SPACE(results->rawbuf[offset], WHYNTER_ZERO_SPACE)) data = (data << 1) | 0 ; 77 | else return false ; 78 | offset++; 79 | } 80 | 81 | // trailing mark 82 | if (!MATCH_MARK(results->rawbuf[offset], WHYNTER_BIT_MARK)) return false ; 83 | 84 | // Success 85 | results->bits = WHYNTER_BITS; 86 | results->value = data; 87 | results->decode_type = WHYNTER; 88 | return true; 89 | } 90 | #endif 91 | 92 | -------------------------------------------------------------------------------- /src/sensors/tca8418.h: -------------------------------------------------------------------------------- 1 | #ifndef TCA8418_H 2 | #define TCA8418_H 3 | 4 | /** Comment this define to disable interrupt support */ 5 | //- #define TCA8418_INTERRUPT_SUPPORT 6 | 7 | /* Retro-compatibility with arduino 0023 and previous version */ 8 | #if ARDUINO >= 100 9 | #include "Arduino.h" 10 | #define I2CWRITE(x) Wire.write(x) 11 | #define I2CREAD() Wire.read() 12 | #else 13 | #include "WProgram.h" 14 | #define I2CWRITE(x) Wire.send(x) 15 | #define I2CREAD() Wire.receive() 16 | #define INPUT_PULLUP 2 17 | #endif 18 | 19 | #include 20 | 21 | 22 | #define KEYPAD 0x37 23 | #define GPIO 0x38 24 | #define EDGE 0x39 25 | #define LEVEL 0x40 26 | #define INTERRUPT 0x41 27 | #define NOINTERRUPT 0x42 28 | #define FIFO 0x43 29 | #define NOFIFO 0x44 30 | #define DEBOUNCE 0x45 31 | #define NODEBOUNCE 0x46 32 | 33 | #ifndef I2CTIMEOUT 34 | #define I2CTIMEOUT 100 35 | #endif 36 | 37 | /* TCA8418 hardware limits */ 38 | #define TCA8418_MAX_ROWS 8 39 | #define TCA8418_MAX_COLS 10 40 | 41 | /* TCA8418 register offsets */ 42 | #define REG_CFG 0x01 43 | #define REG_INT_STAT 0x02 44 | #define REG_KEY_LCK_EC 0x03 45 | #define REG_KEY_EVENT_A 0x04 46 | #define REG_KEY_EVENT_B 0x05 47 | #define REG_KEY_EVENT_C 0x06 48 | #define REG_KEY_EVENT_D 0x07 49 | #define REG_KEY_EVENT_E 0x08 50 | #define REG_KEY_EVENT_F 0x09 51 | #define REG_KEY_EVENT_G 0x0A 52 | #define REG_KEY_EVENT_H 0x0B 53 | #define REG_KEY_EVENT_I 0x0C 54 | #define REG_KEY_EVENT_J 0x0D 55 | #define REG_KP_LCK_TIMER 0x0E 56 | #define REG_UNLOCK1 0x0F 57 | #define REG_UNLOCK2 0x10 58 | #define REG_GPIO_INT_STAT1 0x11 59 | #define REG_GPIO_INT_STAT2 0x12 60 | #define REG_GPIO_INT_STAT3 0x13 61 | #define REG_GPIO_DAT_STAT1 0x14 62 | #define REG_GPIO_DAT_STAT2 0x15 63 | #define REG_GPIO_DAT_STAT3 0x16 64 | #define REG_GPIO_DAT_OUT1 0x17 65 | #define REG_GPIO_DAT_OUT2 0x18 66 | #define REG_GPIO_DAT_OUT3 0x19 67 | #define REG_GPIO_INT_EN1 0x1A 68 | #define REG_GPIO_INT_EN2 0x1B 69 | #define REG_GPIO_INT_EN3 0x1C 70 | #define REG_KP_GPIO1 0x1D 71 | #define REG_KP_GPIO2 0x1E 72 | #define REG_KP_GPIO3 0x1F 73 | #define REG_GPI_EM1 0x20 74 | #define REG_GPI_EM2 0x21 75 | #define REG_GPI_EM3 0x22 76 | #define REG_GPIO_DIR1 0x23 77 | #define REG_GPIO_DIR2 0x24 78 | #define REG_GPIO_DIR3 0x25 79 | #define REG_GPIO_INT_LVL1 0x26 80 | #define REG_GPIO_INT_LVL2 0x27 81 | #define REG_GPIO_INT_LVL3 0x28 82 | #define REG_DEBOUNCE_DIS1 0x29 83 | #define REG_DEBOUNCE_DIS2 0x2A 84 | #define REG_DEBOUNCE_DIS3 0x2B 85 | #define REG_GPIO_PULL1 0x2C 86 | #define REG_GPIO_PULL2 0x2D 87 | #define REG_GPIO_PULL3 0x2E 88 | 89 | /* TCA8418 bit definitions */ 90 | #define CFG_AI 0x80 91 | #define CFG_GPI_E_CFG 0x40 92 | #define CFG_OVR_FLOW_M 0x20 93 | #define CFG_INT_CFG 0x10 94 | #define CFG_OVR_FLOW_IEN 0x08 95 | #define CFG_K_LCK_IEN 0x04 96 | #define CFG_GPI_IEN 0x02 97 | #define CFG_KE_IEN 0x01 98 | 99 | #define INT_STAT_CAD_INT 0x10 100 | #define INT_STAT_OVR_FLOW_INT 0x08 101 | #define INT_STAT_K_LCK_INT 0x04 102 | #define INT_STAT_GPI_INT 0x02 103 | #define INT_STAT_K_INT 0x01 104 | 105 | /* TCA8418 register masks */ 106 | #define KEY_LCK_EC_KEC 0x7 107 | #define KEY_EVENT_CODE 0x7f 108 | #define KEY_EVENT_VALUE 0x80 109 | 110 | /* TCA8418 Rows and Columns */ 111 | #define ROW0 0x01 112 | #define ROW1 0x02 113 | #define ROW2 0x04 114 | #define ROW3 0x08 115 | #define ROW4 0x10 116 | #define ROW5 0x20 117 | #define ROW6 0x40 118 | #define ROW7 0x80 119 | 120 | #define COL0 0x0001 121 | #define COL1 0x0002 122 | #define COL2 0x0004 123 | #define COL3 0x0008 124 | #define COL4 0x0010 125 | #define COL5 0x0020 126 | #define COL6 0x0040 127 | #define COL7 0x0080 128 | #define COL8 0x0100 129 | #define COL9 0x0200 130 | 131 | 132 | class KEYS { 133 | public: 134 | KEYS(); 135 | void begin(void); 136 | void begin(uint8_t rows, uint16_t cols, uint8_t config); 137 | uint8_t readKeypad(void); 138 | bool configureKeys(uint8_t rows, uint16_t cols, uint8_t config); 139 | void writeByte(uint8_t data, uint8_t reg); 140 | bool read3Bytes(uint32_t *data, uint8_t reg); 141 | void write3Bytes(uint32_t data, uint8_t reg); 142 | bool readByte(uint8_t *data, uint8_t reg); 143 | void pinMode(uint32_t pin, uint8_t mode); 144 | void digitalWrite(uint32_t pin, uint8_t value); 145 | uint8_t digitalRead(uint32_t pin); 146 | void write(uint32_t value); 147 | uint32_t read(void); 148 | void toggle(uint32_t pin); 149 | void blink(uint32_t pin, uint16_t count, uint32_t duration); 150 | #ifdef TCA8418_INTERRUPT_SUPPORT 151 | void enableInterrupt(uint8_t pin, void(*selfCheckFunction)(void)); 152 | void disableInterrupt(); 153 | void pinInterruptMode(uint32_t pin, uint8_t mode, uint8_t level, uint8_t fifo); 154 | void pinInterruptMode(uint32_t pin, uint8_t mode); 155 | #endif 156 | void readGPIO(); 157 | void updateGPIO(); 158 | void dumpreg(void); 159 | uint8_t getInterruptStatus(void); 160 | void clearInterruptStatus(uint8_t flags); 161 | void clearInterruptStatus(void); 162 | uint8_t getKeyEvent(uint8_t event); 163 | uint8_t getKeyEvent(void); 164 | uint8_t getKeyEventCount(void); 165 | uint32_t getGPIOInterrupt(void); 166 | bool isKeyDown(uint8_t key); 167 | bool getKey(uint8_t *key); 168 | uint8_t getKey(void); 169 | 170 | protected: 171 | 172 | #ifdef TCA8418_INTERRUPT_SUPPORT 173 | 174 | /** Old value of _PIN variable */ 175 | volatile uint32_t _oldPIN; 176 | 177 | /** ISR ignore flag */ 178 | volatile uint8_t _isrIgnore; 179 | 180 | /** PCINT pin used for "INT" pin handling */ 181 | uint8_t _pcintPin; 182 | 183 | /** Interrupts modes of pins ( LOW, CHANGE, FALLING, RISING) */ 184 | uint8_t _intMode[24]; 185 | 186 | /** Interrupts callback functions */ 187 | void (*_intCallback[24])(void); 188 | #endif 189 | 190 | private: 191 | uint8_t _address; 192 | uint32_t _PKG; // Pin Keypad or GPIO 0=GPIO, 1=Keypad 193 | uint32_t _PORT; 194 | uint32_t _PIN; // Pin State 195 | uint32_t _DDR; //Pin Direction INPUT or OUTPUT 196 | uint32_t _PUR; //Pull-Up Resistor Selection 197 | 198 | }; 199 | 200 | #endif 201 | -------------------------------------------------------------------------------- /src/utility/Button.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------* 2 | * Arduino Button Library v1.0 * 3 | * Jack Christensen Mar 2012 * 4 | * * 5 | * This work is licensed under the Creative Commons Attribution- * 6 | * ShareAlike 3.0 Unported License. To view a copy of this license, * 7 | * visit http://creativecommons.org/licenses/by-sa/3.0/ or send a * 8 | * letter to Creative Commons, 171 Second Street, Suite 300, * 9 | * San Francisco, California, 94105, USA. * 10 | *----------------------------------------------------------------------*/ 11 | #ifndef Button_h 12 | #define Button_h 13 | // #if ARDUINO >= 100 14 | #include 15 | // #else 16 | // #include 17 | // #endif 18 | 19 | #define DPAD_V_FULL 2 20 | #define DPAD_V_HALF 1 21 | #define DPAD_V_NONE 0 22 | 23 | class Button 24 | { 25 | public: 26 | Button(uint8_t pin, uint8_t invert, uint32_t dbTime); 27 | uint8_t read(); 28 | uint8_t readAxis(); 29 | uint8_t isPressed(); 30 | uint8_t isAxisPressed(); 31 | uint8_t isReleased(); 32 | uint8_t wasPressed(); 33 | uint8_t wasAxisPressed(); 34 | uint8_t wasReleased(); 35 | uint8_t pressedFor(uint32_t ms); 36 | uint8_t releasedFor(uint32_t ms); 37 | uint32_t lastChange(); 38 | 39 | private: 40 | uint8_t _pin; //arduino pin number 41 | uint8_t _puEnable; //internal pullup resistor enabled 42 | uint8_t _invert; //if 0, interpret high state as pressed, else interpret low state as pressed 43 | uint8_t _state; //current button state 44 | uint8_t _lastState; //previous button state 45 | uint8_t _changed; //state changed since last read 46 | uint8_t _axis; //state changed since last read 47 | uint32_t _time; //time of current state (all times are in ms) 48 | uint32_t _lastTime; //time of previous state 49 | uint32_t _lastChange; //time of last state change 50 | uint32_t _dbTime; //debounce time 51 | }; 52 | #endif 53 | -------------------------------------------------------------------------------- /src/utility/Config.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H_ 2 | #define _CONFIG_H_ 3 | 4 | // TFT LCD via SPI 5 | #define TFT_DC 21 // Data/Control pin 6 | #define TFT_CS 5 // Chip Select 7 | #define TFT_LED_PIN 14 // Backlight enable 8 | #define TFT_MOSI 23 9 | #define TFT_MISO 19 10 | #define TFT_SCLK 18 11 | #define TFT_RST -1 // (not connected) 12 | 13 | // microSD Card (TF) via SPI 14 | #define SD_CARD_CS 22 15 | 16 | // Digital Buttons 17 | #define BUTTON_A_PIN 32 18 | #define BUTTON_B_PIN 33 19 | 20 | #define BUTTON_MENU 13 21 | #define BUTTON_SELECT 27 22 | #define BUTTON_VOLUME 0 23 | #define BUTTON_START 39 24 | 25 | // Analog Buttons 26 | #define BUTTON_JOY_Y 35 27 | #define BUTTON_JOY_X 34 28 | 29 | // Speaker 30 | #define SPEAKER_ENABLE_PIN 25 31 | #define SPEAKER_PIN 26 32 | #define TONE_PIN_CHANNEL 0 // PWM Channel 33 | 34 | // Status LED (blue) 35 | #define LED_STATUS_PIN 2 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/utility/Display.txt: -------------------------------------------------------------------------------- 1 | This is a library for the Adafruit 2.2" SPI display. 2 | This library works with the Adafruit 2.2" TFT Breakout w/SD card 3 | ----> http://www.adafruit.com/products/1480 4 | 5 | Check out the links above for our tutorials and wiring diagrams. 6 | These displays use SPI to communicate, 4 or 5 pins are required 7 | to interface (RST is optional). 8 | Adafruit invests time and resources providing this open source code, 9 | please support Adafruit and open-source hardware by purchasing 10 | products from Adafruit! 11 | 12 | Written by Limor Fried/Ladyada for Adafruit Industries. 13 | MIT license, all text above must be included in any redistribution 14 | 15 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_ILI9340. Check that the Adafruit_ILI9340 folder contains Adafruit_ILI9340.cpp and Adafruit_ILI9340. 16 | 17 | Place the Adafruit_ILI9340 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE 18 | 19 | Also requires the Adafruit_GFX library for Arduino. 20 | -------------------------------------------------------------------------------- /src/utility/Speaker.cpp: -------------------------------------------------------------------------------- 1 | #include "Speaker.h" 2 | 3 | SPEAKER::SPEAKER(void) { 4 | _volume = 8; 5 | } 6 | 7 | void SPEAKER::begin() { 8 | ledcSetup(TONE_PIN_CHANNEL, 0, 13); // PWM channel, frequency, resolution in bits 9 | ledcAttachPin(SPEAKER_PIN, TONE_PIN_CHANNEL); 10 | // digitalWrite(SPEAKER_PIN, 0); 11 | pinMode(SPEAKER_ENABLE_PIN, OUTPUT); 12 | digitalWrite(SPEAKER_ENABLE_PIN, HIGH); // IO25 drives PAM8304 'IN-' and '/SD' pins 13 | setBeep(1000, 100); // standard beep is 1kHz for 0.1 seconds 14 | } 15 | 16 | void SPEAKER::end() { 17 | ledcDetachPin(SPEAKER_PIN); 18 | // digitalWrite(SPEAKER_ENABLE_PIN, LOW); 19 | } 20 | 21 | void SPEAKER::tone(uint16_t frequency) { 22 | ledcWriteTone(TONE_PIN_CHANNEL, frequency); 23 | } 24 | 25 | void SPEAKER::tone(uint16_t frequency, uint32_t duration) { 26 | tone(frequency); 27 | _count = millis() + duration; 28 | speaker_on = 1; 29 | } 30 | 31 | void SPEAKER::beep() { 32 | tone(_beep_freq, _beep_duration); 33 | } 34 | 35 | void SPEAKER::setBeep(uint16_t frequency, uint16_t duration) { 36 | _beep_freq = frequency; 37 | _beep_duration = duration; 38 | } 39 | 40 | void SPEAKER::setVolume(uint8_t volume) { 41 | _volume = 11 - volume; 42 | } 43 | 44 | void SPEAKER::mute() { 45 | ledcWriteTone(TONE_PIN_CHANNEL, 0); 46 | digitalWrite(SPEAKER_PIN, 0); 47 | } 48 | 49 | void SPEAKER::update() { 50 | if(speaker_on) { 51 | if(millis() > _count) { 52 | speaker_on = 0; 53 | mute(); 54 | } 55 | } 56 | } 57 | 58 | void SPEAKER::write(uint8_t value) { 59 | dacWrite(SPEAKER_PIN, value); 60 | } 61 | 62 | void SPEAKER::playMusic(const uint8_t* music_data, uint16_t sample_rate) { 63 | uint32_t length = strlen((char*)music_data); 64 | uint16_t delay_interval = ((uint32_t)1000000/sample_rate); 65 | if(_volume != 11) { 66 | for(int i=0; i=0; t--) { 72 | dacWrite(SPEAKER_PIN, t); 73 | delay(2); 74 | } 75 | } 76 | // ledcSetup(TONE_PIN_CHANNEL, 0, 13); 77 | ledcAttachPin(SPEAKER_PIN, TONE_PIN_CHANNEL); 78 | } 79 | -------------------------------------------------------------------------------- /src/utility/Speaker.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPEAKER_H_ 2 | #define _SPEAKER_H_ 3 | 4 | #include "Arduino.h" 5 | #include "Config.h" 6 | 7 | extern "C" { 8 | #include "esp32-hal-dac.h" 9 | } 10 | 11 | class SPEAKER { 12 | public: 13 | SPEAKER(void); 14 | 15 | void begin(); 16 | void end(); 17 | void mute(); 18 | void tone(uint16_t frequency); 19 | void tone(uint16_t frequency, uint32_t duration); 20 | void beep(); 21 | void setBeep(uint16_t frequency, uint16_t duration); 22 | void update(); 23 | 24 | void write(uint8_t value); 25 | void setVolume(uint8_t volume); 26 | void playMusic(const uint8_t* music_data, uint16_t sample_rate); 27 | 28 | private: 29 | uint32_t _count; 30 | uint8_t _volume; 31 | uint16_t _beep_duration; 32 | uint16_t _beep_freq; 33 | bool speaker_on; 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /src/utility/battery.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * battery.cpp 3 | * 4 | * Created on: 5 de jul de 2018 5 | * Author: mdrjr 6 | */ 7 | 8 | #include 9 | #include "battery.h" 10 | 11 | Battery::Battery() { 12 | this->_enable_protection = false; 13 | } 14 | 15 | void Battery::begin() { 16 | adc1_config_width(ADC_WIDTH_BIT_12); 17 | adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_11); 18 | esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, ESP_ADC_CAL_VAL_EFUSE_TP, &_adc_chars); 19 | } 20 | 21 | double Battery::getVoltage() { 22 | uint32_t adc_reading = 0; 23 | 24 | for (int i = 0; i < BATTERY_SAMPLES; i++) { 25 | adc_reading += adc1_get_raw((adc1_channel_t) ADC1_CHANNEL_0); 26 | } 27 | 28 | adc_reading /= BATTERY_SAMPLES; 29 | 30 | return (double) esp_adc_cal_raw_to_voltage(adc_reading, &_adc_chars) * BATTERY_RESISTANCE_NUM / 1000; 31 | } 32 | 33 | int Battery::getPercentage() { 34 | int voltage_by_100 = (int)(getVoltage() * 100); 35 | 36 | if(voltage_by_100 > BATTERY_VMAX) { 37 | return 100; 38 | } else if(voltage_by_100 < BATTERY_VMIN) { 39 | return 0; 40 | } else { 41 | int res = 101 - (101 / pow(1 + pow(1.33 * (voltage_by_100 - BATTERY_VMIN)/(BATTERY_VMAX - BATTERY_VMIN), 4.5), 3)); 42 | if(res > 100) 43 | res = 100; 44 | return res; 45 | } 46 | } 47 | 48 | void Battery::setProtection(bool enable) { 49 | this->_enable_protection = enable; 50 | } 51 | 52 | void Battery::update() { 53 | if(this->_enable_protection == true) { 54 | int curr_voltage = (int)(getVoltage() * 100); 55 | 56 | if(curr_voltage <= BATTERY_CUTOFF) { 57 | esp_deep_sleep(30 * 60 * 1000000); 58 | esp_deep_sleep_start(); 59 | } 60 | 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/utility/battery.h: -------------------------------------------------------------------------------- 1 | /* 2 | * battery.h 3 | * 4 | * Created on: 5 de jul de 2018 5 | * Author: mdrjr 6 | */ 7 | 8 | #ifndef LIBRARIES_ODROID_GO_SRC_UTILITY_BATTERY_H_ 9 | #define LIBRARIES_ODROID_GO_SRC_UTILITY_BATTERY_H_ 10 | 11 | #include "Arduino.h" 12 | #include "Config.h" 13 | #include 14 | #include 15 | 16 | #define BATTERY_RESISTANCE_NUM 2 17 | #define BATTERY_SAMPLES 64 18 | #define BATTERY_VMAX 420 19 | #define BATTERY_VMIN 330 20 | #define BATTERY_CUTOFF 325 21 | 22 | class Battery { 23 | public: 24 | Battery(void); 25 | 26 | void begin(); 27 | double getVoltage(); 28 | int getPercentage(); 29 | void setProtection(bool enable); 30 | void update(); 31 | 32 | private: 33 | esp_adc_cal_characteristics_t _adc_chars; 34 | bool _enable_protection; 35 | }; 36 | 37 | #endif /* LIBRARIES_ODROID_GO_SRC_UTILITY_BATTERY_H_ */ 38 | 39 | -------------------------------------------------------------------------------- /src/utility/bmp_map.h: -------------------------------------------------------------------------------- 1 | #ifndef _BMP_MAP_H_ 2 | #define _BMP_MAP_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern const unsigned char gImage_logoM5[]; 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/utility/music_8bit.h: -------------------------------------------------------------------------------- 1 | #ifndef _music_8bit_H_ 2 | #define _music_8bit_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | extern const unsigned char m5stack_startup_music[]; 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /src/utility/qrcode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Richard Moore 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Special thanks to Nayuki (https://www.nayuki.io/) from which this library was 27 | * heavily inspired and compared against. 28 | * 29 | * See: https://github.com/nayuki/QR-Code-generator/tree/master/cpp 30 | */ 31 | 32 | 33 | #ifndef __QRCODE_H_ 34 | #define __QRCODE_H_ 35 | 36 | #ifndef __cplusplus 37 | typedef unsigned char bool; 38 | static const bool false = 0; 39 | static const bool true = 1; 40 | #endif 41 | 42 | #include 43 | 44 | 45 | // QR Code Format Encoding 46 | #define MODE_NUMERIC 0 47 | #define MODE_ALPHANUMERIC 1 48 | #define MODE_BYTE 2 49 | 50 | 51 | // Error Correction Code Levels 52 | #define ECC_LOW 0 53 | #define ECC_MEDIUM 1 54 | #define ECC_QUARTILE 2 55 | #define ECC_HIGH 3 56 | 57 | 58 | // If set to non-zero, this library can ONLY produce QR codes at that version 59 | // This saves a lot of dynamic memory, as the codeword tables are skipped 60 | #ifndef LOCK_VERSION 61 | #define LOCK_VERSION 0 62 | #endif 63 | 64 | 65 | typedef struct QRCode { 66 | uint8_t version; 67 | uint8_t size; 68 | uint8_t ecc; 69 | uint8_t mode; 70 | uint8_t mask; 71 | uint8_t *modules; 72 | } QRCode; 73 | 74 | 75 | #ifdef __cplusplus 76 | extern "C"{ 77 | #endif /* __cplusplus */ 78 | 79 | 80 | 81 | uint16_t qrcode_getBufferSize(uint8_t version); 82 | 83 | int8_t qrcode_initText(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, const char *data); 84 | int8_t qrcode_initBytes(QRCode *qrcode, uint8_t *modules, uint8_t version, uint8_t ecc, uint8_t *data, uint16_t length); 85 | 86 | bool qrcode_getModule(QRCode *qrcode, uint8_t x, uint8_t y); 87 | 88 | 89 | 90 | #ifdef __cplusplus 91 | } 92 | #endif /* __cplusplus */ 93 | 94 | 95 | #endif /* __QRCODE_H_ */ 96 | -------------------------------------------------------------------------------- /src/web/ESP8266WebServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ESP8266WebServer.h - Dead simple web-server. 3 | Supports only one simultaneous client, knows how to handle GET and POST. 4 | 5 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved. 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public 18 | License along with this library; if not, write to the Free Software 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling) 21 | */ 22 | 23 | 24 | #ifndef ESP8266WEBSERVER_H 25 | #define ESP8266WEBSERVER_H 26 | 27 | #include 28 | 29 | #endif //ESP8266WEBSERVER_H 30 | -------------------------------------------------------------------------------- /src/web/SimpleTimer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * SimpleTimer.cpp 3 | * 4 | * SimpleTimer - A timer library for Arduino. 5 | * Author: mromani@ottotecnica.com 6 | * Copyright (c) 2010 OTTOTECNICA Italy 7 | * 8 | * This library is free software; you can redistribute it 9 | * and/or modify it under the terms of the GNU Lesser 10 | * General Public License as published by the Free Software 11 | * Foundation; either version 2.1 of the License, or (at 12 | * your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will 15 | * be useful, but WITHOUT ANY WARRANTY; without even the 16 | * implied warranty of MERCHANTABILITY or FITNESS FOR A 17 | * PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | * License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser 21 | * General Public License along with this library; if not, 22 | * write to the Free Software Foundation, Inc., 23 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | */ 25 | 26 | 27 | #include "SimpleTimer.h" 28 | 29 | 30 | // Select time function: 31 | //static inline unsigned long elapsed() { return micros(); } 32 | static inline unsigned long elapsed() { return millis(); } 33 | 34 | 35 | SimpleTimer::SimpleTimer() { 36 | unsigned long current_millis = elapsed(); 37 | 38 | for (int i = 0; i < MAX_TIMERS; i++) { 39 | enabled[i] = false; 40 | callbacks[i] = 0; // if the callback pointer is zero, the slot is free, i.e. doesn't "contain" any timer 41 | prev_millis[i] = current_millis; 42 | numRuns[i] = 0; 43 | } 44 | 45 | numTimers = 0; 46 | } 47 | 48 | 49 | void SimpleTimer::run() { 50 | int i; 51 | unsigned long current_millis; 52 | 53 | // get current time 54 | current_millis = elapsed(); 55 | 56 | for (i = 0; i < MAX_TIMERS; i++) { 57 | 58 | toBeCalled[i] = DEFCALL_DONTRUN; 59 | 60 | // no callback == no timer, i.e. jump over empty slots 61 | if (callbacks[i]) { 62 | 63 | // is it time to process this timer ? 64 | // see http://arduino.cc/forum/index.php/topic,124048.msg932592.html#msg932592 65 | 66 | if (current_millis - prev_millis[i] >= delays[i]) { 67 | 68 | // update time 69 | //prev_millis[i] = current_millis; 70 | prev_millis[i] += delays[i]; 71 | 72 | // check if the timer callback has to be executed 73 | if (enabled[i]) { 74 | 75 | // "run forever" timers must always be executed 76 | if (maxNumRuns[i] == RUN_FOREVER) { 77 | toBeCalled[i] = DEFCALL_RUNONLY; 78 | } 79 | // other timers get executed the specified number of times 80 | else if (numRuns[i] < maxNumRuns[i]) { 81 | toBeCalled[i] = DEFCALL_RUNONLY; 82 | numRuns[i]++; 83 | 84 | // after the last run, delete the timer 85 | if (numRuns[i] >= maxNumRuns[i]) { 86 | toBeCalled[i] = DEFCALL_RUNANDDEL; 87 | } 88 | } 89 | } 90 | } 91 | } 92 | } 93 | 94 | for (i = 0; i < MAX_TIMERS; i++) { 95 | switch(toBeCalled[i]) { 96 | case DEFCALL_DONTRUN: 97 | break; 98 | 99 | case DEFCALL_RUNONLY: 100 | (*callbacks[i])(); 101 | break; 102 | 103 | case DEFCALL_RUNANDDEL: 104 | (*callbacks[i])(); 105 | deleteTimer(i); 106 | break; 107 | } 108 | } 109 | } 110 | 111 | 112 | // find the first available slot 113 | // return -1 if none found 114 | int SimpleTimer::findFirstFreeSlot() { 115 | int i; 116 | 117 | // all slots are used 118 | if (numTimers >= MAX_TIMERS) { 119 | return -1; 120 | } 121 | 122 | // return the first slot with no callback (i.e. free) 123 | for (i = 0; i < MAX_TIMERS; i++) { 124 | if (callbacks[i] == 0) { 125 | return i; 126 | } 127 | } 128 | 129 | // no free slots found 130 | return -1; 131 | } 132 | 133 | 134 | int SimpleTimer::setTimer(long d, timer_callback f, int n) { 135 | int freeTimer; 136 | 137 | freeTimer = findFirstFreeSlot(); 138 | if (freeTimer < 0) { 139 | return -1; 140 | } 141 | 142 | if (f == NULL) { 143 | return -1; 144 | } 145 | 146 | delays[freeTimer] = d; 147 | callbacks[freeTimer] = f; 148 | maxNumRuns[freeTimer] = n; 149 | enabled[freeTimer] = true; 150 | prev_millis[freeTimer] = elapsed(); 151 | 152 | numTimers++; 153 | 154 | return freeTimer; 155 | } 156 | 157 | 158 | int SimpleTimer::setInterval(long d, timer_callback f) { 159 | return setTimer(d, f, RUN_FOREVER); 160 | } 161 | 162 | 163 | int SimpleTimer::setTimeout(long d, timer_callback f) { 164 | return setTimer(d, f, RUN_ONCE); 165 | } 166 | 167 | 168 | void SimpleTimer::deleteTimer(int timerId) { 169 | if (timerId >= MAX_TIMERS) { 170 | return; 171 | } 172 | 173 | // nothing to delete if no timers are in use 174 | if (numTimers == 0) { 175 | return; 176 | } 177 | 178 | // don't decrease the number of timers if the 179 | // specified slot is already empty 180 | if (callbacks[timerId] != NULL) { 181 | callbacks[timerId] = 0; 182 | enabled[timerId] = false; 183 | toBeCalled[timerId] = DEFCALL_DONTRUN; 184 | delays[timerId] = 0; 185 | numRuns[timerId] = 0; 186 | 187 | // update number of timers 188 | numTimers--; 189 | } 190 | } 191 | 192 | 193 | // function contributed by code@rowansimms.com 194 | void SimpleTimer::restartTimer(int numTimer) { 195 | if (numTimer >= MAX_TIMERS) { 196 | return; 197 | } 198 | 199 | prev_millis[numTimer] = elapsed(); 200 | } 201 | 202 | 203 | boolean SimpleTimer::isEnabled(int numTimer) { 204 | if (numTimer >= MAX_TIMERS) { 205 | return false; 206 | } 207 | 208 | return enabled[numTimer]; 209 | } 210 | 211 | 212 | void SimpleTimer::enable(int numTimer) { 213 | if (numTimer >= MAX_TIMERS) { 214 | return; 215 | } 216 | 217 | enabled[numTimer] = true; 218 | } 219 | 220 | 221 | void SimpleTimer::disable(int numTimer) { 222 | if (numTimer >= MAX_TIMERS) { 223 | return; 224 | } 225 | 226 | enabled[numTimer] = false; 227 | } 228 | 229 | 230 | void SimpleTimer::toggle(int numTimer) { 231 | if (numTimer >= MAX_TIMERS) { 232 | return; 233 | } 234 | 235 | enabled[numTimer] = !enabled[numTimer]; 236 | } 237 | 238 | 239 | int SimpleTimer::getNumTimers() { 240 | return numTimers; 241 | } -------------------------------------------------------------------------------- /src/web/SimpleTimer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SimpleTimer.h 3 | * 4 | * SimpleTimer - A timer library for Arduino. 5 | * Author: mromani@ottotecnica.com 6 | * Copyright (c) 2010 OTTOTECNICA Italy 7 | * 8 | * This library is free software; you can redistribute it 9 | * and/or modify it under the terms of the GNU Lesser 10 | * General Public License as published by the Free Software 11 | * Foundation; either version 2.1 of the License, or (at 12 | * your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will 15 | * be useful, but WITHOUT ANY WARRANTY; without even the 16 | * implied warranty of MERCHANTABILITY or FITNESS FOR A 17 | * PARTICULAR PURPOSE. See the GNU Lesser General Public 18 | * License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser 21 | * General Public License along with this library; if not, 22 | * write to the Free Software Foundation, Inc., 23 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 | * 25 | */ 26 | 27 | 28 | #ifndef SIMPLETIMER_H 29 | #define SIMPLETIMER_H 30 | 31 | #if defined(ARDUINO) && ARDUINO >= 100 32 | #include 33 | #else 34 | #include 35 | #endif 36 | 37 | typedef void (*timer_callback)(void); 38 | 39 | class SimpleTimer { 40 | 41 | public: 42 | // maximum number of timers 43 | const static int MAX_TIMERS = 10; 44 | 45 | // setTimer() constants 46 | const static int RUN_FOREVER = 0; 47 | const static int RUN_ONCE = 1; 48 | 49 | // constructor 50 | SimpleTimer(); 51 | 52 | // this function must be called inside loop() 53 | void run(); 54 | 55 | // call function f every d milliseconds 56 | int setInterval(long d, timer_callback f); 57 | 58 | // call function f once after d milliseconds 59 | int setTimeout(long d, timer_callback f); 60 | 61 | // call function f every d milliseconds for n times 62 | int setTimer(long d, timer_callback f, int n); 63 | 64 | // destroy the specified timer 65 | void deleteTimer(int numTimer); 66 | 67 | // restart the specified timer 68 | void restartTimer(int numTimer); 69 | 70 | // returns true if the specified timer is enabled 71 | boolean isEnabled(int numTimer); 72 | 73 | // enables the specified timer 74 | void enable(int numTimer); 75 | 76 | // disables the specified timer 77 | void disable(int numTimer); 78 | 79 | // enables the specified timer if it's currently disabled, 80 | // and vice-versa 81 | void toggle(int numTimer); 82 | 83 | // returns the number of used timers 84 | int getNumTimers(); 85 | 86 | // returns the number of available timers 87 | int getNumAvailableTimers() { return MAX_TIMERS - numTimers; }; 88 | 89 | private: 90 | // deferred call constants 91 | const static int DEFCALL_DONTRUN = 0; // don't call the callback function 92 | const static int DEFCALL_RUNONLY = 1; // call the callback function but don't delete the timer 93 | const static int DEFCALL_RUNANDDEL = 2; // call the callback function and delete the timer 94 | 95 | // find the first available slot 96 | int findFirstFreeSlot(); 97 | 98 | // value returned by the millis() function 99 | // in the previous run() call 100 | unsigned long prev_millis[MAX_TIMERS]; 101 | 102 | // pointers to the callback functions 103 | timer_callback callbacks[MAX_TIMERS]; 104 | 105 | // delay values 106 | long delays[MAX_TIMERS]; 107 | 108 | // number of runs to be executed for each timer 109 | int maxNumRuns[MAX_TIMERS]; 110 | 111 | // number of executed runs for each timer 112 | int numRuns[MAX_TIMERS]; 113 | 114 | // which timers are enabled 115 | boolean enabled[MAX_TIMERS]; 116 | 117 | // deferred function call (sort of) - N.B.: this array is only used in run() 118 | int toBeCalled[MAX_TIMERS]; 119 | 120 | // actual number of timers in use 121 | int numTimers; 122 | }; 123 | 124 | #endif -------------------------------------------------------------------------------- /src/web/WebSocketsClient.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file WebSocketsClient.h 3 | * @date 20.05.2015 4 | * @author Markus Sattler 5 | * 6 | * Copyright (c) 2015 Markus Sattler. All rights reserved. 7 | * This file is part of the WebSockets for Arduino. 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | #ifndef WEBSOCKETSCLIENT_H_ 26 | #define WEBSOCKETSCLIENT_H_ 27 | 28 | #include "WebSockets.h" 29 | 30 | class WebSocketsClient: private WebSockets { 31 | public: 32 | #ifdef __AVR__ 33 | typedef void (*WebSocketClientEvent)(WStype_t type, uint8_t * payload, size_t length); 34 | #else 35 | typedef std::function WebSocketClientEvent; 36 | #endif 37 | 38 | 39 | WebSocketsClient(void); 40 | virtual ~WebSocketsClient(void); 41 | 42 | void begin(const char *host, uint16_t port, const char * url = "/", const char * protocol = "arduino"); 43 | void begin(String host, uint16_t port, String url = "/", String protocol = "arduino"); 44 | 45 | #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) 46 | void beginSSL(const char *host, uint16_t port, const char * url = "/", const char * = "", const char * protocol = "arduino"); 47 | void beginSSL(String host, uint16_t port, String url = "/", String fingerprint = "", String protocol = "arduino"); 48 | #endif 49 | 50 | void beginSocketIO(const char *host, uint16_t port, const char * url = "/socket.io/?EIO=3", const char * protocol = "arduino"); 51 | void beginSocketIO(String host, uint16_t port, String url = "/socket.io/?EIO=3", String protocol = "arduino"); 52 | 53 | #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) 54 | void beginSocketIOSSL(const char *host, uint16_t port, const char * url = "/socket.io/?EIO=3", const char * protocol = "arduino"); 55 | void beginSocketIOSSL(String host, uint16_t port, String url = "/socket.io/?EIO=3", String protocol = "arduino"); 56 | #endif 57 | 58 | #if (WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC) 59 | void loop(void); 60 | #else 61 | // Async interface not need a loop call 62 | void loop(void) __attribute__ ((deprecated)) {} 63 | #endif 64 | 65 | void onEvent(WebSocketClientEvent cbEvent); 66 | 67 | bool sendTXT(uint8_t * payload, size_t length = 0, bool headerToPayload = false); 68 | bool sendTXT(const uint8_t * payload, size_t length = 0); 69 | bool sendTXT(char * payload, size_t length = 0, bool headerToPayload = false); 70 | bool sendTXT(const char * payload, size_t length = 0); 71 | bool sendTXT(String & payload); 72 | 73 | bool sendBIN(uint8_t * payload, size_t length, bool headerToPayload = false); 74 | bool sendBIN(const uint8_t * payload, size_t length); 75 | 76 | bool sendPing(uint8_t * payload = NULL, size_t length = 0); 77 | bool sendPing(String & payload); 78 | 79 | void disconnect(void); 80 | 81 | void setAuthorization(const char * user, const char * password); 82 | void setAuthorization(const char * auth); 83 | 84 | void setExtraHeaders(const char * extraHeaders = NULL); 85 | 86 | void setReconnectInterval(unsigned long time); 87 | 88 | protected: 89 | String _host; 90 | uint16_t _port; 91 | 92 | #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266) || (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP32) 93 | String _fingerprint; 94 | #endif 95 | WSclient_t _client; 96 | 97 | WebSocketClientEvent _cbEvent; 98 | 99 | unsigned long _lastConnectionFail; 100 | unsigned long _reconnectInterval; 101 | 102 | void messageReceived(WSclient_t * client, WSopcode_t opcode, uint8_t * payload, size_t length, bool fin); 103 | 104 | void clientDisconnect(WSclient_t * client); 105 | bool clientIsConnected(WSclient_t * client); 106 | 107 | #if (WEBSOCKETS_NETWORK_TYPE != NETWORK_ESP8266_ASYNC) 108 | void handleClientData(void); 109 | #endif 110 | 111 | void sendHeader(WSclient_t * client); 112 | void handleHeader(WSclient_t * client, String * headerLine); 113 | 114 | void connectedCb(); 115 | void connectFailedCb(); 116 | 117 | #if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC) 118 | void asyncConnect(); 119 | #endif 120 | 121 | /** 122 | * called for sending a Event to the app 123 | * @param type WStype_t 124 | * @param payload uint8_t * 125 | * @param length size_t 126 | */ 127 | virtual void runCbEvent(WStype_t type, uint8_t * payload, size_t length) { 128 | if(_cbEvent) { 129 | _cbEvent(type, payload, length); 130 | } 131 | } 132 | 133 | }; 134 | 135 | #endif /* WEBSOCKETSCLIENT_H_ */ 136 | -------------------------------------------------------------------------------- /src/web/detail/RequestHandler.h: -------------------------------------------------------------------------------- 1 | #ifndef REQUESTHANDLER_H 2 | #define REQUESTHANDLER_H 3 | 4 | class RequestHandler { 5 | public: 6 | virtual ~RequestHandler() { } 7 | virtual bool canHandle(HTTPMethod method, String uri) { (void) method; (void) uri; return false; } 8 | virtual bool canUpload(String uri) { (void) uri; return false; } 9 | virtual bool handle(WebServer& server, HTTPMethod requestMethod, String requestUri) { (void) server; (void) requestMethod; (void) requestUri; return false; } 10 | virtual void upload(WebServer& server, String requestUri, HTTPUpload& upload) { (void) server; (void) requestUri; (void) upload; } 11 | 12 | RequestHandler* next() { return _next; } 13 | void next(RequestHandler* r) { _next = r; } 14 | 15 | private: 16 | RequestHandler* _next = nullptr; 17 | }; 18 | 19 | #endif //REQUESTHANDLER_H 20 | -------------------------------------------------------------------------------- /src/web/libb64/AUTHORS: -------------------------------------------------------------------------------- 1 | libb64: Base64 Encoding/Decoding Routines 2 | ====================================== 3 | 4 | Authors: 5 | ------- 6 | 7 | Chris Venter chris.venter@gmail.com http://rocketpod.blogspot.com 8 | -------------------------------------------------------------------------------- /src/web/libb64/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright-Only Dedication (based on United States law) 2 | or Public Domain Certification 3 | 4 | The person or persons who have associated work with this document (the 5 | "Dedicator" or "Certifier") hereby either (a) certifies that, to the best of 6 | his knowledge, the work of authorship identified is in the public domain of the 7 | country from which the work is published, or (b) hereby dedicates whatever 8 | copyright the dedicators holds in the work of authorship identified below (the 9 | "Work") to the public domain. A certifier, moreover, dedicates any copyright 10 | interest he may have in the associated work, and for these purposes, is 11 | described as a "dedicator" below. 12 | 13 | A certifier has taken reasonable steps to verify the copyright status of this 14 | work. Certifier recognizes that his good faith efforts may not shield him from 15 | liability if in fact the work certified is not in the public domain. 16 | 17 | Dedicator makes this dedication for the benefit of the public at large and to 18 | the detriment of the Dedicator's heirs and successors. Dedicator intends this 19 | dedication to be an overt act of relinquishment in perpetuity of all present 20 | and future rights under copyright law, whether vested or contingent, in the 21 | Work. Dedicator understands that such relinquishment of all rights includes 22 | the relinquishment of all rights to enforce (by lawsuit or otherwise) those 23 | copyrights in the Work. 24 | 25 | Dedicator recognizes that, once placed in the public domain, the Work may be 26 | freely reproduced, distributed, transmitted, used, modified, built upon, or 27 | otherwise exploited by anyone for any purpose, commercial or non-commercial, 28 | and in any way, including by methods that have not yet been invented or 29 | conceived. -------------------------------------------------------------------------------- /src/web/libb64/cdecode.c: -------------------------------------------------------------------------------- 1 | /* 2 | cdecoder.c - c source to a base64 decoding algorithm implementation 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifdef ESP8266 9 | #include 10 | #endif 11 | 12 | #if defined(ESP32) 13 | #define CORE_HAS_LIBB64 14 | #endif 15 | 16 | #ifndef CORE_HAS_LIBB64 17 | #include "cdecode_inc.h" 18 | 19 | int base64_decode_value(char value_in) 20 | { 21 | static const char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51}; 22 | static const char decoding_size = sizeof(decoding); 23 | value_in -= 43; 24 | if (value_in < 0 || value_in > decoding_size) return -1; 25 | return decoding[(int)value_in]; 26 | } 27 | 28 | void base64_init_decodestate(base64_decodestate* state_in) 29 | { 30 | state_in->step = step_a; 31 | state_in->plainchar = 0; 32 | } 33 | 34 | int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in) 35 | { 36 | const char* codechar = code_in; 37 | char* plainchar = plaintext_out; 38 | char fragment; 39 | 40 | *plainchar = state_in->plainchar; 41 | 42 | switch (state_in->step) 43 | { 44 | while (1) 45 | { 46 | case step_a: 47 | do { 48 | if (codechar == code_in+length_in) 49 | { 50 | state_in->step = step_a; 51 | state_in->plainchar = *plainchar; 52 | return plainchar - plaintext_out; 53 | } 54 | fragment = (char)base64_decode_value(*codechar++); 55 | } while (fragment < 0); 56 | *plainchar = (fragment & 0x03f) << 2; 57 | case step_b: 58 | do { 59 | if (codechar == code_in+length_in) 60 | { 61 | state_in->step = step_b; 62 | state_in->plainchar = *plainchar; 63 | return plainchar - plaintext_out; 64 | } 65 | fragment = (char)base64_decode_value(*codechar++); 66 | } while (fragment < 0); 67 | *plainchar++ |= (fragment & 0x030) >> 4; 68 | *plainchar = (fragment & 0x00f) << 4; 69 | case step_c: 70 | do { 71 | if (codechar == code_in+length_in) 72 | { 73 | state_in->step = step_c; 74 | state_in->plainchar = *plainchar; 75 | return plainchar - plaintext_out; 76 | } 77 | fragment = (char)base64_decode_value(*codechar++); 78 | } while (fragment < 0); 79 | *plainchar++ |= (fragment & 0x03c) >> 2; 80 | *plainchar = (fragment & 0x003) << 6; 81 | case step_d: 82 | do { 83 | if (codechar == code_in+length_in) 84 | { 85 | state_in->step = step_d; 86 | state_in->plainchar = *plainchar; 87 | return plainchar - plaintext_out; 88 | } 89 | fragment = (char)base64_decode_value(*codechar++); 90 | } while (fragment < 0); 91 | *plainchar++ |= (fragment & 0x03f); 92 | } 93 | } 94 | /* control should not reach here */ 95 | return plainchar - plaintext_out; 96 | } 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /src/web/libb64/cdecode_inc.h: -------------------------------------------------------------------------------- 1 | /* 2 | cdecode.h - c header for a base64 decoding algorithm 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifndef BASE64_CDECODE_H 9 | #define BASE64_CDECODE_H 10 | 11 | typedef enum 12 | { 13 | step_a, step_b, step_c, step_d 14 | } base64_decodestep; 15 | 16 | typedef struct 17 | { 18 | base64_decodestep step; 19 | char plainchar; 20 | } base64_decodestate; 21 | 22 | void base64_init_decodestate(base64_decodestate* state_in); 23 | 24 | int base64_decode_value(char value_in); 25 | 26 | int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in); 27 | 28 | #endif /* BASE64_CDECODE_H */ 29 | -------------------------------------------------------------------------------- /src/web/libb64/cencode.c: -------------------------------------------------------------------------------- 1 | /* 2 | cencoder.c - c source to a base64 encoding algorithm implementation 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifdef ESP8266 9 | #include 10 | #endif 11 | 12 | #if defined(ESP32) 13 | #define CORE_HAS_LIBB64 14 | #endif 15 | 16 | #ifndef CORE_HAS_LIBB64 17 | #include "cencode_inc.h" 18 | 19 | const int CHARS_PER_LINE = 72; 20 | 21 | void base64_init_encodestate(base64_encodestate* state_in) 22 | { 23 | state_in->step = step_A; 24 | state_in->result = 0; 25 | state_in->stepcount = 0; 26 | } 27 | 28 | char base64_encode_value(char value_in) 29 | { 30 | static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 31 | if (value_in > 63) return '='; 32 | return encoding[(int)value_in]; 33 | } 34 | 35 | int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in) 36 | { 37 | const char* plainchar = plaintext_in; 38 | const char* const plaintextend = plaintext_in + length_in; 39 | char* codechar = code_out; 40 | char result; 41 | char fragment; 42 | 43 | result = state_in->result; 44 | 45 | switch (state_in->step) 46 | { 47 | while (1) 48 | { 49 | case step_A: 50 | if (plainchar == plaintextend) 51 | { 52 | state_in->result = result; 53 | state_in->step = step_A; 54 | return codechar - code_out; 55 | } 56 | fragment = *plainchar++; 57 | result = (fragment & 0x0fc) >> 2; 58 | *codechar++ = base64_encode_value(result); 59 | result = (fragment & 0x003) << 4; 60 | case step_B: 61 | if (plainchar == plaintextend) 62 | { 63 | state_in->result = result; 64 | state_in->step = step_B; 65 | return codechar - code_out; 66 | } 67 | fragment = *plainchar++; 68 | result |= (fragment & 0x0f0) >> 4; 69 | *codechar++ = base64_encode_value(result); 70 | result = (fragment & 0x00f) << 2; 71 | case step_C: 72 | if (plainchar == plaintextend) 73 | { 74 | state_in->result = result; 75 | state_in->step = step_C; 76 | return codechar - code_out; 77 | } 78 | fragment = *plainchar++; 79 | result |= (fragment & 0x0c0) >> 6; 80 | *codechar++ = base64_encode_value(result); 81 | result = (fragment & 0x03f) >> 0; 82 | *codechar++ = base64_encode_value(result); 83 | 84 | ++(state_in->stepcount); 85 | if (state_in->stepcount == CHARS_PER_LINE/4) 86 | { 87 | *codechar++ = '\n'; 88 | state_in->stepcount = 0; 89 | } 90 | } 91 | } 92 | /* control should not reach here */ 93 | return codechar - code_out; 94 | } 95 | 96 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in) 97 | { 98 | char* codechar = code_out; 99 | 100 | switch (state_in->step) 101 | { 102 | case step_B: 103 | *codechar++ = base64_encode_value(state_in->result); 104 | *codechar++ = '='; 105 | *codechar++ = '='; 106 | break; 107 | case step_C: 108 | *codechar++ = base64_encode_value(state_in->result); 109 | *codechar++ = '='; 110 | break; 111 | case step_A: 112 | break; 113 | } 114 | *codechar++ = 0x00; 115 | 116 | return codechar - code_out; 117 | } 118 | 119 | #endif 120 | -------------------------------------------------------------------------------- /src/web/libb64/cencode_inc.h: -------------------------------------------------------------------------------- 1 | /* 2 | cencode.h - c header for a base64 encoding algorithm 3 | 4 | This is part of the libb64 project, and has been placed in the public domain. 5 | For details, see http://sourceforge.net/projects/libb64 6 | */ 7 | 8 | #ifndef BASE64_CENCODE_H 9 | #define BASE64_CENCODE_H 10 | 11 | typedef enum 12 | { 13 | step_A, step_B, step_C 14 | } base64_encodestep; 15 | 16 | typedef struct 17 | { 18 | base64_encodestep step; 19 | char result; 20 | int stepcount; 21 | } base64_encodestate; 22 | 23 | void base64_init_encodestate(base64_encodestate* state_in); 24 | 25 | char base64_encode_value(char value_in); 26 | 27 | int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); 28 | 29 | int base64_encode_blockend(char* code_out, base64_encodestate* state_in); 30 | 31 | #endif /* BASE64_CENCODE_H */ 32 | -------------------------------------------------------------------------------- /src/web/libsha1/libsha1.h: -------------------------------------------------------------------------------- 1 | /* ================ sha1.h ================ */ 2 | /* 3 | SHA-1 in C 4 | By Steve Reid 5 | 100% Public Domain 6 | */ 7 | 8 | #if !defined(ESP8266) && !defined(ESP32) 9 | 10 | typedef struct { 11 | uint32_t state[5]; 12 | uint32_t count[2]; 13 | unsigned char buffer[64]; 14 | } SHA1_CTX; 15 | 16 | void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]); 17 | void SHA1Init(SHA1_CTX* context); 18 | void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len); 19 | void SHA1Final(unsigned char digest[20], SHA1_CTX* context); 20 | 21 | #endif 22 | --------------------------------------------------------------------------------