diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1ff0c42..0000000 --- a/.gitattributes +++ /dev/null @@ -1,63 +0,0 @@ -############################################################################### -# Set default behavior to automatically normalize line endings. -############################################################################### -* text=auto - -############################################################################### -# Set default behavior for command prompt diff. -# -# This is need for earlier builds of msysgit that does not have it on by -# default for csharp files. -# Note: This is only used by command line -############################################################################### -#*.cs diff=csharp - -############################################################################### -# Set the merge driver for project and solution files -# -# Merging from the command prompt will add diff markers to the files if there -# are conflicts (Merging from VS is not affected by the settings below, in VS -# the diff markers are never inserted). Diff markers may cause the following -# file extensions to fail to load in VS. An alternative would be to treat -# these files as binary and thus will always conflict and require user -# intervention with every merge. To do so, just uncomment the entries below -############################################################################### -#*.sln merge=binary -#*.csproj merge=binary -#*.vbproj merge=binary -#*.vcxproj merge=binary -#*.vcproj merge=binary -#*.dbproj merge=binary -#*.fsproj merge=binary -#*.lsproj merge=binary -#*.wixproj merge=binary -#*.modelproj merge=binary -#*.sqlproj merge=binary -#*.wwaproj merge=binary - -############################################################################### -# behavior for image files -# -# image files are treated as binary by default. -############################################################################### -#*.jpg binary -#*.png binary -#*.gif binary - -############################################################################### -# diff behavior for common document formats -# -# Convert binary document formats to text before diffing them. This feature -# is only available from the command line. Turn it on by uncommenting the -# entries below. -############################################################################### -#*.doc diff=astextplain -#*.DOC diff=astextplain -#*.docx diff=astextplain -#*.DOCX diff=astextplain -#*.dot diff=astextplain -#*.DOT diff=astextplain -#*.pdf diff=astextplain -#*.PDF diff=astextplain -#*.rtf diff=astextplain -#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore deleted file mode 100644 index fd9b5c9..0000000 --- a/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/.vs -/Debug -/*.opensdf -/*.sdf -/*.opendb -/*.suo diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..a0fed17 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,93 @@ +{ + "configurations": [ + { + "name": "Mac", + "includePath": [ + "/usr/include", + "/usr/local/include", + "/opt/arduino-1.8.5/hardware/arduino/avr/cores/arduino", + "/opt/arduino-1.8.5/hardware/tools/avr/avr/include", + "/opt/arduino-1.8.5/hardware/arduino/avr/variants/standard", + "${workspaceRoot}", + "${workspaceRoot}/library/OneWireSlave" + ], + "defines": ["ARDUINO=160","__AVR__","UBRRH","__AVR_ATmega328P__","VS_INTELLISENSE"], + "intelliSenseMode": "clang-x64", + "browse": { + "path": [ + "/usr/include", + "/usr/local/include", + "${workspaceRoot}" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + }, + "macFrameworkPath": [ + "/System/Library/Frameworks", + "/Library/Frameworks" + ] + }, + { + "name": "Linux", + "includePath": [ + "/usr/include/c++/4.9", + "/usr/include/x86_64-linux-gnu/c++/4.9", + "/usr/include/c++/4.9/backward", + "/usr/lib/gcc/x86_64-linux-gnu/4.9/include", + "/usr/local/include", + "/usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed", + "/usr/include/x86_64-linux-gnu", + "/usr/include", + "/opt/arduino-1.8.5/hardware/arduino/avr/cores/arduino", + "/opt/arduino-1.8.5/hardware/tools/avr/avr/include", + "/opt/arduino-1.8.5/hardware/arduino/avr/variants/standard", + "${workspaceRoot}", + "${workspaceRoot}/library/OneWireSlave" + ], + "defines": ["ARDUINO=160","__AVR__","UBRRH","__AVR_ATmega328P__","VS_INTELLISENSE"], + "intelliSenseMode": "clang-x64", + "browse": { + "path": [ + "/usr/include/c++/4.9", + "/usr/include/x86_64-linux-gnu/c++/4.9", + "/usr/include/c++/4.9/backward", + "/usr/lib/gcc/x86_64-linux-gnu/4.9/include", + "/usr/local/include", + "/usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed", + "/usr/include/x86_64-linux-gnu", + "/usr/include", + "${workspaceRoot}" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + } + }, + { + "name": "Win32", + "includePath": [ + "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include", + "/opt/arduino-1.8.5/hardware/arduino/avr/cores/arduino", + "/opt/arduino-1.8.5/hardware/tools/avr/avr/include", + "/opt/arduino-1.8.5/hardware/arduino/avr/variants/standard", + "${workspaceRoot}", + "${workspaceRoot}/library/OneWireSlave" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE", + "ARDUINO=160","__AVR__","UBRRH","__AVR_ATmega328P__","VS_INTELLISENSE" + ], + "intelliSenseMode": "msvc-x64", + "browse": { + "path": [ + "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*", + "${workspaceRoot}" + ], + "limitSymbolsToIncludedHeaders": true, + "databaseFilename": "" + } + } + ], + "version": 3 +} \ No newline at end of file diff --git a/OneWireIO.sln b/OneWireIO.sln deleted file mode 100644 index f10e9f5..0000000 --- a/OneWireIO.sln +++ /dev/null @@ -1,32 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OneWireIO", "OneWireIO.vcxproj", "{3B500971-1570-460F-81C3-22AC3B7764B9}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|Mixed Platforms = Debug|Mixed Platforms - Debug|Win32 = Debug|Win32 - Release|Any CPU = Release|Any CPU - Release|Mixed Platforms = Release|Mixed Platforms - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3B500971-1570-460F-81C3-22AC3B7764B9}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {3B500971-1570-460F-81C3-22AC3B7764B9}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 - {3B500971-1570-460F-81C3-22AC3B7764B9}.Debug|Mixed Platforms.Build.0 = Debug|Win32 - {3B500971-1570-460F-81C3-22AC3B7764B9}.Debug|Win32.ActiveCfg = Debug|Win32 - {3B500971-1570-460F-81C3-22AC3B7764B9}.Debug|Win32.Build.0 = Debug|Win32 - {3B500971-1570-460F-81C3-22AC3B7764B9}.Release|Any CPU.ActiveCfg = Release|Win32 - {3B500971-1570-460F-81C3-22AC3B7764B9}.Release|Mixed Platforms.ActiveCfg = Release|Win32 - {3B500971-1570-460F-81C3-22AC3B7764B9}.Release|Mixed Platforms.Build.0 = Release|Win32 - {3B500971-1570-460F-81C3-22AC3B7764B9}.Release|Win32.ActiveCfg = Release|Win32 - {3B500971-1570-460F-81C3-22AC3B7764B9}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/OneWireIO.vcxproj b/OneWireIO.vcxproj deleted file mode 100644 index 94ae257..0000000 --- a/OneWireIO.vcxproj +++ /dev/null @@ -1,107 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {3B500971-1570-460F-81C3-22AC3B7764B9} - OneWireIO - OneWireIO - - - - Application - true - v140 - MultiByte - - - Application - false - v140 - true - MultiByte - - - - - - - - - - - - - - - Level3 - Disabled - true - D:\Outils\Arduino\hardware\arduino\avr\cores\arduino;D:\Outils\Arduino\hardware\tools\avr\avr\include;C:\Program Files %28x86%29\Arduino\hardware\arduino\avr\cores\arduino;C:\Program Files %28x86%29\Arduino\hardware\tools\avr\avr\include - _MBCS;%(PreprocessorDefinitions);ARDUINO=160;__AVR__;UBRRH;__AVR_ATmega328P__;VS_INTELLISENSE - - - true - - - if exist $(ProjectDir)$(IntDir)$(ProjectName).ino.elf ( -echo Elf generated -) else ( -echo no output -exit /B 1 -) - - - - - - - - - - Level3 - MaxSpeed - true - true - true - - - true - true - true - - - - - Document - false - if exist $(ProjectDir)$(IntDir)$(ProjectName).ino.elf del $(ProjectDir)$(IntDir)$(ProjectName).ino.elf -"C:\Program Files (x86)\Arduino\arduino.exe" --upload --pref build.path=$(ProjectDir)$(Configuration) %(FullPath) | more - - always_build_$(ProjectConfiguration).dummy - - - Building and uploading sketch... - - - - - true - - - - - - - - - - \ No newline at end of file diff --git a/OneWireIO.vcxproj.filters b/OneWireIO.vcxproj.filters deleted file mode 100644 index 6f73395..0000000 --- a/OneWireIO.vcxproj.filters +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index 7304df7..e4399a7 100644 --- a/README.md +++ b/README.md @@ -5,18 +5,4 @@ An arduino library to communicate using the Dallas one-wire protocol, where the 1-wire allows communication over long distances (100m and more, see Dallas documentation for details) with a single wire (plus a ground wire). You can put as much devices as you want on the same wire (they communicate one at a time). 1-wire also allows to send power over the data wire (parasitic power), but, though I haven't tried, I don't believe it would work with an Arduino. You'll need a separate 5V power source, which, if it comes next to your data wire, means you need 3 wires (5V, data, and ground). You'll also need a master controller, for example the USB adapter DS9490R, to connect to a computer, that will control communication with all 1-wire devices. ## How to use this library -This library allows you to emulate existing 1-wire devices with an Arduino, or to create your own protocol. All low-level details are handled by the library, such as reset detection, ROM matching, byte sending and receiving. Look at the demo sketch to see an example. - -There are only 3 important functions: -- `void setReceiveCallback(void(*callback)(ReceiveEvent evt, byte data))` sets the function that will be called back when an event occurs, such as when a byte is received -- `void begin(byte* rom, byte pinNumber)` starts the library, which will respond to the provided ROM (must be unique on your network) on the specified Arduino pin. The ROM is cloned by the library, so you can discard your buffer immediately if you want. -- `void write(byte* bytes, short numBytes, void(*complete)(bool error))` starts writing one or more bytes, and will call the provided callback (optional) when it's done. The buffer you provide here must stay available until the end of the write operation, which happens in background. Do not use local variables. - -## Notes about the interrupt-based implementation -Since the library is implemented using interrupts, none of its functions will block: you can continue execute your code immediately. - -This also means callbacks are called from interrupt handlers, so you must make them very short to not block further communication. - -You must also be careful when you explicitely block interrupts, as the 1-wire protocol has very tight timings, especially when writing bytes (which also happens when searching for device ROMs): a delay of 3 microseconds (yes, microseconds, not milliseconds) can be enough for some (quite intolerant) masters to miss a bit. - -But if your code only blocks interrupts for reasonably short time, the probability to block exactly at the bad moment is low, so you can easily mitigate the issue by adding CRC checks in your high-level communication protocol, and retrying when an error is detected. This is an important thing to do anyway because 1-wire does not natively perform any error checking (excepted for ROM operations which already contain a CRC byte). Standard 1-wire devices also include CRC checks in their specific protocols. +Take a look at [the documentation of the library](./library/OneWireSlave/documentation.md) diff --git a/library/OneWireSlave/LICENSE b/library/OneWireSlave/LICENSE new file mode 100644 index 0000000..40ca408 --- /dev/null +++ b/library/OneWireSlave/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2018 Youen Toupin, aka neuoy + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/LowLevel.h b/library/OneWireSlave/LowLevel.h similarity index 100% rename from LowLevel.h rename to library/OneWireSlave/LowLevel.h diff --git a/OneWireSlave.cpp b/library/OneWireSlave/OneWireSlave.cpp similarity index 100% rename from OneWireSlave.cpp rename to library/OneWireSlave/OneWireSlave.cpp diff --git a/OneWireSlave.h b/library/OneWireSlave/OneWireSlave.h similarity index 100% rename from OneWireSlave.h rename to library/OneWireSlave/OneWireSlave.h diff --git a/library/OneWireSlave/documentation.md b/library/OneWireSlave/documentation.md new file mode 100644 index 0000000..54b0ce2 --- /dev/null +++ b/library/OneWireSlave/documentation.md @@ -0,0 +1,30 @@ +This library allows you to emulate existing 1-wire devices with an Arduino, or to create your own protocol. All low-level details are handled by the library, such as reset detection, ROM matching, byte sending and receiving. Look at the demo sketch to see an example. + +# Reference + +## setReceiveCallback + +`void setReceiveCallback(void(*callback)(ReceiveEvent evt, byte data))` + +Sets the function that will be called back when an event occurs, such as when a byte is received. + +## begin + +`void begin(byte* rom, byte pinNumber)` + +Starts the library, which will respond to the provided ROM (must be unique on your network) on the specified Arduino pin. The ROM is cloned by the library, so you can discard your buffer immediately if you want. + +## write + +`void write(byte* bytes, short numBytes, void(*complete)(bool error))` + +Starts writing one or more bytes, and will call the provided callback (optional) when it's done. The buffer you provide here must stay available until the end of the write operation, which happens in background. Do not use local variables. + +# Notes about the interrupt-based implementation +Since the library is implemented using interrupts, none of its functions will block: you can continue execute your code immediately. + +This also means callbacks are called from interrupt handlers, so you must make them very short to not block further communication. + +You must also be careful when you explicitely block interrupts, as the 1-wire protocol has very tight timings, especially when writing bytes (which also happens when searching for device ROMs): a delay of 3 microseconds (yes, microseconds, not milliseconds) can be enough for some (quite intolerant) masters to miss a bit. + +But if your code only blocks interrupts for reasonably short time, the probability to block exactly at the bad moment is low, so you can easily mitigate the issue by adding CRC checks in your high-level communication protocol, and retrying when an error is detected. This is an important thing to do anyway because 1-wire does not natively perform any error checking (excepted for ROM operations which already contain a CRC byte). Standard 1-wire devices also include CRC checks in their specific protocols. diff --git a/OneWireIO.ino b/library/OneWireSlave/examples/FakeDS18B20/FakeDS18B20.ino similarity index 92% rename from OneWireIO.ino rename to library/OneWireSlave/examples/FakeDS18B20/FakeDS18B20.ino index 62b2ca3..234f9ea 100644 --- a/OneWireIO.ino +++ b/library/OneWireSlave/examples/FakeDS18B20/FakeDS18B20.ino @@ -1,6 +1,9 @@ -#include "Arduino.h" -#include "LowLevel.h" -#include "OneWireSlave.h" +// This examples demonstrates how to use the OneWireSlave library to implement a fake DS18B20 (temperature sensor) with an arduino board. +// The example always ever responds to requests with the same temperature + +#include +#include +#include // This is the pin that will be used for one-wire data (depending on your arduino model, you are limited to a few choices, because some pins don't have complete interrupt support) // On Arduino Uno, you can use pin 2 or pin 3 diff --git a/library/OneWireSlave/keywords.txt b/library/OneWireSlave/keywords.txt new file mode 100644 index 0000000..7a929d7 --- /dev/null +++ b/library/OneWireSlave/keywords.txt @@ -0,0 +1,34 @@ +####################################### +# Syntax Coloring Map For OneWireSlave +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +ReceiveEvent KEYWORD1 +OneWireSlave KEYWORD1 +Pin KEYWORD1 +OWSlave KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +begin KEYWORD2 +end KEYWORD2 +setReceiveCallback KEYWORD2 +setReceiveBitCallback KEYWORD2 +write KEYWORD2 +writeBit KEYWORD2 +stopWrite KEYWORD2 +alarmed KEYWORD2 +crc8 KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + +RE_Reset LITERAL1 +RE_Byte LITERAL1 +RE_Error LITERAL1 diff --git a/library/OneWireSlave/library.properties b/library/OneWireSlave/library.properties new file mode 100644 index 0000000..2873a10 --- /dev/null +++ b/library/OneWireSlave/library.properties @@ -0,0 +1,9 @@ +name=OneWireSlave +version=0.2 +author=neuoy +maintainer=https://github.com/neuoy/OneWireArduinoSlave +sentence=Library to create slave 1-wire devices +paragraph=This library allows you to emulate existing 1-wire devices with an Arduino, or to create your own protocol. All low-level details are handled by the library, such as reset detection, ROM matching, byte sending and receiving. +category=Device Control +url=https://github.com/neuoy/OneWireArduinoSlave +architectures=*