Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Aug 22, 2021
1 parent cafdff3 commit 90c2a1a
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 112 deletions.
40 changes: 2 additions & 38 deletions commandkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ func (b *Talkkonnect) cmdClearScreen() {
if OLEDEnabled {
Oled.DisplayOn()
LCDIsDark = false
oledDisplay(true, 0, 0, "") // clear the screen
oledDisplay(true, 0, 0, "")
}
}
}
Expand Down Expand Up @@ -742,12 +742,6 @@ func (b *Talkkonnect) cmdPanicSimulation() {
b.SendMessage(fmt.Sprintf("My Username is %s and Ident is %s", b.Username, b.Ident), PRecursive)
}

// New. Need to allow sending email / text alert on Panic Event even is the GPS is not enabled or working.
// If no GPS is included in email / Mumble text message, it means GPS in not enabled or not working.

//if PSendGpsLocation && GpsEnabled {
//if GpsEnabled {

if PSendGpsLocation {

var i int = 0
Expand Down Expand Up @@ -811,47 +805,17 @@ func (b *Talkkonnect) cmdPanicSimulation() {
IsPlayStream = false
b.IsTransmitting = false

// New. Decide should TX Led be On or Off during a panic event? I think don't turn off here,
// Want to see PTT key working when testing panic function.
// We shall use another low profile lights/LCD function to turn all the lights and display off during panic event
// They should be dim. Not attracting attention
//if TargetBoard == "rpi" {
//if !LedStripEnabled {
//b.LEDOff(b.TransmitLED)
//} else {
//
//MyLedStripTransmitLEDOff()
//}
//log.Println("--")

//New. Low Profile Leds and LCD during Panic Event. Turn All Lights Off.
//Heartbeat will be running - disable in xml config?
//Backlight LCD led is dim with a transistor control, but it should work...
//Add another feature to enable all lights back on a PTT press after the panic event is over. To do?

if PLowProfile {
b.LEDOffAll()
log.Println("info: Low Profile Lights Option is Enabled. Turning All Leds Off During Panic Event")

//b.LEDOff(b.TransmitLED)
//b.LEDOff(b.BackLightLED)
//b.LEDOff(b.OnlineLED)
//b.LEDOff(b.ParticipantsLED)
//b.LEDOff(b.VoiceActivityLED)
//
//b.LEDOff(b.HeartBeatLED)
//

if LCDEnabled {
log.Println("info: Low Profile Lights is Enabled. Turning Off Display During Panic Event")
LcdText = [4]string{"", "", "", ""}
LcdDisplay(LcdText, LCDRSPin, LCDEPin, LCDD4Pin, LCDD5Pin, LCDD6Pin, LCDD7Pin, LCDInterfaceType, LCDI2CAddress)
}
if OLEDEnabled {
oledDisplay(true, 0, 0, "") // clear OLED screen. How about HD44780 and heartbit?
oledDisplay(true, 0, 0, "")
}
// End of Low Profile Lights

}
}
}
Expand Down
31 changes: 12 additions & 19 deletions htgotts.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,26 +111,19 @@ func localmediaplayer(fileName string) {
localplayer.Run()
}

func (b *Talkkonnect) TTSPlayer(ttsMessage string, ttsMessageReadEnabled bool, ttsLocalPlay bool, ttsLocalPlayRXLed bool, ttlPlayIntoStream bool) {

// check if tts message read is enabled
if ttsMessageReadEnabled {
//check if the user wants local play
if ttsLocalPlay {
//check if the user wants local play with rxled on
if ttsLocalPlayRXLed {
LEDOnFunc(VoiceActivityLED)
}
b.Speak(ttsMessage, "local")
//check if the user wants local play with rxled on
if ttsLocalPlayRXLed {
LEDOffFunc(VoiceActivityLED)
}
}
func (b *Talkkonnect) TTSPlayer(ttsMessage string, ttsLocalPlay bool, ttsLocalPlayRXLed bool, ttlPlayIntoStream bool) {

//check if the user wants this message played into mumble stream
if ttlPlayIntoStream {
b.Speak(ttsMessage, "intostream")
if ttsLocalPlay {
if ttsLocalPlayRXLed {
LEDOnFunc(VoiceActivityLED)
}
b.Speak(ttsMessage, "local")
if ttsLocalPlayRXLed {
LEDOffFunc(VoiceActivityLED)
}
}

if ttlPlayIntoStream {
b.Speak(ttsMessage, "intostream")
}
}
6 changes: 3 additions & 3 deletions mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ func (b *Talkkonnect) onMessageReceived(client MQTT.Client, message MQTT.Message
b.LEDOff(b.AttentionLED)
case "attentionled:blink":
log.Println("info: MQTT Blink Attention LED 20 times Successfully")
for i := 0; i < 20; i++ {
for i := 0; i < MQTTAttentionBlinkTimes; i++ {
b.LEDOn(b.AttentionLED)
time.Sleep(300 * time.Millisecond)
time.Sleep(time.Duration(MQTTAttentionBlinkmsecs) * time.Millisecond)
b.LEDOff(b.AttentionLED)
time.Sleep(300 * time.Millisecond)
time.Sleep(time.Duration(MQTTAttentionBlinkmsecs) * time.Millisecond)
}
case "relay1:on":
log.Println("info: MQTT Turn On Relay 1 Successfully")
Expand Down
7 changes: 4 additions & 3 deletions onevent.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,10 @@ func (b *Talkkonnect) OnTextMessage(e *gumble.TextMessageEvent) {

log.Println(fmt.Sprintf("info: Message ("+strconv.Itoa(len(message))+") from %v %v\n", sender, message))

voiceMessage := fmt.Sprintf("Message from %v %v\n", sender, cleanstring(e.Message))

b.TTSPlayer(voiceMessage, TTSMessageEnabled, TTSLocalPlay, TTSLocalPlayWithRXLED, TTSPlayIntoStream)
if TTSMessageEnabled {
voiceMessage := fmt.Sprintf("Message from %v %v\n", sender, cleanstring(e.Message))
b.TTSPlayer(voiceMessage, TTSLocalPlay, TTSLocalPlayWithRXLED, TTSPlayIntoStream)
}

if TargetBoard == "rpi" {
if LCDEnabled {
Expand Down
6 changes: 6 additions & 0 deletions scripts/update-talkkonnect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ then
echo "copying talkkonnect.xml for safe keeping to /root/talkkonnect.xml"
cp /home/talkkonnect/gocode/src/github.com/talkkonnect/talkkonnect/talkkonnect.xml /root/
fi
if [[ -f "/home/talkkonnect/gocode/src/github.com/talkkonnect/talkkonnect/mumble.pem" ]]
then
echo "copying talkkonnect.xml for safe keeping to /root/mumble.pem"
cp /home/talkkonnect/gocode/src/github.com/talkkonnect/talkkonnect/mumble.pem /root/
fi

rm -rf /home/talkkonnect/gocode/src/github.old
rm -rf /home/talkkonnect/gocode/src/google.golang.org
Expand Down Expand Up @@ -85,6 +90,7 @@ then
echo "copying original talkkonnect.xml back to /home/talkkonnect/gocode/src/github.com/talkkonnect/talkkonnect/talkkonnect.xml"
rm /home/talkkonnect/gocode/src/github.com/talkkonnect/talkkonnect/talkkonnect.xml
cp /home/talkkonnect/gocode/src/github.old/talkkonnect/talkkonnect/talkkonnect.xml /home/talkkonnect/gocode/src/github.com/talkkonnect/talkkonnect/talkkonnect.xml
cp /home/talkkonnect/gocode/src/github.old/talkkonnect/talkkonnect/mumble.pem /home/talkkonnect/gocode/src/github.com/talkkonnect/talkkonnect/mumble.pem
fi


Expand Down
31 changes: 31 additions & 0 deletions usbkeyboard.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
/*
* talkkonnect headless mumble client/gateway with lcd screen and channel control
* Copyright (C) 2018-2019, Suvir Kumar <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* talkkonnect is the based on talkiepi and barnard by Daniel Chote and Tim Cooper
*
* The Initial Developer of the Original Code is
* Suvir Kumar <[email protected]>
* Portions created by the Initial Developer are Copyright (C) Suvir Kumar. All Rights Reserved.
*
* Contributor(s):
*
* Suvir Kumar <[email protected]>
* Library golang-evdev Copyright (c) 2016 Georgi Valkov. All rights reserved. See Copyright Message in Library source code.
*
* My Blog is at www.talkkonnect.com
* The source code is hosted at github.com/talkkonnect
*
* usbkeyboard.go -> function in talkkonnect for reading from external usb keyboard
*/

package talkkonnect

import (
Expand Down Expand Up @@ -56,6 +86,7 @@ func (b *Talkkonnect) USBKeyboard() {
case "setcomment":
CommentMessageOff = USBKeyMap[rune(ke.Scancode)].ParamName
CommentMessageOn = USBKeyMap[rune(ke.Scancode)].ParamName
log.Println("info: User Status Set to Message ", USBKeyMap[rune(ke.Scancode)].ParamName)
case "transmitstart":
b.cmdStartTransmitting()
case "transmitstop":
Expand Down
8 changes: 8 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,11 @@ func FileExists(filepath string) bool {

return !fileinfo.IsDir()
}

func restart() {
time.Sleep(2 * time.Second)
c := exec.Command("reset")
c.Stdout = os.Stdout
c.Run()
os.Exit(0)
}
101 changes: 52 additions & 49 deletions xmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import (

//version and release date
const (
talkkonnectVersion string = "1.67.11"
talkkonnectReleased string = "Aug 21 2021"
talkkonnectVersion string = "1.67.12"
talkkonnectReleased string = "Aug 22 2021"
)

// Generic Global Variables
Expand Down Expand Up @@ -271,23 +271,25 @@ var (

// mqtt settings
var (
MQTTEnabled bool = false
Iotuuid string
RelayAllState bool = false
RelayPulseMills time.Duration
TotalRelays uint
RelayPins = [9]uint{}
MQTTTopic string
MQTTBroker string
MQTTPassword string
MQTTUser string
MQTTId string
MQTTCleansess bool
MQTTQos int
MQTTNum int
MQTTPayload string
MQTTAction string
MQTTStore string
MQTTEnabled bool = false
Iotuuid string
RelayAllState bool = false
RelayPulseMills time.Duration
TotalRelays uint
RelayPins = [9]uint{}
MQTTTopic string
MQTTBroker string
MQTTPassword string
MQTTUser string
MQTTId string
MQTTCleansess bool
MQTTQos int
MQTTNum int
MQTTPayload string
MQTTAction string
MQTTStore string
MQTTAttentionBlinkTimes int
MQTTAttentionBlinkmsecs int
)

// ttsmessages settings
Expand Down Expand Up @@ -693,18 +695,20 @@ type DocumentStruct struct {
PrintUSBKeyboard bool `xml:"printusbkeyboard"`
} `xml:"printvariables"`
MQTT struct {
MQTTEnabled bool `xml:"enabled,attr"`
MQTTTopic string `xml:"mqtttopic"`
MQTTBroker string `xml:"mqttbroker"`
MQTTPassword string `xml:"mqttpassword"`
MQTTUser string `xml:"mqttuser"`
MQTTId string `xml:"mqttid"`
MQTTCleansess bool `xml:"cleansess"`
MQTTQos int `xml:"qos"`
MQTTNum int `xml:"num"`
MQTTPayload string `xml:"payload"`
MQTTAction string `xml:"action"`
MQTTStore string `xml:"store"`
MQTTEnabled bool `xml:"enabled,attr"`
MQTTTopic string `xml:"mqtttopic"`
MQTTBroker string `xml:"mqttbroker"`
MQTTPassword string `xml:"mqttpassword"`
MQTTUser string `xml:"mqttuser"`
MQTTId string `xml:"mqttid"`
MQTTCleansess bool `xml:"cleansess"`
MQTTQos int `xml:"qos"`
MQTTNum int `xml:"num"`
MQTTPayload string `xml:"payload"`
MQTTAction string `xml:"action"`
MQTTStore string `xml:"store"`
MQTTAttentionBlinkTimes int `xml:"attentionblinktimes"`
MQTTAttentionBlinkmsecs int `xml:"attentionblinkmsecs"`
} `xml:"mqtt"`
TTSMessages struct {
TTSMessageEnabled bool `xml:"enabled,attr"`
Expand Down Expand Up @@ -942,8 +946,6 @@ func readxmlconfig(file string) error {
}
}

// insert the voice target back here

exec, err := os.Executable()

if err != nil {
Expand Down Expand Up @@ -1415,6 +1417,8 @@ func readxmlconfig(file string) error {
MQTTPayload = Document.Global.Software.MQTT.MQTTPayload
MQTTAction = Document.Global.Software.MQTT.MQTTAction
MQTTStore = Document.Global.Software.MQTT.MQTTStore
MQTTAttentionBlinkTimes = Document.Global.Software.MQTT.MQTTAttentionBlinkTimes
MQTTAttentionBlinkmsecs = Document.Global.Software.MQTT.MQTTAttentionBlinkmsecs

TTSMessageEnabled = Document.Global.Software.TTSMessages.TTSMessageEnabled
TTSLocalPlay = Document.Global.Software.TTSMessages.TTSLocalPlay
Expand Down Expand Up @@ -1944,17 +1948,19 @@ func printxmlconfig() {
}
if PrintMQTT {
log.Println("info: ------------ MQTT Function -------------- ")
log.Println("info: Enabled " + fmt.Sprintf("%v", MQTTEnabled))
log.Println("info: Topic " + fmt.Sprintf("%v", MQTTTopic))
log.Println("info: Broker " + fmt.Sprintf("%v", MQTTBroker))
log.Println("info: Password " + fmt.Sprintf("%v", MQTTPassword))
log.Println("info: Id " + fmt.Sprintf("%v", MQTTId))
log.Println("info: Cleansess " + fmt.Sprintf("%v", MQTTCleansess))
log.Println("info: Qos " + fmt.Sprintf("%v", MQTTQos))
log.Println("info: Num " + fmt.Sprintf("%v", MQTTNum))
log.Println("info: Payload " + fmt.Sprintf("%v", MQTTPayload))
log.Println("info: Action " + fmt.Sprintf("%v", MQTTAction))
log.Println("info: Store " + fmt.Sprintf("%v", MQTTStore))
log.Println("info: Enabled " + fmt.Sprintf("%v", MQTTEnabled))
log.Println("info: Topic " + fmt.Sprintf("%v", MQTTTopic))
log.Println("info: Broker " + fmt.Sprintf("%v", MQTTBroker))
log.Println("info: Password " + fmt.Sprintf("%v", MQTTPassword))
log.Println("info: Id " + fmt.Sprintf("%v", MQTTId))
log.Println("info: Cleansess " + fmt.Sprintf("%v", MQTTCleansess))
log.Println("info: Qos " + fmt.Sprintf("%v", MQTTQos))
log.Println("info: Num " + fmt.Sprintf("%v", MQTTNum))
log.Println("info: Payload " + fmt.Sprintf("%v", MQTTPayload))
log.Println("info: Action " + fmt.Sprintf("%v", MQTTAction))
log.Println("info: Store " + fmt.Sprintf("%v", MQTTStore))
log.Println("info: AttentionBlinkTimes " + fmt.Sprintf("%v", MQTTAttentionBlinkTimes))
log.Println("info: AttentionBlinkmsecs " + fmt.Sprintf("%v", MQTTAttentionBlinkmsecs))
} else {
log.Println("info: ------------ MQTT Function ------- SKIPPED ")
}
Expand Down Expand Up @@ -2006,11 +2012,8 @@ func modifyXMLTagServerHopping(inputXMLFile string, newserverindex int) {
err := cmd.Run()
if err != nil {
log.Println("error: Failed to Set Next Server XML Tag with Error ", err)
return
}

time.Sleep(2 * time.Second)
c := exec.Command("reset")
c.Stdout = os.Stdout
c.Run()
os.Exit(0)
restart()
}

0 comments on commit 90c2a1a

Please sign in to comment.