AppController.m 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #import "AppController.h"
  2. #import "CommandWrapper.h"
  3. #define UCON64 "/usr/local/bin/ucon64"
  4. #define ROMFILE "/Users/david/Devel/arch/avr/code/quickdev16/roms/mrdo.smc"
  5. @implementation AppController
  6. - (id) init {
  7. [super init];
  8. NSLog(@"init");
  9. return self;
  10. }
  11. - (void)awakeFromNib {
  12. [textFieldLog setStringValue:@"Log field"];
  13. [textFieldInfo setStringValue:@"Info field"];
  14. NSLog(@"awakeFromNib");
  15. }
  16. - (IBAction)romUpload:(id)sender {
  17. NSLog(@"romUpload:");
  18. NSTask *ls=[[NSTask alloc] init];
  19. NSPipe *pipe=[[NSPipe alloc] init];
  20. NSFileHandle *handle;
  21. [ls setLaunchPath:@UCON64];
  22. [ls setArguments:[NSArray arrayWithObjects:@"-smc",@"--port=usb",@"--xquickdev16",@ROMFILE,nil]];
  23. [ls setStandardOutput:pipe];
  24. handle=[pipe fileHandleForReading];
  25. [ls launch];
  26. [NSThread detachNewThreadSelector:@selector(copyData:)
  27. toTarget:self withObject:handle];
  28. [pipe release];
  29. [ls release];
  30. }
  31. - (void)copyData:(NSFileHandle*)handle {
  32. NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
  33. NSData *data;
  34. while([data=[handle availableData] length]) { // until EOF (check reference)
  35. NSString *string=[[NSString alloc] initWithData:data
  36. encoding:NSASCIIStringEncoding];
  37. [textFieldLog setStringValue:string];
  38. [string release];
  39. }
  40. [pool release];
  41. }
  42. - (IBAction)romInfo:(id)sender {
  43. NSTask *ls=[[NSTask alloc] init];
  44. NSPipe *pipe=[[NSPipe alloc] init];
  45. NSFileHandle *handle;
  46. NSString *string;
  47. NSLog(@"romInfo");
  48. [ls setLaunchPath:@"/usr/local/bin/ucon64"];
  49. [ls setArguments:[NSArray arrayWithObjects:@ROMFILE,nil]];
  50. [ls setStandardOutput:pipe];
  51. handle=[pipe fileHandleForReading];
  52. [ls launch];
  53. string=[[NSString alloc] initWithData:[handle readDataToEndOfFile]
  54. encoding:NSASCIIStringEncoding]; // convert NSData -> NSString
  55. NSLog(@"romInfo: %@", string);
  56. [textFieldInfo setStringValue:string];
  57. [string retain];
  58. [pipe release];
  59. [ls release];
  60. }
  61. -(NSSize)windowWillResize:(NSWindow *)send toSize:(NSSize) framesize;
  62. {
  63. float w = framesize.width;
  64. float h = framesize.height;
  65. NSLog(@"called willResize %f x %f ",w,h);
  66. w = w*2;
  67. framesize.width = w;
  68. return framesize;
  69. }
  70. - (void) dealloc {
  71. NSLog(@"dealloc");
  72. [super dealloc];
  73. }
  74. @end