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

Have students scan nest marker to join a sesssion #198

Closed
wants to merge 6 commits into from
Closed
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
11 changes: 11 additions & 0 deletions src/app/components/scan-nest/scan-nest.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<app-ar-view [markers]="this.nestMarkers" (markerStates)="this.onMarkerState($event)"></app-ar-view>
<div class="nest-instruction">
Hover over your nest marker to scan it
<br>
Found Marker: {{(this.foundMarkerValue$ | async)}}
</div>


<ng-container *ngIf="(this.foundMarkerValue$ | async)">
<button mat-raised-button color="primary" class="scan-button">Scan Nest</button>
</ng-container>
41 changes: 41 additions & 0 deletions src/app/components/scan-nest/scan-nest.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@import "../../../variables";

@mixin responsive-font-size(
$for-phone-portrait,
$for-tablet-portrait,
$for-tablet-landscape,
) {
font-size: $for-phone-portrait;
line-height: $for-phone-portrait;
@media (min-width: $tablet-portrait-min-width) {
font-size: $for-tablet-portrait;
line-height: $for-tablet-portrait;
}
@media (min-width: $tablet-landscape-min-width) {
font-size: $for-tablet-landscape;
line-height: $for-tablet-landscape;
}
}

.nest-instruction {
margin-top: 16px;
margin-bottom: 0;
margin-right: 8px;
margin-left: 8px;
text-align: center;

font-weight: bold;
color: white;
text-shadow: 0 0 0.6em #111;

@include responsive-font-size(2rem, 2.5rem, 3rem);
}


.scan-button {
position: absolute;
left: 40%;
bottom: 5%;
width: 150px;
height: 112px;
}
25 changes: 25 additions & 0 deletions src/app/components/scan-nest/scan-nest.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ScanNestComponent } from './scan-nest.component';

xdescribe('ScanNestComponent', () => {
let component: ScanNestComponent;
let fixture: ComponentFixture<ScanNestComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ScanNestComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ScanNestComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
58 changes: 58 additions & 0 deletions src/app/components/scan-nest/scan-nest.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Component, OnInit } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { distinctUntilChanged, map, shareReplay } from 'rxjs/operators';
import { MarkerState } from '../ar-view/ar-view.component';
import { ARMarker, MIN_NEST_MARKER, MAX_NEST_MARKER} from 'src/app/markers';

@Component({
selector: 'app-scan-nest',
templateUrl: './scan-nest.component.html',
styleUrls: ['./scan-nest.component.scss']
})
export class ScanNestComponent implements OnInit {

constructor() { }

currentMarkerStates$ = new BehaviorSubject<MarkerState[]>([]);
nestMarkers: ARMarker[] = [];

foundMarkerValue$: Observable<number | null> = this.currentMarkerStates$.pipe(
map(markers => markers.filter(m => m.found)),
map(markers =>
markers.length > 0
? markers.reduce((prev, curr) =>
prev.distance < curr.distance ? prev : curr
).barcodeValue
: null
),
distinctUntilChanged(),
shareReplay(1)
);

// How can the students distinguish between them scanning the wrong(non-nest) barcode
// and just not holding the camera well enough to detect a nest barcode. We could have
// all markers detectable and then use the following variable to tell students they
// are scanning a non-nest(or flower) barcode.

// foundNestMarker$: Observable<boolean | null> = this.foundMarkerValue$.pipe(
// map(val => val ? val >= MIN_NEST_MARKER && val <= MAX_NEST_MARKER : null),
// distinctUntilChanged(),
// shareReplay(1)
// );

onMarkerState(states: MarkerState[]) {
this.currentMarkerStates$.next(states);
}

ngOnInit() {
// This range specifies which barcode values should be detected.
for (let val = MIN_NEST_MARKER; val <= MAX_NEST_MARKER; val++) {
this.nestMarkers.push({
barcodeValue: val,
// A filler image that makes it easier to tell when a marker is being detected
imgPath: '/assets/art/512-square/nests/cavity.png'
});
}
}

}
7 changes: 6 additions & 1 deletion src/app/pages/student-display/student-display.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ import { SharedModule } from 'src/app/shared.module';
import { ArViewComponent } from 'src/app/components/ar-view/ar-view.component';
import { PlayRoundComponent } from 'src/app/components/play-round/play-round.component';
import { StudentRoundComponent } from 'src/app/components/student-round/student-round.component';
import { ScanNestComponent } from 'src/app/components/scan-nest/scan-nest.component';


const studentComponents = [
StudentRoundComponent,
PlayRoundComponent,
ArViewComponent,
StudentRemovedDialogComponent
StudentRemovedDialogComponent,
// I am not sure how we could have students use AR to scan nest barcodes without loading AR into the main module.
// For now, I just put the ScanNestComponent here, so I can use the ARView Component without disturbing the existing structure
// too much.
ScanNestComponent
];

@NgModule({
Expand Down