added radio transmit power

This commit is contained in:
Peli de Halleux 2016-03-15 13:05:11 -07:00
parent fb65711f08
commit 3c76e86cef
3 changed files with 23 additions and 1 deletions

View File

@ -82,4 +82,16 @@ namespace radio {
//% blockId=radio_set_group block="set group %ID" //% blockId=radio_set_group block="set group %ID"
export function setGroup(id: number) : void { export function setGroup(id: number) : void {
} }
/**
* Change the output power level of the transmitter to the given value.
* @param power a value in the range 0..7, where 0 is the lowest power and 7 is the highest, eg: 7
*/
//% help=/functions/set-transmit-power
//% shim=micro_bit::setTransmitPower
//% weight=9
//% blockId=radio_set_transmit_power block="set transmit power %power"
export function setTransmitPower(power:number) {
}
} }

View File

@ -445,6 +445,9 @@ namespace ks.rt.micro_bit {
board().radio.setGroup(id); board().radio.setGroup(id);
} }
export function setTransmitPower(power: number) : void {
board().radio.setTransmitPower(power);
}
export function datagramSendNumbers(value0 : number, value1: number, value2: number, value3: number) : void { export function datagramSendNumbers(value0 : number, value1: number, value2: number, value3: number) : void {
board().radio.datagram.send([value0, value1, value2, value3]); board().radio.datagram.send([value0, value1, value2, value3]);

View File

@ -98,6 +98,7 @@ namespace ks.rt.micro_bit {
export class RadioBus { export class RadioBus {
// uint8_t radioDefaultGroup = MICROBIT_RADIO_DEFAULT_GROUP; // uint8_t radioDefaultGroup = MICROBIT_RADIO_DEFAULT_GROUP;
groupId = 0; // todo groupId = 0; // todo
power = 0;
datagram: RadioDatagram; datagram: RadioDatagram;
constructor(private runtime: Runtime) { constructor(private runtime: Runtime) {
@ -108,12 +109,18 @@ namespace ks.rt.micro_bit {
this.groupId = id & 0xff; // byte only this.groupId = id & 0xff; // byte only
} }
setTransmitPower(power: number) {
this.power = Math.max(0, Math.min(7, power));
}
broadcast(msg: number) { broadcast(msg: number) {
let ens = enums(); let ens = enums();
Runtime.postMessage(<SimulatorEventBusMessage>{ Runtime.postMessage(<SimulatorEventBusMessage>{
type: 'eventbus', type: 'eventbus',
id: ens.MES_BROADCAST_GENERAL_ID, id: ens.MES_BROADCAST_GENERAL_ID,
eventid: msg eventid: msg,
power: this.power,
group: this.groupId
}) })
} }
} }