Commit 6e352ac4 authored by Chris Prince's avatar Chris Prince

Just cleanup of the interface

parent e83ae163
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
margin-left: 5px; margin-left: 5px;
} }
.centered { .centered {
margin: auto; text-align: center;
margin: 1em auto;
width: 50%; width: 50%;
}
.btn {
margin: auto 1em;
} }
\ No newline at end of file
...@@ -6,21 +6,21 @@ ...@@ -6,21 +6,21 @@
<img width="500" alt="laser cat xkcd" src="https://imgs.xkcd.com/comics/laser_pointer.png"> <img width="500" alt="laser cat xkcd" src="https://imgs.xkcd.com/comics/laser_pointer.png">
</div> </div>
<div class="centered"> <div class="centered">
<div class="btn-group"> <div class="btn-block">
<button (click)="triggerLaser()" class="btn" [ngClass]="{ 'btn-outline-danger': laserState === 'on', 'btn-outline-info': laserState === 'off'}">Turn {{ laserState }} Laser</button> <button (click)="triggerLaser()" class="btn" [ngClass]="{ 'btn-outline-danger': laserState === 'on', 'btn-outline-info': laserState === 'off'}">Turn {{ laserState }} Laser</button>
<button class="btn btn-warning">Start Random Patterns</button> <button class="btn btn-warning" [disabled]="randomRuns">Start Random Patterns</button>
</div> </div>
<div class="btn-group"> <div class="btn-block">
<div class="inline"> <div class="inline">
<div class="pos"> <div class="pos">
<label for="xPos">X:</label> <label for="xPos"><strong>X</strong>: </label>
<input class="mini" maxlength="3" id="xPos" type="number" min="0" max="180" /> <input class="mini" maxlength="3" id="xPos" type="number" min="0" max="180" [formControl]="xCtrl" />
</div> </div>
<div class="pos"> <div class="pos">
<label for="yPos">Y:</label> <label for="yPos"><strong>Y</strong>: </label>
<input class="mini" maxlength="3" id="yPos" type="number" min="0" max="180" /> <input class="mini" maxlength="3" id="yPos" type="number" min="0" max="180" [formControl]="yCtrl" />
</div> </div>
<button class="btn btn-sm btn-link" (click)="moveLaser()">Move</button> <button class="btn btn-sm btn-outline-info" (click)="moveLaser()">Move</button>
</div> </div>
</div> </div>
</div> </div>
......
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Router } from '@angular/router'; import { FormControl, FormGroup } from '@angular/forms';
import { Esp12Service } from './services/esp12.service'; import { Esp12Service } from './services/esp12.service';
@Component({ @Component({
...@@ -10,23 +10,41 @@ import { Esp12Service } from './services/esp12.service'; ...@@ -10,23 +10,41 @@ import { Esp12Service } from './services/esp12.service';
export class AppComponent { export class AppComponent {
title = 'lasercat-ui'; title = 'lasercat-ui';
laserState = 'on'; laserState = 'on';
randomRuns: boolean;
xCtrl: FormControl;
yCtrl: FormControl;
protected form: FormGroup;
constructor(private esp: Esp12Service) {} constructor(private esp: Esp12Service) {}
ngOnInit() {
this.form = new FormGroup({
xPosition: new FormControl(''),
yPosition: new FormControl('')
});
this.xCtrl = this.form.get('xPosition') as FormControl;
this.yCtrl = this.form.get('yPosition') as FormControl;
}
public triggerLaser() { public triggerLaser() {
if (this.laserState === 'on') { if (this.laserState === 'on') {
this.esp.start().subscribe(); this.esp.start().subscribe();
} else { } else {
this.esp.stop().subscribe(); this.esp.stop().subscribe();
this.randomRuns = false;
} }
this.laserState = this.laserState === 'on' ? 'off' : 'on'; // value is inversed; this.laserState = this.laserState === 'on' ? 'off' : 'on'; // value is inversed;
} }
public moveLaser() { public moveLaser() {
this.esp.move(100, 100); const xy = this.form.value;
this.esp.move(xy.xPosition, xy.yPosition);
} }
public randomizeLaser() { public randomizeLaser() {
this.laserState = 'off';
this.randomRuns = true;
this.esp.random().subscribe(); this.esp.random().subscribe();
} }
} }
...@@ -16,7 +16,6 @@ import { HttpClientModule } from '@angular/common/http'; ...@@ -16,7 +16,6 @@ import { HttpClientModule } from '@angular/common/http';
FormsModule, FormsModule,
HttpClientModule, HttpClientModule,
ReactiveFormsModule, ReactiveFormsModule,
], ],
providers: [], providers: [],
bootstrap: [AppComponent] bootstrap: [AppComponent]
......
...@@ -10,8 +10,8 @@ export class Esp12Service { ...@@ -10,8 +10,8 @@ export class Esp12Service {
constructor(private httpCli: HttpClient) { } constructor(private httpCli: HttpClient) { }
move(x: number, y: number): Observable<any> { move(x: string, y: string): Observable<any> {
return this.httpCli.get(`/move?x=${x}&y=${y}`); return this.httpCli.get(`/move`, { params : { x, y }});
} }
random(): Observable<any> { random(): Observable<any> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment