Skip to content

Commit 0ba8989

Browse files
author
Will Dixon
authored
Create code snippets for Kotlin and C++ (#12)
1 parent c25ae54 commit 0ba8989

5 files changed

Lines changed: 76 additions & 20 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dependencies": {
1111
"animate.css": "^3.7.0",
1212
"eagle.js": "^0.4.1",
13+
"highlight.js": "^9.12.0",
1314
"pug": "^2.0.3",
1415
"pug-plain-loader": "^1.0.0",
1516
"vue": "^2.5.17",

src/App.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
</template>
55

66
<style lang="scss">
7-
@import "../node_modules/eagle.js/dist/eagle.css";
8-
@import "../node_modules/eagle.js/dist/themes/agrume/agrume";
9-
@import "../node_modules/animate.css/animate.min.css";
107
body {
118
width: 100%;
129
margin: 0 0;

src/main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ import Vue from "vue";
22
import App from "./App.vue";
33
import router from "./router";
44
import Eagle from "eagle.js";
5-
//import 'animate.css'
5+
import { Options } from "eagle.js";
6+
import Highlight from "highlight.js/lib/highlight";
7+
import HlKotlin from "highlight.js/lib/languages/kotlin";
8+
import HlCpp from "highlight.js/lib/languages/cpp";
9+
Highlight.registerLanguage("kotlin", HlKotlin);
10+
Highlight.registerLanguage("cpp", HlCpp);
11+
Options.hljs = Highlight;
12+
13+
import "eagle.js/dist/eagle.css";
14+
import "eagle.js/dist/themes/agrume/agrume.css";
15+
import "animate.css/animate.min.css";
616

717
Vue.use(Eagle);
818

src/sections/limited/Limited.vue

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,74 @@
8080
| grammer should be able to read many languages
8181
p(v-if="step >= 3") May only be able to write few languages efficiently
8282
p(v-if="step >= 4") But once you know one, others come easier (just like if you learned Latin)
83-
slide(:steps=7, enter="fadeInDown", leave="fadeOutDown")
83+
slide(:steps=13, enter="fadeInDown", leave="fadeOutDown")
8484
h2 Kotlin
8585
.center
86-
p(v-if="step >= 2") Very easy to read and teach
87-
p(v-if="step >= 3") It is an Object Oriented Language (most commonly used languages are)
88-
p(v-if="step >= 4") Runs against JRE (which means our robot can run it)
89-
p(v-if="step >= 5") Can import Java (required as that is what WPI Library is written in)
90-
p(v-if="step >= 6") A lot of build time checks
91-
p(v-if="step >= 7") Becoming Android's standard language
92-
//- TODO(WD): Show example snippet of code
93-
slide(:steps=6, enter="fadeInUp", leave="fadeOutUp")
86+
eg-transition(leave="bounceOutLeft")
87+
.subslide(v-if="step >= 2 && step <= 7")
88+
p(v-if="step >= 2") Very easy to read and teach
89+
p(v-if="step >= 3") It is an Object Oriented Language (most commonly used languages are)
90+
p(v-if="step >= 4") Runs against JRE (which means our robot can run it)
91+
p(v-if="step >= 5") Can import Java (required as that is what WPI Library is written in)
92+
p(v-if="step >= 6") A lot of build time checks
93+
p(v-if="step >= 7") Becoming Android's standard language
94+
eg-transition(enter="bounceInRight", leave="bounceOutLeft")
95+
.subslide(v-if="step >= 8")
96+
eg-code-block(lang="kotlin").
97+
override fun autonomousInit() {
98+
val input = autoChooser.selected <eg-code-comment :active="step >= 9" enter="fadeInRight"> Get what side our robot is on.</eg-code-comment>
99+
val side = DriverStation.getInstance().gameSpecificMessage.toCharArray() <eg-code-comment :active="step >= 10" enter="fadeInRight"> Get what side is ours.</eg-code-comment>
100+
if(input == StartingPosition.LEFT && side[0] == 'L'){
101+
Offensive().start() <eg-code-comment :active="step >= 11" enter="fadeInRight"> If robot is on left and our side is lit.</eg-code-comment>
102+
} else if(input == StartingPosition.RIGHT && side[0]== 'R'){
103+
Offensive().start() <eg-code-comment :active="step >=12" enter="fadeInRight"> If robot is on right and our side is lit.</eg-code-comment>
104+
} else {
105+
Defensive().start() <eg-code-comment :active="step >= 13" enter="fadeInRight"> Anything else (middle position, left but our side is not lit).</eg-code-comment>
106+
}
107+
}
108+
109+
slide(:steps=14, enter="fadeInUp", leave="fadeOutUp")
94110
h2 C++ (Arduino)
95111
.center
96-
p(v-if="step >= 2") A lot of games and programs are written in C++
97-
p(v-if="step >= 3") Very low level language
98-
p(v-if="step >= 4") Harder to read but not difficult
99-
p(v-if="step >= 5") Creates some of the fastest binaries
100-
p(v-if="step >= 6") This is what the Arduino "reads" when it runs
101-
//- TODO(WD): Show example snippet of code
112+
eg-transition(leave="bounceOutLeft")
113+
.subslide(v-if="step >=2 && step <=6")
114+
p(v-if="step >= 2") A lot of games and programs are written in C++
115+
p(v-if="step >= 3") Very low level language
116+
p(v-if="step >= 4") Harder to read but not difficult
117+
p(v-if="step >= 5") Creates some of the fastest binaries
118+
p(v-if="step >= 6") This is what the Arduino "reads" when it runs
119+
eg-transition(enter="bounceInRight", leave="bounceOutLeft")
120+
.subslide(v-if="step >= 7")
121+
eg-code-block(lang="cpp").
122+
int HCSR04::distance(float speedOfSound)
123+
{
124+
unsigned long maxTime = (_maxTol * 2) / speedOfSound; <eg-code-comment :active="step >= 8" enter="fadeInRight"> Max time to listen for ping.</eg-code-comment>
125+
int iteration = 0;
126+
LOOP:
127+
iteration++;
128+
if (iteration > _retries)
129+
{
130+
return _badValue; <eg-code-comment :active="step >= 9" enter="fadeInRight"> If we tried too many times, return a bad value (-1).</eg-code-comment>
131+
}
132+
unsigned long duration = _echoInMicroseconds(maxTime); <eg-code-comment :active="step >= 10" enter="fadeInRight"> Ping and listen.</eg-code-comment>
133+
int distance = (duration * speedOfSound / 2); <eg-code-comment :active="step >= 11" enter="fadeInRight"> Caclulate distance.</eg-code-comment>
134+
if (distance < _minTol || distance > _maxTol)
135+
{
136+
if (_retry){
137+
delayMicroseconds(10);
138+
goto LOOP; <eg-code-comment :active="step >= 12" enter="fadeInRight"> Try again if not within tolerance.</eg-code-comment>
139+
}else{
140+
return _badValue; <eg-code-comment :active="step >= 13" enter="fadeInRight"> Return bad value if we don't want to retry.</eg-code-comment>
141+
}
142+
}
143+
return distance; <eg-code-comment :active="step >= 14" enter="fadeInRight"> Return distance if we think it is a good reading.</eg-code-comment>
144+
}
145+
102146
slide
103147
h3 null reference is not set to an instance of an object
104148
p.center: small Things I am still working on
105149
.quarter
106150
ul
107-
li Code Snippets
108151
li Sensors
109152
ul
110153
li Thermometers

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3975,6 +3975,11 @@ hex-color-regex@^1.1.0:
39753975
resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e"
39763976
integrity sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==
39773977

3978+
highlight.js@^9.12.0:
3979+
version "9.12.0"
3980+
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.12.0.tgz#e6d9dbe57cbefe60751f02af336195870c90c01e"
3981+
integrity sha1-5tnb5Xy+/mB1HwKvM2GVhwyQwB4=
3982+
39783983
hmac-drbg@^1.0.0:
39793984
version "1.0.1"
39803985
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"

0 commit comments

Comments
 (0)