Skip to content

Commit

Permalink
* Fix downloading multiple files from FTP
Browse files Browse the repository at this point in the history
* Add  clicks on filament to configure/load/unload
  • Loading branch information
TFyre committed Feb 2, 2024
1 parent c86cd7e commit 0b43bfa
Show file tree
Hide file tree
Showing 10 changed files with 476 additions and 95 deletions.
62 changes: 4 additions & 58 deletions bambu/src/main/java/com/tfyre/bambu/printer/BambuConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -17,67 +16,14 @@ public class BambuConst {
public static final String CHAMBER_LIGHT = "chamber_light";
public static final String FILE_GCODE = ".gcode";
public static final String FILE_3MF = ".3mf";
public static final Set<String> EXT = Set.of(/*FIXME not working FILE_GCODE,*/FILE_3MF);
//FIXME GCODE not printing public static final Set<String> EXT = Set.of(FILE_GCODE, FILE_3MF);
public static final Set<String> EXT = Set.of(FILE_3MF);
public static final String PATHSEP = "/";
public static final String PRINT_TYPE_IDLE = "idle";
public static final int TEMPERATURE_MAX_BED = 100;
public static final int TEMPERATURE_MAX_NOZZLE = 300;

public static final Map<String, String> FILAMENTS = Map.ofEntries(
Map.entry("default", "Unknown"),
Map.entry("GFB00", "Bambu ABS"),
Map.entry("GFB01", "Bambu ASA"),
Map.entry("GFN03", "Bambu PA-CF"),
Map.entry("GFN05", "Bambu PA6-CF"),
Map.entry("GFN04", "Bambu PAHT-CF"),
Map.entry("GFC00", "Bambu PC"),
Map.entry("GFT01", "Bambu PET-CF"),
Map.entry("GFG00", "Bambu PETG Basic"),
Map.entry("GFG50", "Bambu PETG-CF"),
Map.entry("GFA11", "Bambu PLA Aero"),
Map.entry("GFA00", "Bambu PLA Basic"),
Map.entry("GFA03", "Bambu PLA Impact"),
Map.entry("GFA07", "Bambu PLA Marble"),
Map.entry("GFA01", "Bambu PLA Matte"),
Map.entry("GFA02", "Bambu PLA Metal"),
Map.entry("GFA05", "Bambu PLA Silk"),
Map.entry("GFA08", "Bambu PLA Sparkle"),
Map.entry("GFA09", "Bambu PLA Tough"),
Map.entry("GFA50", "Bambu PLA-CF"),
Map.entry("GFS03", "Bambu Support For PA/PET"),
Map.entry("GFS02", "Bambu Support For PLA"),
Map.entry("GFS01", "Bambu Support G"),
Map.entry("GFS00", "Bambu Support W"),
Map.entry("GFU01", "Bambu TPU 95A"),
Map.entry("GFB99", "Generic ABS"),
Map.entry("GFB98", "Generic ASA"),
Map.entry("GFS98", "Generic HIPS"),
Map.entry("GFN98", "Generic PA-CF"),
Map.entry("GFN99", "Generic PA"),
Map.entry("GFC99", "Generic PC"),
Map.entry("GFG99", "Generic PETG"),
Map.entry("GFG98", "Generic PETG-CF"),
Map.entry("GFL99", "Generic PLA"),
Map.entry("GFL95", "Generic PLA-High Speed"),
Map.entry("GFL96", "Generic PLA Silk"),
Map.entry("GFL98", "Generic PLA-CF"),
Map.entry("GFS99", "Generic PVA"),
Map.entry("GFU99", "Generic TPU"),
Map.entry("GFL05", "Overture Matte PLA"),
Map.entry("GFL04", "Overture PLA"),
Map.entry("GFB60", "PolyLite ABS"),
Map.entry("GFB61", "PolyLite ASA"),
Map.entry("GFG60", "PolyLite PETG"),
Map.entry("GFL00", "PolyLite PLA"),
Map.entry("GFL01", "PolyTerra PLA"),
Map.entry("GFL03", "eSUN PLA+"),
Map.entry("GFSL99_01", "Generic PLA Silk"),
Map.entry("GFSL99_12", "Generic PLA Silk")
);

public static Optional<String> getFilament(final String filament) {
return Optional.ofNullable(FILAMENTS.get(filament));
}
public static final int AMS_TRAY_UNLOAD = 255;
public static final int AMS_TRAY_TEMP = 210;

public static String gcodeTargetTemperatureBed(final int temperature) {
return "M140 S%d".formatted(Math.max(Math.min(temperature, TEMPERATURE_MAX_BED), 0));
Expand Down
6 changes: 6 additions & 0 deletions bambu/src/main/java/com/tfyre/bambu/printer/BambuPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public interface BambuPrinter {

void commandPrintProjectFile(final String filename, final int plateId, final boolean useAms, final boolean timelapse, final boolean bedLevelling);

void commandFilamentLoad(final int amsTrayId);

void commandFilamentUnload();

void commandFilamentSetting(final int amsId, final int trayId, final Filament filament, final String value, final int minTemp, final int maxTemp);

record Message(OffsetDateTime lastUpdated, BambuMessage message, String raw) {

}
Expand Down
50 changes: 50 additions & 0 deletions bambu/src/main/java/com/tfyre/bambu/printer/BambuPrinterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,56 @@ public void commandLight(final BambuConst.LightMode lightMode) {
toJson(message).ifPresent(this::sendData);
}

@Override
public void commandFilamentLoad(final int amsTrayId) {
logUser("%s: commandFilamentLoad %d".formatted(name, amsTrayId));
final BambuMessage message = BambuMessage.newBuilder()
.setPrint(
com.tfyre.bambu.model.Print.newBuilder()
.setSequenceId("%d".formatted(counter.incrementAndGet()))
.setCommand("ams_change_filament")
.setTarget(amsTrayId)
.setCurrTemp(BambuConst.AMS_TRAY_TEMP)
.setTarTemp(BambuConst.AMS_TRAY_TEMP)
)
.build();
toJson(message).ifPresent(this::sendData);
}

@Override
public void commandFilamentSetting(final int amsId, final int trayId, final Filament filament, final String color, final int minTemp, final int maxTemp) {
logUser("%s: commandFilamentSetting ams[%d] tray[%d] filament[%s] color[%s] min[%d] max[%d]"
.formatted(name, amsId, trayId, filament, color, minTemp, maxTemp));
final BambuMessage message = BambuMessage.newBuilder()
.setPrint(
com.tfyre.bambu.model.Print.newBuilder()
.setSequenceId("%d".formatted(counter.incrementAndGet()))
.setCommand("ams_filament_setting")
.setAmsId(amsId)
.setTrayId(trayId)
.setTrayInfoIdx(filament.getCode())
.setTrayColor(color)
.setNozzleTempMin(minTemp)
.setNozzleTempMax(maxTemp)
.setTrayType(filament.getType().getDescription())
)
.build();
toJson(message).ifPresent(this::sendData);
}

@Override
public void commandFilamentUnload() {
logUser("%s: commandFilamentUnload".formatted(name));
final BambuMessage message = BambuMessage.newBuilder()
.setPrint(
com.tfyre.bambu.model.Print.newBuilder()
.setSequenceId("%d".formatted(counter.incrementAndGet()))
.setCommand("unload_filament")
)
.build();
toJson(message).ifPresent(this::sendData);
}

@Override
public void commandControl(final BambuConst.CommandControl control) {
logUser("%s: commandControl: %s".formatted(name, control));
Expand Down
96 changes: 96 additions & 0 deletions bambu/src/main/java/com/tfyre/bambu/printer/Filament.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.tfyre.bambu.printer;

import java.util.EnumSet;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
*
* @author Francois Steyn - ([email protected])
*/
public enum Filament {
UNKNOWN("Unknown", "Unknown", FilamentType.UNKNOWN),
BAMBU_ABS("GFB00", "Bambu ABS", FilamentType.ABS),
BAMBU_ASA("GFB01", "Bambu ASA", FilamentType.ASA),
BAMBU_PACF("GFN03", "Bambu PA-CF", FilamentType.PACF),
BAMBU_PA6CF("GFN05", "Bambu PA6-CF", FilamentType.PA6CF),
BAMBU_PAHTCF("GFN04", "Bambu PAHT-CF", FilamentType.PACF),
BAMBU_PC("GFC00", "Bambu PC", FilamentType.PC),
BAMBU_PET_CF("GFT01", "Bambu PET-CF", FilamentType.PETCF),
BAMBU_PETG_BASIC("GFG00", "Bambu PETG Basic", FilamentType.PETG),
BAMBU_PETG_CF("GFG50", "Bambu PETG-CF", FilamentType.PETGCF),
BAMBU_PLA_AERO("GFA11", "Bambu PLA Aero", FilamentType.PLA_AERO),
BAMBU_PLA_BASIC("GFA00", "Bambu PLA Basic", FilamentType.PLA),
BAMBU_PLA_IMPACT("GFA03", "Bambu PLA Impact", FilamentType.PLA),
BAMBU_PLA_MARBLE("GFA07", "Bambu PLA Marble", FilamentType.PLA),
BAMBU_PLA_MATTE("GFA01", "Bambu PLA Matte", FilamentType.PLA),
BAMBU_PLA_METAL("GFA02", "Bambu PLA Metal", FilamentType.PLA),
BAMBU_PLA_SILK("GFA05", "Bambu PLA Silk", FilamentType.PLA),
BAMBU_PLA_SPARKLE("GFA08", "Bambu PLA Sparkle", FilamentType.PLA),
BAMBU_PLA_TOUGH("GFA09", "Bambu PLA Tough", FilamentType.PLA),
BAMBU_PLA_CF("GFA50", "Bambu PLA-CF", FilamentType.PLA_CF),
BAMBU_SUPPORT_PA("GFS03", "Bambu Support For PA/PET", FilamentType.PLA),
BAMBU_SUPPORT_PLA("GFS02", "Bambu Support For PLA", FilamentType.PLA),
BAMBU_SUPPORT_G("GFS01", "Bambu Support G", FilamentType.PLA),
BAMBU_SUPPORT_W("GFS00", "Bambu Support W", FilamentType.PLA),
BAMBU_TPU("GFU01", "Bambu TPU 95A", FilamentType.TPU),
GENERIC_ABS("GFB99", "Generic ABS", FilamentType.ABS),
GENERIC_ASA("GFB98", "Generic ASA", FilamentType.ASA),
GENERIC_HIPS("GFS98", "Generic HIPS", FilamentType.HIPS),
GENERIC_PACF("GFN98", "Generic PA-CF", FilamentType.PACF),
GENERIC_PA("GFN99", "Generic PA", FilamentType.PA),
GENERIC_PC("GFC99", "Generic PC", FilamentType.PC),
GENERIC_PETG("GFG99", "Generic PETG", FilamentType.PETG),
GENERIC_PETC_CF("GFG98", "Generic PETG-CF", FilamentType.PETGCF),
GENERIC_PLA("GFL99", "Generic PLA", FilamentType.PLA),
GENERIC_PLA_HS("GFL95", "Generic PLA-High Speed", FilamentType.PLA),
GENERIC_PLA_SILK("GFL96", "Generic PLA Silk", FilamentType.PLA),
GENERIC_PLA_CF("GFL98", "Generic PLA-CF", FilamentType.PLA_CF),
GENERIC_PVA("GFS99", "Generic PVA", FilamentType.PVA),
GENERIC_TPU("GFU99", "Generic TPU", FilamentType.TPU),
OVERTURE_PLA("GFL05", "Overture Matte PLA", FilamentType.PLA),
OVERTURE_ABS("GFL04", "Overture PLA", FilamentType.PLA),
POLYLITE_ABS("GFB60", "PolyLite ABS", FilamentType.ABS),
POLYLITE_ASA("GFB61", "PolyLite ASA", FilamentType.ASA),
POLYLITE_PETG("GFG60", "PolyLite PETG", FilamentType.PETG),
POLYLITE_PLA("GFL00", "PolyLite PLA", FilamentType.PLA),
POLYTERRA_PLA("GFL01", "PolyTerra PLA", FilamentType.PLA),
ESUN_PLA("GFL03", "eSUN PLA+", FilamentType.PLA),
GENERIC_PLA_SLIK_01("GFSL99_01", "Generic PLA Silk 01", FilamentType.PLA),
GENERIC_PLA_SLIK_12("GFSL99_12", "Generic PLA Silk 12", FilamentType.PLA);

private static final Map<String, Filament> MAP = EnumSet.allOf(Filament.class).stream().collect(Collectors.toMap(Filament::getCode, Function.identity()));

private final String code;
private final String description;
private final FilamentType type;

private Filament(final String code, final String description, final FilamentType type) {
this.code = code;
this.description = description;
this.type = type;
}

public String getCode() {
return code;
}

public String getDescription() {
return description;
}

public FilamentType getType() {
return type;
}

public static Optional<Filament> getFilament(final String code) {
return Optional.ofNullable(MAP.get(code));
}

public static String getFilamentDescription(final String code) {
return Optional.ofNullable(MAP.get(code)).map(Filament::getDescription).orElse(Filament.UNKNOWN.getDescription());
}

}
35 changes: 35 additions & 0 deletions bambu/src/main/java/com/tfyre/bambu/printer/FilamentType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.tfyre.bambu.printer;

/**
*
* @author Francois Steyn - ([email protected])
*/
public enum FilamentType {
UNKNOWN("Unknown"),
ABS("ABS"),
ASA("ASA"),
HIPS("HIPS"),
PA("PA"),
PVA("PVA"),
PACF("PA-CF"),
PA6CF("PA6-CF"),
PC("PC"),
PETCF("PET-CF"),
PETG("PETG"),
PETGCF("PETG-CF"),
PLA("PLA"),
PLA_AERO("PLA-AERO"),
PLA_CF("PLA-CF"),
TPU("TPU");

private final String description;

private FilamentType(final String description) {
this.description = description;
}

public String getDescription() {
return description;
}

}
36 changes: 36 additions & 0 deletions bambu/src/main/java/com/tfyre/bambu/printer/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.tfyre.bambu.printer;

import org.jboss.logging.Logger;

/**
*
* @author Francois Steyn - ([email protected])
*/
public class Utils {

private static final Logger log = Logger.getLogger(Utils.class.getName());

public static double parseDouble(final String printerName, final String value, final double defaultValue) {
if (value == null) {
return 0;
}
try {
return Double.parseDouble(value);
} catch (NumberFormatException ex) {
log.errorf("%s: Cannot parseInt [%s]", printerName, value);
return defaultValue;
}
}

public static int parseInt(final String printerName, final String value, final int defaultValue) {
if (value == null) {
return 0;
}
try {
return Integer.parseInt(value);
} catch (NumberFormatException ex) {
log.errorf("%s: Cannot parseInt [%s]", printerName, value);
return defaultValue;
}
}
}
Loading

0 comments on commit 0b43bfa

Please sign in to comment.