Mac OS X gamepad emulator for serial RC transmitters
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

MainWindow.m 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // MainWindow.m
  3. // SerialGamepad
  4. //
  5. // Created by Thomas Buck on 14.12.15.
  6. // Copyright © 2015 xythobuz. All rights reserved.
  7. //
  8. #import "MainWindow.h"
  9. #import "Serial.h"
  10. @implementation MainWindow
  11. @synthesize portList, connectButton, createButton;
  12. @synthesize level1, level2, level3, level4, level5, level6;
  13. @synthesize serialThread;
  14. - (IBAction)connectButtonPressed:(id)sender {
  15. if (serialThread == nil) {
  16. serialThread = [[Thread alloc] init];
  17. [serialThread setName:@"Serial Communication"];
  18. [serialThread setPortName:[portList titleOfSelectedItem]];
  19. if ([serialThread openPort] != 0) {
  20. serialThread = nil;
  21. } else {
  22. [serialThread start];
  23. [connectButton setTitle:@"Disconnect"];
  24. }
  25. } else {
  26. [serialThread setRunning:NO];
  27. // TODO disable button, thread should call back when closed
  28. // so we can set serialThread to nil then
  29. serialThread = nil;
  30. [connectButton setTitle:@"Connect"];
  31. }
  32. }
  33. - (IBAction)createButtonPressed:(id)sender {
  34. }
  35. - (void)populatePortList {
  36. NSArray *ports = [Serial listSerialPorts];
  37. if ([ports count] > 0) {
  38. [portList removeAllItems];
  39. [portList addItemsWithTitles:ports];
  40. [portList setEnabled:YES];
  41. [connectButton setEnabled:YES];
  42. } else {
  43. NSLog(@"Couldn't find any serial ports!\n");
  44. }
  45. }
  46. @end