-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUSBWindowController.m
918 lines (704 loc) · 24.3 KB
/
USBWindowController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
#import "USBWindowController.h"
extern int usbstatus;
static NSString *SystemVersion ()
{
NSString *systemVersion = [[NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"] objectForKey:@"ProductVersion"];
// NSLog(@"systemVersion: %@",systemVersion);
// NSArray* VersionArray=[systemVersion componentsSeparatedByString:@"."];
// NSLog(@"VersionArray: %@",[VersionArray description]);
return systemVersion;
}
@implementation IOWarriorWindowController
static NSString * SystemVersion();
int SystemNummer;
// LinkedList
struct list_node
{
int data;
struct list_node *next;
struct list_node *prev;
};
typedef struct list_node node;
struct Abschnitt *first, *last, * curr;
struct Abschnitt * init_list(uint8_t *data)
{
struct Abschnitt * ersterAbschnitt =malloc(sizeof(struct Abschnitt));
ersterAbschnitt->num=0;
ersterAbschnitt->data = data;
first = ersterAbschnitt;
last = ersterAbschnitt;
ersterAbschnitt->next = NULL;
ersterAbschnitt->prev = NULL;
return ersterAbschnitt;
}
struct Abschnitt * insert_right(struct Abschnitt *list, uint8_t *data)
{
struct Abschnitt *neuerAbschnitt = (struct Abschnitt *) malloc(sizeof(struct Abschnitt));
neuerAbschnitt->data = data;
neuerAbschnitt->num = list->num+1;
neuerAbschnitt->prev = list;
if (list->next)
{
//printf("next ist da\n");
neuerAbschnitt->next = list->next;
neuerAbschnitt->next->prev = neuerAbschnitt;
}
else
{
//printf("next ist nicht da\n");
neuerAbschnitt->next=NULL;
}
list->next = neuerAbschnitt;
//neuerAbschnitt->next=NULL;
return neuerAbschnitt;
}
struct Abschnitt * delete(struct Abschnitt *list)
{
if (list->next)// nicht letzter Abschnitt
{
list->next->prev = list->prev; // next von vorherigem Abschnitt setzen
list->prev->next = list->next;
return list->prev;
}
return list->prev;
}
struct Abschnitt * delete_last(struct Abschnitt *list)
{
struct Abschnitt *lastAbschnitt = list;
while (lastAbschnitt->next && lastAbschnitt->next->next) // Ende suchen
{
//printf("%d",lastAbschnitt->num);
lastAbschnitt=lastAbschnitt->next;
}
// Ende erreicht, vorletzter Abschnitt
//return lastAbschnitt;
if (lastAbschnitt->next)
{
struct Abschnitt* temp=lastAbschnitt->next;
free(temp);
lastAbschnitt->next=NULL;
}
return lastAbschnitt;
}
struct Abschnitt * delete_first(struct Abschnitt *list)
{
struct Abschnitt *currAbschnitt = list;
while (currAbschnitt->prev) // Anfang suchen
{
currAbschnitt=currAbschnitt->prev;
}
//return currAbschnitt;
// Anfang erreicht
struct Abschnitt* temp=currAbschnitt;
currAbschnitt=currAbschnitt->next;
currAbschnitt->prev=NULL;
free(temp);
return currAbschnitt;
}
struct Abschnitt * delete_all(struct Abschnitt *list)
{
struct Abschnitt *firstAbschnitt = list;
while (firstAbschnitt->next) // Ende suchen
{
firstAbschnitt=firstAbschnitt->next;
}
// Ende erreicht
while (firstAbschnitt->prev) // prev von erstem Abschnitt ist NULL
{
//struct Abschnitt* temp = ;
firstAbschnitt = firstAbschnitt->prev;
if (firstAbschnitt->next)
{
struct Abschnitt* temp = firstAbschnitt->next;
firstAbschnitt->next = NULL;
free(temp);
}
}
return firstAbschnitt;
}
void print_all_num(struct Abschnitt* list)
{
struct Abschnitt *head = list;
struct Abschnitt *current = list;
printf("%d ", head->num);
while (head != (current = current->next)){
printf("%d ", current->num);
}
printf("\n");
}
// end LinkedList
- (void)Alert:(NSString*)derFehler
{
NSAlert * DebugAlert=[NSAlert alertWithMessageText:@"Debugger!"
defaultButton:NULL
alternateButton:NULL
otherButton:NULL
informativeTextWithFormat:@"Mitteilung: \n%@",derFehler];
[DebugAlert runModal];
}
- (void)observerMethod:(id)note
{
NSLog(@"observerMethod userInfo: %@",[[note userInfo]description]);
NSLog(@"observerMethod note: %@",[note description]);
}
void DeviceAdded(void *refCon, io_iterator_t iterator)
{
NSLog(@"IOWWindowController DeviceAdded");
NSDictionary* NotDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:USBATTACHED],@"usb", nil];
NSNotificationCenter *nc=[NSNotificationCenter defaultCenter];
[nc postNotificationName:@"usbopen" object:NULL userInfo:NotDic];
}
void DeviceRemoved(void *refCon, io_iterator_t iterator)
{
NSLog(@"IOWWindowController DeviceRemoved");
NSDictionary* NotDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:USBREMOVED],@"usb", nil];
NSNotificationCenter *nc=[NSNotificationCenter defaultCenter];
[nc postNotificationName:@"usbopen" object:NULL userInfo:NotDic];
}
- (int)USBOpen
{
int r;
r = rawhid_open(1, 0x16C0, 0x0480, 0xFFAB, 0x0200);
if (r <= 0)
{
//NSLog(@"USBOpen: no rawhid device found");
[AVR setUSB_Device_Status:0];
}
else
{
//NSLog(@"USBOpen: found rawhid device %d",usbstatus);
[AVR setUSB_Device_Status:1];
const char* manu = get_manu();
//fprintf(stderr,"manu: %s\n",manu);
NSString* Manu = [NSString stringWithUTF8String:manu];
const char* prod = get_prod();
//fprintf(stderr,"prod: %s\n",prod);
NSString* Prod = [NSString stringWithUTF8String:prod];
//NSLog(@"Manu: %@ Prod: %@",Manu, Prod);
NSDictionary* USBDatenDic = [NSDictionary dictionaryWithObjectsAndKeys:Prod,@"prod",Manu,@"manu", nil];
[AVR setUSBDaten:USBDatenDic];
// NSNotificationCenter *nc=[NSNotificationCenter defaultCenter];
// [nc postNotificationName:@"usbopen" object:NULL userInfo:NotDic];
}
usbstatus=r;
return r;
}
- (void)setHalt:(int)haltstatus
{
halt = haltstatus;
}
/*" Invoked when the nib file including the window has been loaded. "*/
- (void) awakeFromNib
{
mausistdown=0;
anzrepeat=0;
int listcount=0;
struct Abschnitt *first;
// LinkedList
first=NULL;
//
/*
NSNotificationCenter *notCenter;
notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];
[notCenter addObserver:self
selector:@selector(observerMethod:)
name:NSWorkspaceDidMountNotification object:self]; // Register for all notifications
kern_return_t kr;
mach_port_t masterPort;
kr = IOMasterPort (MACH_PORT_NULL, &masterPort);
static IONotificationPortRef gNotifyPort;
CFRunLoopSourceRef runLoopSource;
CFMutableDictionaryRef matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
//NSMutableDictionary* matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
// gNotifyPort = IONotificationPortCreate(kIOMasterPortDefault);
if (!kr && masterPort)
{
gNotifyPort = IONotificationPortCreate(masterPort);
runLoopSource = IONotificationPortGetRunLoopSource (gNotifyPort);
CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop],
runLoopSource,
kCFRunLoopDefaultMode);
int usbVendor=0;
// kern_return_t kr;
io_iterator_t addedIter;
// CFDictionarySetValue (matchingDict, CFSTR(kUSBVendorID), CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &usbVendor));
// omitting productID here
kr = IOServiceAddMatchingNotification (gNotifyPort, kIOFirstMatchNotification, (CFMutableDictionaryRef)matchingDict,
DeviceAdded, NULL, &addedIter);
DeviceAdded(NULL, addedIter);
// mach_port_deallocate (mach_task_self(), masterPort);
}
//
*/
//int adresse=0xABCD;
//adresse = 0xA030;
//int lbyte=adresse<<8;
//lbyte &= 0xff00;
//lbyte >>=8;
//int hbyte=adresse>>8;
//int lbyte=adresse%0x100;
//int hbyte=adresse/0x100;
//lbyte>>=8;
//NSLog(@"adresse: %x lbyte: %x hbyte; %x",adresse, lbyte,hbyte);
uint8_t zahl=244;
char string[3];
uint8_t l,h; // schleifenzhler
//NSLog(@"zahl: %d hex: %02X ",zahl, zahl);
// string[4]='\0'; // String Terminator
string[2]='\0'; // String Terminator
l=(zahl % 16);
if (l<10)
string[1]=l +'0';
else
{
l%=10;
string[1]=l + 'A';
}
zahl /=16;
h= zahl % 16;
if (h<10)
string[0]=h +'0';
else
{
h%=10;
string[0]=h + 'A';
}
NSImage* myImage = [NSImage imageNamed: @"USB"];
[NSApp setApplicationIconImage: myImage];
// set the global ptr to the main window controller to self, needed for iowarrior callbacks
// NSString *systemVersion = [[NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"] objectForKey:@"ProductVersion"];
// NSLog(@"systemVersion: %@",systemVersion);
// NSArray* VersionArray=[systemVersion componentsSeparatedByString:@"."];
// NSLog(@"VersionArray: %@",[VersionArray description]);
// init the IOWarrior library
NSString* SysVersion=SystemVersion();
NSArray* VersionArray=[SysVersion componentsSeparatedByString:@"."];
SystemNummer=[[VersionArray objectAtIndex:1]intValue];
NSLog(@"SystemVersion: %@",SysVersion);
isReading = false;
isTracking = false;
ignoreDuplicates = YES;
//dumpTabelle=[[NSMutableArray alloc]initWithCapacity:0];
//Dump_DS=[[rDump_DS alloc]init];
//[dumpTable setDelegate:Dump_DS];
//[dumpTable setDataSource:Dump_DS];
dumpCounter=0;
lastValueRead = [[NSData alloc]init];
logEntries = [[NSMutableArray alloc] init];
[logTable setTarget:self];
[logTable setDoubleAction:@selector(logTableDoubleClicked)];
halt=0;
NSNotificationCenter * nc;
nc=[NSNotificationCenter defaultCenter];
// CNC
/*
[nc addObserver:self
selector:@selector(CNCAktion:)
name:@"CNCaktion"
object:nil];
*/
[nc addObserver:self
selector:@selector(USB_SchnittdatenAktion:)
name:@"usbschnittdaten"
object:nil];
[nc addObserver:self
selector:@selector(SlaveResetAktion:)
name:@"slavereset"
object:nil];
[nc addObserver:self
selector:@selector(TastenAktion:)
name:@"Tastenaktion"
object:nil];
[nc addObserver:self
selector:@selector(EinzelTastenAktion:)
name:@"Einzeltastenaktion"
object:nil];
[nc addObserver:self
selector:@selector(SendTastenAktion:)
name:@"SendTastenAktion"
object:nil];
[nc addObserver:self
selector:@selector(SendAktion:)
name:@"SendAktion"
object:nil];
[nc addObserver:self
selector:@selector(InputAktion:)
name:@"InputAktion"
object:nil];
[nc addObserver:self
selector:@selector(BeendenAktion:)
name:@"IOWarriorBeenden"
object:nil];
[nc addObserver:self
selector:@selector(FensterSchliessenAktion:)
name:@"NSWindowWillCloseNotification"
object:nil];
[nc addObserver:self
selector:@selector(sendCmdAktion:)
name:@"sendcmd"
object:nil];
[nc addObserver:self
selector:@selector(sendReportAktion:)
name:@"sendReport"
object:nil];
[nc addObserver:self
selector:@selector(i2cEEPROMReadReportAktion:)
name:@"i2ceepromread"
object:nil];
[nc addObserver:self
selector:@selector(i2cEEPROMWriteReportAktion:)
name:@"i2ceepromwrite"
object:nil];
[nc addObserver:self
selector:@selector(i2cAVRWriteReportAktion:)
name:@"i2cavrwrite"
object:nil];
[nc addObserver:self
selector:@selector(WriteSchnittdatenArrayReportAktion:)
name:@"writeschnittdatenarray"
object:nil];
[nc addObserver:self
selector:@selector(i2cStatusAktion:)
name:@"i2cstatus"
object:nil];
[nc addObserver:self
selector:@selector(twiStatusAktion:)
name:@"twistatus"
object:nil];
[nc addObserver:self
selector:@selector(spiStatusAktion:)
name:@"spistatus"
object:nil];
[nc addObserver:self
selector:@selector(MausAktion:)
name:@"mausdaten"
object:nil];
[nc addObserver:self
selector:@selector(USBAktion:)
name:@"usbopen"
object:nil];
[nc addObserver:self
selector:@selector(PfeilAktion:)
name:@"Pfeil"
object:nil];
[nc addObserver:self
selector:@selector(HaltAktion:)
name:@"Halt"
object:nil];
[nc addObserver:self
selector:@selector(DC_Aktion:)
name:@"DC_pwm"
object:nil];
[nc addObserver:self
selector:@selector(StepperstromAktion:)
name:@"stepperstrom"
object:nil];
lastDataRead=[[NSData alloc]init];
// [self readPList];
[self showAVR:NULL];
[[FileMenu itemWithTag:1005]setTarget :AVR];
//[ProfilMenu setTarget :AVR];
//[[ProfilMenu itemWithTag:5001]setAction:@selector(readProfil:)];
//[AVR setProfilPlan:NULL];
// [self showADWandler:NULL];
//
//CNC
SchnittDatenArray=[[[NSMutableArray alloc]initWithCapacity:0]retain];
pfeilaktion=0; // signalisiert in writeCNCAbschnitt, dass eine der Pfeiltasten im Fenster gedrckt und wieder losgelassen wurde,also Pfeil beenden
HomeAnschlagSet = [[NSMutableIndexSet indexSet]retain];
schliessencounter=0; // Zaehlt FensterschliessenAktionen
ignoreDuplicates=1;
pwm=0;
int r;
//char buf[64];
r = [self USBOpen];
if (usbstatus==0)
{
NSAlert *Warnung = [[[NSAlert alloc] init] autorelease];
[Warnung addButtonWithTitle:@"Einstecken und einschalten"];
[Warnung addButtonWithTitle:@"Weiter"];
// [Warnung addButtonWithTitle:@""];
//[Warnung addButtonWithTitle:@"Abbrechen"];
[Warnung setMessageText:[NSString stringWithFormat:@"%@",@"CNC-Programm starten"]];
NSString* s1=@"USB ist noch nicht eingesteckt.";
NSString* s2=@"";
NSString* InformationString=[NSString stringWithFormat:@"%@\n%@",s1,s2];
[Warnung setInformativeText:InformationString];
[Warnung setAlertStyle:NSWarningAlertStyle];
int antwort=[Warnung runModal];
[AVR DC_ON:0];
[AVR setStepperstrom:0];
// return;
// NSLog(@"antwort: %d",antwort);
switch (antwort)
{
case NSAlertFirstButtonReturn: // Einschalten
{
[self USBOpen];
/*
int r;
r = rawhid_open(1, 0x16C0, 0x0480, 0xFFAB, 0x0200);
if (r <= 0)
{
NSLog(@"USBAktion: no rawhid device found");
[AVR setUSB_Device_Status:0];
return;
}
else
{
NSLog(@"USBAktion: found rawhid device %d",usbstatus);
[AVR setUSB_Device_Status:1];
}
usbstatus=r;
*/
}break;
case NSAlertSecondButtonReturn: // Ignorieren
{
return;
}break;
case NSAlertThirdButtonReturn: // Abbrechen
{
return;
}break;
}
}
/*
r = rawhid_open(1, 0x16C0, 0x0480, 0xFFAB, 0x0200);
if (r <= 0)
{
NSLog(@"no rawhid device found");
//printf("no rawhid device found\n");
[AVR setUSB_Device_Status:0];
usbstatus=0;
//USBStatus=0;
}
else
{
NSLog(@"awake found rawhid device");
[AVR setUSB_Device_Status:1];
usbstatus=1;
//USBStatus=1;
[self StepperstromEinschalten:1];
}
*/
const char* manu = get_manu();
//fprintf(stderr,"manu: %s\n",manu);
NSString* Manu = [NSString stringWithUTF8String:manu];
const char* prod = get_prod();
//fprintf(stderr,"prod: %s\n",prod);
NSString* Prod = [NSString stringWithUTF8String:prod];
NSLog(@"Manu: %@ Prod: %@",Manu, Prod);
NSDictionary* USBDatenDic = [NSDictionary dictionaryWithObjectsAndKeys:Prod,@"prod",Manu,@"manu", nil];
[AVR setUSBDaten:USBDatenDic];
//
// von http://stackoverflow.com/questions/9918429/how-to-know-when-a-hid-usb-bluetooth-device-is-connected-in-cocoa
IONotificationPortRef notificationPort = IONotificationPortCreate(kIOMasterPortDefault);
CFRunLoopAddSource(CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(notificationPort),
kCFRunLoopDefaultMode);
CFMutableDictionaryRef matchingDict2 = IOServiceMatching(kIOUSBDeviceClassName);
CFRetain(matchingDict2); // Need to use it twice and IOServiceAddMatchingNotification() consumes a reference
io_iterator_t portIterator = 0;
// Register for notifications when a serial port is added to the system
kern_return_t result = IOServiceAddMatchingNotification(notificationPort,
kIOPublishNotification,
matchingDict2,
DeviceAdded,
self,
&portIterator);
while (IOIteratorNext(portIterator)) {}; // Run out the iterator or notifications won't start (you can also use it to iterate the available devices).
// Also register for removal notifications
IONotificationPortRef terminationNotificationPort = IONotificationPortCreate(kIOMasterPortDefault);
CFRunLoopAddSource(CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(terminationNotificationPort),
kCFRunLoopDefaultMode);
result = IOServiceAddMatchingNotification(terminationNotificationPort,
kIOTerminatedNotification,
matchingDict2,
DeviceRemoved,
self, // refCon/contextInfo
&portIterator);
while (IOIteratorNext(portIterator)) {}; // Run out the iterator or notifications won't start (you can also use it to iterate the available devices).
//
}
- (void) dealloc
{
NSLog(@"dealloc");
[logEntries release];
[lastValueRead release];
[lastDataRead release];
[super dealloc];
}
- (void) setLastValueRead:(NSData*) inData
{
[inData retain];
[lastValueRead release];
lastValueRead = inData;
}
- (void)readPList
{
BOOL USBDatenDa=NO;
BOOL istOrdner;
NSFileManager *Filemanager = [NSFileManager defaultManager];
NSString* USBPfad=[[NSHomeDirectory() stringByAppendingFormat:@"%@%@",@"/Documents",@"/CNCDaten"]retain];
USBDatenDa= ([Filemanager fileExistsAtPath:USBPfad isDirectory:&istOrdner]&&istOrdner);
//NSLog(@"mountedVolume: USBPfad: %@",USBPfad);
if (USBDatenDa)
{
//NSLog(@"awake: tempPListDic: %@",[tempPListDic description]);
NSString* PListName=@"CNC.plist";
NSString* PListPfad;
//NSLog(@"\n\n");
PListPfad=[USBPfad stringByAppendingPathComponent:PListName];
NSLog(@"awake: PListPfad: %@ ",PListPfad);
if (PListPfad)
{
NSMutableDictionary* tempPListDic;//=[[[NSMutableDictionary alloc]initWithCapacity:0]autorelease];
if ([Filemanager fileExistsAtPath:PListPfad])
{
tempPListDic=[NSMutableDictionary dictionaryWithContentsOfFile:PListPfad];
NSLog(@"awake: tempPListDic: %@",[tempPListDic description]);
if ([tempPListDic objectForKey:@"koordinatentabelle"])
{
//NSArray* PListKoordTabelle=[tempPListDic objectForKey:@"koordinatentabelle"];
//NSLog(@"awake: PListKoordTabelle: %@",[PListKoordTabelle description]);
}
}
}
// NSLog(@"PListOK: %d",PListOK);
}//USBDatenDa
[USBPfad release];
}
- (void)savePListAktion:(NSNotification*)note
{
BOOL USBDatenDa=NO;
BOOL istOrdner;
NSFileManager *Filemanager = [NSFileManager defaultManager];
NSString* USBPfad=[[NSHomeDirectory() stringByAppendingFormat:@"%@%@",@"/Documents",@"/CNCDaten"]retain];
NSURL* USBURL=[NSURL fileURLWithPath:USBPfad];
USBDatenDa= ([Filemanager fileExistsAtPath:USBPfad isDirectory:&istOrdner]&&istOrdner);
//NSLog(@"mountedVolume: USBPfad: %@",USBPfad );
if (USBDatenDa)
{
;
}
else
{
//BOOL OrdnerOK=[Filemanager createDirectoryAtPath:USBPfad attributes:NULL];
BOOL OrdnerOK=[Filemanager createDirectoryAtURL:USBURL withIntermediateDirectories:NO attributes:nil error:nil]; //Datenordner ist noch leer
}
// NSLog(@"savePListAktion: PListDic: %@",[PListDic description]);
// NSLog(@"savePListAktion: PListDic: Testarray: %@",[[PListDic objectForKey:@"testarray"]description]);
NSString* PListName=@"CNC.plist";
NSString* PListPfad;
//NSLog(@"\n\n");
//NSLog(@"savePListAktion: SndCalcPfad: %@ ",SndCalcPfad);
PListPfad=[USBPfad stringByAppendingPathComponent:PListName];
NSURL* PListURL = [NSURL fileURLWithPath:PListPfad];
// NSLog(@"savePListAktion: PListPfad: %@ ",PListPfad);
if (PListPfad)
{
//NSLog(@"savePListAktion: PListPfad: %@ ",PListPfad);
NSMutableDictionary* tempPListDic;//=[[[NSMutableDictionary alloc]initWithCapacity:0]autorelease];
NSFileManager *Filemanager=[NSFileManager defaultManager];
if ([Filemanager fileExistsAtPath:PListPfad])
{
tempPListDic=[NSMutableDictionary dictionaryWithContentsOfFile:PListPfad];
//NSLog(@"savePListAktion: vorhandener PListDic: %@",[tempPListDic description]);
}
else
{
tempPListDic=[[[NSMutableDictionary alloc]initWithCapacity:0]autorelease];
//NSLog(@"savePListAktion: neuer PListDic");
}
//[tempPListDic setObject:[NSNumber numberWithInt:AnzahlAufgaben] forKey:@"anzahlaufgaben"];
//[tempPListDic setObject:[NSNumber numberWithInt:MaximalZeit] forKey:@"zeit"];
if ([[AVR KoordinatenTabelle]count])
{
// [tempPListDic setObject:[AVR KoordinatenTabelle] forKey:@"koordinatentabelle"];
}
int cncspeed = [AVR speed];
[tempPListDic setObject:[NSNumber numberWithInt:[AVR speed]] forKey:@"speed"];
int pwm = [AVR pwm2save];
[tempPListDic setObject:[NSNumber numberWithInt:[AVR pwm2save]] forKey:@"pwm"];
//NSLog(@"savePListAktion: gesicherter PListDic: %@",[tempPListDic description]);
BOOL PListOK=[tempPListDic writeToURL:PListURL atomically:YES];
}
// NSLog(@"PListOK: %d",PListOK);
[USBPfad release];
//[tempUserInfo release];
}
- (BOOL)windowShouldClose:(id)sender
{
NSLog(@"windowShouldClose");
/*
NSNotificationCenter* nc=[NSNotificationCenter defaultCenter];
NSMutableDictionary* BeendenDic=[[[NSMutableDictionary alloc]initWithCapacity:0]autorelease];
[nc postNotificationName:@"IOWarriorBeenden" object:self userInfo:BeendenDic];
*/
return YES;
}
- (BOOL)windowWillClose:(id)sender
{
NSLog(@"windowWillClose");
/*
NSNotificationCenter* nc=[NSNotificationCenter defaultCenter];
NSMutableDictionary* BeendenDic=[[[NSMutableDictionary alloc]initWithCapacity:0]autorelease];
[nc postNotificationName:@"IOWarriorBeenden" object:self userInfo:BeendenDic];
*/
return YES;
}
- (BOOL)Beenden
{
//NSLog(@"Beenden");
[AVR DC_ON:0];
[AVR setStepperstrom:0];
// if (schliessencounter ==0)
{
//NSLog(@"Beenden savePListAktion");
[self savePListAktion:NULL];
}
return YES;
}
- (void) FensterSchliessenAktion:(NSNotification*)note
{
//NSLog(@"FensterSchliessenAktion note: %@ titel: %@ schliessencounter: %d",[note description],[[note object]title],schliessencounter);
//NSLog(@"FensterSchliessenAktion contextInfo: %@",[[note contextInfo]description]);
if (schliessencounter)
{
return;
}
// NSLog(@"Fenster Schliessen");
if ([[[note object]title]length] && ![[[note object]title]isEqualToString:@"Print"]) // nicht bei Printdialog
{
schliessencounter++;
//NSLog(@"hat Title");
// "New Folder" wird bei 10.6.8 als Titel von open zurueckgegeben. Deshalb ausschliessen(iBook schwarz)
if (!([[[note object]title]isEqualToString:@"CNC-Eingabe"]||[[[note object]title]isEqualToString:@"New Folder"]))
{
if ([self Beenden])
{
[NSApp terminate:self];
}
}
else
{
NSLog(@"Nicht beenden");
}
}
}
- (void)BeendenAktion:(NSNotification*)note
{
NSLog(@"BeendenAktion");
[self terminate:self];
}
- (IBAction)terminate:(id)sender
{
BOOL OK=[self Beenden];
NSLog(@"terminate: OK: %d",OK);
if (OK)
{
[NSApp terminate:self];
}
}
@end