├── .gitattributes ├── .gitignore ├── 01.Bootloaders ├── Microduino.rar └── README.txt ├── 02.Library ├── DHT11 │ ├── dht11.cpp │ ├── dht11.h │ └── examples │ │ └── basic │ │ └── basic.pde ├── EEPROM │ ├── EEPROM.cpp │ ├── EEPROM.h │ ├── examples │ │ ├── eeprom_clear │ │ │ └── eeprom_clear.ino │ │ ├── eeprom_read │ │ │ └── eeprom_read.ino │ │ └── eeprom_write │ │ │ └── eeprom_write.ino │ └── keywords.txt ├── IRremote │ ├── IRremote.cpp │ ├── IRremote.h │ ├── IRremoteInt.h │ ├── LICENSE.txt │ ├── examples │ │ ├── IRrecord │ │ │ └── IRrecord.pde │ │ ├── IRrecvDemo │ │ │ └── IRrecvDemo.pde │ │ ├── IRrecvDump │ │ │ └── IRrecvDump.pde │ │ ├── IRrelay │ │ │ └── IRrelay.pde │ │ ├── IRsendDemo │ │ │ └── IRsendDemo.pde │ │ └── IRtest │ │ │ └── IRtest.pde │ └── keywords.txt ├── PKJ │ ├── PKJ.cpp │ ├── PKJ.h │ └── examples │ │ ├── VOLtiaobian │ │ └── VOLtiaobian.pde │ │ └── VOLxianzhi │ │ └── VOLxianzhi.pde ├── README.txt ├── RF24 │ ├── .gitignore │ ├── Doxyfile │ ├── FAQ │ ├── README.md │ ├── RF24.cpp │ ├── RF24.h │ ├── RF24_config.h │ ├── doxygen-custom.css │ ├── examples │ │ ├── GettingStarted │ │ │ ├── GettingStarted.pde │ │ │ ├── Jamfile │ │ │ └── printf.h │ │ ├── led_remote │ │ │ ├── Jamfile │ │ │ ├── led_remote.pde │ │ │ └── printf.h │ │ ├── nordic_fob │ │ │ ├── Jamfile │ │ │ ├── nordic_fob.pde │ │ │ └── printf.h │ │ ├── pingpair │ │ │ ├── Jamfile │ │ │ ├── pingpair.pde │ │ │ └── printf.h │ │ ├── pingpair_dyn │ │ │ ├── Jamfile │ │ │ ├── pingpair_dyn.pde │ │ │ └── printf.h │ │ ├── pingpair_irq │ │ │ ├── Jamfile │ │ │ ├── pingpair_irq.pde │ │ │ └── printf.h │ │ ├── pingpair_maple │ │ │ ├── Jamfile │ │ │ ├── main.cpp │ │ │ └── pingpair_maple.pde │ │ ├── pingpair_pl │ │ │ ├── Jamfile │ │ │ ├── pingpair_pl.pde │ │ │ └── printf.h │ │ ├── pingpair_sleepy │ │ │ ├── Jamfile │ │ │ ├── pingpair_sleepy.pde │ │ │ └── printf.h │ │ ├── scanner │ │ │ ├── Jamfile │ │ │ ├── printf.h │ │ │ └── scanner.pde │ │ └── starping │ │ │ ├── Jamfile │ │ │ ├── printf.h │ │ │ └── starping.pde │ ├── keywords.txt │ ├── nRF24L01.h │ ├── tests │ │ ├── README │ │ ├── native │ │ │ ├── Jamfile │ │ │ ├── pingpair_irq.pde │ │ │ └── printf.h │ │ ├── pingpair_blocking │ │ │ ├── Jamfile │ │ │ ├── pingpair_blocking.pde │ │ │ ├── printf.h │ │ │ ├── runtest.py │ │ │ ├── runtests.sh │ │ │ └── test.ex │ │ └── pingpair_test │ │ │ ├── Jamfile │ │ │ ├── pingpair_test.pde │ │ │ ├── printf.h │ │ │ ├── runtest.py │ │ │ ├── runtests.sh │ │ │ └── test.ex │ └── wikidoc.xslt ├── RF24Network │ ├── .gitignore │ ├── Doxyfile │ ├── README.md │ ├── RF24Network.cpp │ ├── RF24Network.h │ ├── RF24Network_config.h │ ├── Sync.cpp │ ├── Sync.h │ ├── examples │ │ ├── helloworld_rx │ │ │ ├── .gitignore │ │ │ ├── Jamfile │ │ │ └── helloworld_rx.pde │ │ ├── helloworld_tx │ │ │ ├── .gitignore │ │ │ ├── Jamfile │ │ │ └── helloworld_tx.pde │ │ ├── maple │ │ │ ├── Jamfile │ │ │ ├── Jamrules │ │ │ ├── helloworld_tx.pde │ │ │ └── main.cpp │ │ ├── meshping │ │ │ ├── .gitignore │ │ │ ├── Jamfile │ │ │ ├── meshping.pde │ │ │ ├── nodeconfig.cpp │ │ │ ├── nodeconfig.h │ │ │ └── printf.h │ │ └── sensornet │ │ │ ├── .gitignore │ │ │ ├── DuinodeV1.h │ │ │ ├── DuinodeV3.h │ │ │ ├── DuinodeV5.h │ │ │ ├── Jamfile │ │ │ ├── S_message.cpp │ │ │ ├── S_message.h │ │ │ ├── duinode1.sh │ │ │ ├── duinode3.sh │ │ │ ├── duinode5.sh │ │ │ ├── nodeconfig.cpp │ │ │ ├── nodeconfig.h │ │ │ ├── printf.h │ │ │ ├── sensornet.pde │ │ │ ├── sleep.cpp │ │ │ ├── sleep.h │ │ │ └── timer.h │ └── tests.rar ├── SPI │ ├── SPI.cpp │ ├── SPI.h │ ├── examples │ │ ├── BarometricPressureSensor │ │ │ ├── BarometricPressureSensor.ino │ │ │ └── BarometricPressureSensor │ │ │ │ └── BarometricPressureSensor.ino │ │ └── DigitalPotControl │ │ │ └── DigitalPotControl.ino │ └── keywords.txt ├── U8glib │ ├── ChangeLog │ ├── INSTALL.TXT │ ├── U8glib.cpp │ ├── U8glib.h │ ├── examples │ │ ├── Bitmap │ │ │ └── Bitmap.pde │ │ ├── Chess │ │ │ └── Chess.pde │ │ ├── Console │ │ │ └── Console.pde │ │ ├── F │ │ │ └── F.pde │ │ ├── GraphicsTest │ │ │ └── GraphicsTest.pde │ │ ├── HelloWorld │ │ │ └── HelloWorld.pde │ │ ├── Menu │ │ │ └── Menu.pde │ │ ├── PrintTest │ │ │ └── PrintTest.pde │ │ ├── Rotation │ │ │ └── Rotation.pde │ │ ├── Scale │ │ │ └── Scale.pde │ │ ├── TextRotX │ │ │ └── TextRotX.pde │ │ ├── Touch4WSetup │ │ │ └── Touch4WSetup.pde │ │ ├── Touch4WTest │ │ │ └── Touch4WTest.pde │ │ ├── U8gLogo │ │ │ └── U8gLogo.pde │ │ └── XBM │ │ │ └── XBM.pde │ ├── license.txt │ └── utility │ │ ├── chessengine.c │ │ ├── u8g.h │ │ ├── u8g_bitmap.c │ │ ├── u8g_circle.c │ │ ├── u8g_clip.c │ │ ├── u8g_com_api.c │ │ ├── u8g_com_api_16gr.c │ │ ├── u8g_com_arduino_common.c │ │ ├── u8g_com_arduino_fast_parallel.c │ │ ├── u8g_com_arduino_hw_spi.c │ │ ├── u8g_com_arduino_no_en_parallel.c │ │ ├── u8g_com_arduino_parallel.c │ │ ├── u8g_com_arduino_port_d_wr.c │ │ ├── u8g_com_arduino_ssd_i2c.c │ │ ├── u8g_com_arduino_st7920_hw_spi.c │ │ ├── u8g_com_arduino_st7920_spi.c │ │ ├── u8g_com_arduino_std_sw_spi.c │ │ ├── u8g_com_arduino_sw_spi.c │ │ ├── u8g_com_arduino_t6963.c │ │ ├── u8g_com_atmega_hw_spi.c │ │ ├── u8g_com_atmega_parallel.c │ │ ├── u8g_com_atmega_st7920_hw_spi.c │ │ ├── u8g_com_atmega_st7920_spi.c │ │ ├── u8g_com_atmega_sw_spi.c │ │ ├── u8g_com_i2c.c │ │ ├── u8g_com_io.c │ │ ├── u8g_com_null.c │ │ ├── u8g_cursor.c │ │ ├── u8g_delay.c │ │ ├── u8g_dev_flipdisc_2x7.c │ │ ├── u8g_dev_gprof.c │ │ ├── u8g_dev_ili9325d_320x240.c │ │ ├── u8g_dev_ks0108_128x64.c │ │ ├── u8g_dev_lc7981_160x80.c │ │ ├── u8g_dev_lc7981_240x128.c │ │ ├── u8g_dev_lc7981_240x64.c │ │ ├── u8g_dev_lc7981_320x64.c │ │ ├── u8g_dev_null.c │ │ ├── u8g_dev_pcd8544_84x48.c │ │ ├── u8g_dev_pcf8812_96x65.c │ │ ├── u8g_dev_sbn1661_122x32.c │ │ ├── u8g_dev_ssd1306_128x32.c │ │ ├── u8g_dev_ssd1306_128x64.c │ │ ├── u8g_dev_ssd1309_128x64.c │ │ ├── u8g_dev_ssd1322_nhd31oled_bw.c │ │ ├── u8g_dev_ssd1322_nhd31oled_gr.c │ │ ├── u8g_dev_ssd1325_nhd27oled_bw.c │ │ ├── u8g_dev_ssd1325_nhd27oled_bw_new.c │ │ ├── u8g_dev_ssd1325_nhd27oled_gr.c │ │ ├── u8g_dev_ssd1325_nhd27oled_gr_new.c │ │ ├── u8g_dev_ssd1327_96x96_gr.c │ │ ├── u8g_dev_st7565_64128n.c │ │ ├── u8g_dev_st7565_dogm128.c │ │ ├── u8g_dev_st7565_dogm132.c │ │ ├── u8g_dev_st7565_lm6059.c │ │ ├── u8g_dev_st7565_lm6063.c │ │ ├── u8g_dev_st7565_nhd_c12832.c │ │ ├── u8g_dev_st7565_nhd_c12864.c │ │ ├── u8g_dev_st7687_c144mvgd.c │ │ ├── u8g_dev_st7920_128x64.c │ │ ├── u8g_dev_st7920_192x32.c │ │ ├── u8g_dev_st7920_202x32.c │ │ ├── u8g_dev_t6963_128x64.c │ │ ├── u8g_dev_t6963_240x128.c │ │ ├── u8g_dev_t6963_240x64.c │ │ ├── u8g_dev_tls8204_84x48.c │ │ ├── u8g_dev_uc1610_dogxl160.c │ │ ├── u8g_dev_uc1701_dogs102.c │ │ ├── u8g_dev_uc1701_mini12864.c │ │ ├── u8g_ellipse.c │ │ ├── u8g_font.c │ │ ├── u8g_font_data.c │ │ ├── u8g_line.c │ │ ├── u8g_ll_api.c │ │ ├── u8g_page.c │ │ ├── u8g_pb.c │ │ ├── u8g_pb14v1.c │ │ ├── u8g_pb16h1.c │ │ ├── u8g_pb16h2.c │ │ ├── u8g_pb16v1.c │ │ ├── u8g_pb16v2.c │ │ ├── u8g_pb32h1.c │ │ ├── u8g_pb8h1.c │ │ ├── u8g_pb8h1f.c │ │ ├── u8g_pb8h2.c │ │ ├── u8g_pb8h8.c │ │ ├── u8g_pb8v1.c │ │ ├── u8g_pb8v2.c │ │ ├── u8g_rect.c │ │ ├── u8g_rot.c │ │ ├── u8g_scale.c │ │ ├── u8g_state.c │ │ ├── u8g_u16toa.c │ │ ├── u8g_u8toa.c │ │ └── u8g_virtual_screen.c ├── Wire │ ├── Wire.cpp │ ├── Wire.h │ ├── examples │ │ ├── SFRRanger_reader │ │ │ └── SFRRanger_reader.ino │ │ ├── digital_potentiometer │ │ │ └── digital_potentiometer.ino │ │ ├── master_reader │ │ │ └── master_reader.ino │ │ ├── master_writer │ │ │ └── master_writer.ino │ │ ├── slave_receiver │ │ │ └── slave_receiver.ino │ │ └── slave_sender │ │ │ └── slave_sender.ino │ ├── keywords.txt │ └── utility │ │ ├── twi.c │ │ └── twi.h └── ethercard │ ├── .gitignore │ ├── Doxyfile │ ├── Doxylogo.png │ ├── Doxymods.css │ ├── EtherCard.cpp │ ├── EtherCard.h │ ├── README.md │ ├── dhcp.cpp │ ├── dns.cpp │ ├── enc28j60.cpp │ ├── enc28j60.h │ ├── examples │ ├── JeeUdp │ │ └── JeeUdp.ino │ ├── backSoon │ │ └── backSoon.ino │ ├── etherNode │ │ └── etherNode.ino │ ├── getDHCPandDNS │ │ └── getDHCPandDNS.ino │ ├── getStaticIP │ │ └── getStaticIP.ino │ ├── getViaDNS │ │ └── getViaDNS.ino │ ├── nanether │ │ └── nanether.ino │ ├── noipClient │ │ └── noipClient.ino │ ├── pachube │ │ └── pachube.ino │ ├── pings │ │ └── pings.ino │ ├── rbbb_server │ │ └── rbbb_server.ino │ ├── stashTest │ │ └── stashTest.ino │ ├── testDHCP │ │ └── testDHCP.ino │ ├── twitter │ │ └── twitter.ino │ └── webClient │ │ └── webClient.ino │ ├── net.h │ ├── tcpip.cpp │ ├── tcpip.rar │ └── webutil.cpp ├── 03.Program ├── main_v0.8 │ └── main_v0.8.ino ├── 主机 - Microduino V0.1.c ├── 主机 - Microduino V0.2.c ├── 主机 - Microduino V0.3.c ├── 主机 - 通用 V0.4.ino ├── 主机 - 通用 V0.5.ino ├── 主机 - 通用 V0.6.ino ├── 主机 - 通用 V0.7.ino ├── 主机 - 通用 V0.8(SHT11).ino ├── 主机 - 通用 V0.8.ino ├── 主机 V0.1.c ├── 主机 V0.2.c ├── 主机 V0.3.c ├── 主机eeprom.bin ├── 从机 多路 V0.1.c ├── 从机 节点 V0.1.c └── 从机 节点 V0.2.c ├── 04.PCB ├── README.txt ├── 主机 Microduino v0.1.brd ├── 主机 Microduino v0.1.sch ├── 主机 Microduino v0.5.brd ├── 主机 Microduino v0.5.sch ├── 主机 Microduino v1.0.brd ├── 主机 Microduino v1.0.sch ├── 主机 v0.1.brd ├── 主机 v0.1.sch ├── 主机 v0.2.brd ├── 主机 v0.2.sch ├── 副机 多路式 v0.1.brd ├── 副机 多路式 v0.1.sch ├── 副机 插座 v0.1.brd ├── 副机 插座 v0.1.sch ├── 副机 插座 v0.2.brd ├── 副机 插座 v0.2.sch ├── 副机 插座 v0.3.brd ├── 副机 插座 v0.3.sch ├── 副机 插座 v0.4.brd ├── 副机 插座 v0.4.sch ├── 副机 插座 v1.0.brd ├── 副机 插座 v1.0.sch ├── 可控硅控制.brd └── 可控硅控制.sch ├── README.txt └── web.rar /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /01.Bootloaders/Microduino.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/01.Bootloaders/Microduino.rar -------------------------------------------------------------------------------- /01.Bootloaders/README.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/01.Bootloaders/README.txt -------------------------------------------------------------------------------- /02.Library/DHT11/dht11.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: dht11.cpp 3 | // VERSION: 0.4.1 4 | // PURPOSE: DHT11 Temperature & Humidity Sensor library for Arduino 5 | // LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html) 6 | // 7 | // DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf 8 | // 9 | // HISTORY: 10 | // George Hadjikyriacou - Original version (??) 11 | // Mod by SimKard - Version 0.2 (24/11/2010) 12 | // Mod by Rob Tillaart - Version 0.3 (28/03/2011) 13 | // + added comments 14 | // + removed all non DHT11 specific code 15 | // + added references 16 | // Mod by Rob Tillaart - Version 0.4 (17/03/2012) 17 | // + added 1.0 support 18 | // Mod by Rob Tillaart - Version 0.4.1 (19/05/2012) 19 | // + added error codes 20 | // 21 | 22 | #include "dht11.h" 23 | 24 | // Return values: 25 | // DHTLIB_OK 26 | // DHTLIB_ERROR_CHECKSUM 27 | // DHTLIB_ERROR_TIMEOUT 28 | int dht11::read(int pin) 29 | { 30 | // BUFFER TO RECEIVE 31 | uint8_t bits[5]; 32 | uint8_t cnt = 7; 33 | uint8_t idx = 0; 34 | 35 | // EMPTY BUFFER 36 | for (int i=0; i< 5; i++) bits[i] = 0; 37 | 38 | // REQUEST SAMPLE 39 | pinMode(pin, OUTPUT); 40 | digitalWrite(pin, LOW); 41 | delay(18); 42 | digitalWrite(pin, HIGH); 43 | delayMicroseconds(40); 44 | pinMode(pin, INPUT); 45 | 46 | // ACKNOWLEDGE or TIMEOUT 47 | unsigned int loopCnt = 10000; 48 | while(digitalRead(pin) == LOW) 49 | if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT; 50 | 51 | loopCnt = 10000; 52 | while(digitalRead(pin) == HIGH) 53 | if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT; 54 | 55 | // READ OUTPUT - 40 BITS => 5 BYTES or TIMEOUT 56 | for (int i=0; i<40; i++) 57 | { 58 | loopCnt = 10000; 59 | while(digitalRead(pin) == LOW) 60 | if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT; 61 | 62 | unsigned long t = micros(); 63 | 64 | loopCnt = 10000; 65 | while(digitalRead(pin) == HIGH) 66 | if (loopCnt-- == 0) return DHTLIB_ERROR_TIMEOUT; 67 | 68 | if ((micros() - t) > 40) bits[idx] |= (1 << cnt); 69 | if (cnt == 0) // next byte? 70 | { 71 | cnt = 7; // restart at MSB 72 | idx++; // next byte! 73 | } 74 | else cnt--; 75 | } 76 | 77 | // WRITE TO RIGHT VARS 78 | // as bits[1] and bits[3] are allways zero they are omitted in formulas. 79 | humidity = bits[0]; 80 | temperature = bits[2]; 81 | 82 | uint8_t sum = bits[0] + bits[2]; 83 | 84 | if (bits[4] != sum) return DHTLIB_ERROR_CHECKSUM; 85 | return DHTLIB_OK; 86 | } 87 | // 88 | // END OF FILE 89 | // -------------------------------------------------------------------------------- /02.Library/DHT11/dht11.h: -------------------------------------------------------------------------------- 1 | // 2 | // FILE: dht11.h 3 | // VERSION: 0.4.1 4 | // PURPOSE: DHT11 Temperature & Humidity Sensor library for Arduino 5 | // LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html) 6 | // 7 | // DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf 8 | // 9 | // URL: http://arduino.cc/playground/Main/DHT11Lib 10 | // 11 | // HISTORY: 12 | // George Hadjikyriacou - Original version 13 | // see dht.cpp file 14 | // 15 | 16 | #ifndef dht11_h 17 | #define dht11_h 18 | 19 | #if defined(ARDUINO) && (ARDUINO >= 100) 20 | #include 21 | #else 22 | #include 23 | #endif 24 | 25 | #define DHT11LIB_VERSION "0.4.1" 26 | 27 | #define DHTLIB_OK 0 28 | #define DHTLIB_ERROR_CHECKSUM -1 29 | #define DHTLIB_ERROR_TIMEOUT -2 30 | 31 | class dht11 32 | { 33 | public: 34 | int read(int pin); 35 | int humidity; 36 | int temperature; 37 | }; 38 | #endif 39 | // 40 | // END OF FILE 41 | // -------------------------------------------------------------------------------- /02.Library/DHT11/examples/basic/basic.pde: -------------------------------------------------------------------------------- 1 | #include 2 | dht11 DHT11; 3 | #define DHT11PIN 3 //DHT11 PIN 3 ????UNO 3 4 | 5 | void setup() 6 | { 7 | Serial.begin(9600); 8 | Serial.println("DHT11 TEST PROGRAM "); 9 | Serial.print("LIBRARY VERSION: "); 10 | Serial.println(DHT11LIB_VERSION); 11 | Serial.println(); 12 | } 13 | 14 | void loop() 15 | { 16 | Serial.println("\n"); 17 | 18 | int chk = DHT11.read(DHT11PIN); 19 | 20 | Serial.print("Read sensor: "); 21 | switch (chk) 22 | { 23 | case DHTLIB_OK: 24 | Serial.println("OK"); 25 | break; 26 | case DHTLIB_ERROR_CHECKSUM: 27 | Serial.println("Checksum error"); 28 | break; 29 | case DHTLIB_ERROR_TIMEOUT: 30 | Serial.println("Time out error"); 31 | break; 32 | default: 33 | Serial.println("Unknown error"); 34 | break; 35 | } 36 | Serial.print("Humidity (%): "); 37 | Serial.println((float)DHT11.humidity, 2); 38 | Serial.print("Temperature (oC): "); 39 | Serial.println((float)DHT11.temperature-2, 2); 40 | delay(2000); 41 | } -------------------------------------------------------------------------------- /02.Library/EEPROM/EEPROM.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | EEPROM.cpp - EEPROM library 3 | Copyright (c) 2006 David A. Mellis. 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 | /****************************************************************************** 21 | * Includes 22 | ******************************************************************************/ 23 | 24 | #include 25 | #include "Arduino.h" 26 | #include "EEPROM.h" 27 | 28 | /****************************************************************************** 29 | * Definitions 30 | ******************************************************************************/ 31 | 32 | /****************************************************************************** 33 | * Constructors 34 | ******************************************************************************/ 35 | 36 | /****************************************************************************** 37 | * User API 38 | ******************************************************************************/ 39 | 40 | uint8_t EEPROMClass::read(int address) 41 | { 42 | return eeprom_read_byte((unsigned char *) address); 43 | } 44 | 45 | void EEPROMClass::write(int address, uint8_t value) 46 | { 47 | eeprom_write_byte((unsigned char *) address, value); 48 | } 49 | 50 | EEPROMClass EEPROM; 51 | -------------------------------------------------------------------------------- /02.Library/EEPROM/EEPROM.h: -------------------------------------------------------------------------------- 1 | /* 2 | EEPROM.h - EEPROM library 3 | Copyright (c) 2006 David A. Mellis. 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 EEPROM_h 21 | #define EEPROM_h 22 | 23 | #include 24 | 25 | class EEPROMClass 26 | { 27 | public: 28 | uint8_t read(int); 29 | void write(int, uint8_t); 30 | }; 31 | 32 | extern EEPROMClass EEPROM; 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /02.Library/EEPROM/examples/eeprom_clear/eeprom_clear.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Clear 3 | * 4 | * Sets all of the bytes of the EEPROM to 0. 5 | * This example code is in the public domain. 6 | 7 | */ 8 | 9 | #include 10 | 11 | void setup() 12 | { 13 | // write a 0 to all 512 bytes of the EEPROM 14 | for (int i = 0; i < 512; i++) 15 | EEPROM.write(i, 0); 16 | 17 | // turn the LED on when we're done 18 | digitalWrite(13, HIGH); 19 | } 20 | 21 | void loop() 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /02.Library/EEPROM/examples/eeprom_read/eeprom_read.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Read 3 | * 4 | * Reads the value of each byte of the EEPROM and prints it 5 | * to the computer. 6 | * This example code is in the public domain. 7 | */ 8 | 9 | #include 10 | 11 | // start reading from the first byte (address 0) of the EEPROM 12 | int address = 0; 13 | byte value; 14 | 15 | void setup() 16 | { 17 | // initialize serial and wait for port to open: 18 | Serial.begin(9600); 19 | while (!Serial) { 20 | ; // wait for serial port to connect. Needed for Leonardo only 21 | } 22 | } 23 | 24 | void loop() 25 | { 26 | // read a byte from the current address of the EEPROM 27 | value = EEPROM.read(address); 28 | 29 | Serial.print(address); 30 | Serial.print("\t"); 31 | Serial.print(value, DEC); 32 | Serial.println(); 33 | 34 | // advance to the next address of the EEPROM 35 | address = address + 1; 36 | 37 | // there are only 512 bytes of EEPROM, from 0 to 511, so if we're 38 | // on address 512, wrap around to address 0 39 | if (address == 512) 40 | address = 0; 41 | 42 | delay(500); 43 | } 44 | -------------------------------------------------------------------------------- /02.Library/EEPROM/examples/eeprom_write/eeprom_write.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * EEPROM Write 3 | * 4 | * Stores values read from analog input 0 into the EEPROM. 5 | * These values will stay in the EEPROM when the board is 6 | * turned off and may be retrieved later by another sketch. 7 | */ 8 | 9 | #include 10 | 11 | // the current address in the EEPROM (i.e. which byte 12 | // we're going to write to next) 13 | int addr = 0; 14 | 15 | void setup() 16 | { 17 | } 18 | 19 | void loop() 20 | { 21 | // need to divide by 4 because analog inputs range from 22 | // 0 to 1023 and each byte of the EEPROM can only hold a 23 | // value from 0 to 255. 24 | int val = analogRead(0) / 4; 25 | 26 | // write the value to the appropriate byte of the EEPROM. 27 | // these values will remain there when the board is 28 | // turned off. 29 | EEPROM.write(addr, val); 30 | 31 | // advance to the next address. there are 512 bytes in 32 | // the EEPROM, so go back to 0 when we hit 512. 33 | addr = addr + 1; 34 | if (addr == 512) 35 | addr = 0; 36 | 37 | delay(100); 38 | } 39 | -------------------------------------------------------------------------------- /02.Library/EEPROM/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Ultrasound 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | EEPROM KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | ####################################### 16 | # Constants (LITERAL1) 17 | ####################################### 18 | 19 | -------------------------------------------------------------------------------- /02.Library/IRremote/IRremote.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote 3 | * Version 0.1 July, 2009 4 | * Copyright 2009 Ken Shirriff 5 | * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.htm http://arcfn.com 6 | * 7 | * Interrupt code based on NECIRrcv by Joe Knapp 8 | * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 9 | * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ 10 | */ 11 | 12 | #ifndef IRremote_h 13 | #define IRremote_h 14 | 15 | // The following are compile-time library options. 16 | // If you change them, recompile the library. 17 | // If DEBUG is defined, a lot of debugging output will be printed during decoding. 18 | // TEST must be defined for the IRtest unittests to work. It will make some 19 | // methods virtual, which will be slightly slower, which is why it is optional. 20 | // #define DEBUG 21 | // #define TEST 22 | 23 | // Results returned from the decoder 24 | class decode_results { 25 | public: 26 | int decode_type; // NEC, SONY, RC5, UNKNOWN 27 | unsigned long value; // Decoded value 28 | int bits; // Number of bits in decoded value 29 | volatile unsigned int *rawbuf; // Raw intervals in .5 us ticks 30 | int rawlen; // Number of records in rawbuf. 31 | }; 32 | 33 | // Values for decode_type 34 | #define NEC 1 35 | #define SONY 2 36 | #define RC5 3 37 | #define RC6 4 38 | #define UNKNOWN -1 39 | 40 | // Decoded value for NEC when a repeat code is received 41 | #define REPEAT 0xffffffff 42 | 43 | // main class for receiving IR 44 | class IRrecv 45 | { 46 | public: 47 | IRrecv(int recvpin); 48 | void blinkLED(int blinkflag); 49 | int decode(decode_results *results); 50 | void enableIRIn(); 51 | void resume(); 52 | private: 53 | // These are called by decode 54 | int getRClevel(decode_results *results, int *offset, int *used, int t1); 55 | long decodeNEC(decode_results *results); 56 | long decodeSony(decode_results *results); 57 | long decodeRC5(decode_results *results); 58 | long decodeRC6(decode_results *results); 59 | } 60 | ; 61 | 62 | // Only used for testing; can remove virtual for shorter code 63 | #ifdef TEST 64 | #define VIRTUAL virtual 65 | #else 66 | #define VIRTUAL 67 | #endif 68 | 69 | class IRsend 70 | { 71 | public: 72 | IRsend() {} 73 | void sendNEC(unsigned long data, int nbits); 74 | void sendSony(unsigned long data, int nbits); 75 | void sendRaw(unsigned int buf[], int len, int hz); 76 | void sendRC5(unsigned long data, int nbits); 77 | void sendRC6(unsigned long data, int nbits); 78 | // private: 79 | void enableIROut(int khz); 80 | VIRTUAL void mark(int usec); 81 | VIRTUAL void space(int usec); 82 | } 83 | ; 84 | 85 | // Some useful constants 86 | 87 | #define USECPERTICK 50 // microseconds per clock interrupt tick 88 | #define RAWBUF 76 // Length of raw duration buffer 89 | 90 | // Marks tend to be 100us too long, and spaces 100us too short 91 | // when received due to sensor lag. 92 | #define MARK_EXCESS 100 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /02.Library/IRremote/IRremoteInt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote 3 | * Version 0.1 July, 2009 4 | * Copyright 2009 Ken Shirriff 5 | * For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html 6 | * 7 | * Interrupt code based on NECIRrcv by Joe Knapp 8 | * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556 9 | * Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/ 10 | */ 11 | 12 | #ifndef IRremoteint_h 13 | #define IRremoteint_h 14 | 15 | #if ARDUINO >= 100 16 | #include 17 | #else 18 | #include 19 | #endif 20 | 21 | #define CLKFUDGE 5 // fudge factor for clock interrupt overhead 22 | #define CLK 256 // max value for clock (timer 2) 23 | #define PRESCALE 8 // timer2 clock prescale 24 | #define SYSCLOCK 16000000 // main Arduino clock 25 | #define CLKSPERUSEC (SYSCLOCK/PRESCALE/1000000) // timer clocks per microsecond 26 | 27 | #define ERR 0 28 | #define DECODED 1 29 | 30 | #define BLINKLED 4 31 | 32 | // defines for setting and clearing register bits 33 | #ifndef cbi 34 | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) 35 | #endif 36 | #ifndef sbi 37 | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) 38 | #endif 39 | 40 | // clock timer reset value 41 | #define INIT_TIMER_COUNT2 (CLK - USECPERTICK*CLKSPERUSEC + CLKFUDGE) 42 | #define RESET_TIMER2 TCNT2 = INIT_TIMER_COUNT2 43 | 44 | // pulse parameters in usec 45 | #define NEC_HDR_MARK 9000 46 | #define NEC_HDR_SPACE 4500 47 | #define NEC_BIT_MARK 560 48 | #define NEC_ONE_SPACE 1600 49 | #define NEC_ZERO_SPACE 560 50 | #define NEC_RPT_SPACE 2250 51 | 52 | #define SONY_HDR_MARK 2400 53 | #define SONY_HDR_SPACE 600 54 | #define SONY_ONE_MARK 1200 55 | #define SONY_ZERO_MARK 600 56 | #define SONY_RPT_LENGTH 45000 57 | 58 | #define RC5_T1 889 59 | #define RC5_RPT_LENGTH 46000 60 | 61 | #define RC6_HDR_MARK 2666 62 | #define RC6_HDR_SPACE 889 63 | #define RC6_T1 444 64 | #define RC6_RPT_LENGTH 46000 65 | 66 | #define TOLERANCE 25 // percent tolerance in measurements 67 | #define LTOL (1.0 - TOLERANCE/100.) 68 | #define UTOL (1.0 + TOLERANCE/100.) 69 | 70 | #define _GAP 5000 // Minimum map between transmissions 71 | #define GAP_TICKS (_GAP/USECPERTICK) 72 | 73 | #define TICKS_LOW(us) (int) (((us)*LTOL/USECPERTICK)) 74 | #define TICKS_HIGH(us) (int) (((us)*UTOL/USECPERTICK + 1)) 75 | 76 | #ifndef DEBUG 77 | #define MATCH(measured_ticks, desired_us) ((measured_ticks) >= TICKS_LOW(desired_us) && (measured_ticks) <= TICKS_HIGH(desired_us)) 78 | #define MATCH_MARK(measured_ticks, desired_us) MATCH(measured_ticks, (desired_us) + MARK_EXCESS) 79 | #define MATCH_SPACE(measured_ticks, desired_us) MATCH((measured_ticks), (desired_us) - MARK_EXCESS) 80 | // Debugging versions are in IRremote.cpp 81 | #endif 82 | 83 | // receiver states 84 | #define STATE_IDLE 2 85 | #define STATE_MARK 3 86 | #define STATE_SPACE 4 87 | #define STATE_STOP 5 88 | 89 | // information for the interrupt handler 90 | typedef struct { 91 | uint8_t recvpin; // pin for IR data from detector 92 | uint8_t rcvstate; // state machine 93 | uint8_t blinkflag; // TRUE to enable blinking of pin 13 on IR processing 94 | unsigned int timer; // state timer, counts 50uS ticks. 95 | unsigned int rawbuf[RAWBUF]; // raw data 96 | uint8_t rawlen; // counter of entries in rawbuf 97 | } 98 | irparams_t; 99 | 100 | // Defined in IRremote.cpp 101 | extern volatile irparams_t irparams; 102 | 103 | // IR detector output is active low 104 | #define MARK 0 105 | #define SPACE 1 106 | 107 | #define TOPBIT 0x80000000 108 | 109 | #define NEC_BITS 32 110 | #define SONY_BITS 12 111 | #define MIN_RC5_SAMPLES 11 112 | #define MIN_RC6_SAMPLES 1 113 | 114 | #endif 115 | 116 | -------------------------------------------------------------------------------- /02.Library/IRremote/examples/IRrecvDemo/IRrecvDemo.pde: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv 3 | * An IR detector/demodulator must be connected to the input RECV_PIN. 4 | * Version 0.1 July, 2009 5 | * Copyright 2009 Ken Shirriff 6 | * http://arcfn.com 7 | */ 8 | 9 | #include 10 | 11 | int RECV_PIN = 11; 12 | 13 | IRrecv irrecv(RECV_PIN); 14 | 15 | decode_results results; 16 | 17 | void setup() 18 | { 19 | Serial.begin(9600); 20 | irrecv.enableIRIn(); // Start the receiver 21 | } 22 | 23 | void loop() { 24 | if (irrecv.decode(&results)) { 25 | Serial.println(results.value, HEX); 26 | irrecv.resume(); // Receive the next value 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /02.Library/IRremote/examples/IRrecvDump/IRrecvDump.pde: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote: IRrecvDump - dump details of IR codes with IRrecv 3 | * An IR detector/demodulator must be connected to the input RECV_PIN. 4 | * Version 0.1 July, 2009 5 | * Copyright 2009 Ken Shirriff 6 | * http://arcfn.com 7 | */ 8 | 9 | #include 10 | 11 | int RECV_PIN = 11; 12 | 13 | IRrecv irrecv(RECV_PIN); 14 | 15 | decode_results results; 16 | 17 | void setup() 18 | { 19 | Serial.begin(9600); 20 | irrecv.enableIRIn(); // Start the receiver 21 | } 22 | 23 | // Dumps out the decode_results structure. 24 | // Call this after IRrecv::decode() 25 | // void * to work around compiler issue 26 | //void dump(void *v) { 27 | // decode_results *results = (decode_results *)v 28 | void dump(decode_results *results) { 29 | int count = results->rawlen; 30 | if (results->decode_type == UNKNOWN) { 31 | Serial.println("Could not decode message"); 32 | } 33 | else { 34 | if (results->decode_type == NEC) { 35 | Serial.print("Decoded NEC: "); 36 | } 37 | else if (results->decode_type == SONY) { 38 | Serial.print("Decoded SONY: "); 39 | } 40 | else if (results->decode_type == RC5) { 41 | Serial.print("Decoded RC5: "); 42 | } 43 | else if (results->decode_type == RC6) { 44 | Serial.print("Decoded RC6: "); 45 | } 46 | Serial.print(results->value, HEX); 47 | Serial.print(" ("); 48 | Serial.print(results->bits, DEC); 49 | Serial.println(" bits)"); 50 | } 51 | Serial.print("Raw ("); 52 | Serial.print(count, DEC); 53 | Serial.print("): "); 54 | 55 | for (int i = 0; i < count; i++) { 56 | if ((i % 2) == 1) { 57 | Serial.print(results->rawbuf[i]*USECPERTICK, DEC); 58 | } 59 | else { 60 | Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC); 61 | } 62 | Serial.print(" "); 63 | } 64 | Serial.println(""); 65 | } 66 | 67 | 68 | void loop() { 69 | if (irrecv.decode(&results)) { 70 | Serial.println(results.value, HEX); 71 | dump(&results); 72 | irrecv.resume(); // Receive the next value 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /02.Library/IRremote/examples/IRrelay/IRrelay.pde: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv 3 | * An IR detector/demodulator must be connected to the input RECV_PIN. 4 | * Version 0.1 July, 2009 5 | * Copyright 2009 Ken Shirriff 6 | * http://arcfn.com 7 | */ 8 | 9 | #include 10 | 11 | int RECV_PIN = 11; 12 | int RELAY_PIN = 4; 13 | 14 | IRrecv irrecv(RECV_PIN); 15 | decode_results results; 16 | 17 | // Dumps out the decode_results structure. 18 | // Call this after IRrecv::decode() 19 | // void * to work around compiler issue 20 | //void dump(void *v) { 21 | // decode_results *results = (decode_results *)v 22 | void dump(decode_results *results) { 23 | int count = results->rawlen; 24 | if (results->decode_type == UNKNOWN) { 25 | Serial.println("Could not decode message"); 26 | } 27 | else { 28 | if (results->decode_type == NEC) { 29 | Serial.print("Decoded NEC: "); 30 | } 31 | else if (results->decode_type == SONY) { 32 | Serial.print("Decoded SONY: "); 33 | } 34 | else if (results->decode_type == RC5) { 35 | Serial.print("Decoded RC5: "); 36 | } 37 | else if (results->decode_type == RC6) { 38 | Serial.print("Decoded RC6: "); 39 | } 40 | Serial.print(results->value, HEX); 41 | Serial.print(" ("); 42 | Serial.print(results->bits, DEC); 43 | Serial.println(" bits)"); 44 | } 45 | Serial.print("Raw ("); 46 | Serial.print(count, DEC); 47 | Serial.print("): "); 48 | 49 | for (int i = 0; i < count; i++) { 50 | if ((i % 2) == 1) { 51 | Serial.print(results->rawbuf[i]*USECPERTICK, DEC); 52 | } 53 | else { 54 | Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC); 55 | } 56 | Serial.print(" "); 57 | } 58 | Serial.println(""); 59 | } 60 | 61 | void setup() 62 | { 63 | pinMode(RELAY_PIN, OUTPUT); 64 | pinMode(13, OUTPUT); 65 | Serial.begin(9600); 66 | irrecv.enableIRIn(); // Start the receiver 67 | } 68 | 69 | int on = 0; 70 | unsigned long last = millis(); 71 | 72 | void loop() { 73 | if (irrecv.decode(&results)) { 74 | // If it's been at least 1/4 second since the last 75 | // IR received, toggle the relay 76 | if (millis() - last > 250) { 77 | on = !on; 78 | digitalWrite(RELAY_PIN, on ? HIGH : LOW); 79 | digitalWrite(13, on ? HIGH : LOW); 80 | dump(&results); 81 | } 82 | last = millis(); 83 | irrecv.resume(); // Receive the next value 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /02.Library/IRremote/examples/IRsendDemo/IRsendDemo.pde: -------------------------------------------------------------------------------- 1 | /* 2 | * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend 3 | * An IR LED must be connected to Arduino PWM pin 3. 4 | * Version 0.1 July, 2009 5 | * Copyright 2009 Ken Shirriff 6 | * http://arcfn.com 7 | */ 8 | 9 | #include 10 | 11 | IRsend irsend; 12 | 13 | void setup() 14 | { 15 | Serial.begin(9600); 16 | } 17 | 18 | void loop() { 19 | if (Serial.read() != -1) { 20 | for (int i = 0; i < 3; i++) { 21 | irsend.sendSony(0xa90, 12); // Sony TV power code 22 | delay(100); 23 | } 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /02.Library/IRremote/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For IRremote 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | decode_results KEYWORD1 10 | IRrecv KEYWORD1 11 | IRsend KEYWORD1 12 | 13 | ####################################### 14 | # Methods and Functions (KEYWORD2) 15 | ####################################### 16 | 17 | blink13 KEYWORD2 18 | decode KEYWORD2 19 | enableIRIn KEYWORD2 20 | resume KEYWORD2 21 | enableIROut KEYWORD2 22 | sendNEC KEYWORD2 23 | sendSony KEYWORD2 24 | sendRaw KEYWORD2 25 | sendRC5 KEYWORD2 26 | sendRC6 KEYWORD2 27 | # 28 | ####################################### 29 | # Constants (LITERAL1) 30 | ####################################### 31 | 32 | NEC LITERAL1 33 | SONY LITERAL1 34 | RC5 LITERAL1 35 | RC6 LITERAL1 36 | UNKNOWN LITERAL1 37 | REPEAT LITERAL1 38 | -------------------------------------------------------------------------------- /02.Library/PKJ/PKJ.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "PKJ.h" 3 | 4 | int PKJ::VOLxianzhi(int _num,int _volL,int _volH) 5 | { 6 | if (_num>_volH) 7 | _num=_volH; 8 | if(_num<_volL) 9 | _num=_volL; 10 | return _num; 11 | } 12 | 13 | int PKJ::VOLtiaobian(int _num,int _volL,int _volH) 14 | { 15 | if (_num>_volH) 16 | _num=_volL; 17 | if(_num<_volL) 18 | _num=_volH; 19 | return _num; 20 | } 21 | -------------------------------------------------------------------------------- /02.Library/PKJ/PKJ.h: -------------------------------------------------------------------------------- 1 | #ifndef PKJ_h 2 | #define PKJ_h 3 | 4 | #include "Arduino.h" 5 | 6 | class PKJ 7 | { 8 | public: 9 | int VOLxianzhi(int,int,int); 10 | int VOLtiaobian(int,int,int); 11 | private: 12 | int _num; 13 | int _volL; 14 | int _volH; 15 | }; 16 | 17 | #endif -------------------------------------------------------------------------------- /02.Library/PKJ/examples/VOLtiaobian/VOLtiaobian.pde: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/02.Library/PKJ/examples/VOLtiaobian/VOLtiaobian.pde -------------------------------------------------------------------------------- /02.Library/PKJ/examples/VOLxianzhi/VOLxianzhi.pde: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/02.Library/PKJ/examples/VOLxianzhi/VOLxianzhi.pde -------------------------------------------------------------------------------- /02.Library/README.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/02.Library/README.txt -------------------------------------------------------------------------------- /02.Library/RF24/.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | *.o 3 | .*.swp 4 | *.orig 5 | .swp 6 | docs/ 7 | output/ 8 | ojam/ 9 | out/ 10 | 16000000/ 11 | 8000000/ 12 | out_native/ 13 | version.h 14 | Session.vim 15 | -------------------------------------------------------------------------------- /02.Library/RF24/FAQ: -------------------------------------------------------------------------------- 1 | /** 2 | * @page FAQ Frequently Asked Questions 3 | * 4 | * @ref starting 5 | * 6 | * @ref hardware 7 | * 8 | * @ref range 9 | * 10 | * @ref issues 11 | * 12 | * @ref ram 13 | * 14 | * @ref tests 15 | * 16 | * @section starting Where do I start? 17 | * 18 | * See my blog post: 19 | * Getting Started with nRF24L01+ on Arduino 20 | * 21 | * @section hardware Where can I buy some hardware? 22 | * 23 | * @li iTeadStudio sells the basic 2.4G Wireless nRF24L01+ Module for $4. Such a deal! 24 | * @li MDfly.com sells the same unit, 2.4Ghz Wireless nRF24L01+ Transceiver Module for $6.95, but it ships from the US so it gets there a lot faster. Great place to get a few units and get started quickly. 25 | * @li MDfly.com also has the nRF24L01 2.4GHz Transceiver Module w/ Power Amplifier for $13.95, which increases range dramatically and uses a chip antenna 26 | * @li MDfly.com also has the 2.4GHz Transceiver Module w/ Power Amplifier with an external antenna for $19.95 27 | * 28 | * @section range What is the range of these units? 29 | * 30 | * Here are some results from measurements I have taken, using the basic $4 iTeadStudio units. 31 | * I recommend that everyone take their own measurements in their particular circumstances. 32 | * 33 | * @li non-plus unit, 2MBps (worst case), 41+ ft line of sight indoors, immediate dropoff with any deviation from LOS. (41 ft is as far as I can go in my house without turning a corner) 34 | * @li Plus unit, 250kbps (best case), 46 ft around two corners indoors, 49 ft around one corner. More importantly, at 250k, packet loss is almost negligible through almost all of that range. 35 | * @li Both units at 1MBps, plus unit gets about 10% range improvement over non-plus in almost all situations. 36 | * 37 | * @section issues What should I do if I find a problem? 38 | * 39 | * Please open an issue on github if you find any problems using it with any version of Arduino or Maple. 40 | * 41 | * @section ram What is the RAM footprint of this library? 42 | * 43 | * 16 bytes. A single radio object consumes 16 bytes of RAM, and the library 44 | * does not use any other RAM statically. 45 | * 46 | * @section tests Why are the examples in the 'tests' directory failing? 47 | * 48 | * The sketches in the 'tests' directory are not for general use. 49 | * Please use the examples in the 'examples' directory instead. 50 | * 51 | * The 'tests' directory is only for people making changes to the library 52 | * to ensure that their changes do not break anything. 53 | */ 54 | -------------------------------------------------------------------------------- /02.Library/RF24/README.md: -------------------------------------------------------------------------------- 1 | # Arduino driver for nRF24L01 2.4GHz Wireless Transceiver 2 | 3 | Design Goals: This library is designed to be... 4 | 5 | * Maximally compliant with the intended operation of the chip 6 | * Easy for beginners to use 7 | * Consumed with a public interface that's similiar to other Arduino standard libraries 8 | * Built against the standard SPI library. 9 | 10 | Please refer to: 11 | 12 | * [Documentation Main Page](http://maniacbug.github.com/RF24) 13 | * [RF24 Class Documentation](http://maniacbug.github.com/RF24/classRF24.html) 14 | * [Source Code](https://github.com/maniacbug/RF24) 15 | * [Downloads](https://github.com/maniacbug/RF24/archives/master) 16 | * [Chip Datasheet](http://www.nordicsemi.com/files/Product/data_sheet/nRF24L01_Product_Specification_v2_0.pdf) 17 | 18 | This chip uses the SPI bus, plus two chip control pins. Remember that pin 10 must still remain an output, or 19 | the SPI hardware will go into 'slave' mode. 20 | 21 | -------------------------------------------------------------------------------- /02.Library/RF24/RF24_config.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright (C) 2011 J. Coliz 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | version 2 as published by the Free Software Foundation. 8 | */ 9 | 10 | #ifndef __RF24_CONFIG_H__ 11 | #define __RF24_CONFIG_H__ 12 | 13 | #if ARDUINO < 100 14 | #include 15 | #else 16 | #include 17 | #endif 18 | 19 | #include 20 | 21 | // Stuff that is normally provided by Arduino 22 | #ifdef ARDUINO 23 | #include 24 | #else 25 | #include 26 | #include 27 | #include 28 | extern HardwareSPI SPI; 29 | #define _BV(x) (1<<(x)) 30 | #endif 31 | 32 | #undef SERIAL_DEBUG 33 | #ifdef SERIAL_DEBUG 34 | #define IF_SERIAL_DEBUG(x) ({x;}) 35 | #else 36 | #define IF_SERIAL_DEBUG(x) 37 | #endif 38 | 39 | // Avoid spurious warnings 40 | #if 1 41 | #if ! defined( NATIVE ) && defined( ARDUINO ) 42 | #undef PROGMEM 43 | #define PROGMEM __attribute__(( section(".progmem.data") )) 44 | #undef PSTR 45 | #define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];})) 46 | #endif 47 | #endif 48 | 49 | // Progmem is Arduino-specific 50 | #ifdef ARDUINO 51 | #include 52 | #define PRIPSTR "%S" 53 | #else 54 | typedef char const char; 55 | typedef uint16_t prog_uint16_t; 56 | #define PSTR(x) (x) 57 | #define printf_P printf 58 | #define strlen_P strlen 59 | #define PROGMEM 60 | #define pgm_read_word(p) (*(p)) 61 | #define PRIPSTR "%s" 62 | #endif 63 | 64 | #endif // __RF24_CONFIG_H__ 65 | // vim:ai:cin:sts=2 sw=2 ft=cpp 66 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/GettingStarted/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/led_remote/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/nordic_fob/nordic_fob.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example Nordic FOB Receiver 11 | * 12 | * This is an example of how to use the RF24 class to receive signals from the 13 | * Sparkfun Nordic FOB. Thanks to Kirk Mower for providing test hardware. 14 | * 15 | * See blog post at http://maniacbug.wordpress.com/2012/01/08/nordic-fob/ 16 | */ 17 | 18 | #include 19 | #include 20 | #include "nRF24L01.h" 21 | #include "printf.h" 22 | 23 | // 24 | // Hardware configuration 25 | // 26 | 27 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 28 | 29 | RF24 radio(9,10); 30 | 31 | // 32 | // Payload 33 | // 34 | 35 | struct payload_t 36 | { 37 | uint8_t buttons; 38 | uint16_t id; 39 | uint8_t empty; 40 | }; 41 | 42 | const char* button_names[] = { "Up", "Down", "Left", "Right", "Center" }; 43 | const int num_buttons = 5; 44 | 45 | // 46 | // Forward declarations 47 | // 48 | 49 | uint16_t flip_endian(uint16_t in); 50 | 51 | // 52 | // Setup 53 | // 54 | 55 | void setup(void) 56 | { 57 | // 58 | // Print preamble 59 | // 60 | 61 | Serial.begin(57600); 62 | printf_begin(); 63 | printf("\r\nRF24/examples/nordic_fob/\r\n"); 64 | 65 | // 66 | // Setup and configure rf radio according to the built-in parameters 67 | // of the FOB. 68 | // 69 | 70 | radio.begin(); 71 | radio.setChannel(2); 72 | radio.setPayloadSize(4); 73 | radio.setAutoAck(false); 74 | radio.setCRCLength(RF24_CRC_8); 75 | radio.openReadingPipe(1,0xE7E7E7E7E7LL); 76 | 77 | // 78 | // Start listening 79 | // 80 | 81 | radio.startListening(); 82 | 83 | // 84 | // Dump the configuration of the rf unit for debugging 85 | // 86 | 87 | radio.printDetails(); 88 | } 89 | 90 | // 91 | // Loop 92 | // 93 | 94 | void loop(void) 95 | { 96 | // 97 | // Receive each packet, dump it out 98 | // 99 | 100 | // if there is data ready 101 | if ( radio.available() ) 102 | { 103 | // Get the packet from the radio 104 | payload_t payload; 105 | radio.read( &payload, sizeof(payload) ); 106 | 107 | // Print the ID of this message. Note that the message 108 | // is sent 'big-endian', so we have to flip it. 109 | printf("#%05u Buttons ",flip_endian(payload.id)); 110 | 111 | // Print the name of each button 112 | int i = num_buttons; 113 | while (i--) 114 | { 115 | if ( ! ( payload.buttons & _BV(i) ) ) 116 | { 117 | printf("%s ",button_names[i]); 118 | } 119 | } 120 | 121 | // If no buttons, print None 122 | if ( payload.buttons == _BV(num_buttons) - 1 ) 123 | printf("None"); 124 | 125 | printf("\r\n"); 126 | } 127 | } 128 | 129 | // 130 | // Helper functions 131 | // 132 | 133 | // Change a big-endian word into a little-endian 134 | uint16_t flip_endian(uint16_t in) 135 | { 136 | uint16_t low = in >> 8; 137 | uint16_t high = in << 8; 138 | 139 | return high | low; 140 | } 141 | 142 | // vim:cin:ai:sts=2 sw=2 ft=cpp 143 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/nordic_fob/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/pingpair/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/pingpair_dyn/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/pingpair_irq/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/pingpair_maple/main.cpp: -------------------------------------------------------------------------------- 1 | #ifdef MAPLE_IDE 2 | 3 | #include 4 | #include "wirish.h" 5 | 6 | extern void setup(void); 7 | extern void loop(void); 8 | 9 | void board_start(const char* program_name) 10 | { 11 | // Set up the LED to steady on 12 | pinMode(BOARD_LED_PIN, OUTPUT); 13 | digitalWrite(BOARD_LED_PIN, HIGH); 14 | 15 | // Setup the button as input 16 | pinMode(BOARD_BUTTON_PIN, INPUT); 17 | digitalWrite(BOARD_BUTTON_PIN, HIGH); 18 | 19 | SerialUSB.begin(); 20 | SerialUSB.println("Press BUT"); 21 | 22 | // Wait for button press 23 | while ( !isButtonPressed() ) 24 | { 25 | } 26 | 27 | SerialUSB.println("Welcome!"); 28 | SerialUSB.println(program_name); 29 | 30 | int i = 11; 31 | while (i--) 32 | { 33 | toggleLED(); 34 | delay(50); 35 | } 36 | } 37 | 38 | /** 39 | * Custom version of _write, which will print to the USB. 40 | * In order to use it you MUST ADD __attribute__((weak)) 41 | * to _write in libmaple/syscalls.c 42 | */ 43 | extern "C" int _write (int file, char * ptr, int len) 44 | { 45 | if ( (file != 1) && (file != 2) ) 46 | return 0; 47 | else 48 | SerialUSB.write(ptr,len); 49 | return len; 50 | } 51 | 52 | /** 53 | * Re-entrant version of _write. Yagarto and Devkit now use 54 | * the re-entrant newlib, so these get called instead of the 55 | * non_r versions. 56 | */ 57 | extern "C" int _write_r (void*, int file, char * ptr, int len) 58 | { 59 | return _write( file, ptr, len); 60 | } 61 | 62 | __attribute__((constructor)) __attribute__ ((weak)) void premain() 63 | { 64 | init(); 65 | } 66 | 67 | __attribute__((weak)) void setup(void) 68 | { 69 | board_start("No program defined"); 70 | } 71 | 72 | __attribute__((weak)) void loop(void) 73 | { 74 | } 75 | 76 | __attribute__((weak)) int main(void) 77 | { 78 | setup(); 79 | 80 | while (true) 81 | { 82 | loop(); 83 | } 84 | return 0; 85 | } 86 | #endif // ifdef MAPLE_IDE 87 | // vim:cin:ai:sts=2 sw=2 ft=cpp 88 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/pingpair_pl/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/pingpair_sleepy/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/scanner/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | int serial_putc( char c, FILE * ) 20 | { 21 | Serial.write( c ); 22 | 23 | return c; 24 | } 25 | 26 | void printf_begin(void) 27 | { 28 | fdevopen( &serial_putc, 0 ); 29 | } 30 | 31 | #endif // __PRINTF_H__ 32 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/scanner/scanner.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Channel scanner 11 | * 12 | * Example to detect interference on the various channels available. 13 | * This is a good diagnostic tool to check whether you're picking a 14 | * good channel for your application. 15 | * 16 | * Inspired by cpixip. 17 | * See http://arduino.cc/forum/index.php/topic,54795.0.html 18 | */ 19 | 20 | #include 21 | #include "nRF24L01.h" 22 | #include "RF24.h" 23 | #include "printf.h" 24 | 25 | // 26 | // Hardware configuration 27 | // 28 | 29 | // Set up nRF24L01 radio on SPI bus plus pins 9 & 10 30 | 31 | RF24 radio(9,10); 32 | 33 | // 34 | // Channel info 35 | // 36 | 37 | const uint8_t num_channels = 128; 38 | uint8_t values[num_channels]; 39 | 40 | // 41 | // Setup 42 | // 43 | 44 | void setup(void) 45 | { 46 | // 47 | // Print preamble 48 | // 49 | 50 | Serial.begin(57600); 51 | printf_begin(); 52 | printf("\n\rRF24/examples/scanner/\n\r"); 53 | 54 | // 55 | // Setup and configure rf radio 56 | // 57 | 58 | radio.begin(); 59 | radio.setAutoAck(false); 60 | 61 | // Get into standby mode 62 | radio.startListening(); 63 | radio.stopListening(); 64 | 65 | // Print out header, high then low digit 66 | int i = 0; 67 | while ( i < num_channels ) 68 | { 69 | printf("%x",i>>4); 70 | ++i; 71 | } 72 | printf("\n\r"); 73 | i = 0; 74 | while ( i < num_channels ) 75 | { 76 | printf("%x",i&0xf); 77 | ++i; 78 | } 79 | printf("\n\r"); 80 | } 81 | 82 | // 83 | // Loop 84 | // 85 | 86 | const int num_reps = 100; 87 | 88 | void loop(void) 89 | { 90 | // Clear measurement values 91 | memset(values,0,sizeof(values)); 92 | 93 | // Scan all channels num_reps times 94 | int rep_counter = num_reps; 95 | while (rep_counter--) 96 | { 97 | int i = num_channels; 98 | while (i--) 99 | { 100 | // Select this channel 101 | radio.setChannel(i); 102 | 103 | // Listen for a little 104 | radio.startListening(); 105 | delayMicroseconds(128); 106 | radio.stopListening(); 107 | 108 | // Did we get a carrier? 109 | if ( radio.testCarrier() ) 110 | ++values[i]; 111 | } 112 | } 113 | 114 | // Print out channel measurements, clamped to a single hex digit 115 | int i = 0; 116 | while ( i < num_channels ) 117 | { 118 | printf("%x",min(0xf,values[i]&0xf)); 119 | ++i; 120 | } 121 | printf("\n\r"); 122 | } 123 | 124 | // vim:ai:cin:sts=2 sw=2 ft=cpp 125 | -------------------------------------------------------------------------------- /02.Library/RF24/examples/starping/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24/keywords.txt: -------------------------------------------------------------------------------- 1 | RF24 KEYWORD1 2 | begin KEYWORD2 3 | setChannel KEYWORD2 4 | setPayloadSize KEYWORD2 5 | getPayloadSize KEYWORD2 6 | print_details KEYWORD2 7 | startListening KEYWORD2 8 | stopListening KEYWORD2 9 | write KEYWORD2 10 | available KEYWORD2 11 | read KEYWORD2 12 | openWritingPipe KEYWORD2 13 | openReadingPipe KEYWORD2 -------------------------------------------------------------------------------- /02.Library/RF24/nRF24L01.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007 Stefan Engelke 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, copy, 8 | modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | 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 22 | DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | /* Memory Map */ 26 | #define CONFIG 0x00 27 | #define EN_AA 0x01 28 | #define EN_RXADDR 0x02 29 | #define SETUP_AW 0x03 30 | #define SETUP_RETR 0x04 31 | #define RF_CH 0x05 32 | #define RF_SETUP 0x06 33 | #define STATUS 0x07 34 | #define OBSERVE_TX 0x08 35 | #define CD 0x09 36 | #define RX_ADDR_P0 0x0A 37 | #define RX_ADDR_P1 0x0B 38 | #define RX_ADDR_P2 0x0C 39 | #define RX_ADDR_P3 0x0D 40 | #define RX_ADDR_P4 0x0E 41 | #define RX_ADDR_P5 0x0F 42 | #define TX_ADDR 0x10 43 | #define RX_PW_P0 0x11 44 | #define RX_PW_P1 0x12 45 | #define RX_PW_P2 0x13 46 | #define RX_PW_P3 0x14 47 | #define RX_PW_P4 0x15 48 | #define RX_PW_P5 0x16 49 | #define FIFO_STATUS 0x17 50 | #define DYNPD 0x1C 51 | #define FEATURE 0x1D 52 | 53 | /* Bit Mnemonics */ 54 | #define MASK_RX_DR 6 55 | #define MASK_TX_DS 5 56 | #define MASK_MAX_RT 4 57 | #define EN_CRC 3 58 | #define CRCO 2 59 | #define PWR_UP 1 60 | #define PRIM_RX 0 61 | #define ENAA_P5 5 62 | #define ENAA_P4 4 63 | #define ENAA_P3 3 64 | #define ENAA_P2 2 65 | #define ENAA_P1 1 66 | #define ENAA_P0 0 67 | #define ERX_P5 5 68 | #define ERX_P4 4 69 | #define ERX_P3 3 70 | #define ERX_P2 2 71 | #define ERX_P1 1 72 | #define ERX_P0 0 73 | #define AW 0 74 | #define ARD 4 75 | #define ARC 0 76 | #define PLL_LOCK 4 77 | #define RF_DR 3 78 | #define RF_PWR 6 79 | #define RX_DR 6 80 | #define TX_DS 5 81 | #define MAX_RT 4 82 | #define RX_P_NO 1 83 | #define TX_FULL 0 84 | #define PLOS_CNT 4 85 | #define ARC_CNT 0 86 | #define TX_REUSE 6 87 | #define FIFO_FULL 5 88 | #define TX_EMPTY 4 89 | #define RX_FULL 1 90 | #define RX_EMPTY 0 91 | #define DPL_P5 5 92 | #define DPL_P4 4 93 | #define DPL_P3 3 94 | #define DPL_P2 2 95 | #define DPL_P1 1 96 | #define DPL_P0 0 97 | #define EN_DPL 2 98 | #define EN_ACK_PAY 1 99 | #define EN_DYN_ACK 0 100 | 101 | /* Instruction Mnemonics */ 102 | #define R_REGISTER 0x00 103 | #define W_REGISTER 0x20 104 | #define REGISTER_MASK 0x1F 105 | #define ACTIVATE 0x50 106 | #define R_RX_PL_WID 0x60 107 | #define R_RX_PAYLOAD 0x61 108 | #define W_TX_PAYLOAD 0xA0 109 | #define W_ACK_PAYLOAD 0xA8 110 | #define FLUSH_TX 0xE1 111 | #define FLUSH_RX 0xE2 112 | #define REUSE_TX_PL 0xE3 113 | #define NOP 0xFF 114 | 115 | /* Non-P omissions */ 116 | #define LNA_HCURR 0 117 | 118 | /* P model memory Map */ 119 | #define RPD 0x09 120 | 121 | /* P model bit Mnemonics */ 122 | #define RF_DR_LOW 5 123 | #define RF_DR_HIGH 3 124 | #define RF_PWR_LOW 1 125 | #define RF_PWR_HIGH 2 126 | -------------------------------------------------------------------------------- /02.Library/RF24/tests/README: -------------------------------------------------------------------------------- 1 | The sketches in this directory are intended to be checkin tests. 2 | No code should be pushed to github without these tests passing. 3 | 4 | See "runtests.sh" script inside each sketch dir. This script is fully compatible with 5 | git bisest. 6 | 7 | Note that this requires python and py-serial 8 | -------------------------------------------------------------------------------- /02.Library/RF24/tests/native/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #include "Arduino.h" 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #endif // __PRINTF_H__ 34 | -------------------------------------------------------------------------------- /02.Library/RF24/tests/pingpair_blocking/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24/tests/pingpair_blocking/runtest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys,serial 4 | 5 | def read_until(token): 6 | while 1: 7 | line = ser.readline(None) 8 | sys.stdout.write(line) 9 | 10 | if (line.startswith(token)): 11 | break 12 | return line 13 | 14 | 15 | ser = serial.Serial(sys.argv[1], 57600, timeout=5, dsrdtr=False, rtscts=False) 16 | 17 | read_until("+READY") 18 | ser.write(sys.argv[2]) 19 | 20 | line = read_until("+OK") 21 | ser.close() 22 | if (line.find("PASS") != -1): 23 | sys.exit(0) 24 | else: 25 | sys.exit(1) 26 | -------------------------------------------------------------------------------- /02.Library/RF24/tests/pingpair_blocking/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Connect u0 to receiver, u1 to sender 4 | 5 | jam u0 u1 && expect test.ex 6 | -------------------------------------------------------------------------------- /02.Library/RF24/tests/pingpair_blocking/test.ex: -------------------------------------------------------------------------------- 1 | #/usr/bin/expect 2 | 3 | set timeout 100 4 | spawn picocom -b 57600 /dev/ttyUSB0 5 | expect "+READY" 6 | send "1" 7 | expect "+OK" 8 | spawn picocom -b 57600 /dev/ttyUSB1 9 | expect "+READY" 10 | send "1" 11 | expect "+OK" 12 | -------------------------------------------------------------------------------- /02.Library/RF24/tests/pingpair_test/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24/tests/pingpair_test/runtest.py: -------------------------------------------------------------------------------- 1 | #!/opt/local/bin/python 2 | 3 | import sys,serial 4 | 5 | def read_until(token): 6 | while 1: 7 | line = ser.readline(None,"\r") 8 | sys.stdout.write(line) 9 | 10 | if (line.startswith(token)): 11 | break 12 | return line 13 | 14 | 15 | ser = serial.Serial(sys.argv[1], 57600, timeout=5, dsrdtr=False, rtscts=False) 16 | 17 | read_until("+READY") 18 | ser.write(sys.argv[2]) 19 | 20 | line = read_until("+OK") 21 | ser.close() 22 | if (line.find("PASS") != -1): 23 | sys.exit(0) 24 | else: 25 | sys.exit(1) 26 | -------------------------------------------------------------------------------- /02.Library/RF24/tests/pingpair_test/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Connect u0 to receiver, u0 to sender 4 | # WARNING: Test config 2 only works with PLUS units. 5 | 6 | jam u0 u1 && expect test.ex 1 7 | sleep 1 8 | stty 57600 raw ignbrk hup < /dev/ttyUSB0 9 | sleep 1 10 | stty 57600 raw ignbrk hup < /dev/ttyUSB1 11 | expect test.ex 2 12 | sleep 1 13 | stty 57600 raw ignbrk hup < /dev/ttyUSB0 14 | sleep 1 15 | stty 57600 raw ignbrk hup < /dev/ttyUSB1 16 | expect test.ex 3 17 | sleep 1 18 | stty 57600 raw ignbrk hup < /dev/ttyUSB0 19 | sleep 1 20 | stty 57600 raw ignbrk hup < /dev/ttyUSB1 21 | expect test.ex 4 22 | -------------------------------------------------------------------------------- /02.Library/RF24/tests/pingpair_test/test.ex: -------------------------------------------------------------------------------- 1 | #/usr/bin/expect 2 | 3 | set timeout 100 4 | spawn picocom -b 57600 /dev/ttyUSB0 5 | expect "+READY" 6 | send [lindex $argv 0] 7 | expect "+OK" 8 | spawn picocom -b 57600 /dev/ttyUSB1 9 | expect "+READY" 10 | send [lindex $argv 0] 11 | expect "+OK" 12 | -------------------------------------------------------------------------------- /02.Library/RF24/wikidoc.xslt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | === === 9 | 10 | 11 | 12 | 13 | '''' 14 | 15 | Parameters: 16 | 17 | 18 | 19 | * '''': 20 | 21 | 22 | 23 | 24 | 25 | Returns: 26 | 27 | * 28 | 29 | 30 | Warning: 31 | 32 | 33 | 34 | <pre> </pre> 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /02.Library/RF24Network/.gitignore: -------------------------------------------------------------------------------- 1 | 16000000/ 2 | 8000000/ 3 | out/ 4 | docs/ 5 | .*.swp 6 | Session.vim 7 | *.swp 8 | version.h 9 | *.orig 10 | *.bak 11 | -------------------------------------------------------------------------------- /02.Library/RF24Network/README.md: -------------------------------------------------------------------------------- 1 | # Network Layer for nRF24L01(+) radios 2 | 3 | Please see the full documentation at http://maniacbug.github.com/RF24Network/index.html 4 | -------------------------------------------------------------------------------- /02.Library/RF24Network/RF24Network_config.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright (C) 2011 James Coliz, Jr. 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | version 2 as published by the Free Software Foundation. 8 | */ 9 | 10 | #ifndef __RF24_CONFIG_H__ 11 | #define __RF24_CONFIG_H__ 12 | 13 | #if ARDUINO < 100 14 | #include 15 | #else 16 | #include 17 | #endif 18 | 19 | #include 20 | 21 | // Stuff that is normally provided by Arduino 22 | #ifndef ARDUINO 23 | #include 24 | #include 25 | #include 26 | extern HardwareSPI SPI; 27 | #define _BV(x) (1<<(x)) 28 | #endif 29 | 30 | #undef SERIAL_DEBUG 31 | #ifdef SERIAL_DEBUG 32 | #define IF_SERIAL_DEBUG(x) ({x;}) 33 | #else 34 | #define IF_SERIAL_DEBUG(x) 35 | #endif 36 | 37 | // Avoid spurious warnings 38 | #if ! defined( NATIVE ) && defined( ARDUINO ) 39 | #undef PROGMEM 40 | #define PROGMEM __attribute__(( section(".progmem.data") )) 41 | #undef PSTR 42 | #define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];})) 43 | #endif 44 | 45 | // Progmem is Arduino-specific 46 | #ifdef ARDUINO 47 | #include 48 | #define PRIPSTR "%S" 49 | #else 50 | typedef char const prog_char; 51 | typedef uint16_t prog_uint16_t; 52 | #define PSTR(x) (x) 53 | #define printf_P printf 54 | #define strlen_P strlen 55 | #define PROGMEM 56 | #define pgm_read_word(p) (*(p)) 57 | #define PRIPSTR "%s" 58 | #endif 59 | 60 | #endif // __RF24_CONFIG_H__ 61 | // vim:ai:cin:sts=2 sw=2 ft=cpp 62 | -------------------------------------------------------------------------------- /02.Library/RF24Network/Sync.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | // STL headers 10 | // C headers 11 | #include 12 | // Framework headers 13 | // Library headers 14 | #include 15 | // Project headers 16 | // This component's header 17 | #include 18 | 19 | /****************************************************************************/ 20 | 21 | void Sync::update(void) 22 | { 23 | // Pump the network 24 | network.update(); 25 | 26 | // Look for changes to the data 27 | uint8_t message[32]; 28 | uint8_t *mptr = message; 29 | unsigned at = 0; 30 | while ( at < len ) 31 | { 32 | if ( app_data && internal_data && app_data[at] != internal_data[at] ) 33 | { 34 | // Compose a message with the deltas 35 | *mptr++ = at + 1; 36 | *mptr++ = app_data[at]; 37 | 38 | // Update our internal view 39 | internal_data[at] = app_data[at]; 40 | } 41 | ++at; 42 | } 43 | // Zero out the remainder 44 | while ( at++ < sizeof(message) ) 45 | *mptr++ = 0; 46 | 47 | // If changes, send a message 48 | if ( *message ) 49 | { 50 | // TODO handle the case where this has to be broken into 51 | // multiple messages 52 | RF24NetworkHeader header(/*to node*/ to_node, /*type*/ 'S' /*Sync*/); 53 | network.write(header,message,sizeof(message)); 54 | } 55 | 56 | // Look for messages from the network 57 | // Is there anything ready for us? 58 | if ( network.available() ) 59 | { 60 | // If so, take a look at it 61 | RF24NetworkHeader header; 62 | network.peek(header); 63 | 64 | switch (header.type) 65 | { 66 | case 'S': 67 | IF_SERIAL_DEBUG(printf_P(PSTR("%lu: SYN Received sync message\n\r"),millis())); 68 | 69 | network.read(header,&message,sizeof(message)); 70 | // Parse the message and update the vars 71 | mptr = message; 72 | at = 0; 73 | while ( mptr < message + sizeof(message) ) 74 | { 75 | // A '0' in the first position means we are done 76 | if ( !*mptr ) 77 | break; 78 | uint8_t pos = (*mptr++) - 1; 79 | uint8_t val = *mptr++; 80 | 81 | IF_SERIAL_DEBUG(printf_P(PSTR("%lu: SYN Updated position %u to value %u\n\r"),millis(),pos,val)); 82 | 83 | app_data[pos] = val; 84 | internal_data[pos] = val; 85 | } 86 | break; 87 | default: 88 | // Leave other messages for the app 89 | break; 90 | }; 91 | } 92 | } 93 | // vim:cin:ai:sts=2 sw=2 ft=cpp 94 | -------------------------------------------------------------------------------- /02.Library/RF24Network/Sync.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | #ifndef __SYNC_H__ 10 | #define __SYNC_H__ 11 | 12 | // STL headers 13 | // C headers 14 | #include 15 | #include 16 | // Framework headers 17 | // Library headers 18 | #include 19 | // Project headers 20 | 21 | class RF24Network; 22 | 23 | /** 24 | * Synchronizes a shared set of variables between multiple nodes 25 | */ 26 | 27 | class Sync 28 | { 29 | private: 30 | RF24Network& network; 31 | uint8_t* app_data; /**< Application's copy of the data */ 32 | uint8_t* internal_data; /**< Our copy of the data */ 33 | size_t len; /**< Length of the data in bytes */ 34 | uint16_t to_node; /**< The other node we're syncing with */ 35 | 36 | protected: 37 | public: 38 | /** 39 | * Constructor 40 | * 41 | * @param _network Which network to syncrhonize over 42 | */ 43 | Sync(RF24Network& _network): network(_network), app_data(NULL), 44 | internal_data(NULL), len(0), to_node(0) 45 | { 46 | } 47 | /** 48 | * Begin the object 49 | * 50 | * @param _to_node Which node we are syncing with 51 | */ 52 | void begin(uint16_t _to_node) 53 | { 54 | to_node = _to_node; 55 | } 56 | /** 57 | * Declare the shared data set 58 | * 59 | * @param _data Location of shared data to be syncrhonized 60 | */ 61 | template 62 | void register_me(T& _data) 63 | { 64 | app_data = reinterpret_cast(&_data); 65 | len = sizeof(_data); 66 | internal_data = reinterpret_cast(malloc(len)); 67 | reset(); 68 | } 69 | 70 | /** 71 | * Reset the internal copy of the shared data set 72 | */ 73 | void reset(void) 74 | { 75 | memcpy(internal_data,app_data,len); 76 | } 77 | 78 | /** 79 | * Update the network and the shared data set 80 | */ 81 | void update(void); 82 | }; 83 | 84 | #endif // __SYNC_H__ 85 | // vim:cin:ai:sts=2 sw=2 ft=cpp 86 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/helloworld_rx/.gitignore: -------------------------------------------------------------------------------- 1 | version.h 2 | output/ 3 | ojam/ 4 | .*.swp 5 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/helloworld_rx/helloworld_rx.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Simplest possible example of using RF24Network, 11 | * 12 | * RECEIVER NODE 13 | * Listens for messages from the transmitter and prints them out. 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | // nRF24L01(+) radio attached using Getting Started board 21 | RF24 radio(9,10); 22 | 23 | // Network uses that radio 24 | RF24Network network(radio); 25 | 26 | // Address of our node 27 | const uint16_t this_node = 0; 28 | 29 | // Address of the other node 30 | const uint16_t other_node = 1; 31 | 32 | // Structure of our payload 33 | struct payload_t 34 | { 35 | unsigned long ms; 36 | unsigned long counter; 37 | }; 38 | 39 | void setup(void) 40 | { 41 | Serial.begin(57600); 42 | Serial.println("RF24Network/examples/helloworld_rx/"); 43 | 44 | SPI.begin(); 45 | radio.begin(); 46 | network.begin(/*channel*/ 90, /*node address*/ this_node); 47 | } 48 | 49 | void loop(void) 50 | { 51 | // Pump the network regularly 52 | network.update(); 53 | 54 | // Is there anything ready for us? 55 | while ( network.available() ) 56 | { 57 | // If so, grab it and print it out 58 | RF24NetworkHeader header; 59 | payload_t payload; 60 | network.read(header,&payload,sizeof(payload)); 61 | Serial.print("Received packet #"); 62 | Serial.print(payload.counter); 63 | Serial.print(" at "); 64 | Serial.println(payload.ms); 65 | } 66 | } 67 | // vim:ai:cin:sts=2 sw=2 ft=cpp 68 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/helloworld_tx/.gitignore: -------------------------------------------------------------------------------- 1 | version.h 2 | output/ 3 | ojam/ 4 | .*.swp 5 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/helloworld_tx/helloworld_tx.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2012 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Simplest possible example of using RF24Network 11 | * 12 | * TRANSMITTER NODE 13 | * Every 2 seconds, send a payload to the receiver node. 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | // nRF24L01(+) radio attached using Getting Started board 21 | RF24 radio(9,10); 22 | 23 | // Network uses that radio 24 | RF24Network network(radio); 25 | 26 | // Address of our node 27 | const uint16_t this_node = 1; 28 | 29 | // Address of the other node 30 | const uint16_t other_node = 0; 31 | 32 | // How often to send 'hello world to the other unit 33 | const unsigned long interval = 2000; //ms 34 | 35 | // When did we last send? 36 | unsigned long last_sent; 37 | 38 | // How many have we sent already 39 | unsigned long packets_sent; 40 | 41 | // Structure of our payload 42 | struct payload_t 43 | { 44 | unsigned long ms; 45 | unsigned long counter; 46 | }; 47 | 48 | void setup(void) 49 | { 50 | Serial.begin(57600); 51 | Serial.println("RF24Network/examples/helloworld_tx/"); 52 | 53 | SPI.begin(); 54 | radio.begin(); 55 | network.begin(/*channel*/ 90, /*node address*/ this_node); 56 | } 57 | 58 | void loop(void) 59 | { 60 | // Pump the network regularly 61 | network.update(); 62 | 63 | // If it's time to send a message, send it! 64 | unsigned long now = millis(); 65 | if ( now - last_sent >= interval ) 66 | { 67 | last_sent = now; 68 | 69 | Serial.print("Sending..."); 70 | payload_t payload = { millis(), packets_sent++ }; 71 | RF24NetworkHeader header(/*to node*/ other_node); 72 | bool ok = network.write(header,&payload,sizeof(payload)); 73 | if (ok) 74 | Serial.println("ok."); 75 | else 76 | Serial.println("failed."); 77 | } 78 | } 79 | // vim:ai:cin:sts=2 sw=2 ft=cpp 80 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/maple/Jamfile: -------------------------------------------------------------------------------- 1 | SubDir TOP ; 2 | 3 | # Set up output directories 4 | LOCATE_TARGET = $(SEARCH_SOURCE)/out/$(TOOLSET) ; 5 | LOCATE_SOURCE = $(LOCATE_TARGET) ; 6 | 7 | # Pull in local libraries 8 | SKETCH_LIBS += RF24Network RF24 ; 9 | HDRS += $(HOME)/Source/Arduino/libraries/$(SKETCH_LIBS) ; 10 | 11 | # Main output executable 12 | Maple $(SEARCH_SOURCE:B).elf : [ GLOB $(SEARCH_SOURCE) $(HOME)/Source/Arduino/libraries/$(SKETCH_LIBS) : $(MODULE_EXT) ] ; 13 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/maple/helloworld_tx.pde: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Simplest possible example of using RF24Network 11 | * 12 | * TRANSMITTER NODE 13 | * Every 2 seconds, says hello to the receiver node. 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | // 21 | // Maple specific setup. Other than this section, the sketch is the same on Maple as on 22 | // Arduino 23 | // 24 | 25 | #ifdef MAPLE_IDE 26 | 27 | // External startup function 28 | extern void board_start(const char* program_name); 29 | 30 | // Use SPI #2. 31 | HardwareSPI SPI(2); 32 | 33 | inline void serial_begin(int _baud) 34 | { 35 | } 36 | #else 37 | inline void serial_begin(int _baud) 38 | { 39 | Serial.begin(_baud); 40 | } 41 | #define board_startup printf 42 | #define toggleLED(x) (x) 43 | #endif 44 | 45 | // 46 | // Hardware configuration 47 | // 48 | 49 | // Set up nRF24L01 radio on SPI bus plus pins 7 & 6 50 | // (This works for the Getting Started board plugged into the 51 | // Maple Native backwards.) 52 | 53 | RF24 radio(7,6); 54 | 55 | // Network uses that radio 56 | RF24Network network(radio); 57 | 58 | // Address of our node 59 | const uint16_t this_node = 1; 60 | 61 | // Address of the other node 62 | const uint16_t other_node = 0; 63 | 64 | // How often to send 'hello world to the other unit 65 | const unsigned long interval = 2000; //ms 66 | 67 | // When did we last send? 68 | unsigned long last_sent; 69 | 70 | void setup(void) 71 | { 72 | serial_begin(57600); 73 | board_start("RF24Network/examples/helloworld_tx/"); 74 | 75 | SPI.begin(); 76 | radio.begin(); 77 | network.begin(/*channel*/ 90, /*node address*/ this_node); 78 | } 79 | 80 | void loop(void) 81 | { 82 | // Pump the network regularly 83 | network.update(); 84 | 85 | // If it's time to send a message, send it! 86 | unsigned long now = millis(); 87 | if ( now - last_sent > interval ) 88 | { 89 | last_sent = now; 90 | 91 | toggleLED(); 92 | printf("Sending...\r\n"); 93 | const char* hello = "Hello, world!"; 94 | RF24NetworkHeader header(/*to node*/ other_node); 95 | bool ok = network.write(header,hello,strlen(hello)); 96 | if (ok) 97 | printf("\tok.\r\n"); 98 | else 99 | { 100 | printf("\tfailed.\r\n"); 101 | delay(250); // extra delay on fail to keep light on longer 102 | } 103 | toggleLED(); 104 | } 105 | } 106 | // vim:ai:cin:sts=2 sw=2 ft=cpp 107 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/maple/main.cpp: -------------------------------------------------------------------------------- 1 | #ifdef MAPLE_IDE 2 | 3 | #include 4 | #include "wirish.h" 5 | 6 | extern void setup(void); 7 | extern void loop(void); 8 | 9 | void board_start(const char* program_name) 10 | { 11 | // Set up the LED to steady on 12 | pinMode(BOARD_LED_PIN, OUTPUT); 13 | digitalWrite(BOARD_LED_PIN, HIGH); 14 | 15 | // Setup the button as input 16 | pinMode(BOARD_BUTTON_PIN, INPUT); 17 | digitalWrite(BOARD_BUTTON_PIN, HIGH); 18 | 19 | SerialUSB.begin(); 20 | SerialUSB.println("Press BUT"); 21 | 22 | // Wait for button press 23 | while ( !isButtonPressed() ) 24 | { 25 | } 26 | 27 | SerialUSB.println("Welcome!"); 28 | SerialUSB.println(program_name); 29 | 30 | int i = 11; 31 | while (i--) 32 | { 33 | toggleLED(); 34 | delay(50); 35 | } 36 | } 37 | 38 | /** 39 | * Custom version of _write, which will print to the USB. 40 | * In order to use it you MUST ADD __attribute__((weak)) 41 | * to _write in libmaple/syscalls.c 42 | */ 43 | extern "C" int _write(int file, char * ptr, int len) 44 | { 45 | if ( (file != 1) && (file != 2) ) 46 | return 0; 47 | else 48 | SerialUSB.write(ptr,len); 49 | return len; 50 | } 51 | 52 | __attribute__((constructor)) __attribute__ ((weak)) void premain() 53 | { 54 | init(); 55 | } 56 | 57 | __attribute__((weak)) void setup(void) 58 | { 59 | board_start("No program defined"); 60 | } 61 | 62 | __attribute__((weak)) void loop(void) 63 | { 64 | } 65 | 66 | __attribute__((weak)) int main(void) 67 | { 68 | setup(); 69 | 70 | while (true) 71 | { 72 | loop(); 73 | } 74 | return 0; 75 | } 76 | #endif // ifdef MAPLE_IDE 77 | // vim:cin:ai:sts=2 sw=2 ft=cpp 78 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/meshping/.gitignore: -------------------------------------------------------------------------------- 1 | version.h 2 | output/ 3 | ojam/ 4 | .*.swp 5 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/meshping/nodeconfig.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | #include "RF24Network_config.h" 10 | #include 11 | #include 12 | #include "nodeconfig.h" 13 | 14 | // Where in EEPROM is the address stored? 15 | uint8_t* address_at_eeprom_location = (uint8_t*)10; 16 | 17 | // What flag value is stored there so we know the value is valid? 18 | const uint8_t valid_eeprom_flag = 0xdf; 19 | 20 | // What are the actual node values that we want to use? 21 | // EEPROM locations are actually just indices into this array 22 | const uint16_t node_address_set[10] = { 00, 02, 05, 012, 015, 022, 025, 032, 035, 045 }; 23 | 24 | uint8_t nodeconfig_read(void) 25 | { 26 | uint8_t result = 0; 27 | 28 | // Look for the token in EEPROM to indicate the following value is 29 | // a validly set node address 30 | if ( eeprom_read_byte(address_at_eeprom_location) == valid_eeprom_flag ) 31 | { 32 | // Read the address from EEPROM 33 | result = node_address_set[ eeprom_read_byte(address_at_eeprom_location+1) ]; 34 | printf_P(PSTR("ADDRESS: %u\n\r"),result); 35 | } 36 | else 37 | { 38 | printf_P(PSTR("*** No valid address found. Send 0-9 via serial to set node address\n\r")); 39 | while(1) 40 | { 41 | nodeconfig_listen(); 42 | } 43 | } 44 | 45 | return result; 46 | } 47 | 48 | void nodeconfig_listen(void) 49 | { 50 | // 51 | // Listen for serial input, which is how we set the address 52 | // 53 | if (Serial.available()) 54 | { 55 | // If the character on serial input is in a valid range... 56 | char c = Serial.read(); 57 | if ( c >= '0' && c <= '9' ) 58 | { 59 | // It is our address 60 | eeprom_write_byte(address_at_eeprom_location,valid_eeprom_flag); 61 | eeprom_write_byte(address_at_eeprom_location+1,c-'0'); 62 | 63 | // And we are done right now (no easy way to soft reset) 64 | printf_P(PSTR("\n\rManually reset index to: %c, address 0%o\n\rPress RESET to continue!"),c,node_address_set[c-'0']); 65 | while(1); 66 | } 67 | } 68 | } 69 | // vim:ai:cin:sts=2 sw=2 ft=cpp 70 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/meshping/nodeconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | #ifndef __NODECONFIG_H__ 10 | #define __NODECONFIG_H__ 11 | 12 | uint8_t nodeconfig_read(void); 13 | void nodeconfig_listen(void); 14 | 15 | #endif // __NODECONFIG_H__ 16 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/meshping/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/.gitignore: -------------------------------------------------------------------------------- 1 | version.h 2 | output/ 3 | ojam/ 4 | .*.swp 5 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/DuinodeV1.h: -------------------------------------------------------------------------------- 1 | #ifndef __DUINODE_V3_H__ 2 | #define __DUINODE_V3_H__ 3 | 4 | /** 5 | * @file DuinodeV1.h 6 | * 7 | * Contains hardware definitions for RF Duinode V1 (3V3) 8 | */ 9 | 10 | #define PINS_DEFINED 1 11 | #define __PLATFORM__ "RF Duinode V1 (3V3)" 12 | 13 | const int rf_irq = 0; 14 | 15 | const int led_red = 0; 16 | const int led_yellow = 0; 17 | const int led_green = 0; 18 | const int button_a = 0; 19 | 20 | const int rf_ce = 8; 21 | const int rf_csn = 9; 22 | 23 | const int temp_pin = 2; // analog 24 | const int voltage_pin = 3; // analog 25 | 26 | // 1.1V internal reference after 1M/470k divider, in 8-bit fixed point 27 | const unsigned voltage_reference = 0x371; 28 | 29 | #endif // __DUINODE_V3_H__ 30 | // vim:cin:ai:sts=2 sw=2 ft=cpp 31 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/DuinodeV3.h: -------------------------------------------------------------------------------- 1 | #ifndef __DUINODE_V3_H__ 2 | #define __DUINODE_V3_H__ 3 | 4 | /** 5 | * @file DuinodeV3.h 6 | * 7 | * Contains hardware definitions for RF Duinode V3 (2V4) 8 | */ 9 | 10 | #define PINS_DEFINED 1 11 | #define __PLATFORM__ "RF Duinode V3/V4 (2V4)" 12 | 13 | const int rf_irq = 0; 14 | 15 | const int led_red = 3; 16 | const int led_yellow = 4; 17 | const int led_green = 5; 18 | const int button_a = 6; 19 | 20 | const int rf_ce = 8; 21 | const int rf_csn = 7; 22 | 23 | const int temp_pin = 2; // analog 24 | const int voltage_pin = 3; // analog 25 | 26 | // 1.1V internal reference after 1M/470k divider, in 8-bit fixed point 27 | const unsigned voltage_reference = 0x371; 28 | 29 | #endif // __DUINODE_V3_H__ 30 | // vim:cin:ai:sts=2 sw=2 ft=cpp 31 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/DuinodeV5.h: -------------------------------------------------------------------------------- 1 | #ifndef __DUINODE_V5_H__ 2 | #define __DUINODE_V5_H__ 3 | 4 | /** 5 | * @file DuinodeV3.h 6 | * 7 | * Contains hardware definitions for RF Duinode V5 (2V4) 8 | */ 9 | 10 | #define PINS_DEFINED 1 11 | #define __PLATFORM__ "RF Duinode V5 (2V4)" 12 | 13 | const int rf_irq = 0; 14 | 15 | const int led_red = 3; 16 | const int led_yellow = 4; 17 | const int led_green = 5; 18 | const int button_a = 6; 19 | 20 | const int rf_ce = 14; 21 | const int rf_csn = 15; 22 | 23 | const int temp_pin = 2; // analog 24 | const int voltage_pin = 3; // analog 25 | 26 | // 1.1V internal reference after 1M/470k divider, in 8-bit fixed point 27 | const unsigned voltage_reference = 0x371; 28 | 29 | #endif // __DUINODE_V5_H__ 30 | // vim:cin:ai:sts=2 sw=2 ft=cpp 31 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/S_message.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | // STL headers 10 | // C headers 11 | // Framework headers 12 | // Library headers 13 | #include "RF24Network_config.h" 14 | // Project headers 15 | // This component's header 16 | #include 17 | 18 | char S_message::buffer[32]; 19 | 20 | /****************************************************************************/ 21 | 22 | char* S_message::toString(void) 23 | { 24 | snprintf(buffer,sizeof(buffer),"%2u.%02uC /%2u.%02uV", 25 | temp_reading >> 8, 26 | ( temp_reading & 0xFF ) * 100 / 256, 27 | voltage_reading >> 8, 28 | ( voltage_reading & 0xFF ) * 100 / 256 29 | ); 30 | return buffer; 31 | } 32 | 33 | /****************************************************************************/ 34 | // vim:cin:ai:sts=2 sw=2 ft=cpp 35 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/S_message.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | #ifndef __S_MESSAGE_H__ 10 | #define __S_MESSAGE_H__ 11 | 12 | // STL headers 13 | // C headers 14 | // Framework headers 15 | // Library headers 16 | // Project headers 17 | 18 | /** 19 | * Sensor message (type 'S') 20 | */ 21 | 22 | struct S_message 23 | { 24 | uint16_t temp_reading; 25 | uint16_t voltage_reading; 26 | static char buffer[]; 27 | S_message(void): temp_reading(0), voltage_reading(0) {} 28 | char* toString(void); 29 | }; 30 | 31 | #endif // __S_MESSAGE_H__ 32 | // vim:cin:ai:sts=2 sw=2 ft=cpp 33 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/duinode1.sh: -------------------------------------------------------------------------------- 1 | jam F_CPU=16000000 "CCFLAGS=-include DuinodeV1.h" -dx UPLOAD_SPEED=115200 u1 && screen /dev/ttyUSB1 57600 2 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/duinode3.sh: -------------------------------------------------------------------------------- 1 | jam F_CPU=8000000 "CCFLAGS=-include DuinodeV3.h" -dx UPLOAD_SPEED=57600 u0 && screen /dev/ttyUSB0 57600 2 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/duinode5.sh: -------------------------------------------------------------------------------- 1 | jam F_CPU=8000000 "CCFLAGS=-include DuinodeV5.h" -dx UPLOAD_SPEED=57600 u0 && picocom -b 57600 /dev/ttyUSB0 2 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/nodeconfig.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | #include "RF24Network_config.h" 10 | #include 11 | #include 12 | #include "nodeconfig.h" 13 | 14 | // Where in EEPROM is the address stored? 15 | uint8_t* address_at_eeprom_location = (uint8_t*)10; 16 | 17 | // What flag value is stored there so we know the value is valid? 18 | const uint8_t valid_eeprom_flag = 0xde; 19 | 20 | eeprom_info_t eeprom_info; 21 | 22 | const eeprom_info_t& nodeconfig_read(void) 23 | { 24 | memset(&eeprom_info,0,sizeof(eeprom_info)); 25 | 26 | // Look for the token in EEPROM to indicate the following value is 27 | // a validly set node address 28 | if ( eeprom_read_byte(address_at_eeprom_location) == valid_eeprom_flag ) 29 | { 30 | eeprom_read_block(&eeprom_info,address_at_eeprom_location,sizeof(eeprom_info)); 31 | printf_P(PSTR("ADDRESS: %o\n\r"),eeprom_info.address); 32 | printf_P(PSTR("ROLE: %S\n\r"),eeprom_info.relay ? PSTR("Relay") : PSTR("Leaf") ); 33 | } 34 | else 35 | { 36 | printf_P(PSTR("*** No valid address found. Send node address via serial of the form 011\n\r")); 37 | while(1) 38 | { 39 | nodeconfig_listen(); 40 | } 41 | } 42 | 43 | return eeprom_info; 44 | } 45 | 46 | char serialdata[10]; 47 | char* nextserialat = serialdata; 48 | const char* maxserial = serialdata + sizeof(serialdata) - 1; 49 | 50 | void nodeconfig_listen(void) 51 | { 52 | // 53 | // Listen for serial input, which is how we set the address 54 | // 55 | if (Serial.available()) 56 | { 57 | // If the character on serial input is in a valid range... 58 | char c = Serial.read(); 59 | if ( c >= '0' && c <= '5' ) 60 | { 61 | *nextserialat++ = c; 62 | if ( nextserialat == maxserial ) 63 | { 64 | *nextserialat = 0; 65 | printf_P(PSTR("\r\n*** Unknown serial command: %s\r\n"),serialdata); 66 | nextserialat = serialdata; 67 | } 68 | } 69 | else if ( tolower(c) == 'r' ) 70 | { 71 | eeprom_info.relay = true; 72 | printf_P(PSTR("ROLE: %S\n\r"),eeprom_info.relay ? PSTR("Relay") : PSTR("Leaf") ); 73 | if ( eeprom_info.flag == valid_eeprom_flag ) 74 | eeprom_update_block(&eeprom_info,address_at_eeprom_location,sizeof(eeprom_info)); 75 | else 76 | printf_P(PSTR("Please assign an address to commit this role to EEPROM\r\n")); 77 | } 78 | else if ( tolower(c) == 'l' ) 79 | { 80 | eeprom_info.relay = false; 81 | printf_P(PSTR("ROLE: %S\n\r"),eeprom_info.relay ? PSTR("Relay") : PSTR("Leaf") ); 82 | if ( eeprom_info.flag == valid_eeprom_flag ) 83 | eeprom_update_block(&eeprom_info,address_at_eeprom_location,sizeof(eeprom_info)); 84 | else 85 | printf_P(PSTR("Please assign an address to commit this role to EEPROM\r\n")); 86 | } 87 | else if ( c == 13 ) 88 | { 89 | // Convert to octal 90 | char *pc = serialdata; 91 | uint16_t address = 0; 92 | while ( pc < nextserialat ) 93 | { 94 | address <<= 3; 95 | address |= (*pc++ - '0'); 96 | } 97 | 98 | // It is our address 99 | eeprom_info.flag = valid_eeprom_flag; 100 | eeprom_info.address = address; 101 | eeprom_update_block(&eeprom_info,address_at_eeprom_location,sizeof(eeprom_info)); 102 | 103 | // And we are done right now (no easy way to soft reset) 104 | printf_P(PSTR("\n\rManually set to address 0%o\n\rPress RESET to continue!"),address); 105 | while(1); 106 | } 107 | } 108 | } 109 | // vim:ai:cin:sts=2 sw=2 ft=cpp 110 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/nodeconfig.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 James Coliz, Jr. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | #ifndef __NODECONFIG_H__ 10 | #define __NODECONFIG_H__ 11 | 12 | // Additional info 13 | struct eeprom_info_t 14 | { 15 | uint8_t flag; 16 | uint16_t address; 17 | bool relay:1; 18 | }; 19 | 20 | const eeprom_info_t& nodeconfig_read(void); 21 | void nodeconfig_listen(void); 22 | 23 | #endif // __NODECONFIG_H__ 24 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/sleep.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright (C) 2011 James Coliz, Jr. 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | version 2 as published by the Free Software Foundation. 8 | */ 9 | 10 | /** 11 | * @file sleep.cpp 12 | * 13 | * Sleep helpers, definitions 14 | */ 15 | 16 | #include "RF24Network_config.h" 17 | #include 18 | #include "sleep.h" 19 | 20 | sleep_c Sleep; 21 | 22 | /******************************************************************/ 23 | 24 | void sleep_c::begin(wdt_prescalar_e prescalar_in,short cycles) 25 | { 26 | sleep_cycles_remaining = cycles; 27 | sleep_cycles_per_transmission = cycles; 28 | 29 | uint8_t prescalar = min(9,(uint8_t)prescalar_in); 30 | uint8_t wdtcsr = prescalar & 7; 31 | if ( prescalar & 8 ) 32 | wdtcsr |= _BV(WDP3); 33 | 34 | MCUSR &= ~_BV(WDRF); 35 | WDTCSR = _BV(WDCE) | _BV(WDE); 36 | WDTCSR = _BV(WDCE) | wdtcsr | _BV(WDIE); 37 | } 38 | 39 | /******************************************************************/ 40 | 41 | void sleep_c::go(void) 42 | { 43 | while( sleep_cycles_remaining-- ) 44 | { 45 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); 46 | sleep_mode(); 47 | } 48 | 49 | sleep_cycles_remaining = sleep_cycles_per_transmission; 50 | } 51 | 52 | ISR(WDT_vect) { 53 | } 54 | 55 | // vim:ai:cin:sts=2 sw=2 ft=cpp 56 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/sleep.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright (C) 2011 James Coliz, Jr. 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | version 2 as published by the Free Software Foundation. 8 | */ 9 | 10 | /** 11 | * @file sleep.h 12 | * 13 | * Declaration of the sleep_c class. 14 | */ 15 | 16 | #ifndef __SLEEP_H__ 17 | #define __SLEEP_H__ 18 | 19 | /** 20 | * Enums for the duration of the watchdog timer 21 | */ 22 | 23 | typedef enum { wdt_16ms = 0, wdt_32ms, wdt_64ms, wdt_128ms, wdt_250ms, wdt_500ms, wdt_1s, wdt_2s, wdt_4s, wdt_8s } wdt_prescalar_e; 24 | 25 | /** 26 | * Simplified sleeping handler 27 | */ 28 | 29 | class sleep_c 30 | { 31 | public: 32 | /** 33 | * Enable the system to be able to sleep 34 | * 35 | * Does not actually do any sleeping. 36 | * 37 | * For example, to do something roughly evert minute, configure 38 | * it like this: 39 | * 40 | * @code 41 | * Sleep.begin(wdt_8s,7); 42 | * @endcode 43 | * 44 | * @param prescalar Duration of the watchdog timer interrupt. 45 | * The system will actually sleep for this long. 46 | * @param cycles Number of times the system will wake up before 47 | * returning from @p go(). 48 | */ 49 | void begin(wdt_prescalar_e prescalar,short cycles); 50 | 51 | /** 52 | * Go to sleep 53 | * 54 | * This will return after the watchdog has awoken for the number 55 | * of times specified in begin(). 56 | */ 57 | void go(void); 58 | 59 | /** 60 | * Test whether the node sleeps 61 | * 62 | * @retval true if the node will sleep 63 | */ 64 | operator bool(void) const 65 | { 66 | return sleep_cycles_per_transmission; 67 | } 68 | 69 | private: 70 | volatile short sleep_cycles_remaining; 71 | short sleep_cycles_per_transmission; 72 | }; 73 | 74 | /** 75 | * Singleton instance for general use 76 | * 77 | * @warning: This class is hard-coded to ONLY work with this singleton. 78 | * Any other instances will fail. 79 | */ 80 | 81 | extern sleep_c Sleep; 82 | 83 | #endif // __SLEEP_H__ 84 | // vim:ai:cin:sts=2 sw=2 ft=cpp 85 | -------------------------------------------------------------------------------- /02.Library/RF24Network/examples/sensornet/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | #ifndef __TIMER_H__ 10 | #define __TIMER_H__ 11 | 12 | // STL headers 13 | // C headers 14 | // Framework headers 15 | // Library headers 16 | // Project headers 17 | 18 | /** 19 | * Simple timer 20 | */ 21 | 22 | struct timer_t 23 | { 24 | unsigned long last; 25 | unsigned long interval; 26 | timer_t(unsigned long _interval): interval(_interval) {} 27 | operator bool(void) 28 | { 29 | unsigned long now = millis(); 30 | bool result = now - last >= interval; 31 | if ( result ) 32 | last = now; 33 | return result; 34 | } 35 | }; 36 | 37 | #endif // __TEMPLATE_H__ 38 | // vim:cin:ai:sts=2 sw=2 ft=cpp 39 | -------------------------------------------------------------------------------- /02.Library/RF24Network/tests.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/02.Library/RF24Network/tests.rar -------------------------------------------------------------------------------- /02.Library/SPI/SPI.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 by Cristian Maglie 3 | * SPI Master library for arduino. 4 | * 5 | * This file is free software; you can redistribute it and/or modify 6 | * it under the terms of either the GNU General Public License version 2 7 | * or the GNU Lesser General Public License version 2.1, both as 8 | * published by the Free Software Foundation. 9 | */ 10 | 11 | #include "pins_arduino.h" 12 | #include "SPI.h" 13 | 14 | SPIClass SPI; 15 | 16 | void SPIClass::begin() { 17 | 18 | // Set SS to high so a connected chip will be "deselected" by default 19 | digitalWrite(SS, HIGH); 20 | 21 | // When the SS pin is set as OUTPUT, it can be used as 22 | // a general purpose output port (it doesn't influence 23 | // SPI operations). 24 | pinMode(SS, OUTPUT); 25 | 26 | // Warning: if the SS pin ever becomes a LOW INPUT then SPI 27 | // automatically switches to Slave, so the data direction of 28 | // the SS pin MUST be kept as OUTPUT. 29 | SPCR |= _BV(MSTR); 30 | SPCR |= _BV(SPE); 31 | 32 | // Set direction register for SCK and MOSI pin. 33 | // MISO pin automatically overrides to INPUT. 34 | // By doing this AFTER enabling SPI, we avoid accidentally 35 | // clocking in a single bit since the lines go directly 36 | // from "input" to SPI control. 37 | // http://code.google.com/p/arduino/issues/detail?id=888 38 | pinMode(SCK, OUTPUT); 39 | pinMode(MOSI, OUTPUT); 40 | } 41 | 42 | 43 | void SPIClass::end() { 44 | SPCR &= ~_BV(SPE); 45 | } 46 | 47 | void SPIClass::setBitOrder(uint8_t bitOrder) 48 | { 49 | if(bitOrder == LSBFIRST) { 50 | SPCR |= _BV(DORD); 51 | } else { 52 | SPCR &= ~(_BV(DORD)); 53 | } 54 | } 55 | 56 | void SPIClass::setDataMode(uint8_t mode) 57 | { 58 | SPCR = (SPCR & ~SPI_MODE_MASK) | mode; 59 | } 60 | 61 | void SPIClass::setClockDivider(uint8_t rate) 62 | { 63 | SPCR = (SPCR & ~SPI_CLOCK_MASK) | (rate & SPI_CLOCK_MASK); 64 | SPSR = (SPSR & ~SPI_2XCLOCK_MASK) | ((rate >> 2) & SPI_2XCLOCK_MASK); 65 | } 66 | 67 | -------------------------------------------------------------------------------- /02.Library/SPI/SPI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 by Cristian Maglie 3 | * SPI Master library for arduino. 4 | * 5 | * This file is free software; you can redistribute it and/or modify 6 | * it under the terms of either the GNU General Public License version 2 7 | * or the GNU Lesser General Public License version 2.1, both as 8 | * published by the Free Software Foundation. 9 | */ 10 | 11 | #ifndef _SPI_H_INCLUDED 12 | #define _SPI_H_INCLUDED 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #define SPI_CLOCK_DIV4 0x00 19 | #define SPI_CLOCK_DIV16 0x01 20 | #define SPI_CLOCK_DIV64 0x02 21 | #define SPI_CLOCK_DIV128 0x03 22 | #define SPI_CLOCK_DIV2 0x04 23 | #define SPI_CLOCK_DIV8 0x05 24 | #define SPI_CLOCK_DIV32 0x06 25 | //#define SPI_CLOCK_DIV64 0x07 26 | 27 | #define SPI_MODE0 0x00 28 | #define SPI_MODE1 0x04 29 | #define SPI_MODE2 0x08 30 | #define SPI_MODE3 0x0C 31 | 32 | #define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR 33 | #define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR 34 | #define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR 35 | 36 | class SPIClass { 37 | public: 38 | inline static byte transfer(byte _data); 39 | 40 | // SPI Configuration methods 41 | 42 | inline static void attachInterrupt(); 43 | inline static void detachInterrupt(); // Default 44 | 45 | static void begin(); // Default 46 | static void end(); 47 | 48 | static void setBitOrder(uint8_t); 49 | static void setDataMode(uint8_t); 50 | static void setClockDivider(uint8_t); 51 | }; 52 | 53 | extern SPIClass SPI; 54 | 55 | byte SPIClass::transfer(byte _data) { 56 | SPDR = _data; 57 | while (!(SPSR & _BV(SPIF))) 58 | ; 59 | return SPDR; 60 | } 61 | 62 | void SPIClass::attachInterrupt() { 63 | SPCR |= _BV(SPIE); 64 | } 65 | 66 | void SPIClass::detachInterrupt() { 67 | SPCR &= ~_BV(SPIE); 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /02.Library/SPI/examples/DigitalPotControl/DigitalPotControl.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Digital Pot Control 3 | 4 | This example controls an Analog Devices AD5206 digital potentiometer. 5 | The AD5206 has 6 potentiometer channels. Each channel's pins are labeled 6 | A - connect this to voltage 7 | W - this is the pot's wiper, which changes when you set it 8 | B - connect this to ground. 9 | 10 | The AD5206 is SPI-compatible,and to command it, you send two bytes, 11 | one with the channel number (0 - 5) and one with the resistance value for the 12 | channel (0 - 255). 13 | 14 | The circuit: 15 | * All A pins of AD5206 connected to +5V 16 | * All B pins of AD5206 connected to ground 17 | * An LED and a 220-ohm resisor in series connected from each W pin to ground 18 | * CS - to digital pin 10 (SS pin) 19 | * SDI - to digital pin 11 (MOSI pin) 20 | * CLK - to digital pin 13 (SCK pin) 21 | 22 | created 10 Aug 2010 23 | by Tom Igoe 24 | 25 | Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 26 | 27 | */ 28 | 29 | 30 | // inslude the SPI library: 31 | #include 32 | 33 | 34 | // set pin 10 as the slave select for the digital pot: 35 | const int slaveSelectPin = 10; 36 | 37 | void setup() { 38 | // set the slaveSelectPin as an output: 39 | pinMode (slaveSelectPin, OUTPUT); 40 | // initialize SPI: 41 | SPI.begin(); 42 | } 43 | 44 | void loop() { 45 | // go through the six channels of the digital pot: 46 | for (int channel = 0; channel < 6; channel++) { 47 | // change the resistance on this channel from min to max: 48 | for (int level = 0; level < 255; level++) { 49 | digitalPotWrite(channel, level); 50 | delay(10); 51 | } 52 | // wait a second at the top: 53 | delay(100); 54 | // change the resistance on this channel from max to min: 55 | for (int level = 0; level < 255; level++) { 56 | digitalPotWrite(channel, 255 - level); 57 | delay(10); 58 | } 59 | } 60 | 61 | } 62 | 63 | int digitalPotWrite(int address, int value) { 64 | // take the SS pin low to select the chip: 65 | digitalWrite(slaveSelectPin,LOW); 66 | // send in the address and value via SPI: 67 | SPI.transfer(address); 68 | SPI.transfer(value); 69 | // take the SS pin high to de-select the chip: 70 | digitalWrite(slaveSelectPin,HIGH); 71 | } -------------------------------------------------------------------------------- /02.Library/SPI/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map SPI 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SPI KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | begin KEYWORD2 15 | end KEYWORD2 16 | transfer KEYWORD2 17 | setBitOrder KEYWORD2 18 | setDataMode KEYWORD2 19 | setClockDivider KEYWORD2 20 | 21 | 22 | ####################################### 23 | # Constants (LITERAL1) 24 | ####################################### 25 | SPI_CLOCK_DIV4 LITERAL1 26 | SPI_CLOCK_DIV16 LITERAL1 27 | SPI_CLOCK_DIV64 LITERAL1 28 | SPI_CLOCK_DIV128 LITERAL1 29 | SPI_CLOCK_DIV2 LITERAL1 30 | SPI_CLOCK_DIV8 LITERAL1 31 | SPI_CLOCK_DIV32 LITERAL1 32 | SPI_CLOCK_DIV64 LITERAL1 33 | SPI_MODE0 LITERAL1 34 | SPI_MODE1 LITERAL1 35 | SPI_MODE2 LITERAL1 36 | SPI_MODE3 LITERAL1 -------------------------------------------------------------------------------- /02.Library/U8glib/INSTALL.TXT: -------------------------------------------------------------------------------- 1 | 2 | U8GLIB 3 | http://code.google.com/p/u8glib/ 4 | 5 | 6 | Install instructions for the Arduino environment. 7 | 8 | 1. Unzip u8glib_arduino_vX.XX.zip into the "libraries" folder 9 | 2. Start Arduino IDE 10 | 11 | Install instructions for the Chipkit (Arduino) environment. 12 | 13 | 1. cd /libraries 14 | 2. unzip u8glib_arduino_vX.XX.zip 15 | 3. cd ///hardware/pic32/libraries 16 | 4. again: u8glib_arduino_vX.XX.zip 17 | 5. Open hardware/pic32/cores/pic32/Print.h 18 | Remove line 19 | #define BYTE 0 20 | from the file, use PRINT_BYTE instead of BYTE. 21 | -------------------------------------------------------------------------------- /02.Library/U8glib/U8glib.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | U8glib.cpp 4 | 5 | C++ Interface 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | */ 37 | 38 | #include "U8glib.h" 39 | 40 | 41 | 42 | uint8_t U8GLIB::initSPI(u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset) 43 | { 44 | prepare(); 45 | return u8g_InitSPI(&u8g, dev, sck, mosi, cs, a0, reset); 46 | } 47 | 48 | uint8_t U8GLIB::initHWSPI(u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset) 49 | { 50 | prepare(); 51 | return u8g_InitHWSPI(&u8g, dev, cs, a0, reset); 52 | } 53 | 54 | uint8_t U8GLIB::initI2C(u8g_dev_t *dev, uint8_t options) 55 | { 56 | prepare(); 57 | return u8g_InitI2C(&u8g, dev, options); 58 | } 59 | 60 | uint8_t U8GLIB::init8Bit(u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, 61 | uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw, uint8_t reset) 62 | { 63 | prepare(); 64 | return u8g_Init8Bit(&u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset); 65 | } 66 | 67 | uint8_t U8GLIB::init8BitFixedPort(u8g_dev_t *dev, uint8_t en, uint8_t cs, uint8_t di, uint8_t rw, uint8_t reset) 68 | { 69 | prepare(); 70 | return u8g_Init8BitFixedPort(&u8g, dev, en, cs, di, rw, reset); 71 | } 72 | 73 | uint8_t U8GLIB::initRW8Bit(u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, 74 | uint8_t cs, uint8_t a0, uint8_t wr, uint8_t rd, uint8_t reset) 75 | { 76 | prepare(); 77 | return u8g_InitRW8Bit(&u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, cs, a0, wr, rd, reset); 78 | } 79 | 80 | 81 | -------------------------------------------------------------------------------- /02.Library/U8glib/license.txt: -------------------------------------------------------------------------------- 1 | 2 | The U8glib code (http://code.google.com/p/u8glib/) is licensed under the terms of 3 | the new-bsd license (two-clause bsd license). 4 | See also: http://www.opensource.org/licenses/bsd-license.php 5 | 6 | The repository and optionally the releases contain icons, which are 7 | derived from the WPZOOM Developer Icon Set: 8 | http://www.wpzoom.com/wpzoom/new-freebie-wpzoom-developer-icon-set-154-free-icons/ 9 | WPZOOM Developer Icon Set by WPZOOM is licensed under a Creative Commons 10 | Attribution-ShareAlike 3.0 Unported License. 11 | 12 | Fonts are licensed under different conditions. 13 | See http://code.google.com/p/u8glib/wiki/fontgroup for 14 | detailed information on the licensing conditions for each font. 15 | 16 | ============ X11 Fonts COUR, HELV, NCEN, TIM, SYMB ============ 17 | 18 | For fonts derived from the following files, the license below applies. 19 | COURB08.BDF COURB10.BDF COURB12.BDF COURB14.BDF COURB18.BDF 20 | COURB24.BDF COURR08.BDF COURR10.BDF COURR12.BDF COURR14.BDF 21 | COURR18.BDF COURR24.BDF HELVB08.BDF HELVB10.BDF HELVB12.BDF HELVB14.BDF 22 | HELVB18.BDF HELVB24.BDF HELVR08.BDF HELVR10.BDF HELVR12.BDF HELVR14.BDF 23 | HELVR18.BDF HELVR24.BDF NCENB08.BDF NCENB10.BDF NCENB12.BDF 24 | NCENB14.BDF NCENB18.BDF NCENB24.BDF NCENR08.BDF NCENR10.BDF 25 | NCENR12.BDF NCENR14.BDF NCENR18.BDF NCENR24.BDF SYMB08.BDF SYMB10.BDF 26 | SYMB12.BDF SYMB14.BDF SYMB18.BDF SYMB24.BDF TIMB08.BDF TIMB10.BDF 27 | TIMB12.BDF TIMB14.BDF TIMB18.BDF TIMB24.BDF TIMR08.BDF TIMR10.BDF 28 | TIMR12.BDF TIMR14.BDF TIMR18.BDF TIMR24.BDF 29 | 30 | Copyright 1984-1989, 1994 Adobe Systems Incorporated. 31 | Copyright 1988, 1994 Digital Equipment Corporation. 32 | 33 | Adobe is a trademark of Adobe Systems Incorporated which may be 34 | registered in certain jurisdictions. 35 | Permission to use these trademarks is hereby granted only in 36 | association with the images described in this file. 37 | 38 | Permission to use, copy, modify, distribute and sell this software 39 | and its documentation for any purpose and without fee is hereby 40 | granted, provided that the above copyright notices appear in all 41 | copies and that both those copyright notices and this permission 42 | notice appear in supporting documentation, and that the names of 43 | Adobe Systems and Digital Equipment Corporation not be used in 44 | advertising or publicity pertaining to distribution of the software 45 | without specific, written prior permission. Adobe Systems and 46 | Digital Equipment Corporation make no representations about the 47 | suitability of this software for any purpose. It is provided "as 48 | is" without express or implied warranty. 49 | 50 | 51 | ============ BSD License for U8glib Code ============ 52 | 53 | Universal 8bit Graphics Library (http://code.google.com/p/u8glib/) 54 | 55 | Copyright (c) 2011, olikraus@gmail.com 56 | All rights reserved. 57 | 58 | Redistribution and use in source and binary forms, with or without modification, 59 | are permitted provided that the following conditions are met: 60 | 61 | * Redistributions of source code must retain the above copyright notice, this list 62 | of conditions and the following disclaimer. 63 | 64 | * Redistributions in binary form must reproduce the above copyright notice, this 65 | list of conditions and the following disclaimer in the documentation and/or other 66 | materials provided with the distribution. 67 | 68 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 69 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 70 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 71 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 72 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 73 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 74 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 75 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 76 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 77 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 78 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 79 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 80 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 81 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/chessengine.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/02.Library/U8glib/utility/chessengine.c -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_com_api_16gr.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_api_16gr.c 4 | 5 | Extension of the com api for devices with 16 graylevels (4 bit per pixel). 6 | This should fit to the 8h and 16h architectures (pb8v1, pb8v2, pb16v1, pb16v2), 7 | mainly intended for SSD OLEDs 8 | 9 | Universal 8bit Graphics Library 10 | 11 | Copyright (c) 2011, olikraus@gmail.com 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without modification, 15 | are permitted provided that the following conditions are met: 16 | 17 | * Redistributions of source code must retain the above copyright notice, this list 18 | of conditions and the following disclaimer. 19 | 20 | * Redistributions in binary form must reproduce the above copyright notice, this 21 | list of conditions and the following disclaimer in the documentation and/or other 22 | materials provided with the distribution. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 25 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 26 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 29 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 36 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | 39 | */ 40 | 41 | #include "u8g.h" 42 | 43 | /* interpret b as a monochrome bit pattern, write value 15 for high bit and value 0 for a low bit */ 44 | /* topbit (msb) is sent last */ 45 | /* example: b = 0x083 will send 0xff, 0x00, 0x00, 0xf0 */ 46 | uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b) 47 | { 48 | static uint8_t buf[4]; 49 | static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff }; 50 | buf [3] = map[b & 3]; 51 | b>>=2; 52 | buf [2] = map[b & 3]; 53 | b>>=2; 54 | buf [1] = map[b & 3]; 55 | b>>=2; 56 | buf [0] = map[b & 3]; 57 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, 4, buf); 58 | } 59 | 60 | uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr) 61 | { 62 | do 63 | { 64 | if ( u8g_WriteByteBWTo16GrDevice(u8g, dev, *ptr++) == 0 ) 65 | return 0; 66 | cnt--; 67 | } while( cnt != 0 ); 68 | return 1; 69 | } 70 | 71 | /* interpret b as a 4L bit pattern, write values 0x000, 0x004, 0x008, 0x00c */ 72 | uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b) 73 | { 74 | //static uint8_t map[16] = { 0x000, 0x004, 0x008, 0x00c, 0x040, 0x044, 0x048, 0x04c, 0x080, 0x084, 0x088, 0x08c, 0x0c0, 0x0c4, 0x0c8, 0x0cc}; 75 | //static uint8_t map[16] = { 0x000, 0x004, 0x00a, 0x00f, 0x040, 0x044, 0x04a, 0x04f, 0x0a0, 0x0a4, 0x0aa, 0x0af, 0x0f0, 0x0f4, 0x0fa, 0x0ff}; 76 | static uint8_t map[16] = { 0x000, 0x040, 0x0a0, 0x0f0, 0x004, 0x044, 0x0a4, 0x0f4, 0x00a, 0x04a, 0x0aa, 0x0fa, 0x00f, 0x04f, 0x0af, 0x0ff}; 77 | uint8_t bb; 78 | bb = b; 79 | bb &= 15; 80 | b>>=4; 81 | dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[bb], NULL); 82 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[b], NULL); 83 | } 84 | 85 | uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr) 86 | { 87 | do 88 | { 89 | if ( u8g_WriteByte4LTo16GrDevice(u8g, dev, *ptr++) == 0 ) 90 | return 0; 91 | cnt--; 92 | } while( cnt != 0 ); 93 | return 1; 94 | } 95 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_com_arduino_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_arduino_common.c 4 | 5 | shared procedures for the arduino communication procedures 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | #if defined(ARDUINO) 42 | 43 | #if ARDUINO < 100 44 | #include 45 | #else 46 | #include 47 | #endif 48 | 49 | void u8g_com_arduino_digital_write(u8g_t *u8g, uint8_t pin_index, uint8_t value) 50 | { 51 | uint8_t pin; 52 | pin = u8g->pin_list[pin_index]; 53 | if ( pin != U8G_PIN_NONE ) 54 | digitalWrite(pin, value); 55 | } 56 | 57 | /* this procedure does not set the RW pin */ 58 | void u8g_com_arduino_assign_pin_output_high(u8g_t *u8g) 59 | { 60 | uint8_t i; 61 | /* skip the RW pin, which is the last pin in the list */ 62 | for( i = 0; i < U8G_PIN_LIST_LEN-1; i++ ) 63 | { 64 | if ( u8g->pin_list[i] != U8G_PIN_NONE ) 65 | { 66 | pinMode(u8g->pin_list[i], OUTPUT); 67 | digitalWrite(u8g->pin_list[i], HIGH); 68 | } 69 | } 70 | } 71 | 72 | 73 | #endif 74 | 75 | 76 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_com_atmega_sw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_atmega_sw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | #if defined(__AVR__) 40 | 41 | static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE; 42 | static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) 43 | { 44 | uint8_t i = 8; 45 | do 46 | { 47 | u8g_SetPILevel(u8g, U8G_PI_MOSI, val & 128 ); 48 | val <<= 1; 49 | u8g_SetPILevel(u8g, U8G_PI_SCK, 1 ); 50 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 51 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 52 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 53 | i--; 54 | } while( i != 0 ); 55 | } 56 | 57 | uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 58 | { 59 | switch(msg) 60 | { 61 | case U8G_COM_MSG_INIT: 62 | u8g_SetPIOutput(u8g, U8G_PI_SCK); 63 | u8g_SetPIOutput(u8g, U8G_PI_MOSI); 64 | u8g_SetPIOutput(u8g, U8G_PI_A0); 65 | u8g_SetPIOutput(u8g, U8G_PI_CS); 66 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 67 | 68 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 69 | u8g_SetPILevel(u8g, U8G_PI_MOSI, 0 ); 70 | u8g_SetPILevel(u8g, U8G_PI_CS, 1 ); 71 | u8g_SetPILevel(u8g, U8G_PI_A0, 0); 72 | break; 73 | 74 | case U8G_COM_MSG_STOP: 75 | break; 76 | 77 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 78 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 79 | break; 80 | 81 | case U8G_COM_MSG_CHIP_SELECT: 82 | 83 | if ( arg_val == 0 ) 84 | { 85 | /* disable */ 86 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 87 | } 88 | else 89 | { 90 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 91 | /* enable */ 92 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); /* CS = 0 (low active) */ 93 | } 94 | break; 95 | 96 | case U8G_COM_MSG_RESET: 97 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 98 | break; 99 | 100 | 101 | case U8G_COM_MSG_WRITE_BYTE: 102 | u8g_atmega_sw_spi_shift_out(u8g, arg_val); 103 | break; 104 | 105 | case U8G_COM_MSG_WRITE_SEQ: 106 | { 107 | register uint8_t *ptr = arg_ptr; 108 | while( arg_val > 0 ) 109 | { 110 | u8g_atmega_sw_spi_shift_out(u8g, *ptr++); 111 | arg_val--; 112 | } 113 | } 114 | break; 115 | 116 | case U8G_COM_MSG_WRITE_SEQ_P: 117 | { 118 | register uint8_t *ptr = arg_ptr; 119 | while( arg_val > 0 ) 120 | { 121 | u8g_atmega_sw_spi_shift_out(u8g, u8g_pgm_read(ptr)); 122 | ptr++; 123 | arg_val--; 124 | } 125 | } 126 | break; 127 | } 128 | return 1; 129 | } 130 | 131 | #else 132 | 133 | 134 | uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 135 | { 136 | return 1; 137 | } 138 | 139 | 140 | #endif 141 | 142 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_com_null.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_null.c 4 | 5 | communication null device 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | uint8_t u8g_com_null_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 42 | { 43 | switch(msg) 44 | { 45 | case U8G_COM_MSG_INIT: 46 | break; 47 | case U8G_COM_MSG_STOP: 48 | break; 49 | 50 | 51 | case U8G_COM_MSG_CHIP_SELECT: 52 | /* arg_val contains the chip number, which should be enabled */ 53 | break; 54 | 55 | 56 | case U8G_COM_MSG_WRITE_BYTE: 57 | break; 58 | case U8G_COM_MSG_WRITE_SEQ: 59 | break; 60 | } 61 | return 1; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_cursor.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_cursor.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | void u8g_SetCursorFont(u8g_t *u8g, const u8g_pgm_uint8_t *cursor_font) 40 | { 41 | u8g->cursor_font = cursor_font; 42 | } 43 | 44 | void u8g_SetCursorStyle(u8g_t *u8g, uint8_t encoding) 45 | { 46 | u8g->cursor_encoding = encoding; 47 | } 48 | 49 | void u8g_SetCursorColor(u8g_t *u8g, uint8_t fg, uint8_t bg) 50 | { 51 | u8g->cursor_bg_color = bg; 52 | u8g->cursor_fg_color = fg; 53 | } 54 | 55 | void u8g_SetCursorPos(u8g_t *u8g, u8g_uint_t cursor_x, u8g_uint_t cursor_y) 56 | { 57 | u8g->cursor_x = cursor_x; 58 | u8g->cursor_y = cursor_y; 59 | } 60 | 61 | void u8g_EnableCursor(u8g_t *u8g) 62 | { 63 | u8g->cursor_fn = u8g_DrawCursor; 64 | } 65 | 66 | void u8g_DisableCursor(u8g_t *u8g) 67 | { 68 | u8g->cursor_fn = (u8g_draw_cursor_fn)0; 69 | } 70 | 71 | void u8g_DrawCursor(u8g_t *u8g) 72 | { 73 | const u8g_pgm_uint8_t *font; 74 | uint8_t color; 75 | uint8_t encoding = u8g->cursor_encoding; 76 | 77 | /* get current values */ 78 | color = u8g_GetColorIndex(u8g); 79 | font = u8g->font; 80 | 81 | /* draw cursor */ 82 | u8g->font = u8g->cursor_font; 83 | encoding++; 84 | u8g_SetColorIndex(u8g, u8g->cursor_bg_color); 85 | /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */ 86 | /* required, because y adjustment should not happen to the cursor fonts */ 87 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); 88 | encoding--; 89 | u8g_SetColorIndex(u8g, u8g->cursor_fg_color); 90 | /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */ 91 | /* required, because y adjustment should not happen to the cursor fonts */ 92 | /* u8g_DrawGlyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); */ 93 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); 94 | 95 | /* restore previous values */ 96 | u8g->font = font; 97 | u8g_SetColorIndex(u8g, color); 98 | } 99 | 100 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_dev_flipdisc_2x7.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_flipdisc.c 4 | 5 | 1-Bit (BW) Driver for flip disc matrix 6 | 2x 7 pixel height 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | #define WIDTH 28 42 | #define HEIGHT 14 43 | #define PAGE_HEIGHT 14 44 | 45 | /* 46 | Write data to the flip disc matrix. 47 | This procedure must be implemented by the user. 48 | Arguments: 49 | id: Id for the matrix. Currently always 0. 50 | page: A page has a height of 14 pixel. For a matrix with HEIGHT == 14 this will be always 0 51 | width: The width of the flip disc matrix. Always equal to WIDTH 52 | row1: first data line (7 pixel per byte) 53 | row2: first data line (7 pixel per byte) 54 | */ 55 | void writeFlipDiscMatrix(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2); 56 | 57 | 58 | 59 | void (*u8g_write_flip_disc_matrix)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2); 60 | 61 | void u8g_SetFlipDiscCallback(u8g_t *u8g, void (*cb)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2)) 62 | { 63 | u8g_write_flip_disc_matrix = cb; 64 | } 65 | 66 | uint8_t u8g_dev_flipdisc_2x7_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 67 | { 68 | switch(msg) 69 | { 70 | case U8G_DEV_MSG_INIT: 71 | break; 72 | case U8G_DEV_MSG_STOP: 73 | break; 74 | case U8G_DEV_MSG_PAGE_NEXT: 75 | { 76 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 77 | 78 | /* current page: pb->p.page */ 79 | /* ptr to the buffer: pb->buf */ 80 | 81 | (*u8g_write_flip_disc_matrix)(0, pb->p.page, WIDTH, pb->buf, pb->buf+WIDTH); 82 | } 83 | break; 84 | case U8G_DEV_MSG_CONTRAST: 85 | return 1; 86 | } 87 | return u8g_dev_pb14v1_base_fn(u8g, dev, msg, arg); 88 | } 89 | 90 | uint8_t u8g_dev_flipdisc_2x7_bw_buf[WIDTH*2] U8G_NOCOMMON ; 91 | u8g_pb_t u8g_dev_flipdisc_2x7_bw_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_flipdisc_2x7_bw_buf}; 92 | u8g_dev_t u8g_dev_flipdisc_2x7 = { u8g_dev_flipdisc_2x7_bw_fn, &u8g_dev_flipdisc_2x7_bw_pb, u8g_com_null_fn }; 93 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_dev_gprof.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_gprof.c 4 | 5 | Device for performance measurement with gprof. 6 | Does not write any data, but uses a buffer. 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | 39 | */ 40 | 41 | #include "u8g.h" 42 | 43 | 44 | #define WIDTH 128 45 | #define HEIGHT 64 46 | #define PAGE_HEIGHT 8 47 | 48 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); 49 | 50 | uint8_t u8g_pb_dev_gprof_buf[WIDTH]; 51 | u8g_pb_t u8g_pb_dev_gprof = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_pb_dev_gprof_buf }; 52 | 53 | u8g_dev_t u8g_dev_gprof = { u8g_dev_gprof_fn, &u8g_pb_dev_gprof, NULL }; 54 | 55 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 56 | { 57 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 58 | 59 | switch(msg) 60 | { 61 | case U8G_DEV_MSG_INIT: 62 | break; 63 | case U8G_DEV_MSG_STOP: 64 | break; 65 | case U8G_DEV_MSG_PAGE_FIRST: 66 | u8g_pb_Clear(pb); 67 | u8g_page_First(&(pb->p)); 68 | break; 69 | case U8G_DEV_MSG_PAGE_NEXT: 70 | /* 71 | { 72 | uint8_t i, j; 73 | uint8_t page_height; 74 | page_height = pb->p.page_y1; 75 | page_height -= pb->p.page_y0; 76 | page_height++; 77 | for( j = 0; j < page_height; j++ ) 78 | { 79 | printf("%02d ", j); 80 | for( i = 0; i < WIDTH; i++ ) 81 | { 82 | if ( (u8g_pb_dev_stdout_buf[i] & (1<p)) == 0 ) 92 | { 93 | //printf("\n"); 94 | return 0; 95 | } 96 | u8g_pb_Clear(pb); 97 | break; 98 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 99 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 100 | { 101 | u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg; 102 | u8g_uint_t x2, y2; 103 | 104 | y2 = bbx->y; 105 | y2 += bbx->h; 106 | y2--; 107 | 108 | if ( u8g_pb_IsYIntersection(pb, bbx->y, y2) == 0 ) 109 | return 0; 110 | 111 | /* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */ 112 | x2 = bbx->x; 113 | x2 += bbx->w; 114 | x2--; 115 | 116 | if ( u8g_pb_IsXIntersection(pb, bbx->x, x2) == 0 ) 117 | return 0; 118 | } 119 | return 1; 120 | #endif 121 | case U8G_DEV_MSG_GET_PAGE_BOX: 122 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 123 | break; 124 | case U8G_DEV_MSG_SET_COLOR_INDEX: 125 | break; 126 | case U8G_DEV_MSG_SET_XY_CB: 127 | break; 128 | } 129 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 130 | } 131 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_dev_null.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_null.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | uint8_t u8g_dev_null(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 40 | { 41 | switch(msg) 42 | { 43 | case U8G_DEV_MSG_SET_8PIXEL: /* most often used command */ 44 | break; 45 | case U8G_DEV_MSG_SET_PIXEL: 46 | break; 47 | case U8G_DEV_MSG_INIT: 48 | break; 49 | case U8G_DEV_MSG_STOP: 50 | break; 51 | case U8G_DEV_MSG_PAGE_FIRST: 52 | break; 53 | case U8G_DEV_MSG_PAGE_NEXT: 54 | break; 55 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 56 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 57 | return 1; 58 | #endif 59 | case U8G_DEV_MSG_GET_PAGE_BOX: 60 | break; 61 | case U8G_DEV_MSG_SET_COLOR_INDEX: 62 | break; 63 | case U8G_DEV_MSG_SET_XY_CB: 64 | break; 65 | } 66 | return 1; 67 | } 68 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_dev_sbn1661_122x32.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_sbn1661_122x32.c 4 | 5 | WG12232 display with 2xSBN1661 / SED1520 controller (122x32 display) 6 | At the moment only available in the Arduino Environment 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | */ 39 | 40 | #include "u8g.h" 41 | 42 | #define WIDTH 122 43 | #define HEIGHT 32 44 | #define PAGE_HEIGHT 8 45 | 46 | 47 | static const uint8_t u8g_dev_sbn1661_122x32_init_seq[] PROGMEM = { 48 | U8G_ESC_CS(0), /* disable chip */ 49 | U8G_ESC_ADR(0), /* instruction mode */ 50 | U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds */ 51 | U8G_ESC_CS(1), /* enable chip 1 */ 52 | 0x0af, /* display on */ 53 | 0x0c0, /* display start at line 0 */ 54 | 0x0a0, /* a0: ADC forward, a1: ADC reverse */ 55 | 0x0a9, /* a8: 1/16, a9: 1/32 duty */ 56 | U8G_ESC_CS(2), /* enable chip 2 */ 57 | 0x0af, /* display on */ 58 | 0x0c0, /* display start at line 0 */ 59 | 0x0a0, /* a0: ADC forward, a1: ADC reverse */ 60 | 0x0a9, /* a8: 1/16, a9: 1/32 duty */ 61 | 62 | U8G_ESC_CS(0), /* disable chip */ 63 | 64 | 65 | U8G_ESC_END /* end of sequence */ 66 | }; 67 | 68 | uint8_t u8g_dev_sbn1661_122x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 69 | { 70 | switch(msg) 71 | { 72 | case U8G_DEV_MSG_INIT: 73 | u8g_InitCom(u8g, dev); 74 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_sbn1661_122x32_init_seq); 75 | break; 76 | case U8G_DEV_MSG_STOP: 77 | break; 78 | case U8G_DEV_MSG_PAGE_NEXT: 79 | { 80 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 81 | 82 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 83 | u8g_SetChipSelect(u8g, dev, 1); 84 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */ 85 | u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */ 86 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 87 | u8g_WriteSequence(u8g, dev, WIDTH/2, pb->buf); 88 | 89 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 90 | u8g_SetChipSelect(u8g, dev, 2); 91 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */ 92 | u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */ 93 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 94 | u8g_WriteSequence(u8g, dev, WIDTH/2, WIDTH/2+(uint8_t *)pb->buf); 95 | 96 | u8g_SetChipSelect(u8g, dev, 0); 97 | 98 | } 99 | break; 100 | case U8G_DEV_MSG_CONTRAST: 101 | break; 102 | } 103 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 104 | } 105 | 106 | /* u8g_com_arduino_sw_spi_fn does not work, too fast??? */ 107 | U8G_PB_DEV(u8g_dev_sbn1661_122x32 , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sbn1661_122x32_fn, u8g_com_arduino_no_en_parallel_fn); 108 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_ellipse.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_ellipse.c 4 | 5 | Utility to draw empty and filled ellipses. 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, bjthom@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | Addition to the U8G Library as of 02/29/12 37 | Adapted from Bresenham's Algorithm and the following websites: 38 | http://free.pages.at/easyfilter/bresenham.html 39 | http://homepage.smc.edu/kennedy_john/belipse.pdf 40 | 41 | */ 42 | 43 | #include "u8g.h" 44 | 45 | 46 | #ifdef WORK_IN_PROGRESS 47 | 48 | void u8g_DrawEllipseRect(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t x1, u8g_uint_t y1) 49 | { 50 | int a = abs(x1 - x0); 51 | int b = abs(y1 - y0); //get diameters 52 | int b1 = b&1; 53 | long dx = 4*(1-a)*b*b; 54 | long dy = 4*(b1+1)*a*a; 55 | long err = dx+dy+b1*a*a; 56 | long e2; 57 | 58 | if (x0 > x1) { x0 = x1; x1 += a; } 59 | if (y0 > y1) { y0 = y1; } 60 | y0 += (b+1)/2; 61 | y1 = y0-b1; 62 | a *= 8*a; 63 | b1 = 8*b*b; 64 | 65 | do { 66 | u8g_DrawPixel(u8g, x1, y0); 67 | u8g_DrawPixel(u8g, x0, y0); 68 | u8g_DrawPixel(u8g, x0, y1); 69 | u8g_DrawPixel(u8g, x1, y1); 70 | e2 = 2*err; 71 | if (e2 >= dx) { 72 | x0++; 73 | x1--; 74 | err += dx += b1; 75 | } 76 | if (e2 <= dy) { 77 | y0++; 78 | y1--; 79 | err += dy += a; 80 | } 81 | } while (x0 <= x1); 82 | 83 | while (y0-y1 < b) { 84 | u8g_DrawPixel(u8g, x0-1, y0); 85 | u8g_DrawPixel(u8g, x1+1, y0++); 86 | u8g_DrawPixel(u8g, x0-1, y1); 87 | u8g_DrawPixel(u8g, x1+1, y1--); 88 | } 89 | } 90 | 91 | void u8g_DrawEllipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t xr, u8g_uint_t yr) 92 | { 93 | u8g_DrawPixel(u8g, x0, y0+yr); 94 | u8g_DrawPixel(u8g, x0, y0-yr); 95 | u8g_DrawPixel(u8g, x0+xr, y0); 96 | u8g_DrawPixel(u8g, x0-xr, y0); 97 | } 98 | 99 | #endif 100 | 101 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_font_data.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/02.Library/U8glib/utility/u8g_font_data.c -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_line.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_line.h 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | #include "u8g.h" 37 | 38 | void u8g_DrawLine(u8g_t *u8g, u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2) 39 | { 40 | u8g_uint_t tmp; 41 | u8g_uint_t x,y; 42 | u8g_uint_t dx, dy; 43 | u8g_int_t err; 44 | u8g_int_t ystep; 45 | 46 | uint8_t swapxy = 0; 47 | 48 | /* no BBX intersection check at the moment, should be added... */ 49 | 50 | if ( x1 > x2 ) dx = x1-x2; else dx = x2-x1; 51 | if ( y1 > y2 ) dy = y1-y2; else dy = y2-y1; 52 | 53 | if ( dy > dx ) 54 | { 55 | swapxy = 1; 56 | tmp = dx; dx =dy; dy = tmp; 57 | tmp = x1; x1 =y1; y1 = tmp; 58 | tmp = x2; x2 =y2; y2 = tmp; 59 | } 60 | if ( x1 > x2 ) 61 | { 62 | tmp = x1; x1 =x2; x2 = tmp; 63 | tmp = y1; y1 =y2; y2 = tmp; 64 | } 65 | err = dx >> 1; 66 | if ( y2 > y1 ) ystep = 1; else ystep = -1; 67 | y = y1; 68 | for( x = x1; x <= x2; x++ ) 69 | { 70 | if ( swapxy == 0 ) 71 | u8g_DrawPixel(u8g, x, y); 72 | else 73 | u8g_DrawPixel(u8g, y, x); 74 | err -= (uint8_t)dy; 75 | if ( err < 0 ) 76 | { 77 | y += (u8g_uint_t)ystep; 78 | err += (u8g_uint_t)dx; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_page.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_page.c 4 | 5 | page helper functions, only called by the dev handler. 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | /* 42 | setup page count structure 43 | conditions: page_height <= total_height 44 | */ 45 | void u8g_page_Init(u8g_page_t *p, u8g_uint_t page_height, u8g_uint_t total_height ) 46 | { 47 | p->page_height = page_height; 48 | p->total_height = total_height; 49 | p->page = 0; 50 | u8g_page_First(p); 51 | } 52 | 53 | void u8g_page_First(u8g_page_t *p) 54 | { 55 | p->page_y0 = 0; 56 | p->page_y1 = p->page_height; 57 | p->page_y1--; 58 | p->page = 0; 59 | } 60 | 61 | uint8_t u8g_page_Next(u8g_page_t * p) 62 | { 63 | register u8g_uint_t y1; 64 | p->page_y0 += p->page_height; 65 | if ( p->page_y0 >= p->total_height ) 66 | return 0; 67 | p->page++; 68 | y1 = p->page_y1; 69 | y1 += p->page_height; 70 | if ( y1 >= p->total_height ) 71 | { 72 | y1 = p->total_height; 73 | y1--; 74 | } 75 | p->page_y1 = y1; 76 | 77 | return 1; 78 | } 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_state.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_state.c 4 | 5 | backup and restore hardware state 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | state callback: backup env U8G_STATE_MSG_BACKUP_ENV 38 | device callback: DEV_MSG_INIT 39 | state callback: backup u8g U8G_STATE_MSG_BACKUP_U8G 40 | state callback: restore env U8G_STATE_MSG_RESTORE_ENV 41 | 42 | state callback: backup env U8G_STATE_MSG_BACKUP_ENV 43 | state callback: retore u8g U8G_STATE_MSG_RESTORE_U8G 44 | DEV_MSG_PAGE_FIRST or DEV_MSG_PAGE_NEXT 45 | state callback: restore env U8G_STATE_MSG_RESTORE_ENV 46 | 47 | */ 48 | 49 | #include 50 | #include "u8g.h" 51 | 52 | void u8g_state_dummy_cb(uint8_t msg) 53 | { 54 | /* the dummy procedure does nothing */ 55 | } 56 | 57 | void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb) 58 | { 59 | u8g->state_cb = backup_cb; 60 | /* in most cases the init message was already sent, so this will backup the */ 61 | /* current u8g state */ 62 | backup_cb(U8G_STATE_MSG_BACKUP_U8G); 63 | } 64 | 65 | 66 | /*===============================================================*/ 67 | /* AVR */ 68 | 69 | #if defined(__AVR__) 70 | #define U8G_ATMEGA_HW_SPI 71 | 72 | /* remove the definition for attiny */ 73 | #if __AVR_ARCH__ == 2 74 | #undef U8G_ATMEGA_HW_SPI 75 | #endif 76 | #if __AVR_ARCH__ == 25 77 | #undef U8G_ATMEGA_HW_SPI 78 | #endif 79 | #endif 80 | 81 | #if defined(U8G_ATMEGA_HW_SPI) 82 | #include 83 | static uint8_t u8g_state_avr_spi_memory[2]; 84 | 85 | void u8g_backup_avr_spi(uint8_t msg) 86 | { 87 | if ( U8G_STATE_MSG_IS_BACKUP(msg) ) 88 | { 89 | u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)] = SPCR; 90 | } 91 | else 92 | { 93 | uint8_t tmp = SREG; 94 | cli(); 95 | SPCR = 0; 96 | SPCR = u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)]; 97 | SREG = tmp; 98 | } 99 | } 100 | 101 | #endif 102 | 103 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_u16toa.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_u16toa.c 4 | 5 | 6 | Universal 8bit Graphics Library 7 | 8 | Copyright (c) 2012, olikraus@gmail.com 9 | All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | * Redistributions of source code must retain the above copyright notice, this list 15 | of conditions and the following disclaimer. 16 | 17 | * Redistributions in binary form must reproduce the above copyright notice, this 18 | list of conditions and the following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | 38 | #include "u8g.h" 39 | 40 | const char *u8g_u16toap(char * dest, uint16_t v) 41 | { 42 | uint8_t pos; 43 | uint8_t d; 44 | uint16_t c; 45 | c = 10000; 46 | for( pos = 0; pos < 5; pos++ ) 47 | { 48 | d = '0'; 49 | while( v >= c ) 50 | { 51 | v -= c; 52 | d++; 53 | } 54 | dest[pos] = d; 55 | c /= 10; 56 | } 57 | dest[5] = '\0'; 58 | return dest; 59 | } 60 | 61 | /* v = value, d = number of digits */ 62 | const char *u8g_u16toa(uint16_t v, uint8_t d) 63 | { 64 | static char buf[6]; 65 | d = 5-d; 66 | return u8g_u16toap(buf, v) + d; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /02.Library/U8glib/utility/u8g_u8toa.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_u8toa.c 4 | 5 | 6 | Universal 8bit Graphics Library 7 | 8 | Copyright (c) 2011, olikraus@gmail.com 9 | All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | * Redistributions of source code must retain the above copyright notice, this list 15 | of conditions and the following disclaimer. 16 | 17 | * Redistributions in binary form must reproduce the above copyright notice, this 18 | list of conditions and the following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | 38 | #include "u8g.h" 39 | 40 | static const unsigned char u8g_u8toa_tab[3] = { 100, 10, 1 } ; 41 | const char *u8g_u8toap(char * dest, uint8_t v) 42 | { 43 | uint8_t pos; 44 | uint8_t d; 45 | uint8_t c; 46 | for( pos = 0; pos < 3; pos++ ) 47 | { 48 | d = '0'; 49 | c = *(u8g_u8toa_tab+pos); 50 | while( v >= c ) 51 | { 52 | v -= c; 53 | d++; 54 | } 55 | dest[pos] = d; 56 | } 57 | dest[3] = '\0'; 58 | return dest; 59 | } 60 | 61 | /* v = value, d = number of digits */ 62 | const char *u8g_u8toa(uint8_t v, uint8_t d) 63 | { 64 | static char buf[4]; 65 | d = 3-d; 66 | return u8g_u8toap(buf, v) + d; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /02.Library/Wire/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 | */ 21 | 22 | #ifndef TwoWire_h 23 | #define TwoWire_h 24 | 25 | #include 26 | #include "Stream.h" 27 | 28 | #define BUFFER_LENGTH 32 29 | 30 | class TwoWire : public Stream 31 | { 32 | private: 33 | static uint8_t rxBuffer[]; 34 | static uint8_t rxBufferIndex; 35 | static uint8_t rxBufferLength; 36 | 37 | static uint8_t txAddress; 38 | static uint8_t txBuffer[]; 39 | static uint8_t txBufferIndex; 40 | static uint8_t txBufferLength; 41 | 42 | static uint8_t transmitting; 43 | static void (*user_onRequest)(void); 44 | static void (*user_onReceive)(int); 45 | static void onRequestService(void); 46 | static void onReceiveService(uint8_t*, int); 47 | public: 48 | TwoWire(); 49 | void begin(); 50 | void begin(uint8_t); 51 | void begin(int); 52 | void beginTransmission(uint8_t); 53 | void beginTransmission(int); 54 | uint8_t endTransmission(void); 55 | uint8_t endTransmission(uint8_t); 56 | uint8_t requestFrom(uint8_t, uint8_t); 57 | uint8_t requestFrom(uint8_t, uint8_t, uint8_t); 58 | uint8_t requestFrom(int, int); 59 | uint8_t requestFrom(int, int, int); 60 | virtual size_t write(uint8_t); 61 | virtual size_t write(const uint8_t *, size_t); 62 | virtual int available(void); 63 | virtual int read(void); 64 | virtual int peek(void); 65 | virtual void flush(void); 66 | void onReceive( void (*)(int) ); 67 | void onRequest( void (*)(void) ); 68 | 69 | inline size_t write(unsigned long n) { return write((uint8_t)n); } 70 | inline size_t write(long n) { return write((uint8_t)n); } 71 | inline size_t write(unsigned int n) { return write((uint8_t)n); } 72 | inline size_t write(int n) { return write((uint8_t)n); } 73 | using Print::write; 74 | }; 75 | 76 | extern TwoWire Wire; 77 | 78 | #endif 79 | 80 | -------------------------------------------------------------------------------- /02.Library/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino: -------------------------------------------------------------------------------- 1 | // I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder 2 | // by Nicholas Zambetti 3 | // and James Tichenor 4 | 5 | // Demonstrates use of the Wire library reading data from the 6 | // Devantech Utrasonic Rangers SFR08 and SFR10 7 | 8 | // Created 29 April 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(); // join i2c bus (address optional for master) 18 | Serial.begin(9600); // start serial communication at 9600bps 19 | } 20 | 21 | int reading = 0; 22 | 23 | void loop() 24 | { 25 | // step 1: instruct sensor to read echoes 26 | Wire.beginTransmission(112); // transmit to device #112 (0x70) 27 | // the address specified in the datasheet is 224 (0xE0) 28 | // but i2c adressing uses the high 7 bits so it's 112 29 | Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) 30 | Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) 31 | // use 0x51 for centimeters 32 | // use 0x52 for ping microseconds 33 | Wire.endTransmission(); // stop transmitting 34 | 35 | // step 2: wait for readings to happen 36 | delay(70); // datasheet suggests at least 65 milliseconds 37 | 38 | // step 3: instruct sensor to return a particular echo reading 39 | Wire.beginTransmission(112); // transmit to device #112 40 | Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02) 41 | Wire.endTransmission(); // stop transmitting 42 | 43 | // step 4: request reading from sensor 44 | Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 45 | 46 | // step 5: receive reading from sensor 47 | if(2 <= Wire.available()) // if two bytes were received 48 | { 49 | reading = Wire.read(); // receive high byte (overwrites previous reading) 50 | reading = reading << 8; // shift high byte to be high 8 bits 51 | reading |= Wire.read(); // receive low byte as lower 8 bits 52 | Serial.println(reading); // print the reading 53 | } 54 | 55 | delay(250); // wait a bit since people have to read the output :) 56 | } 57 | 58 | 59 | /* 60 | 61 | // The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) 62 | // usage: changeAddress(0x70, 0xE6); 63 | 64 | void changeAddress(byte oldAddress, byte newAddress) 65 | { 66 | Wire.beginTransmission(oldAddress); 67 | Wire.write(byte(0x00)); 68 | Wire.write(byte(0xA0)); 69 | Wire.endTransmission(); 70 | 71 | Wire.beginTransmission(oldAddress); 72 | Wire.write(byte(0x00)); 73 | Wire.write(byte(0xAA)); 74 | Wire.endTransmission(); 75 | 76 | Wire.beginTransmission(oldAddress); 77 | Wire.write(byte(0x00)); 78 | Wire.write(byte(0xA5)); 79 | Wire.endTransmission(); 80 | 81 | Wire.beginTransmission(oldAddress); 82 | Wire.write(byte(0x00)); 83 | Wire.write(newAddress); 84 | Wire.endTransmission(); 85 | } 86 | 87 | */ 88 | -------------------------------------------------------------------------------- /02.Library/Wire/examples/digital_potentiometer/digital_potentiometer.ino: -------------------------------------------------------------------------------- 1 | // I2C Digital Potentiometer 2 | // by Nicholas Zambetti 3 | // and Shawn Bonkowski 4 | 5 | // Demonstrates use of the Wire library 6 | // Controls AD5171 digital potentiometer via I2C/TWI 7 | 8 | // Created 31 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | // This example code is in the public domain. 13 | 14 | 15 | #include 16 | 17 | void setup() 18 | { 19 | Wire.begin(); // join i2c bus (address optional for master) 20 | } 21 | 22 | byte val = 0; 23 | 24 | void loop() 25 | { 26 | Wire.beginTransmission(44); // transmit to device #44 (0x2c) 27 | // device address is specified in datasheet 28 | Wire.write(byte(0x00)); // sends instruction byte 29 | Wire.write(val); // sends potentiometer value byte 30 | Wire.endTransmission(); // stop transmitting 31 | 32 | val++; // increment value 33 | if(val == 64) // if reached 64th position (max) 34 | { 35 | val = 0; // start over from lowest value 36 | } 37 | delay(500); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /02.Library/Wire/examples/master_reader/master_reader.ino: -------------------------------------------------------------------------------- 1 | // Wire Master Reader 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Reads data from an I2C/TWI slave device 6 | // Refer to the "Wire Slave Sender" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(); // join i2c bus (address optional for master) 18 | Serial.begin(9600); // start serial for output 19 | } 20 | 21 | void loop() 22 | { 23 | Wire.requestFrom(2, 6); // request 6 bytes from slave device #2 24 | 25 | while(Wire.available()) // slave may send less than requested 26 | { 27 | char c = Wire.read(); // receive a byte as character 28 | Serial.print(c); // print the character 29 | } 30 | 31 | delay(500); 32 | } 33 | -------------------------------------------------------------------------------- /02.Library/Wire/examples/master_writer/master_writer.ino: -------------------------------------------------------------------------------- 1 | // Wire Master Writer 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Writes data to an I2C/TWI slave device 6 | // Refer to the "Wire Slave Receiver" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(); // join i2c bus (address optional for master) 18 | } 19 | 20 | byte x = 0; 21 | 22 | void loop() 23 | { 24 | Wire.beginTransmission(4); // transmit to device #4 25 | Wire.write("x is "); // sends five bytes 26 | Wire.write(x); // sends one byte 27 | Wire.endTransmission(); // stop transmitting 28 | 29 | x++; 30 | delay(500); 31 | } 32 | -------------------------------------------------------------------------------- /02.Library/Wire/examples/slave_receiver/slave_receiver.ino: -------------------------------------------------------------------------------- 1 | // Wire Slave Receiver 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Receives data as an I2C/TWI slave device 6 | // Refer to the "Wire Master Writer" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(4); // join i2c bus with address #4 18 | Wire.onReceive(receiveEvent); // register event 19 | Serial.begin(9600); // start serial for output 20 | } 21 | 22 | void loop() 23 | { 24 | delay(100); 25 | } 26 | 27 | // function that executes whenever data is received from master 28 | // this function is registered as an event, see setup() 29 | void receiveEvent(int howMany) 30 | { 31 | while(1 < Wire.available()) // loop through all but the last 32 | { 33 | char c = Wire.read(); // receive byte as a character 34 | Serial.print(c); // print the character 35 | } 36 | int x = Wire.read(); // receive byte as an integer 37 | Serial.println(x); // print the integer 38 | } 39 | -------------------------------------------------------------------------------- /02.Library/Wire/examples/slave_sender/slave_sender.ino: -------------------------------------------------------------------------------- 1 | // Wire Slave Sender 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Sends data as an I2C/TWI slave device 6 | // Refer to the "Wire Master Reader" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(2); // join i2c bus with address #2 18 | Wire.onRequest(requestEvent); // register event 19 | } 20 | 21 | void loop() 22 | { 23 | delay(100); 24 | } 25 | 26 | // function that executes whenever data is requested by master 27 | // this function is registered as an event, see setup() 28 | void requestEvent() 29 | { 30 | Wire.write("hello "); // respond with message of 6 bytes 31 | // as expected by master 32 | } 33 | -------------------------------------------------------------------------------- /02.Library/Wire/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Wire 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | begin KEYWORD2 14 | beginTransmission KEYWORD2 15 | endTransmission KEYWORD2 16 | requestFrom KEYWORD2 17 | send KEYWORD2 18 | receive KEYWORD2 19 | onReceive KEYWORD2 20 | onRequest KEYWORD2 21 | 22 | ####################################### 23 | # Instances (KEYWORD2) 24 | ####################################### 25 | 26 | Wire KEYWORD2 27 | 28 | ####################################### 29 | # Constants (LITERAL1) 30 | ####################################### 31 | 32 | -------------------------------------------------------------------------------- /02.Library/Wire/utility/twi.h: -------------------------------------------------------------------------------- 1 | /* 2 | twi.h - TWI/I2C library for Wiring & Arduino 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 | 20 | #ifndef twi_h 21 | #define twi_h 22 | 23 | #include 24 | 25 | //#define ATMEGA8 26 | 27 | #ifndef TWI_FREQ 28 | #define TWI_FREQ 100000L 29 | #endif 30 | 31 | #ifndef TWI_BUFFER_LENGTH 32 | #define TWI_BUFFER_LENGTH 32 33 | #endif 34 | 35 | #define TWI_READY 0 36 | #define TWI_MRX 1 37 | #define TWI_MTX 2 38 | #define TWI_SRX 3 39 | #define TWI_STX 4 40 | 41 | void twi_init(void); 42 | void twi_setAddress(uint8_t); 43 | uint8_t twi_readFrom(uint8_t, uint8_t*, uint8_t, uint8_t); 44 | uint8_t twi_writeTo(uint8_t, uint8_t*, uint8_t, uint8_t, uint8_t); 45 | uint8_t twi_transmit(const uint8_t*, uint8_t); 46 | void twi_attachSlaveRxEvent( void (*)(uint8_t*, int) ); 47 | void twi_attachSlaveTxEvent( void (*)(void) ); 48 | void twi_reply(uint8_t); 49 | void twi_stop(void); 50 | void twi_releaseBus(void); 51 | 52 | #endif 53 | 54 | -------------------------------------------------------------------------------- /02.Library/ethercard/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.esproj 3 | /html 4 | -------------------------------------------------------------------------------- /02.Library/ethercard/Doxylogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/02.Library/ethercard/Doxylogo.png -------------------------------------------------------------------------------- /02.Library/ethercard/Doxymods.css: -------------------------------------------------------------------------------- 1 | /* Get rid of all those overriden font families */ 2 | body, table, div, p, dl, 3 | #projectname, 4 | #projectbrief, 5 | #nav-tree .label { 6 | font: 15px/21px Georgia,serif 7 | } 8 | 9 | #projectname { 10 | color: #990000; 11 | font-weight: bold; 12 | font-size: 24px; 13 | } 14 | 15 | #titlearea table { 16 | padding: 20px; 17 | } 18 | 19 | dl.reflist dt, div.memproto { 20 | border: 1px solid #A8B8D9; 21 | } 22 | 23 | dl.reflist dd, div.memdoc { 24 | border-width: 0; 25 | } 26 | 27 | div.contents { 28 | margin-left: 20px; margin-right: 16px; 29 | width: 700 px; 30 | } 31 | 32 | /* Get rid of the gradient backgrounds and background colors */ 33 | div.header, 34 | #nav-tree, 35 | .navpath ul, 36 | .memproto, dl.reflist dt { 37 | background: none; 38 | } 39 | #nav-tree .selected { 40 | background: none; 41 | background-color: #990000; 42 | text-shadow: none; 43 | } 44 | 45 | a, a:link, a:visited { 46 | color: #2A5685; 47 | text-decoration: underline; 48 | } 49 | a:active, a:hover { 50 | color: #CC0000; 51 | } 52 | 53 | .directory tr.even, 54 | pre.fragment, 55 | .mdescLeft, .mdescRight, .memItemLeft, .memItemRight, .memTemplItemLeft, .memTemplItemRight, .memTemplParams, 56 | .memproto, dl.reflist dt { 57 | background-color: #EEE; 58 | box-shadow: none; 59 | border-radius: 0; 60 | } 61 | .memdoc, dl.reflist dd { 62 | background: none; 63 | box-shadow: none; 64 | border-radius: 0; 65 | } 66 | pre.fragment { 67 | background-color: #FAFAFA; 68 | border: 1px solid #DADADA; 69 | margin: 1em 1em 1em 1.6em; 70 | overflow-x: auto; 71 | overflow-y: hidden; 72 | width: auto; 73 | } 74 | -------------------------------------------------------------------------------- /02.Library/ethercard/README.md: -------------------------------------------------------------------------------- 1 | About {#index} 2 | ===== 3 | 4 | **EtherCard** is a driver for the ENC28J60 chip, compatible with Arduino IDE. 5 | 6 | Work in progress - see [this discussion][1] for some background info. 7 | 8 | Derived from code by Guido Socher and Pascal Stang, hence under GPL2 license. 9 | 10 | ---- 11 | 12 | The latest source code for this project is maintained on [GitHub][2]. 13 | 14 | You can download all the project source files in [ZIP][3] or [TAR][4] format: 15 | 16 | * Unpack the archive and rename the resulting folder to "EtherCard". 17 | * Move it to the "libraries" folder in your Arduino sketches area. 18 | * Restart the Arduino IDE to make sure it sees the new files. 19 | 20 | The wiki for this library is at . 21 | 22 | The API documentation is generated by Doxygen and can be found [here][5]. 23 | 24 | For questions and reporting bugs, check out the JeeLabs [forums][6]. 25 | 26 | [1]: http://forum.jeelabs.net/node/457 27 | [2]: https://github.com/jcw/ethercard 28 | [3]: https://github.com/jcw/ethercard/zipball/master 29 | [4]: https://github.com/jcw/ethercard/tarball/master 30 | [5]: http://jeelabs.net/pub/docs/ethercard/ 31 | [6]: http://forum.jeelabs.net/forum 32 | -------------------------------------------------------------------------------- /02.Library/ethercard/dns.cpp: -------------------------------------------------------------------------------- 1 | // DNS look-up functions based on the udp client 2 | // Author: Guido Socher 3 | // Copyright: GPL V2 4 | // 5 | // 2010-05-20 6 | 7 | #include "EtherCard.h" 8 | #include "net.h" 9 | 10 | #define gPB ether.buffer 11 | 12 | static byte dnstid_l; // a counter for transaction ID 13 | #define DNSCLIENT_SRC_PORT_H 0xE0 14 | 15 | static void dnsRequest (const prog_char *progmem_hostname, bool fromRam) { 16 | ++dnstid_l; // increment for next request, finally wrap 17 | if (ether.dnsip[0] == 0) 18 | memset(ether.dnsip, 8, 4); // use 8.8.8.8 Google DNS as default 19 | ether.udpPrepare((DNSCLIENT_SRC_PORT_H << 8) | dnstid_l, 20 | ether.dnsip, 53); 21 | memset(gPB + UDP_DATA_P, 0, 12); 22 | 23 | byte *p = gPB + UDP_DATA_P + 12; 24 | char c; 25 | do { 26 | byte n = 0; 27 | for(;;) { 28 | c = fromRam ? *progmem_hostname : pgm_read_byte(progmem_hostname); 29 | ++progmem_hostname; 30 | if (c == '.' || c == 0) 31 | break; 32 | p[++n] = c; 33 | } 34 | *p++ = n; 35 | p += n; 36 | } while (c != 0); 37 | 38 | *p++ = 0; // terminate with zero, means root domain. 39 | *p++ = 0; 40 | *p++ = 1; // type A 41 | *p++ = 0; 42 | *p++ = 1; // class IN 43 | byte i = p - gPB - UDP_DATA_P; 44 | gPB[UDP_DATA_P] = i; 45 | gPB[UDP_DATA_P+1] = dnstid_l; 46 | gPB[UDP_DATA_P+2] = 1; // flags, standard recursive query 47 | gPB[UDP_DATA_P+5] = 1; // 1 question 48 | ether.udpTransmit(i); 49 | } 50 | 51 | static void checkForDnsAnswer (uint16_t plen) { 52 | byte *p = gPB + UDP_DATA_P; 53 | if (plen < 70 || gPB[UDP_SRC_PORT_L_P] != 53 || 54 | gPB[UDP_DST_PORT_H_P] != DNSCLIENT_SRC_PORT_H || 55 | gPB[UDP_DST_PORT_L_P] != dnstid_l || 56 | p[1] != dnstid_l || 57 | (p[3] & 0x0F) != 0) 58 | return; 59 | 60 | p += *p; // we encoded the query len into tid 61 | for (;;) { 62 | if (*p & 0xC0) 63 | p += 2; 64 | else 65 | while (++p < gPB + plen) { 66 | if (*p == 0) { 67 | ++p; 68 | break; 69 | } 70 | } 71 | if (p + 14 > gPB + plen) 72 | break; 73 | if (p[1] == 1 && p[9] == 4) { // type "A" and IPv4 74 | ether.copyIp(ether.hisip, p + 10); 75 | break; 76 | } 77 | p += p[9] + 10; 78 | } 79 | } 80 | 81 | // use during setup, as this discards all incoming requests until it returns 82 | bool EtherCard::dnsLookup (prog_char* name, bool fromRam) { 83 | word start = millis(); 84 | while (!isLinkUp() || clientWaitingGw()) { 85 | packetLoop(packetReceive()); 86 | if ((word) (millis() - start) >= 15000) 87 | return false; 88 | } 89 | 90 | memset(hisip, 0, 4); 91 | dnsRequest(name, fromRam); 92 | 93 | start = millis(); 94 | while (hisip[0] == 0) { 95 | if ((word) (millis() - start) >= 15000) 96 | return false; 97 | word len = packetReceive(); 98 | if (len > 0 && packetLoop(len) == 0) 99 | checkForDnsAnswer(len); 100 | } 101 | 102 | return true; 103 | } 104 | -------------------------------------------------------------------------------- /02.Library/ethercard/enc28j60.h: -------------------------------------------------------------------------------- 1 | // Microchip ENC28J60 Ethernet Interface Driver 2 | // Author: Pascal Stang 3 | // Modified by: Guido Socher 4 | // Copyright: GPL V2 5 | // 6 | // This driver provides initialization and transmit/receive 7 | // functions for the Microchip ENC28J60 10Mb Ethernet Controller and PHY. 8 | // This chip is novel in that it is a full MAC+PHY interface all in a 28-pin 9 | // chip, using an SPI interface to the host processor. 10 | // 11 | // 2010-05-20 12 | 13 | #ifndef ENC28J60_H 14 | #define ENC28J60_H 15 | 16 | class ENC28J60 { 17 | public: 18 | static uint8_t buffer[]; 19 | static uint16_t bufferSize; 20 | 21 | static uint8_t* tcpOffset () { return buffer + 0x36; } 22 | 23 | static void initSPI (); 24 | static uint8_t initialize (const uint16_t size, const uint8_t* macaddr, 25 | uint8_t csPin =8); 26 | static bool isLinkUp (); 27 | 28 | static void packetSend (uint16_t len); 29 | static uint16_t packetReceive (); 30 | 31 | static void copyout (uint8_t page, const uint8_t* data); 32 | static void copyin (uint8_t page, uint8_t* data); 33 | static uint8_t peekin (uint8_t page, uint8_t off); 34 | 35 | static void powerDown(); // contrib by Alex M. 36 | static void powerUp(); // contrib by Alex M. 37 | 38 | static void enableBroadcast(); 39 | static void disableBroadcast(); 40 | 41 | static uint8_t doBIST(uint8_t csPin =8); 42 | }; 43 | 44 | typedef ENC28J60 Ethernet; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/backSoon/backSoon.ino: -------------------------------------------------------------------------------- 1 | // Present a "Will be back soon web page", as stand-in webserver. 2 | // 2011-01-30 http://opensource.org/licenses/mit-license.php 3 | 4 | #include 5 | 6 | #define STATIC 0 // set to 1 to disable DHCP (adjust myip/gwip values below) 7 | 8 | #if STATIC 9 | // ethernet interface ip address 10 | static byte myip[] = { 192,168,1,200 }; 11 | // gateway ip address 12 | static byte gwip[] = { 192,168,1,1 }; 13 | #endif 14 | 15 | // ethernet mac address - must be unique on your network 16 | static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; 17 | 18 | byte Ethernet::buffer[500]; // tcp/ip send and receive buffer 19 | 20 | char page[] PROGMEM = 21 | "HTTP/1.0 503 Service Unavailable\r\n" 22 | "Content-Type: text/html\r\n" 23 | "Retry-After: 600\r\n" 24 | "\r\n" 25 | "" 26 | "" 27 | "Service Temporarily Unavailable" 28 | "" 29 | "" 30 | "

This service is currently unavailable

" 31 | "

" 32 | "The main server is currently off-line.
" 33 | "Please try again later." 34 | "

" 35 | "" 36 | "" 37 | ; 38 | 39 | void setup(){ 40 | Serial.begin(57600); 41 | Serial.println("\n[backSoon]"); 42 | 43 | if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 44 | Serial.println( "Failed to access Ethernet controller"); 45 | #if STATIC 46 | ether.staticSetup(myip, gwip); 47 | #else 48 | if (!ether.dhcpSetup()) 49 | Serial.println("DHCP failed"); 50 | #endif 51 | 52 | ether.printIp("IP: ", ether.myip); 53 | ether.printIp("GW: ", ether.gwip); 54 | ether.printIp("DNS: ", ether.dnsip); 55 | } 56 | 57 | void loop(){ 58 | // wait for an incoming TCP packet, but ignore its contents 59 | if (ether.packetLoop(ether.packetReceive())) { 60 | memcpy_P(ether.tcpOffset(), page, sizeof page); 61 | ether.httpServerReply(sizeof page - 1); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/getDHCPandDNS/getDHCPandDNS.ino: -------------------------------------------------------------------------------- 1 | // This demo does web requests via DHCP and DNS lookup. 2 | // 2011-07-05 http://opensource.org/licenses/mit-license.php 3 | 4 | #include 5 | 6 | #define REQUEST_RATE 5000 // milliseconds 7 | 8 | // ethernet interface mac address 9 | static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; 10 | // remote website name 11 | char website[] PROGMEM = "google.com"; 12 | 13 | byte Ethernet::buffer[700]; 14 | static long timer; 15 | 16 | // called when the client request is complete 17 | static void my_result_cb (byte status, word off, word len) { 18 | Serial.print("<<< reply "); 19 | Serial.print(millis() - timer); 20 | Serial.println(" ms"); 21 | Serial.println((const char*) Ethernet::buffer + off); 22 | } 23 | 24 | void setup () { 25 | Serial.begin(57600); 26 | Serial.println("\n[getDHCPandDNS]"); 27 | 28 | if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 29 | Serial.println( "Failed to access Ethernet controller"); 30 | 31 | if (!ether.dhcpSetup()) 32 | Serial.println("DHCP failed"); 33 | 34 | ether.printIp("My IP: ", ether.myip); 35 | // ether.printIp("Netmask: ", ether.mymask); 36 | ether.printIp("GW IP: ", ether.gwip); 37 | ether.printIp("DNS IP: ", ether.dnsip); 38 | 39 | if (!ether.dnsLookup(website)) 40 | Serial.println("DNS failed"); 41 | ether.printIp("Server: ", ether.hisip); 42 | 43 | timer = - REQUEST_RATE; // start timing out right away 44 | } 45 | 46 | void loop () { 47 | 48 | ether.packetLoop(ether.packetReceive()); 49 | 50 | if (millis() > timer + REQUEST_RATE) { 51 | timer = millis(); 52 | Serial.println("\n>>> REQ"); 53 | ether.browseUrl(PSTR("/foo/"), "bar", website, my_result_cb); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/getStaticIP/getStaticIP.ino: -------------------------------------------------------------------------------- 1 | // This demo does web requests to a fixed IP address, using a fixed gateway. 2 | // 2010-11-27 http://opensource.org/licenses/mit-license.php 3 | 4 | #include 5 | 6 | #define REQUEST_RATE 5000 // milliseconds 7 | 8 | // ethernet interface mac address 9 | static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; 10 | // ethernet interface ip address 11 | static byte myip[] = { 192,168,1,203 }; 12 | // gateway ip address 13 | static byte gwip[] = { 192,168,1,1 }; 14 | // remote website ip address and port 15 | static byte hisip[] = { 74,125,79,99 }; 16 | // remote website name 17 | char website[] PROGMEM = "google.com"; 18 | 19 | byte Ethernet::buffer[300]; // a very small tcp/ip buffer is enough here 20 | static long timer; 21 | 22 | // called when the client request is complete 23 | static void my_result_cb (byte status, word off, word len) { 24 | Serial.print("<<< reply "); 25 | Serial.print(millis() - timer); 26 | Serial.println(" ms"); 27 | Serial.println((const char*) Ethernet::buffer + off); 28 | } 29 | 30 | void setup () { 31 | Serial.begin(57600); 32 | Serial.println("\n[getStaticIP]"); 33 | 34 | if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 35 | Serial.println( "Failed to access Ethernet controller"); 36 | 37 | ether.staticSetup(myip, gwip); 38 | 39 | ether.copyIp(ether.hisip, hisip); 40 | ether.printIp("Server: ", ether.hisip); 41 | 42 | while (ether.clientWaitingGw()) 43 | ether.packetLoop(ether.packetReceive()); 44 | Serial.println("Gateway found"); 45 | 46 | timer = - REQUEST_RATE; // start timing out right away 47 | } 48 | 49 | void loop () { 50 | ether.packetLoop(ether.packetReceive()); 51 | 52 | if (millis() > timer + REQUEST_RATE) { 53 | timer = millis(); 54 | Serial.println("\n>>> REQ"); 55 | ether.browseUrl(PSTR("/foo/"), "bar", website, my_result_cb); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/getViaDNS/getViaDNS.ino: -------------------------------------------------------------------------------- 1 | // This demo does web requests via DNS lookup, using a fixed gateway. 2 | // 2010-11-27 http://opensource.org/licenses/mit-license.php 3 | 4 | #include 5 | 6 | #define REQUEST_RATE 5000 // milliseconds 7 | 8 | // ethernet interface mac address 9 | static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; 10 | // ethernet interface ip address 11 | static byte myip[] = { 192,168,1,203 }; 12 | // gateway ip address 13 | static byte gwip[] = { 192,168,1,1 }; 14 | // remote website name 15 | char website[] PROGMEM = "google.com"; 16 | 17 | byte Ethernet::buffer[300]; // a very small tcp/ip buffer is enough here 18 | static long timer; 19 | 20 | // called when the client request is complete 21 | static void my_result_cb (byte status, word off, word len) { 22 | Serial.print("<<< reply "); 23 | Serial.print(millis() - timer); 24 | Serial.println(" ms"); 25 | Serial.println((const char*) Ethernet::buffer + off); 26 | } 27 | 28 | void setup () { 29 | Serial.begin(57600); 30 | Serial.println("\n[getViaDNS]"); 31 | 32 | if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 33 | Serial.println( "Failed to access Ethernet controller"); 34 | 35 | ether.staticSetup(myip, gwip); 36 | 37 | if (!ether.dnsLookup(website)) 38 | Serial.println("DNS failed"); 39 | ether.printIp("Server: ", ether.hisip); 40 | 41 | timer = - REQUEST_RATE; // start timing out right away 42 | } 43 | 44 | void loop () { 45 | ether.packetLoop(ether.packetReceive()); 46 | 47 | if (millis() > timer + REQUEST_RATE) { 48 | timer = millis(); 49 | Serial.println("\n>>> REQ"); 50 | ether.browseUrl(PSTR("/foo/"), "bar", website, my_result_cb); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/nanether/nanether.ino: -------------------------------------------------------------------------------- 1 | // Example of EtherCard usage, contributed by Will Rose, 2012-07-05. 2 | 3 | #include 4 | 5 | #define BUF_SIZE 512 6 | 7 | byte mac[] = { 0x00, 0x04, 0xA3, 0x21, 0xCA, 0x38 }; // Nanode MAC address. 8 | 9 | uint8_t ip[] = { 192, 168, 1, 8 }; // The fallback board address. 10 | uint8_t dns[] = { 192, 168, 1, 20 }; // The DNS server address. 11 | uint8_t gateway[] = { 192, 168, 1, 20 }; // The gateway router address. 12 | uint8_t subnet[] = { 255, 255, 255, 0 }; // The subnet mask. 13 | byte Ethernet::buffer[BUF_SIZE]; 14 | byte fixed; // Address fixed, no DHCP 15 | 16 | void setup(void) 17 | { 18 | Serial.begin(57600); 19 | delay(2000); 20 | 21 | /* Check that the Ethernet controller exists */ 22 | Serial.println("Initialising the Ethernet controller"); 23 | if (ether.begin(sizeof Ethernet::buffer, mac, 8) == 0) { 24 | Serial.println( "Ethernet controller NOT initialised"); 25 | while (true) 26 | /* MT */ ; 27 | } 28 | 29 | /* Get a DHCP connection */ 30 | Serial.println("Attempting to get an IP address using DHCP"); 31 | fixed = false; 32 | if (ether.dhcpSetup()) { 33 | ether.printIp("Got an IP address using DHCP: ", ether.myip); 34 | } 35 | /* If DHCP fails, start with a hard-coded address */ 36 | else { 37 | ether.staticSetup(ip, gateway, dns); 38 | ether.printIp("DHCP FAILED, using fixed address: ", ether.myip); 39 | fixed = true; 40 | } 41 | 42 | return; 43 | } 44 | 45 | void loop(void) 46 | { 47 | word rc; 48 | 49 | /* These function calls are required if ICMP packets are to be accepted */ 50 | rc = ether.packetLoop(ether.packetReceive()); 51 | Serial.print("ether.packetLoop() returned "); 52 | Serial.println(rc, DEC); 53 | 54 | // For debugging 55 | delay(5000); 56 | 57 | return; 58 | } 59 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/pachube/pachube.ino: -------------------------------------------------------------------------------- 1 | // Simple demo for feeding some random data to Pachube. 2 | // 2011-07-08 http://opensource.org/licenses/mit-license.php 3 | 4 | #include 5 | 6 | // change these settings to match your own setup 7 | #define FEED "5942" 8 | #define APIKEY "bXkPFCiYm57f7flLyD86bm0HK3TXsfuQF-Jeyh3HeMg" 9 | 10 | // ethernet interface mac address, must be unique on the LAN 11 | byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; 12 | 13 | char website[] PROGMEM = "api.pachube.com"; 14 | 15 | byte Ethernet::buffer[700]; 16 | uint32_t timer; 17 | Stash stash; 18 | 19 | void setup () { 20 | Serial.begin(57600); 21 | Serial.println("\n[webClient]"); 22 | 23 | if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 24 | Serial.println( "Failed to access Ethernet controller"); 25 | if (!ether.dhcpSetup()) 26 | Serial.println("DHCP failed"); 27 | 28 | ether.printIp("IP: ", ether.myip); 29 | ether.printIp("GW: ", ether.gwip); 30 | ether.printIp("DNS: ", ether.dnsip); 31 | 32 | if (!ether.dnsLookup(website)) 33 | Serial.println("DNS failed"); 34 | 35 | ether.printIp("SRV: ", ether.hisip); 36 | } 37 | 38 | void loop () { 39 | ether.packetLoop(ether.packetReceive()); 40 | 41 | if (millis() > timer) { 42 | timer = millis() + 10000; 43 | 44 | // generate two fake values as payload - by using a separate stash, 45 | // we can determine the size of the generated message ahead of time 46 | byte sd = stash.create(); 47 | stash.print("0,"); 48 | stash.println((word) millis() / 123); 49 | stash.print("1,"); 50 | stash.println((word) micros() / 456); 51 | stash.save(); 52 | 53 | // generate the header with payload - note that the stash size is used, 54 | // and that a "stash descriptor" is passed in as argument using "$H" 55 | Stash::prepare(PSTR("PUT http://$F/v2/feeds/$F.csv HTTP/1.0" "\r\n" 56 | "Host: $F" "\r\n" 57 | "X-PachubeApiKey: $F" "\r\n" 58 | "Content-Length: $D" "\r\n" 59 | "\r\n" 60 | "$H"), 61 | website, PSTR(FEED), website, PSTR(APIKEY), stash.size(), sd); 62 | 63 | // send the packet - this also releases all stash buffers once done 64 | ether.tcpSend(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/pings/pings.ino: -------------------------------------------------------------------------------- 1 | // Ping a remote server, also uses DHCP and DNS. 2 | // 2011-06-12 http://opensource.org/licenses/mit-license.php 3 | 4 | #include 5 | 6 | // ethernet interface mac address, must be unique on the LAN 7 | static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; 8 | 9 | byte Ethernet::buffer[700]; 10 | static uint32_t timer; 11 | 12 | // called when a ping comes in (replies to it are automatic) 13 | static void gotPinged (byte* ptr) { 14 | ether.printIp(">>> ping from: ", ptr); 15 | } 16 | 17 | void setup () { 18 | Serial.begin(57600); 19 | Serial.println("\n[pings]"); 20 | 21 | if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 22 | Serial.println( "Failed to access Ethernet controller"); 23 | if (!ether.dhcpSetup()) 24 | Serial.println("DHCP failed"); 25 | 26 | ether.printIp("IP: ", ether.myip); 27 | ether.printIp("GW: ", ether.gwip); 28 | 29 | #if 1 30 | // use DNS to locate the IP address we want to ping 31 | if (!ether.dnsLookup(PSTR("www.google.com"))) 32 | Serial.println("DNS failed"); 33 | #else 34 | ether.parseIp(ether.hisip, "74.125.77.99"); 35 | #endif 36 | ether.printIp("SRV: ", ether.hisip); 37 | 38 | // call this to report others pinging us 39 | ether.registerPingCallback(gotPinged); 40 | 41 | timer = -9999999; // start timing out right away 42 | Serial.println(); 43 | } 44 | 45 | void loop () { 46 | word len = ether.packetReceive(); // go receive new packets 47 | word pos = ether.packetLoop(len); // respond to incoming pings 48 | 49 | // report whenever a reply to our outgoing ping comes back 50 | if (len > 0 && ether.packetLoopIcmpCheckReply(ether.hisip)) { 51 | Serial.print(" "); 52 | Serial.print((micros() - timer) * 0.001, 3); 53 | Serial.println(" ms"); 54 | } 55 | 56 | // ping a remote server once every few seconds 57 | if (micros() - timer >= 5000000) { 58 | ether.printIp("Pinging: ", ether.hisip); 59 | timer = micros(); 60 | ether.clientIcmpRequest(ether.hisip); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/rbbb_server/rbbb_server.ino: -------------------------------------------------------------------------------- 1 | // This is a demo of the RBBB running as webserver with the Ether Card 2 | // 2010-05-28 http://opensource.org/licenses/mit-license.php 3 | 4 | #include 5 | 6 | // ethernet interface mac address, must be unique on the LAN 7 | static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; 8 | static byte myip[] = { 192,168,1,203 }; 9 | 10 | byte Ethernet::buffer[500]; 11 | BufferFiller bfill; 12 | 13 | void setup () { 14 | if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 15 | Serial.println( "Failed to access Ethernet controller"); 16 | ether.staticSetup(myip); 17 | } 18 | 19 | static word homePage() { 20 | long t = millis() / 1000; 21 | word h = t / 3600; 22 | byte m = (t / 60) % 60; 23 | byte s = t % 60; 24 | bfill = ether.tcpOffset(); 25 | bfill.emit_p(PSTR( 26 | "HTTP/1.0 200 OK\r\n" 27 | "Content-Type: text/html\r\n" 28 | "Pragma: no-cache\r\n" 29 | "\r\n" 30 | "" 31 | "RBBB server" 32 | "

$D$D:$D$D:$D$D

"), 33 | h/10, h%10, m/10, m%10, s/10, s%10); 34 | return bfill.position(); 35 | } 36 | 37 | void loop () { 38 | word len = ether.packetReceive(); 39 | word pos = ether.packetLoop(len); 40 | 41 | if (pos) // check if valid tcp data is received 42 | ether.httpServerReply(homePage()); // send web page data 43 | } 44 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/stashTest/stashTest.ino: -------------------------------------------------------------------------------- 1 | // Test the offloaded RAM stash mechanism. 2 | // 2011-07-10 http://opensource.org/licenses/mit-license.php 3 | 4 | #include 5 | #include 6 | 7 | // ethernet interface mac address, must be unique on the LAN 8 | byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; 9 | 10 | byte Ethernet::buffer[700]; 11 | 12 | void dumpBlock (const char* msg, byte idx) { 13 | Serial.print(msg); 14 | Serial.print(" ["); 15 | Serial.print(idx, DEC); 16 | Serial.print("] @ "); 17 | Serial.print(Stash::bufs[idx].bnum, DEC); 18 | Serial.print(" free "); 19 | Serial.print(Stash::freeCount(), DEC); 20 | for (byte i = 0; i < 64; ++i) { 21 | if (i % 16 == 0) 22 | Serial.println(); 23 | Serial.print(' '); 24 | Serial.print(Stash::bufs[idx].bytes[i], DEC); 25 | } 26 | Serial.println(); 27 | } 28 | 29 | void dumpStash (const char* msg, void* ptr) { 30 | Stash& buf = *(Stash*) ptr; 31 | Serial.print(msg); 32 | Serial.print(" c"); 33 | Serial.print(buf.count, DEC); 34 | Serial.print(" f"); 35 | Serial.print(buf.first, DEC); 36 | Serial.print(" l"); 37 | Serial.print(buf.last, DEC); 38 | Serial.print(" u"); 39 | Serial.print(buf.curr, DEC); 40 | Serial.print(" o"); 41 | Serial.print(buf.offs, DEC); 42 | Serial.print(" #"); 43 | Serial.println(buf.size()); 44 | } 45 | 46 | void setup () { 47 | Serial.begin(57600); 48 | Serial.println("\n[stashTest]"); 49 | ether.begin(sizeof Ethernet::buffer, mymac); 50 | 51 | #if 1 52 | Stash buf; 53 | dumpStash("> AAA", &buf); 54 | byte fd = buf.create(); 55 | Serial.print("fd "); 56 | Serial.println(fd, DEC); 57 | dumpStash("> BBB", &buf); 58 | dumpBlock("EMPTY", 0); 59 | for (char c = 'a'; c <= 'z'; ++c) 60 | buf.put(c); 61 | for (char c = 'A'; c <= 'Z'; ++c) 62 | buf.put(c); 63 | dumpBlock("LETTERS", 0); 64 | dumpStash("> CCC", &buf); 65 | for (char c = '0'; c <= '9'; ++c) 66 | buf.put(c); 67 | dumpBlock("DIGITS", 0); 68 | dumpStash("> DDD", &buf); 69 | buf.print(" x = "); 70 | buf.println(123.45); 71 | dumpBlock("PRINT", 0); 72 | dumpStash("> EEE", &buf); 73 | buf.load(1, 1); 74 | dumpBlock("FIRST", 1); 75 | buf.save(); 76 | buf.load(1, 1); 77 | dumpBlock("FLUSHED", 1); 78 | dumpStash("> FFF", &buf); 79 | for (;;) { 80 | char c = buf.get(); 81 | if (c == 0) 82 | break; 83 | Serial.print(c); 84 | } 85 | Serial.println(); 86 | dumpStash("> GGG", &buf); 87 | #endif 88 | 89 | Stash buf2; 90 | byte fd2 = buf2.create(); 91 | buf2.print(""); 92 | buf2.save(); 93 | buf2.load(1, fd2); 94 | dumpBlock("SECOND", 1); 95 | dumpStash("> HHH", &buf2); 96 | 97 | Stash::prepare(PSTR("a $S b $F c $D d $H e"), 98 | "123", PSTR("4567"), -12345, fd2); 99 | dumpBlock("BUFFER", 0); 100 | Serial.println(Stash::length()); 101 | for (word i = 0, n = Stash::length(); i < n; ++i) { 102 | char c; 103 | Stash::extract(i, 1, &c); 104 | Serial.print(c); 105 | } 106 | Serial.println(); 107 | Stash::cleanup(); 108 | #if 1 109 | buf.release(); 110 | #endif 111 | Serial.print("free "); 112 | Serial.println(Stash::freeCount(), DEC); 113 | Serial.println("DONE"); 114 | } 115 | 116 | void loop () { 117 | // ether.packetLoop(ether.packetReceive()); 118 | } 119 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/testDHCP/testDHCP.ino: -------------------------------------------------------------------------------- 1 | // Arduino demo sketch for testing the DHCP client code 2 | // 3 | // Original author: Andrew Lindsay 4 | // Major rewrite and API overhaul by jcw, 2011-06-07 5 | // 6 | // Copyright: GPL V2 7 | // See http://www.gnu.org/licenses/gpl.html 8 | 9 | #include 10 | 11 | static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; 12 | 13 | byte Ethernet::buffer[700]; 14 | 15 | void setup () { 16 | Serial.begin(57600); 17 | Serial.println("\n[testDHCP]"); 18 | 19 | Serial.print("MAC: "); 20 | for (byte i = 0; i < 6; ++i) { 21 | Serial.print(mymac[i], HEX); 22 | if (i < 5) 23 | Serial.print(':'); 24 | } 25 | Serial.println(); 26 | 27 | if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 28 | Serial.println( "Failed to access Ethernet controller"); 29 | 30 | Serial.println("Setting up DHCP"); 31 | if (!ether.dhcpSetup()) 32 | Serial.println( "DHCP failed"); 33 | 34 | ether.printIp("My IP: ", ether.myip); 35 | ether.printIp("Netmask: ", ether.mymask); 36 | ether.printIp("GW IP: ", ether.gwip); 37 | ether.printIp("DNS IP: ", ether.dnsip); 38 | } 39 | 40 | void loop () {} 41 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/twitter/twitter.ino: -------------------------------------------------------------------------------- 1 | // Twitter client sketch for ENC28J60 based Ethernet Shield. Uses supertweet.net 2 | // as an OAuth authentication proxy. Step by step instructions: 3 | // 4 | // 1. Create an account on www.supertweet.net by logging with your twitter 5 | // credentials. 6 | // 2. You'll be redirected to twitter to allow supertweet to post for you 7 | // on twitter. 8 | // 3. Back on supertweet, set a password (different than your twitter one) and 9 | // activate your account clicking on "Make Active" link in from the table. 10 | // 4. Wait for supertweet email to confirm your email address - won't work 11 | // otherwise. 12 | // 5. Encode "un:pw" in base64: "un" being your twitter username and "pw" the 13 | // password you just set for supertweet.net. You can use this tool: 14 | // http://tuxgraphics.org/~guido/javascript/base64-javascript.html 15 | // 6. Paste the result as the KEY string in the code bellow. 16 | // 17 | // Contributed by Inouk Bourgon 18 | // http://opensource.org/licenses/mit-license.php 19 | 20 | #include 21 | 22 | // supertweet.net username:password in base64 23 | #define KEY "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 24 | 25 | // ethernet interface mac address, must be unique on the LAN 26 | byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; 27 | 28 | char website[] PROGMEM = "api.supertweet.net"; 29 | 30 | byte Ethernet::buffer[700]; 31 | Stash stash; 32 | uint8_t runTime; 33 | 34 | static void sendToTwitter () { 35 | // generate two fake values as payload - by using a separate stash, 36 | // we can determine the size of the generated message ahead of time 37 | byte sd = stash.create(); 38 | stash.println("status=@inoukb my #Arduino tweets :-)"); 39 | stash.save(); 40 | 41 | // generate the header with payload - note that the stash size is used, 42 | // and that a "stash descriptor" is passed in as argument using "$H" 43 | Stash::prepare(PSTR("POST /1/statuses/update.xml HTTP/1.1" "\r\n" 44 | "Host: $F" "\r\n" 45 | "Authorization: Basic $F" "\r\n" 46 | "User-Agent: Arduino EtherCard lib" "\r\n" 47 | "Content-Length: $D" "\r\n" 48 | "Content-Type: application/x-www-form-urlencoded" "\r\n" 49 | "\r\n" 50 | "$H"), 51 | website, PSTR(KEY), stash.size(), sd); 52 | 53 | // send the packet - this also releases all stash buffers once done 54 | ether.tcpSend(); 55 | } 56 | 57 | void setup () { 58 | Serial.begin(57600); 59 | Serial.println("\n[webClient]"); 60 | 61 | if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 62 | Serial.println( "Failed to access Ethernet controller"); 63 | if (!ether.dhcpSetup()) 64 | Serial.println("DHCP failed"); 65 | 66 | ether.printIp("IP: ", ether.myip); 67 | ether.printIp("GW: ", ether.gwip); 68 | ether.printIp("DNS: ", ether.dnsip); 69 | 70 | if (!ether.dnsLookup(website)) 71 | Serial.println("DNS failed"); 72 | 73 | ether.printIp("SRV: ", ether.hisip); 74 | 75 | sendToTwitter(); 76 | } 77 | 78 | void loop () { 79 | ether.packetLoop(ether.packetReceive()); 80 | } 81 | -------------------------------------------------------------------------------- /02.Library/ethercard/examples/webClient/webClient.ino: -------------------------------------------------------------------------------- 1 | // Demo using DHCP and DNS to perform a web client request. 2 | // 2011-06-08 http://opensource.org/licenses/mit-license.php 3 | 4 | #include 5 | 6 | // ethernet interface mac address, must be unique on the LAN 7 | static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 }; 8 | 9 | byte Ethernet::buffer[700]; 10 | static uint32_t timer; 11 | 12 | char website[] PROGMEM = "www.google.com"; 13 | 14 | // called when the client request is complete 15 | static void my_callback (byte status, word off, word len) { 16 | Serial.println(">>>"); 17 | Ethernet::buffer[off+300] = 0; 18 | Serial.print((const char*) Ethernet::buffer + off); 19 | Serial.println("..."); 20 | } 21 | 22 | void setup () { 23 | Serial.begin(57600); 24 | Serial.println("\n[webClient]"); 25 | 26 | if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 27 | Serial.println( "Failed to access Ethernet controller"); 28 | if (!ether.dhcpSetup()) 29 | Serial.println("DHCP failed"); 30 | 31 | ether.printIp("IP: ", ether.myip); 32 | ether.printIp("GW: ", ether.gwip); 33 | ether.printIp("DNS: ", ether.dnsip); 34 | 35 | if (!ether.dnsLookup(website)) 36 | Serial.println("DNS failed"); 37 | 38 | ether.printIp("SRV: ", ether.hisip); 39 | } 40 | 41 | void loop () { 42 | ether.packetLoop(ether.packetReceive()); 43 | 44 | if (millis() > timer) { 45 | timer = millis() + 5000; 46 | Serial.println(); 47 | Serial.print("<<< REQ "); 48 | ether.browseUrl(PSTR("/foo/"), "bar", website, my_callback); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /02.Library/ethercard/net.h: -------------------------------------------------------------------------------- 1 | // Based on the net.h file from the AVRlib library by Pascal Stang. 2 | // Author: Guido Socher 3 | // Copyright: GPL V2 4 | // 5 | // For AVRlib See http://www.procyonengineering.com/ 6 | // Used with explicit permission of Pascal Stang. 7 | // 8 | // 2010-05-20 9 | 10 | // notation: _P = position of a field 11 | // _V = value of a field 12 | 13 | #ifndef NET_H 14 | #define NET_H 15 | 16 | // ******* ETH ******* 17 | #define ETH_HEADER_LEN 14 18 | // values of certain bytes: 19 | #define ETHTYPE_ARP_H_V 0x08 20 | #define ETHTYPE_ARP_L_V 0x06 21 | #define ETHTYPE_IP_H_V 0x08 22 | #define ETHTYPE_IP_L_V 0x00 23 | // byte positions in the ethernet frame: 24 | // 25 | // Ethernet type field (2bytes): 26 | #define ETH_TYPE_H_P 12 27 | #define ETH_TYPE_L_P 13 28 | // 29 | #define ETH_DST_MAC 0 30 | #define ETH_SRC_MAC 6 31 | 32 | 33 | // ******* ARP ******* 34 | #define ETH_ARP_OPCODE_REPLY_H_V 0x0 35 | #define ETH_ARP_OPCODE_REPLY_L_V 0x02 36 | #define ETH_ARP_OPCODE_REQ_H_V 0x0 37 | #define ETH_ARP_OPCODE_REQ_L_V 0x01 38 | // start of arp header: 39 | #define ETH_ARP_P 0xe 40 | // 41 | #define ETHTYPE_ARP_L_V 0x06 42 | // arp.dst.ip 43 | #define ETH_ARP_DST_IP_P 0x26 44 | // arp.opcode 45 | #define ETH_ARP_OPCODE_H_P 0x14 46 | #define ETH_ARP_OPCODE_L_P 0x15 47 | // arp.src.mac 48 | #define ETH_ARP_SRC_MAC_P 0x16 49 | #define ETH_ARP_SRC_IP_P 0x1c 50 | #define ETH_ARP_DST_MAC_P 0x20 51 | #define ETH_ARP_DST_IP_P 0x26 52 | 53 | // ******* IP ******* 54 | #define IP_HEADER_LEN 20 55 | // ip.src 56 | #define IP_SRC_P 0x1a 57 | #define IP_DST_P 0x1e 58 | #define IP_HEADER_LEN_VER_P 0xe 59 | #define IP_CHECKSUM_P 0x18 60 | #define IP_TTL_P 0x16 61 | #define IP_FLAGS_P 0x14 62 | #define IP_P 0xe 63 | #define IP_TOTLEN_H_P 0x10 64 | #define IP_TOTLEN_L_P 0x11 65 | 66 | #define IP_PROTO_P 0x17 67 | 68 | #define IP_PROTO_ICMP_V 1 69 | #define IP_PROTO_TCP_V 6 70 | // 17=0x11 71 | #define IP_PROTO_UDP_V 17 72 | // ******* ICMP ******* 73 | #define ICMP_TYPE_ECHOREPLY_V 0 74 | #define ICMP_TYPE_ECHOREQUEST_V 8 75 | // 76 | #define ICMP_TYPE_P 0x22 77 | #define ICMP_CHECKSUM_P 0x24 78 | #define ICMP_CHECKSUM_H_P 0x24 79 | #define ICMP_CHECKSUM_L_P 0x25 80 | #define ICMP_IDENT_H_P 0x26 81 | #define ICMP_IDENT_L_P 0x27 82 | #define ICMP_DATA_P 0x2a 83 | 84 | // ******* UDP ******* 85 | #define UDP_HEADER_LEN 8 86 | // 87 | #define UDP_SRC_PORT_H_P 0x22 88 | #define UDP_SRC_PORT_L_P 0x23 89 | #define UDP_DST_PORT_H_P 0x24 90 | #define UDP_DST_PORT_L_P 0x25 91 | // 92 | #define UDP_LEN_H_P 0x26 93 | #define UDP_LEN_L_P 0x27 94 | #define UDP_CHECKSUM_H_P 0x28 95 | #define UDP_CHECKSUM_L_P 0x29 96 | #define UDP_DATA_P 0x2a 97 | 98 | // ******* TCP ******* 99 | #define TCP_SRC_PORT_H_P 0x22 100 | #define TCP_SRC_PORT_L_P 0x23 101 | #define TCP_DST_PORT_H_P 0x24 102 | #define TCP_DST_PORT_L_P 0x25 103 | // the tcp seq number is 4 bytes 0x26-0x29 104 | #define TCP_SEQ_H_P 0x26 105 | #define TCP_SEQACK_H_P 0x2a 106 | // flags: SYN=2 107 | #define TCP_FLAGS_P 0x2f 108 | #define TCP_FLAGS_SYN_V 2 109 | #define TCP_FLAGS_FIN_V 1 110 | #define TCP_FLAGS_RST_V 4 111 | #define TCP_FLAGS_PUSH_V 8 112 | #define TCP_FLAGS_SYNACK_V 0x12 113 | #define TCP_FLAGS_ACK_V 0x10 114 | #define TCP_FLAGS_PSHACK_V 0x18 115 | // plain len without the options: 116 | #define TCP_HEADER_LEN_PLAIN 20 117 | #define TCP_HEADER_LEN_P 0x2e 118 | #define TCP_WIN_SIZE 0x30 119 | #define TCP_CHECKSUM_H_P 0x32 120 | #define TCP_CHECKSUM_L_P 0x33 121 | #define TCP_OPTIONS_P 0x36 122 | // 123 | #endif 124 | -------------------------------------------------------------------------------- /02.Library/ethercard/tcpip.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/02.Library/ethercard/tcpip.rar -------------------------------------------------------------------------------- /03.Program/主机eeprom.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/03.Program/主机eeprom.bin -------------------------------------------------------------------------------- /03.Program/从机 多路 V0.1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/03.Program/从机 多路 V0.1.c -------------------------------------------------------------------------------- /03.Program/从机 节点 V0.1.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/03.Program/从机 节点 V0.1.c -------------------------------------------------------------------------------- /03.Program/从机 节点 V0.2.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/03.Program/从机 节点 V0.2.c -------------------------------------------------------------------------------- /04.PCB/README.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/04.PCB/README.txt -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/README.txt -------------------------------------------------------------------------------- /web.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wasdpkj/Roomduino/f833b5d648e74bbcdd257263d287fc8b5b24fd26/web.rar --------------------------------------------------------------------------------