PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
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.

97 satır
2.3KB

  1. /*
  2. x10.h - - X10 transmission library for Arduino - Version 0.4
  3. Original library (0.1) by Tom Igoe.
  4. Timing bug fixes (0.2) " " "
  5. Sends X10 commands.
  6. */
  7. // ensure this library description is only included once
  8. #ifndef x10_h
  9. #define x10_h
  10. // include types & constants of Wiring core API
  11. #include "Arduino.h"
  12. #define BIT_DELAY 1778 // 1778 us between bit repeats in a half-cycle
  13. #define BIT_LENGTH 800 // each bit is slightly less than 1ms long
  14. #define HOUSE_A B0110
  15. #define HOUSE_B B1110
  16. #define HOUSE_C B0010
  17. #define HOUSE_D B1010
  18. #define HOUSE_E B0001
  19. #define HOUSE_F B1001
  20. #define HOUSE_G B0101
  21. #define HOUSE_H B1101
  22. #define HOUSE_I B0111
  23. #define HOUSE_J B1111
  24. #define HOUSE_K B0011
  25. #define HOUSE_L B1011
  26. #define HOUSE_M B0000
  27. #define HOUSE_N B1000
  28. #define HOUSE_O B0100
  29. #define HOUSE_P B1100
  30. #define UNIT_1 B01100
  31. #define UNIT_2 B11100
  32. #define UNIT_3 B00100
  33. #define UNIT_4 B10100
  34. #define UNIT_5 B00010
  35. #define UNIT_6 B10010
  36. #define UNIT_7 B01010
  37. #define UNIT_8 B11010
  38. #define UNIT_9 B01110
  39. #define UNIT_10 B11110
  40. #define UNIT_11 B00110
  41. #define UNIT_12 B10110
  42. #define UNIT_13 B00000
  43. #define UNIT_14 B10000
  44. #define UNIT_15 B01000
  45. #define UNIT_16 B11000
  46. #define ALL_UNITS_OFF B00001
  47. #define ALL_LIGHTS_ON B00011
  48. #define ON B00101
  49. #define OFF B00111
  50. #define DIM B01001
  51. #define BRIGHT B01011
  52. #define ALL_LIGHTS_OFF B01101
  53. #define EXTENDED_CODE B01111
  54. #define HAIL_REQUEST B10001
  55. #define HAIL_ACKNOWLEDGE B10011
  56. #define PRE_SET_DIM B10101
  57. #define EXTENDED_DATA B11001
  58. #define STATUS_ON B11011
  59. #define STATUS_OFF B11101
  60. #define STATUS_REQUEST B11111
  61. // library interface description
  62. class x10 {
  63. public:
  64. // constructors:
  65. x10(uint8_t zeroCrossingPin, uint8_t dataPin);
  66. // write command method:
  67. void write(byte houseCode, byte numberCode, byte numRepeats);
  68. // returns the version number:
  69. int version(void);
  70. private:
  71. #if defined(__AVR__) || defined(KINETISK) || defined(KINETISL)
  72. volatile uint8_t *zeroCrossingReg; // AC zero crossing pin
  73. #else
  74. volatile uint32_t *zeroCrossingReg; // AC zero crossing pin
  75. #endif
  76. uint8_t zeroCrossingBit;
  77. uint8_t dataPin; // data out pin
  78. // sends the individual bits of the commands:
  79. void sendBits(byte cmd, byte numBits, byte isStartCode);
  80. // checks for AC zero crossing
  81. void waitForZeroCross(void);
  82. };
  83. #endif