Advertisement
Reykez

Yeelights

Feb 25th, 2020
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using YeelightAPI;
  4. using Shortcut;
  5. using System.Windows.Forms;
  6. using System.Runtime.InteropServices;
  7.  
  8.  
  9. namespace Yeelight
  10. {
  11. class Program
  12. {
  13. // --- SETTINGS
  14. static void settings()
  15. {
  16. firstModifier = Modifiers.Alt;
  17. secondModifier = Modifiers.Control;
  18. key = Keys.D8;
  19. lamps.Add(new Device("192.168.0.88"));
  20. lamps.Add(new Device("192.168.0.11"));
  21. lamps.Add(new Device("192.168.0.21"));
  22. }
  23. // --- END OF SETTINGS
  24.  
  25.  
  26. [DllImport("kernel32.dll")] public static extern IntPtr GetConsoleWindow();
  27.  
  28. [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
  29.  
  30. // --- VARIABLES
  31. static List<Device> lamps = new List<Device>();
  32. static DeviceGroup group;
  33. private static readonly HotkeyBinder _hotkeyBinder = new HotkeyBinder();
  34. static Modifiers firstModifier, secondModifier;
  35. static Keys key;
  36.  
  37. // --- MAINNo
  38. static void Main(string[] args)
  39. {
  40. settings();
  41. var handle = GetConsoleWindow();
  42. ShowWindow(handle, 0);
  43.  
  44. Console.Write("Connecting...");
  45. connect();
  46. Console.WriteLine(" Connected");
  47.  
  48. _hotkeyBinder.Bind(firstModifier, key).To(HotkeyCallback);
  49. _hotkeyBinder.Bind(firstModifier | secondModifier, Keys.D8).To(HotkeyCallback2);
  50. Application.Run();
  51. }
  52.  
  53. // --- CONNECTION
  54. static void connect()
  55. {
  56. group = new DeviceGroup();
  57. foreach (var item in lamps)
  58. {
  59. group.Add(item);
  60. }
  61. group.Connect();
  62. }
  63.  
  64. static void toggle()
  65. {
  66. group.Toggle();
  67. }
  68.  
  69. // --- HOTKEYS
  70. private static void HotkeyCallback()
  71. {
  72. toggle();
  73. }
  74.  
  75. private static void HotkeyCallback2()
  76. {
  77. Console.WriteLine("Reconnecting");
  78. connect();
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement