diff --git a/USV/Sensor-Pod-Comms.ts b/USV/Sensor-Pod-Comms.ts new file mode 100644 index 0000000..84974c1 --- /dev/null +++ b/USV/Sensor-Pod-Comms.ts @@ -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)) + } + } +}) diff --git a/USV/USV.ts b/USV/USV.ts index 21cf7c1..29e77ee 100644 --- a/USV/USV.ts +++ b/USV/USV.ts @@ -11,7 +11,7 @@ namespace USV { let Arm = 1 } - //% blockId=1disarmUSV + //% blockId=disarmUSV //% block="Disarm USV" //% weight=50 //% color=#2bd9ad @@ -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); }