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

feat: Added Sensor Pod to USV Comms. #24

Merged
merged 3 commits into from
Apr 4, 2024
Merged
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
57 changes: 57 additions & 0 deletions USV/Sensor-Pod-Comms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Starter Implementation
// Change on button A and B pressed to physical circuit
input.onButtonPressed(Button.A, function () {
isSubmerged = 0
})
input.onButtonPressed(Button.B, function () {
isSubmerged = 1
})
let isSubmerged = 0
radio.setGroup(213)
basic.showIcon(IconNames.Yes)
USVSensorPod.initLocalDisplay()
let ph_list: number[] = []
let light_list: number[] = []
let temp_list: number[] = []
isSubmerged = 1
basic.forever(function () {
USVSensorPod.ShowString("Temp:" + USVSensorPod.calculateTempC() + "°C", 0, 0)
USVSensorPod.ShowString("pH:" + USVSensorPod.calculatePh(), 0, 1)
})
basic.forever(function () {
if (isSubmerged == 1) {
ph_list.push(USVSensorPod.calculatePh())
temp_list.push(USVSensorPod.calculateTempC())
light_list.push(USVSensorPod.getLight())
basic.pause(100)
led.toggle(4, 0)
}
})
basic.forever(function () {
if (isSubmerged == 0) {
for (let value of ph_list) {
radio.sendValue("pH", value)
basic.pause(1000)
ph_list.removeAt(ph_list.indexOf(value))
}
}
})
basic.forever(function () {
if (isSubmerged == 0) {
for (let value of light_list) {
radio.sendValue("light", value)
basic.pause(1000)
led.toggle(0, 0)
light_list.removeAt(light_list.indexOf(value))
}
}
})
basic.forever(function () {
if (isSubmerged == 0) {
for (let value of temp_list) {
radio.sendValue("tempC", value)
basic.pause(100)
temp_list.removeAt(temp_list.indexOf(value))
}
}
})
58 changes: 26 additions & 32 deletions USV/USV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace USV {
let Arm = 1
}

//% blockId=1disarmUSV
//% blockId=disarmUSV
//% block="Disarm USV"
//% weight=50
//% color=#2bd9ad
Expand Down Expand Up @@ -197,44 +197,38 @@ namespace USV {
}
}

//% blockId=getTempC
//% block="Sensor Pod Temperature °C"
//% subcategory=Sensor Pod
//% color=#442FDE
//% group="Sensors"
export function getTempC(): number {
// Ask sensor pod for temperature through radio
return 0
}

//% blockId=getTempF
//% block="Sensor Pod Temperature °F"
//% subcategory=Sensor Pod
//% color=#442FDE
//% group="Sensors"
export function getTempF(): number {
// Ask sensor pod for temperature
return 0
export enum SensorType {
pH = 0,
tempC = 1,
light = 2,
}

//% blockId=getPh
//% block="Sensor Pod pH"
//% subcategory=Sensor Pod
//% color=#442FDE
//% group="Sensors"
export function getPh(): number {
// Ask sensor pod for pH
return 0
function sensorListener(sensorType: SensorType) {
let sensorName: string;

if(sensorType == 0) {
sensorName = "pH";
} else if (sensorType == 1){
sensorName = "tempC";
} else if (sensorType == 2) {
sensorName = "light";
}

radio.onReceivedValue(function (name, value) {
if (name == sensorName) {
serial.writeValue(name, value);
}
});
}

//% blockId=Sensor Pod Light
//% block="Sensor Pod Light"
//% subcategory=Sensor Pod
//% blockId="sensorListenerBlock"
//% block="Listen for Sensor Pod |%SensorType value"
//% subcategory="Sensors"
//% color=#442FDE
//% group="Sensors"
export function getLight(): number {
// Ask sensor pod for LDR reading
return 0
export function sensorListenerBlock(sensorType: SensorType): void {
sensorListener(sensorType);
}


Expand Down