Laying the new foundations of ExPing

Words
387
Reading
2 min
Listen
Play
9y

Intro

Since the base code have been written years ago and back then I lacked the foresight to predict how the program would perform, I made quite few mistake and kept creating and deleting labels to show the pings delay. This caused the program to eat more and more of the computers memory and after leaving it open for few days I realized it took a gigabyte of RAM, not it's time to fix this problem by recycling the same labels over and over.

Stripping the code

First i had to strip the program from most of it's old code and the logging functionality to have the minimal amount of the code to work with that's basically the main loop.
1.jpg

Fixing responsibility problem

Those whom are familiar with AutoIt know that: sleep() makes the program freeze and not response to the user input, to fix this problem I added a simple counter to run the ping code every fifty cycle of the main loop, this also gives me the option to add the function to adjust the delay between pings later on.

   if $delays > 50 then
      pingit()
      $delays = 0
   EndIf
   sleep(10)
   $delays += 1

Ping as a function

In the first version everything was happening in the main loop, by moving the ping into its own function the code would become simpler and I can pass variable to it easier.

Func pingit()
   $var = ping($Ping)
   if $var == 0 Then
      GUICtrlSetData ($p1, "Out")
      GUICtrlSetColor($p1, 0xff0000)
   ElseIf $var < 50 Then
      GUICtrlSetData ($p1, $var)
      GUICtrlSetColor($p1, 0x0055ff)
   ElseIf $var < 100 Then
      GUICtrlSetData ($p1, $var)
      GUICtrlSetColor($p1, 0x8800ff)
   ElseIf $var < 150 Then
      GUICtrlSetData ($p1, $var)
      GUICtrlSetColor($p1, 0x8800ff)
   ElseIf $var < 200 Then
      GUICtrlSetData ($p1, $var)
      GUICtrlSetColor($p1, 0xff0000)
   EndIf
EndFunc

At the moment it's only updating the same label over and over, adding the rest of the labels and make the ping, loop through them to show a brief history of the speed would be the next step,
I'm planing to add the option to let the user input their threshold for colors based on the usual speed of their internet, for me: my ping doesn't go lower than 150ms but I'm sure the rest of the world have faster Internets.

Prof of work

You can see the changes in this commit

Conclusion

Now the foundation is correct I can keep adding more and more functions to make it a program beyond a simple delay monitor for your ping, since it would be open while online, mostly gaming, maybe I add some function to assist you in your game, type things, break up with your girlfriend/boyfriend or kill your cat... maybe not the last one though.



Posted on Utopian.io - Rewarding Open Source Contributors

Laying the new foundations of ExPing | Ecency