Skip to content

Commit

Permalink
Merge pull request #4 from microbit-apps/hardware-tested
Browse files Browse the repository at this point in the history
Re-enabled noArcadeShieldMode, reworked sensors to reduce memory, optimisations + documentation.
  • Loading branch information
KierPalin authored Nov 22, 2024
2 parents a5d90b7 + 00491cf commit 9516205
Show file tree
Hide file tree
Showing 16 changed files with 275 additions and 275 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ crowdinstats.csv
.vscode/.BROWSE.VC.DB-wal
package-lock.json
.DS_Store
build.sh
5 changes: 2 additions & 3 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ namespace microdata {
this.pushScene(new microdata.Home(this))

// Temp disabled elements relating to callbackObj (no mem)
// else
// new DistributedLoggingProtocol(this, false);
// new NoArcadeShieldMode(this);
else
new NoArcadeShieldMode(this);
}

public pushScene(scene: Scene) {
Expand Down
4 changes: 2 additions & 2 deletions clearDataloggerScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ namespace microdata {
const tutorialTextLength = ("Clear the data log?".length * font.charWidth)
screen().print(
"Clear the data log?",
headerX - (tutorialTextLength / 2),
headerX - (tutorialTextLength>> 1),
Screen.HALF_HEIGHT - 40 + 7,
15 // Black
)

// Underline the title:
screen().fillRect(
headerX - (tutorialTextLength / 2) + 2,
headerX - (tutorialTextLength>> 1) + 2,
Screen.HALF_HEIGHT - 40 + 25,
tutorialTextLength - (1 * font.charWidth),
2,
Expand Down
8 changes: 4 additions & 4 deletions dataRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ namespace microdata {

// Check if all sensors have finished their work:
if (this.scheduler.loggingComplete()) {
screen().printCenter("Data Logging Complete.", (screen().height / 2) - 10);
screen().printCenter("Press B to back out.", screen().height / 2);
screen().printCenter("Data Logging Complete.", (screen().height>> 1) - 10);
screen().printCenter("Press B to back out.", screen().height>> 1);
}

else {
Expand Down Expand Up @@ -263,14 +263,14 @@ namespace microdata {
const tutorialTextLength = ("Cancel recording?".length * font.charWidth)
screen().print(
"Cancel recording?",
headerX - (tutorialTextLength / 2),
headerX - (tutorialTextLength>> 1),
Screen.HALF_HEIGHT - 30 + 7,
15 // Black
)

// Underline the title:
screen().fillRect(
headerX - (tutorialTextLength / 2) - 1,
headerX - (tutorialTextLength>> 1) - 1,
Screen.HALF_HEIGHT - 30 + 16,
tutorialTextLength,
2,
Expand Down
6 changes: 3 additions & 3 deletions distributedLogging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ namespace microdata {
}
else {
const scheduler = new SensorScheduler(this.sensors, true)
scheduler.start(((this.streamDataBack) ? this : null))
scheduler.start() //((this.streamDataBack) ? this : null))
}
}
}
Expand Down Expand Up @@ -711,14 +711,14 @@ namespace microdata {

screen().print(
connectedText,
Screen.HALF_WIDTH - ((connectedText.length * font.charWidth) / 2),
Screen.HALF_WIDTH - ((connectedText.length * font.charWidth)>> 1),
2
)

// Left-aligned with above text
screen().print(
asMicrobit,
Screen.HALF_WIDTH - ((connectedText.length * font.charWidth) / 2),
Screen.HALF_WIDTH - ((connectedText.length * font.charWidth)>> 1),
12
)
break;
Expand Down
8 changes: 4 additions & 4 deletions generateGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,18 @@ namespace microdata {
this.lowestPeriod = currentPeriod

// Add reading & period; check if full:
if (this.rawCoordinates[cols[SENSOR_COLUMNS.NAME]].length / 2 < targetNumberOfReadings) {
if (this.rawCoordinates[cols[SENSOR_COLUMNS.NAME]].length>> 1 < targetNumberOfReadings) {
this.rawCoordinates[cols[SENSOR_COLUMNS.NAME]].push(currentPeriod) // X
this.rawCoordinates[cols[SENSOR_COLUMNS.NAME]].push(currentReading) // Y

// rawCoordinates for this sensor is full: Thus start reading next chunk (where next RIGHT press starts) here:
if ((this.rawCoordinates[cols[SENSOR_COLUMNS.NAME]].length / 2) >= targetNumberOfReadings && this.startReadingAt[this.xScrollOffset + 1] == 0)
if ((this.rawCoordinates[cols[SENSOR_COLUMNS.NAME]].length>> 1) >= targetNumberOfReadings && this.startReadingAt[this.xScrollOffset + 1] == 0)
this.startReadingAt[this.xScrollOffset + 1] = dataStart + i

// Check if all are done:
foundAllReadings = true
for (let j = 0; j < this.sensors.length; j++) {
if ((this.rawCoordinates[this.sensors[j].getName()].length / 2) < targetNumberOfReadings) {
if ((this.rawCoordinates[this.sensors[j].getName()].length>> 1) < targetNumberOfReadings) {
foundAllReadings = false
break
}
Expand Down Expand Up @@ -503,7 +503,7 @@ namespace microdata {
const diff = Math.abs(this.processedCoordinates[sensor][i+1] - this.processedCoordinates[sensor][i+3])

// Duplicate the line along the y axis to smooth out aliasing:
for (let j = -(PLOT_SMOOTHING_CONSTANT / 2); j < PLOT_SMOOTHING_CONSTANT / 2; j++) {
for (let j = -(PLOT_SMOOTHING_CONSTANT>> 1); j < PLOT_SMOOTHING_CONSTANT>> 1; j++) {
screen().drawLine(
this.processedCoordinates[sensor][i] + 1,
this.processedCoordinates[sensor][i+1] + j,
Expand Down
6 changes: 3 additions & 3 deletions home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace microdata {
x: 20,
y,
onClick: () => {
this.app.popScene()
// this.app.popScene()
// this.app.pushScene(new DistributedLoggingScreen(this.app)) // Temp disabled elements relating to callbackObj (no mem)
},
})
Expand All @@ -84,8 +84,8 @@ namespace microdata {
private drawVersion() {
const font = bitmaps.font5
Screen.print(
"v1.5.2",
Screen.RIGHT_EDGE - font.charWidth * "v1.5.2".length,
"v1.5.3",
Screen.RIGHT_EDGE - font.charWidth * "v1.5.3".length,
Screen.BOTTOM_EDGE - font.charHeight - 2,
0xb,
font
Expand Down
86 changes: 55 additions & 31 deletions jacdacSensors.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,91 @@
namespace microdata {
/**
/**
* See modules.lightLevel1.lightLevel sensor from pxt-jacdac/jacdac-light-level.
* Overrides .isJacdac()
*/
export class JacdacLightSensor extends Sensor {
constructor() {super(); modules.lightLevel1.start()}

public static getName(): string {return "Jac Light"}
public static getRadioName(): string {return "JL"}
public static getReading(): number {return modules.lightLevel1.isConnected() ? modules.lightLevel1.lightLevel() : undefined}
public static isJacdac(): boolean {return true;}
constructor() {
super({
name: "Jac Light",
rName: "JL",
f: () => modules.lightLevel1.isConnected() ? modules.lightLevel1.lightLevel() : undefined,
min: 0,
max: 100,
isJacdacSensor: true
});
modules.lightLevel1.start();
}
}

/**
* See modules.distance1.distance sensor from pxt-jacdac/jacdac-distance.
* Overrides .isJacdac()
*/
export class JacdacDistanceSensor extends Sensor {
constructor() {super(); modules.distance1.start()}

public static getName(): string {return "Jac Dist"}
public static getRadioName(): string {return "JD"}
public static getReading(): number {return modules.distance1.isConnected() ? modules.distance1.distance() : undefined}
public static isJacdac(): boolean {return true;}
constructor() {
super({
name: "Jac Dist",
rName: "JD",
f: () => modules.distance1.isConnected() ? modules.distance1.distance() : undefined,
min: 0,
max: 100,
isJacdacSensor: true
});
modules.distance1.start();
}
}

/**
* See modules.soilMoisture1.moisture sensor from pxt-jacdac/jacdac-soil-moisture.
* Overrides .isJacdac()
*/
export class JacdacSoilMoistureSensor extends Sensor {
constructor() {super(); modules.soilMoisture1.start()
constructor() {
super({
name: "Jac Moist",
rName: "JM",
f: () => modules.soilMoisture1.isConnected() ? modules.soilMoisture1.moisture() : undefined,
min: 0,
max: 100,
isJacdacSensor: true
});
modules.soilMoisture1.start();
}

public static getName(): string {return "Jac Moist"}
public static getRadioName(): string {return "JM"}
public static getReading(): number {return modules.soilMoisture1.isConnected() ? modules.soilMoisture1.moisture() : undefined}
public static isJacdac(): boolean {return true;}
}

/**
* See modules.flex1.bending sensor from pxt-jacdac/flex.
* Overrides .isJacdac()
*/
export class JacdacFlexSensor extends Sensor {
constructor() {super(); modules.flex1.start()}

public static getName(): string {return "Jac Flex"}
public static getRadioName(): string {return "JF"}
public static getReading(): number {return modules.flex1.isConnected() ? modules.flex1.bending() : undefined}
public static isJacdac(): boolean {return true;}
constructor() {
super({
name: "Jac Flex",
rName: "JF",
f: () => modules.flex1.isConnected() ? modules.flex1.bending() : undefined,
min: 0,
max: 100, // Assuming bending level ranges from 0 to 100 (adjust as needed)
isJacdacSensor: true
});
modules.flex1.start();
}
}

/**
* See modules.temperature1.temperature sensor from pxt-jacdac/temperature.
* Overrides .isJacdac()
*/
export class JacdacTemperatureSensor extends Sensor {
constructor() {super(); modules.temperature1.start()}

public static getName(): string {return "Jac Temp"}
public static getRadioName(): string {return "JT"}
public static getReading(): number {return modules.temperature1.isConnected() ? modules.temperature1.temperature() : undefined}
public static isJacdac(): boolean {return true;}
constructor() {
super({
name: "Jac Temp",
rName: "JT",
f: () => modules.temperature1.isConnected() ? modules.temperature1.temperature() : undefined,
min: 0,
max: 100,
isJacdacSensor: true
});
modules.temperature1.start();
}
}
}
12 changes: 7 additions & 5 deletions liveDataViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace microdata {
/** The colours that will be used for the lines & sensor information boxes */
const SENSOR_COLORS: number[] = [2,3,4,6,7,9]

/** Time to wait inbetween updating each frame of the graph - new sensor reading requests are made.
/**
* Time to wait inbetween updating each frame of the graph - new sensor reading requests are made.
* The rest of the UI is still responsive though - since UP, DOWN, LEFT, RIGHT movements will invoke .update() immediately.
*/
const GRAPH_FRAME_TIME_MS: number = 100
Expand Down Expand Up @@ -97,6 +98,7 @@ namespace microdata {
/** Greatest of sensor.maximum for all sensors: required to write at the top of the y-axis */
private globalSensorMaximum: number;


constructor(app: AppInterface, sensors: Sensor[]) {
super(app, "liveDataViewer")
this.backgroundColor = 3
Expand Down Expand Up @@ -130,7 +132,6 @@ namespace microdata {
this.setGlobalMinAndMax()
}


/* override */ startup() {
super.startup()

Expand All @@ -152,9 +153,9 @@ namespace microdata {
this.sensors.forEach((sensor) => sensor.setBufferSize(140));

const sensor = this.sensors[this.oscSensorIndex];
this.oscXCoordinate = Math.round(sensor.getHeightNormalisedBufferLength() / 2);
this.oscXCoordinate = Math.round(sensor.getHeightNormalisedBufferLength()>> 1);
this.oscReading = sensor.getNthHeightNormalisedReading(this.oscXCoordinate);
;

this.windowLeftBuffer = 0;
this.windowRightBuffer = 0;
this.windowTopBuffer = 0;
Expand Down Expand Up @@ -574,7 +575,8 @@ namespace microdata {
15
)

// End:

// End:
const end: string = (this.sensors[0].numberOfReadings + this.sensors[0].getHeightNormalisedBufferLength()).toString()
screen().print(
end,
Expand Down
8 changes: 4 additions & 4 deletions loggingConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ namespace microdata {
)

screen().drawRect(
Screen.HALF_WIDTH - ((measurementsText.length * font.charWidth) / 2) - 4,
Screen.HALF_WIDTH - ((measurementsText.length * font.charWidth)>> 1) - 4,
yWindowStart + (Screen.HEIGHT * 0.1640), // 21
(measurementsText.length * font.charWidth) + 8,
(Screen.HEIGHT * 0.1093), // 13
Expand Down Expand Up @@ -688,7 +688,7 @@ namespace microdata {
switch (this.eventOrPeriodIndex) {
case 0:
screen().drawRect(
Screen.HALF_WIDTH - ((expression.length * font.charWidth) / 2) + ((sensor.getName().length + 1) * font.charWidth) - 4,
Screen.HALF_WIDTH - ((expression.length * font.charWidth)>> 1) + ((sensor.getName().length + 1) * font.charWidth) - 4,
Screen.HALF_HEIGHT + (Screen.HEIGHT * 0.09375), // 12
(inequalitySymbol.length * font.charWidth) + 8,
Screen.HEIGHT * 0.109, // 14
Expand All @@ -698,7 +698,7 @@ namespace microdata {

case 1:
screen().drawRect(
Screen.HALF_WIDTH - ((expression.length * font.charWidth) / 2) + ((sensor.getName() + " " + inequalitySymbol + " ").length * font.charWidth) - 4,
Screen.HALF_WIDTH - ((expression.length * font.charWidth)>> 1) + ((sensor.getName() + " " + inequalitySymbol + " ").length * font.charWidth) - 4,
Screen.HALF_HEIGHT + (Screen.HEIGHT * 0.09375), // 12
(inequalityOperand.length * font.charWidth) + 8,
Screen.HEIGHT * 0.109, // 13
Expand Down Expand Up @@ -728,7 +728,7 @@ namespace microdata {
for (let col = 0; col < this.guiConfigValues[this.sensorIndex].length; col++) {
if (col == this.eventOrPeriodIndex) {
screen().drawRect(
Screen.HALF_WIDTH - ((periodConfigString.length * font.charWidth) / 2) + (distance * font.charWidth) - 4,
Screen.HALF_WIDTH - ((periodConfigString.length * font.charWidth)>> 1) + (distance * font.charWidth) - 4,
Screen.HALF_HEIGHT + (Screen.HEIGHT * 0.0625), // 8
(this.guiConfigValues[this.sensorIndex][this.eventOrPeriodIndex].toString().length * font.charWidth) + 8,
(Screen.HEIGHT * 0.1171), // 15
Expand Down
Loading

0 comments on commit 9516205

Please sign in to comment.