Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AltSoftSerial.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* An Alternative Software Serial Library
  2. * http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
  3. * Copyright (c) 2014 PJRC.COM, LLC, Paul Stoffregen, paul@pjrc.com
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies 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 included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. * THE SOFTWARE.
  22. */
  23. #ifndef AltSoftSerial_h
  24. #define AltSoftSerial_h
  25. #include <inttypes.h>
  26. #if ARDUINO >= 100
  27. #include "Arduino.h"
  28. #else
  29. #include "WProgram.h"
  30. #include "pins_arduino.h"
  31. #endif
  32. #if defined(__arm__) && defined(CORE_TEENSY)
  33. #define ALTSS_BASE_FREQ F_BUS
  34. #else
  35. #define ALTSS_BASE_FREQ F_CPU
  36. #endif
  37. /** AltSoftSerial class */
  38. class AltSoftSerial : public Stream
  39. {
  40. public:
  41. AltSoftSerial() { } //!< Constructor
  42. ~AltSoftSerial()
  43. {
  44. end(); //!< Destructor
  45. }
  46. static void begin(uint32_t baud)
  47. {
  48. init((ALTSS_BASE_FREQ + baud / 2) / baud); //!< begin
  49. }
  50. static void end(); //!< end
  51. int peek(); //!< peek
  52. int read(); //!< read
  53. int available(); //!< available
  54. #if ARDUINO >= 100
  55. size_t write(uint8_t byte)
  56. {
  57. writeByte(byte); //!< write
  58. return 1;
  59. }
  60. void flush()
  61. {
  62. flushOutput(); //!< flush
  63. }
  64. #else
  65. void write(uint8_t byte)
  66. {
  67. writeByte(byte); //!< write
  68. }
  69. void flush()
  70. {
  71. flushInput(); //!< flush
  72. }
  73. #endif
  74. using Print::write;
  75. static void flushInput(); //!< flushInput
  76. static void flushOutput(); //!< flushOutput
  77. // for drop-in compatibility with NewSoftSerial, rxPin & txPin ignored
  78. AltSoftSerial(uint8_t rxPin, uint8_t txPin, bool inverse = false)
  79. {
  80. (void)rxPin; //!< AltSoftSerial
  81. (void)txPin;
  82. (void)inverse;
  83. }
  84. bool listen()
  85. {
  86. return false; //!< listen
  87. }
  88. bool isListening()
  89. {
  90. return true; //!< isListening
  91. }
  92. bool overflow()
  93. {
  94. bool r = timing_error; //!< overflow
  95. timing_error = false;
  96. return r;
  97. }
  98. static int library_version()
  99. {
  100. return 1; //!< library_version
  101. }
  102. static void enable_timer0(bool enable)
  103. {
  104. (void)enable; //!< enable_timer0
  105. }
  106. static bool timing_error; //!< timing_error
  107. private:
  108. static void init(uint32_t cycles_per_bit);
  109. static void writeByte(uint8_t byte);
  110. };
  111. #endif