Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My first set of patches #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions microprint/TFPCLIController.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ - (void)runWithArgumentCount:(int)argc arguments:(char **)argv {
TFLog(@"No connected printer found!");
exit(EXIT_FAILURE);
}
TFLog(@"M3D printer found!");

[weakSelf.printer establishConnectionWithCompletionHandler:^(NSError *error) {
TFLog(@"M3D printer connected!");
TFPPrinter *printer = weakSelf.printer;
if(!error) {
TFLog(@"Connected to printer %@ with firmware version %@.", printer.serialNumber, printer.firmwareVersion);
Expand Down
4 changes: 2 additions & 2 deletions microprint/TFPPrintJob.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ - (void)jobDidComplete {
- (void)sendGCode:(TFPGCode*)code {
__weak __typeof__(self) weakSelf = self;

if(self.parameters.verbose) {
// if(self.parameters.verbose) {
TFLog(@"Sending %@", code);
}
// }

uint64_t sendTime = TFNanosecondTime();
self.pendingRequestCount++;
Expand Down
41 changes: 28 additions & 13 deletions microprint/TFPPrinter.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ - (void)establishConnectionWithCompletionHandler:(void(^)(NSError *error))comple
if(self.connectionFinished) {
completionHandler(nil);
} else {
if(!self.pendingConnection) {
[self.serialPort open];
[self.establishBlocks addObject:[completionHandler copy]];
self.serialPort.delegate = self;
if(!self.pendingConnection) {
self.pendingConnection = YES;
[self.serialPort open];
}
[self.establishBlocks addObject:[completionHandler copy]];
}
}

Expand Down Expand Up @@ -125,13 +126,12 @@ - (void)serialPort:(ORSSerialPort *)serialPort didEncounterError:(NSError *)erro


- (void)sendGCode:(TFPGCode*)GCode responseHandler:(void(^)(BOOL success, NSString *value))block {
[self.serialPort sendData:GCode.repetierV2Representation];

if([GCode hasField:'N']) {
self.numberedResponseListenerBlocks[@((NSUInteger)[GCode valueForField:'N'])] = [block copy];
}else{
[self.unnumberedResponseListenerBlocks addObject:[block copy]];
}
[self.serialPort sendData:GCode.repetierV2Representation];
}


Expand Down Expand Up @@ -244,10 +244,23 @@ - (void)processIncomingString:(NSString*)incomingLine {
TFLog(@"* %@", incomingLine);
}

if([scanner scanString:@"wait"]) {
// Do nothing

}else if([scanner scanString:@"ok"]){
if([scanner scanString:@"wait"] || [scanner scanString:@"e1"]) {
if(self.serialNumber) {
// Do nothing, printer is telling us it's waiting (for movement)
} else {
// Bootloader? Who knows, just whack it with another M115
TFLog(@"* RE-SENDING M115");
TFPGCode *getCapabilities = [TFPGCode codeWithString:@"M115"];
[self.serialPort sendData:getCapabilities.repetierV2Representation];
}
} else if([scanner scanString:@"B004"]){
// Bootloader for sure, whack it with a Q then resend M115
TFLog(@"* SENDING Q and M115");
TFPGCode *getCapabilities = [TFPGCode codeWithString:@"Q"];
[self.serialPort sendData:getCapabilities.repetierV2Representation];
getCapabilities = [TFPGCode codeWithString:@"M115"];
[self.serialPort sendData:getCapabilities.repetierV2Representation];
} else if([scanner scanString:@"ok"]){
NSInteger lineNumber = -1;

NSUInteger pos = scanner.location;
Expand Down Expand Up @@ -277,15 +290,15 @@ - (void)processIncomingString:(NSString*)incomingLine {
}
}

}else if([scanner scanString:@"T:"]) {
} else if([scanner scanString:@"T:"]) {
double temperature = [[scanner scanToString:@"\n"] doubleValue];
[self processTemperatureUpdate:temperature];

}else if([scanner scanString:@"Resend:"]) {
} else if([scanner scanString:@"Resend:"]) {
NSInteger lineNumber = [[scanner scanToString:@"\n"] integerValue];
[self handleResendRequest:lineNumber];

}else{
} else {
TFLog(@"Unhandled input: %@", incomingLine);
}
}
Expand All @@ -304,7 +317,9 @@ - (void)processIncomingData {
}
}


/*
* THis is where data from serial port gets handed to us.
*/
- (void)serialPort:(ORSSerialPort * __nonnull)serialPort didReceiveData:(NSData * __nonnull)data {
[self.incomingData appendData:data];
[self processIncomingData];
Expand Down
13 changes: 7 additions & 6 deletions microprint/TFPPrinterManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#import "ORSSerialPortManager.h"


static const uint16_t M3DMicroUSBVendorID = 0x03EB;
static const uint16_t M3DMicroUSBProductID = 0x2404;
//static const uint16_t M3DMicroUSBVendorID = 0x03EB;
//static const uint16_t M3DMicroUSBProductID = 0x2404;


@interface TFPPrinterManager ()
Expand All @@ -35,10 +35,11 @@ - (instancetype)init {
if(!(self = [super init])) return nil;

self.printers = [[[ORSSerialPortManager sharedSerialPortManager].availablePorts tf_selectWithBlock:^BOOL(ORSSerialPort *port) {
uint16_t vendorID, productID;
if([port getUSBVendorID:&vendorID productID:&productID]) {
return vendorID == M3DMicroUSBVendorID && productID == M3DMicroUSBProductID;
}else{

if([port.name hasPrefix: @"usbmodem"]) {
printf("Found Modem POrt: %s\n",[port.name UTF8String]);
return YES;
} else {
return NO;
}
}] tf_mapWithBlock:^TFPPrinter*(ORSSerialPort *serialPort) {
Expand Down