Skip to content

Commit

Permalink
New driver for "Ruida" class lasercutters, like ThunderLaser (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaempf authored Sep 26, 2022
1 parent eb5df38 commit 3f7575a
Show file tree
Hide file tree
Showing 5 changed files with 1,739 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/**
* This file is part of LibLaserCut.
* Copyright (C) 2011 - 2014 Thomas Oster <mail@thomas-oster.de>
* Copyright (C) 2018 - 2020 Klaus Kämpf <kkaempf@suse.de>
*
* LibLaserCut is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LibLaserCut is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LibLaserCut. If not, see <http://www.gnu.org/licenses/>.
*
**/
package de.thomas_oster.liblasercut.drivers;

import de.thomas_oster.liblasercut.LaserProperty;
import de.thomas_oster.liblasercut.FloatPowerSpeedFrequencyProperty;
import java.util.Arrays;
import java.util.LinkedList;

/*
* Add 'min power' to FloatPowerSpeedFrequencyProperty
*/

public class FloatMinMaxPowerSpeedFrequencyProperty extends FloatPowerSpeedFrequencyProperty {

private float min_power = 10.0f;
private static final String MIN_POWER = "min power";

public FloatMinMaxPowerSpeedFrequencyProperty()
{
super();
}

public FloatMinMaxPowerSpeedFrequencyProperty(LaserProperty o)
{
for (String k : o.getPropertyKeys())
{
Object p;
p = o.getProperty(k);
if (p != null) {
this.setProperty(k, p);
}
}
}

/**
* Get the value of min power
*
* @return float
*/
public float getMinPower()
{
return min_power;
}

/**
* Set the value of min power
*
* @param min power
*/
public void setMinPower(float power)
{
if (power > this.getPower()) { /* minimum must not be larger than maximum */
power = this.getPower();
}
this.min_power = power;
}

@Override
public String[] getPropertyKeys()
{
LinkedList<String> result = new LinkedList<String>();
result.add(MIN_POWER);
result.addAll(Arrays.asList(super.getPropertyKeys()));
return result.toArray(new String[0]);
}

@Override
public Object getProperty(String name)
{
if (MIN_POWER.equals(name)) {
return (Float) this.getMinPower();
}
else {
return super.getProperty(name);
}
}

@Override
public Object getMinimumValue(String name)
{
if (MIN_POWER.equals(name)) {
return 0f;
}
else {
return super.getProperty(name);
}
}

@Override
public Object getMaximumValue(String name)
{
if (MIN_POWER.equals(name)) {
return 100f;
}
else {
return super.getProperty(name);
}
}

@Override
public void setProperty(String name, Object value)
{
if (MIN_POWER.equals(name)) {
this.setMinPower((Float) value);
}
else {
super.setProperty(name, value);
}
}

@Override
public FloatMinMaxPowerSpeedFrequencyProperty clone()
{
FloatMinMaxPowerSpeedFrequencyProperty result = new FloatMinMaxPowerSpeedFrequencyProperty();
Object p;
for (String s:this.getPropertyKeys())
{
p = this.getProperty(s);
if (p != null) {
result.setProperty(s, p);
}
}
return result;
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof FloatMinMaxPowerSpeedFrequencyProperty)) {
return false;
}
final FloatMinMaxPowerSpeedFrequencyProperty other = (FloatMinMaxPowerSpeedFrequencyProperty) obj;
if (this.min_power != other.min_power) {
return false;
}
return super.equals(other);
}

@Override
public int hashCode() {
int hash = 5;
hash = 97 * hash + (int)min_power;
hash = 97 * hash + super.hashCode();
return hash;
}

public String toString()
{
return "FloatMinMaxPowerSpeedFrequencyProperty(min power="+getMinPower()+", max power="+getPower()+", speed="+getSpeed()+", frequency="+getFrequency()+")";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
/*
This file is part of LibLaserCut.
Copyright (C) 2011 - 2014 Thomas Oster <mail@thomas-oster.de>
LibLaserCut is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
LibLaserCut is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with LibLaserCut. If not, see <http://www.gnu.org/licenses/>.
*/
package de.thomas_oster.liblasercut;

/**
* The LaserProperty holds all the parameters for parts of the LaserJob.
* The Frequency value is ignored for Engraving operations
*
* @author oster
*/
public class FloatPowerSpeedFrequencyProperty implements LaserProperty
{

private float power = 0;
private float speed = 100;
private int frequency = 500;

public FloatPowerSpeedFrequencyProperty()
{
}

/**
* Sets the Laserpower. Valid values are from 0 to 100.
* In 3d-Raster mode, the intensity is scaled to this power setting
*/
@Override
public void setPower(float power)
{
power = power < 0 ? 0 : power;
power = power > 100 ? 100 : power;
this.power = power;
}

@Override
public float getPower()
{
return power;
}

/**
* Sets the speed for the Laser. Valid values is from 0 to 100
*/
public void setSpeed(float speed)
{
speed = speed < 0 ? 0 : speed;
speed = speed > 100 ? 100 : speed;
this.speed = speed;
}

@Override
public float getSpeed()
{
return speed;
}

public void setFrequency(int f)
{
this.frequency = f;
}

public int getFrequency()
{
return this.frequency;
}

@Override
public FloatPowerSpeedFrequencyProperty clone()
{
FloatPowerSpeedFrequencyProperty p = new FloatPowerSpeedFrequencyProperty();
p.frequency = frequency;
p.power = power;
p.speed = speed;
return p;
}

private static final String[] propertyNames = new String[]{"power", "speed", "frequency"};

@Override
public String[] getPropertyKeys()
{
return propertyNames;
}

@Override
public Object getProperty(String name)
{
if ("power".equals(name))
{
return this.getPower();
}
else if ("speed".equals(name))
{
return this.getSpeed();
}
else if ("frequency".equals(name))
{
return this.getFrequency();
}
return null;
}

@Override
public void setProperty(String name, Object value)
{
if ("power".equals(name))
{
this.setPower((Float) value);
}
else if ("speed".equals(name))
{
this.setSpeed((Float) value);
}
else if ("frequency".equals(name))
{
this.setFrequency((Integer) value);
}
else
{
throw new IllegalArgumentException("Unknown setting '"+name+"'");
}
}

@Override
public Object getMinimumValue(String name)
{
if ("power".equals(name))
{
return 0f;
}
else if ("speed".equals(name))
{
return 0f;
}
else if ("frequency".equals(name))
{
return null;
}
else
{
throw new IllegalArgumentException("Unknown setting '"+name+"'");
}
}

@Override
public Object getMaximumValue(String name)
{
if ("power".equals(name))
{
return 100f;
}
else if ("speed".equals(name))
{
return 100f;
}
else if ("frequency".equals(name))
{
return null;
}
else
{
throw new IllegalArgumentException("Unknown setting '"+name+"'");
}
}

@Override
public Object[] getPossibleValues(String name)
{
return null;
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final FloatPowerSpeedFrequencyProperty other = (FloatPowerSpeedFrequencyProperty) obj;
if (Float.floatToIntBits(this.power) != Float.floatToIntBits(other.power)) {
return false;
}
if (Float.floatToIntBits(this.speed) != Float.floatToIntBits(other.speed)) {
return false;
}
return this.frequency == other.frequency;
}

@Override
public int hashCode() {
int hash = 7;
hash = 67 * hash + Float.floatToIntBits(this.power);
hash = 67 * hash + Float.floatToIntBits(this.speed);
hash = 67 * hash + this.frequency;
return hash;
}


}
3 changes: 2 additions & 1 deletion src/main/java/de/thomas_oster/liblasercut/LibInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public static List<Class<? extends LaserCutter>> getSupportedDrivers()
FullSpectrumCutter.class,
LaserToolsTechnicsCutter.class,
K40NanoDriver.class,
K3EngraverDriver.class
K3EngraverDriver.class,
Ruida.class
);
}
}
Loading

1 comment on commit 3f7575a

@jnweiger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

Please sign in to comment.