Announcement

Collapse
No announcement yet.

Automatic Copy Writing Machine problem with "Drawing via Web Using PHPoC" Project

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Automatic Copy Writing Machine problem with "Drawing via Web Using PHPoC" Project

    Hey, I had built a "Drawing via Web Using PHPoC" Project. It's successful run with no error. It's smooth.
    I want to record my drawing, so that it can automatically draw my previous drawing again.
    Can you give me some code to achieve this result?

    here's my code now.
    https://drive.google.com/drive/folde...DD?usp=sharing

  • #2
    Wow good to hear, mate.

    Of course, to record the drawing, you will need to save all the drawing data to a memory (literally, all the data you send from browser to PHPoC via WebSocket).

    If you want to save it to memory using web browser, you can use local storage:
    https://developer.mozilla.org/en-US/...w/localStorage

    And yes, another option is to store that data in PHPoC.
    https://www.phpoc.com/support/manual...hp?id=l_sd_340
    You can refer to some functions like um_read(), um_write(), nm_read(), nm_write() to read/write data to PHPoC memory.

    Personally, I prefer to use browser memory, cause we won't have to worry a lot about memory size limitation .

    Cheers

    Comment


    • #3
      Thanks, I think I will use the browser memory. Since I have to record the drawing, Do I need to do the sampling and then set the timer to draw it again?
      I don't know the library of PHPoC. What should I add to the original code?

      Comment


      • #4
        Well, in my opinion, there may be a way to make it not so complicated.

        Let's say you use browser memory.
        When recording the data, you can also calculate the time interval between two consecutive drawing commands, and save it to memory.

        Then when you load the data from memory, you know exactly what commands you should send to PHPoC device, and the time intervals between those commands. Voila .
        And you can make a web interface, thing like a button to trigger the event to load data from memory, and repeat the drawing steps.
        It won't involve lots of PHPoC code. With JavaScript, doing such things may be not so tough, I guess.

        Cheers

        Comment


        • #5
          Thx, so I have to set a timer to calculate the time interval between two consecutive drawing commands. Then save the time and drawing commands in a txt file.
          When I need to load the file, write a function to upload the txt file to the website. the write a while loop function to read the file and send the command to the server?
          I afraid I am not very clear the step. Can you provide the pseudo code to me. I am sorry that I am a beginner...

          Comment


          • #6
            The reason why I suggest you use browser memory because I assume that you want to do it locally, no need internet connection.
            It will allow you to remake your drawing if you are on the same web browser where you first made your drawing.

            There should be more than a couple of ways to save the data (to local/cloud/SQL server ...), but it is one way that may work:

            - Record all the data (command and time interval with the previous one) to browser memory.

            Tasks like taking the time difference between two events wouldn't be so hard with JavaScript.
            For example, you can refer to this https://stackoverflow.com/questions/...tes-in-seconds
            Basically, you could find your sensei for almost every JavaScript problem on Stack Overflow then

            - After the recorded data is well stored in browser memory, you can load it back whenever you want.
            Don't worry, using local storage on web browser is quite straightforward. You can take a look at the link in my previous post.

            And the data may look like this [Command A: time 0; Command B: time xyz ...]
            You will load and run command A, after xyz, execute command B, and so on.
            You can refer to this https://www.w3schools.com/jsref/met_win_settimeout.asp

            Yep, between PHPoC and web browser, there is still a WebSocket connection. But I don't think you need to modify server code that runs on PHPoC.
            You just need JavaScript for doing those steps on the client side.

            Cheers

            Comment

            Working...
            X