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

Squash the warning #47

Open
wants to merge 2 commits 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
14 changes: 11 additions & 3 deletions src/com/lushprojects/circuitjs1/client/ACRailElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
package com.lushprojects.circuitjs1.client;

class ACRailElm extends RailElm {
public ACRailElm(int xx, int yy) { super(xx, yy, WF_AC); }
Class getDumpClass() { return RailElm.class; }
int getShortcut() { return 0; }
public ACRailElm(int xx, int yy) {
super(xx, yy, WF_AC);
}

Class<RailElm> getDumpClass() {
return RailElm.class;
}

int getShortcut() {
return 0;
}
}
9 changes: 7 additions & 2 deletions src/com/lushprojects/circuitjs1/client/ACVoltageElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
package com.lushprojects.circuitjs1.client;

class ACVoltageElm extends VoltageElm {
public ACVoltageElm(int xx, int yy) { super(xx, yy, WF_AC); }
Class getDumpClass() { return VoltageElm.class; }
public ACVoltageElm(int xx, int yy) {
super(xx, yy, WF_AC);
}

Class<VoltageElm> getDumpClass() {
return VoltageElm.class;
}
}
73 changes: 49 additions & 24 deletions src/com/lushprojects/circuitjs1/client/ADCElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,52 +20,77 @@
package com.lushprojects.circuitjs1.client;

class ADCElm extends ChipElm {
public ADCElm(int xx, int yy) { super(xx, yy); }
public ADCElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {
public ADCElm(int xx, int yy) {
super(xx, yy);
}

public ADCElm(int xa, int ya, int xb, int yb, int f, StringTokenizer st) {
super(xa, ya, xb, yb, f, st);
}
String getChipName() { return "ADC"; }
boolean needsBits() { return true; }

String getChipName() {
return "ADC";
}

boolean needsBits() {
return true;
}

void setupPins() {
sizeX = 2;
sizeY = bits > 2 ? bits : 2;
pins = new Pin[getPostCount()];
int i;
for (i = 0; i != bits; i++) {
pins[i] = new Pin(bits-1-i, SIDE_E, "D" + i);
pins[i] = new Pin(bits - 1 - i, SIDE_E, "D" + i);
pins[i].output = true;
}
pins[bits] = new Pin(0, SIDE_W, "In");
pins[bits+1] = new Pin(sizeY-1, SIDE_W, "V+");
pins[bits] = new Pin(0, SIDE_W, "In");
pins[bits + 1] = new Pin(sizeY - 1, SIDE_W, "V+");
allocNodes();
}

void execute() {
int imax = (1<<bits)-1;
int imax = (1 << bits) - 1;
// if we round, the half-flash doesn't work
double val = imax*volts[bits]/volts[bits+1]; // + .5;
double val = imax * volts[bits] / volts[bits + 1]; // + .5;
int ival = (int) val;
ival = min(imax, max(0, ival));
int i;
for (i = 0; i != bits; i++)
pins[i].value = ((ival & (1<<i)) != 0);
pins[i].value = ((ival & (1 << i)) != 0);
}

int getVoltageSourceCount() {
return bits;
}

int getPostCount() {
return bits + 2;
}

int getDumpType() {
return 167;
}

// there's already a V+ pin, how does that relate to high logic voltage? figure
// out later
@Override
boolean isDigitalChip() {
return false;
}
int getVoltageSourceCount() { return bits; }
int getPostCount() { return bits+2; }
int getDumpType() { return 167; }

// there's already a V+ pin, how does that relate to high logic voltage? figure out later
@Override boolean isDigitalChip() { return false; }
public EditInfo getChipEditInfo(int n) {
if (n == 0)
return new EditInfo("# of Bits", bits, 1, 1).setDimensionless();
return null;
if (n == 0)
return new EditInfo("# of Bits", bits, 1, 1).setDimensionless();
return null;
}

public void setChipEditValue(int n, EditInfo ei) {
if (n == 0 && ei.value >= 2) {
bits = (int)ei.value;
setupPins();
setPoints();
}
if (n == 0 && ei.value >= 2) {
bits = (int) ei.value;
setupPins();
setPoints();
}
}
}
117 changes: 68 additions & 49 deletions src/com/lushprojects/circuitjs1/client/AMElm.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,121 +23,140 @@

class AMElm extends CircuitElm {
static final int FLAG_COS = 2;
double carrierfreq,signalfreq, maxVoltage, freqTimeZero;
double carrierfreq, signalfreq, maxVoltage, freqTimeZero;

public AMElm(int xx, int yy) {
super(xx, yy);
maxVoltage = 5;
carrierfreq = 1000;
signalfreq=40;
signalfreq = 40;
reset();
}
public AMElm(int xa, int ya, int xb, int yb, int f,
StringTokenizer st) {

public AMElm(int xa, int ya, int xb, int yb, int f, StringTokenizer st) {
super(xa, ya, xb, yb, f);
carrierfreq = new Double(st.nextToken()).doubleValue();
signalfreq= new Double(st.nextToken()).doubleValue();
maxVoltage = new Double(st.nextToken()).doubleValue();
carrierfreq = Double.valueOf(st.nextToken()).doubleValue();
signalfreq = Double.valueOf(st.nextToken()).doubleValue();
maxVoltage = Double.valueOf(st.nextToken()).doubleValue();
if ((flags & FLAG_COS) != 0) {
flags &= ~FLAG_COS;
}
reset();
}
int getDumpType() { return 200; }

int getDumpType() {
return 200;
}

String dump() {
return super.dump() + " " +carrierfreq+" " + signalfreq + " " +maxVoltage;
return super.dump() + " " + carrierfreq + " " + signalfreq + " " + maxVoltage;
}
/*void setCurrent(double c) {
current = c;
System.out.print("v current set to " + c + "\n");
}*/
/*
* void setCurrent(double c) { current = c; System.out.print("v current set to "
* + c + "\n"); }
*/

void reset() {
freqTimeZero = 0;
curcount = 0;
}
int getPostCount() { return 1; }

void stamp() {
sim.stampVoltageSource(0, nodes[0], voltSource);

int getPostCount() {
return 1;
}

void stamp() {
sim.stampVoltageSource(0, nodes[0], voltSource);
}

void doStep() {
sim.updateVoltageSource(0, nodes[0], voltSource, getVoltage());
sim.updateVoltageSource(0, nodes[0], voltSource, getVoltage());
}

double getVoltage() {
double w = 2*pi*(sim.t-freqTimeZero);
return ((Math.sin(w*signalfreq)+1)/2)*Math.sin(w*carrierfreq)*maxVoltage;
double w = 2 * pi * (sim.t - freqTimeZero);
return ((Math.sin(w * signalfreq) + 1) / 2) * Math.sin(w * carrierfreq) * maxVoltage;
}

final int circleSize = 17;

void draw(Graphics g) {
setBbox(point1, point2, circleSize);
setVoltageColor(g, volts[0]);
drawThickLine(g, point1, lead1);

Font f = new Font("SansSerif", 0, 12);
g.setFont(f);
g.setColor(needsHighlight() ? selectColor : whiteColor);
setPowerColor(g, false);
double v = getVoltage();
String s = "AM";
drawCenteredText(g, s, x2, y2, true);
drawWaveform(g, point2);
Font f = new Font("SansSerif", 0, 12);
g.setFont(f);
g.setColor(needsHighlight() ? selectColor : whiteColor);
setPowerColor(g, false);
double v = getVoltage();
String s = "AM";
drawCenteredText(g, s, x2, y2, true);
drawWaveform(g, point2);
drawPosts(g);
curcount = updateDotCount(-current, curcount);
if (sim.dragElm != this)
drawDots(g, point1, lead1, curcount);
}

void drawWaveform(Graphics g, Point center) {
g.setColor(needsHighlight() ? selectColor : Color.gray);
setPowerColor(g, false);
int xc = center.x; int yc = center.y;
int xc = center.x;
int yc = center.y;
drawThickCircle(g, xc, yc, circleSize);
int wl = 8;
adjustBbox(xc-circleSize, yc-circleSize,
xc+circleSize, yc+circleSize);
adjustBbox(xc - circleSize, yc - circleSize, xc + circleSize, yc + circleSize);
}


void setPoints() {
void setPoints() {
super.setPoints();
lead1 = interpPoint(point1, point2, 1-circleSize/dn);
lead1 = interpPoint(point1, point2, 1 - circleSize / dn);
}

double getVoltageDiff() { return volts[0]; }

boolean hasGroundConnection(int n1) { return true; }


double getVoltageDiff() {
return volts[0];
}

boolean hasGroundConnection(int n1) {
return true;
}

int getVoltageSourceCount() {
return 1;
}
double getPower() { return -getVoltageDiff()*current; }

double getPower() {
return -getVoltageDiff() * current;
}

void getInfo(String arr[]) {

arr[0] = "AM Source";
arr[1] = "I = " + getCurrentText(getCurrent());
arr[2] = "V = " +
getVoltageText(getVoltageDiff());
arr[3] = "cf = " + getUnitText(carrierfreq, "Hz");
arr[4] = "sf = " + getUnitText(signalfreq, "Hz");
arr[5] = "Vmax = " + getVoltageText(maxVoltage);
arr[2] = "V = " + getVoltageText(getVoltageDiff());
arr[3] = "cf = " + getUnitText(carrierfreq, "Hz");
arr[4] = "sf = " + getUnitText(signalfreq, "Hz");
arr[5] = "Vmax = " + getVoltageText(maxVoltage);
}

public EditInfo getEditInfo(int n) {
if (n == 0)
return new EditInfo("Max Voltage", maxVoltage, -20, 20);
if (n == 1)
return new EditInfo("Carrier Frequency (Hz)", carrierfreq, 4, 500);
if (n == 2)
return new EditInfo("Signal Frequency (Hz)", signalfreq, 4, 500);

return null;
}

public void setEditValue(int n, EditInfo ei) {
if (n == 0)
maxVoltage = ei.value;
if (n == 1)
carrierfreq = ei.value;
if (n == 2)
signalfreq=ei.value;
signalfreq = ei.value;
}
}
60 changes: 30 additions & 30 deletions src/com/lushprojects/circuitjs1/client/AboutBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,34 @@
import com.google.gwt.user.client.ui.Button;

public class AboutBox extends PopupPanel {
VerticalPanel vp;
Button okButton;
AboutBox(String version) {
super();
// Add versionString variable to SessionStorage for iFrame in AboutBox
Storage sstor = Storage.getSessionStorageIfSupported();
sstor.setItem("versionString", version);
vp = new VerticalPanel();
setWidget(vp);
vp.setWidth("400px");
vp.add(new HTML("<iframe src=\"about.html\" width=\"400\" height=\"430\" scrolling=\"auto\" frameborder=\"0\"></iframe><br>"));

vp.add(okButton = new Button("OK"));
okButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
close();
}
});
center();
show();
}

public void close() {
hide();
}

VerticalPanel vp;
Button okButton;

AboutBox(String version) {
super();

// Add versionString variable to SessionStorage for iFrame in AboutBox
Storage sstor = Storage.getSessionStorageIfSupported();
sstor.setItem("versionString", version);

vp = new VerticalPanel();
setWidget(vp);
vp.setWidth("400px");
vp.add(new HTML(
"<iframe src=\"about.html\" width=\"400\" height=\"430\" scrolling=\"auto\" frameborder=\"0\"></iframe><br>"));

vp.add(okButton = new Button("OK"));
okButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
close();
}
});
center();
show();
}

public void close() {
hide();
}
}
Loading