Add TX power adjustment

This commit is contained in:
Nonoo 2020-10-30 23:06:34 +01:00
parent d1511bc15d
commit 27a86293bf
3 changed files with 40 additions and 4 deletions

View file

@ -158,6 +158,8 @@ not available.
You can transmit your own voice using a mic attached to your computer for
example.
- `t`: toggles the tune process
- `+`: increase TX power
- `-`: decrease TX power
## Authors

View file

@ -11,8 +11,9 @@ type civControlStruct struct {
st *serialStream
state struct {
ptt bool
tune bool
ptt bool
tune bool
pwrPercent int
}
}
@ -129,9 +130,9 @@ func (s *civControlStruct) decodePower(d []byte) {
}
hex := uint16(d[1])<<8 | uint16(d[2])
percent := int(math.Round((float64(hex) / 0x0255) * 100))
s.state.pwrPercent = int(math.Round((float64(hex) / 0x0255) * 100))
statusLog.reportTxPower(percent)
statusLog.reportTxPower(s.state.pwrPercent)
}
func (s *civControlStruct) decodeTransmitStatus(d []byte) {
@ -161,6 +162,27 @@ func (s *civControlStruct) decodeTransmitStatus(d []byte) {
statusLog.reportPTT(s.state.ptt, s.state.tune)
}
func (s *civControlStruct) setPwr(percent int) error {
v := uint16(0x0255 * (float64(percent) / 100))
return s.st.send([]byte{254, 254, civAddress, 224, 0x14, 0x0a, byte(v >> 8), byte(v & 0xff), 253})
}
func (s *civControlStruct) incPwr() error {
if s.state.pwrPercent < 100 {
s.state.pwrPercent++
return s.setPwr(s.state.pwrPercent)
}
return nil
}
func (s *civControlStruct) decPwr() error {
if s.state.pwrPercent > 0 {
s.state.pwrPercent--
return s.setPwr(s.state.pwrPercent)
}
return nil
}
func (s *civControlStruct) setPTT(enable bool) error {
var b byte
if enable {

View file

@ -24,6 +24,18 @@ func (s *keyboardStruct) handleKey(k byte) {
log.Error("can't toggle tune: ", err)
}
}
case '+':
if civControl != nil {
if err := civControl.incPwr(); err != nil {
log.Error("can't increase power: ", err)
}
}
case '-':
if civControl != nil {
if err := civControl.decPwr(); err != nil {
log.Error("can't decrease power: ", err)
}
}
}
}