Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help with obtaining firmware config (select params) #46

Open
ghost opened this issue Aug 3, 2017 · 23 comments
Open

Help with obtaining firmware config (select params) #46

ghost opened this issue Aug 3, 2017 · 23 comments

Comments

@ghost
Copy link

ghost commented Aug 3, 2017

I am working on another frontend where I intend using lw.comms-server as well.

In this frontend, I want to obtain the Smoothie config file and then parse it.
In my old project CoPrint, i used (which should not be used) MSD to access the Config file from SD over nodejs-fs: See https://github.com/openhardwarecoza/CoPrint/blob/9b602c256c2fab10158bd9033d4c14ab33bbdccc/server-smoothie.js#L192-L205

Of course that being the wrong way, i am now trying to do the same over Serial. using Smoothie command 'cat /sd/config' works beautifully, but instead of getting the file as a whole, i am getting each line as a seperate event. This makes parsing it much harder

I almost have to do

if ( data.indexOf('alpha_steps_per_mm') === 0 || data.indexOf('beta_steps_per_mm') === 0 || data.indexOf('gamma_steps_per_mm') === 0 || data.indexOf('x_axis_max_speed') === 0 || data.indexOf('y_axis_max_speed') === 0 || data.indexOf('z_axis_max_speed') === 0 || data.indexOf('acceleration') === 0 || data.indexOf('z_acceleration') === 0 || data.indexOf('endstops_enable') === 0) {...}

for each value i want to work with... yikes.

each line is an event

@cprezzi any ideas how I can go about reading the file using 'cat' and get it in ONE event?

@ghost
Copy link
Author

ghost commented Aug 3, 2017

(Goal: In the end i assemble it into a smoothieParams object:

config

with the eventual goal of then sending set-config commands back to update the popular settings for noobs

@ghost
Copy link
Author

ghost commented Aug 3, 2017

For what its further worth, I get the output of '$$" from Grbl in seperate events too, but that very useful "$number..." is easy to get with

 } else if (data.indexOf('$') === 0) {
           grblSettings(data)
       }

grblparams

@cprezzi
Copy link
Member

cprezzi commented Aug 3, 2017

You get it line by line, because lw.comm-server get linebreaks from smoothieware. I think cat is the wrong way to do it, because there are no start or end of file marks.

Instead, you could read value by value with config-get and change a param with config-set.

@cprezzi
Copy link
Member

cprezzi commented Aug 3, 2017

This should be easy to implement as you anyways have a structured array.

@ghost ghost closed this as completed Aug 4, 2017
@ghost
Copy link
Author

ghost commented Aug 4, 2017

Thanks!

@ghost
Copy link
Author

ghost commented Aug 4, 2017

I think cat is the wrong way to do it, vs ...

cat sd

@cprezzi
Copy link
Member

cprezzi commented Aug 4, 2017

Hm. didn't see that. There is no such hint in smoothiehappy api (https://lautr3k.github.io/smoothie-happy/docs/function/index.html#static-function-cmd_config_get) and I think @lautr3k is also using it for his new configuration dialog.

@ghost
Copy link
Author

ghost commented Aug 4, 2017 via email

@cprezzi
Copy link
Member

cprezzi commented Aug 4, 2017

Yes, I think so.

@cprezzi
Copy link
Member

cprezzi commented Aug 4, 2017

In the smoothie code I found that if the limit param of cat is -d we should get a eof at the end of the file :)
https://github.com/Smoothieware/Smoothieware/blob/edge/src/modules/utils/simpleshell/SimpleShell.cpp#L380

But we still need to make sure the queue is empty and all timers are off before sending the cat command.

@cprezzi
Copy link
Member

cprezzi commented Aug 4, 2017

What do you think about lw.comm-server providing a command "getFirmwareConfig" which delivers a complete json object with all config parameters?

The app could then dynamically create a form with all settings. It should also be possible to embed all field options in the json object. Something like:

{ 
    laser_mode: 1,
    laser_mode_options: [
        1: On, 
        0: Off
    ]
}

This way, the app (frontend) can stay firmware independant.

@ghost
Copy link
Author

ghost commented Aug 4, 2017 via email

@cprezzi
Copy link
Member

cprezzi commented Aug 4, 2017

I think it's hard to find parameter names that match every firmware (because they are so different), but that wouldn't be needed if the frontend form is created dynamically with the names & options in the json object.

@cprezzi
Copy link
Member

cprezzi commented Aug 4, 2017

I know this could be less flexible for a frontend (for adding help or designing super nice tabbed forms).

@ghost
Copy link
Author

ghost commented Aug 4, 2017 via email

@cprezzi
Copy link
Member

cprezzi commented Aug 4, 2017

That's correct, but wouldn't it be confusing for a user, if the param in the frontend doesn't have the same name like in the config file?

@ghost
Copy link
Author

ghost commented Aug 4, 2017 via email

@cprezzi
Copy link
Member

cprezzi commented Aug 4, 2017

Ok. Let me think about this over the weekend. Probably I get flashed with a genious solution ;)

@cprezzi
Copy link
Member

cprezzi commented Aug 4, 2017

Could you write down a complete list of params needed and how they map to Smoothie and Grbl params?

@ghost
Copy link
Author

ghost commented Aug 4, 2017 via email

@ghost
Copy link
Author

ghost commented Aug 4, 2017 via email

@cprezzi
Copy link
Member

cprezzi commented Aug 4, 2017

Remember that I also have implemented a firmware feature list (https://github.com/LaserWeb/lw.comm-server/wiki/Firmware-feature-list) which could complement the settings feature.

@ghost ghost changed the title cat /sd/config sends each line as a 'data' event Help with obtaining firmware config (select params) Aug 10, 2017
@ghost ghost reopened this Aug 10, 2017
@ghost
Copy link
Author

ghost commented Aug 10, 2017

#47 touches on the new object way mentioned in #46 (comment)

The configuration i am interested in (for now) is:

configuration: {
      x_steps_per_mm: 0,
      y_steps_per_mm: 0,
      z_steps_per_mm: 0,
      x_acceleration: 0,
      y_acceleration: 0,
      z_acceleration: 0,
      x_max_rate: 0,
      y_max_rate: 0,
      z_max_rate: 0,
      x_axis_length: 0, // Max lenght of axes: Used for soft limits in grbl and smoothie - also maybe useful to autodraw grid size
      y_axis_length: 0, // Max lenght of axes: Used for soft limits in grbl and smoothie - also maybe useful to autodraw grid size
      z_axis_length: 0, // Max lenght of axes: Used for soft limits in grbl and smoothie - also maybe useful to autodraw grid size
      x_homing: 0, // 0 = none, 1 = min, 2 = max
      y_homing: 0, // 0 = none, 1 = min, 2 = max
      z_homing: 0, // 0 = none, 1 = min, 2 = max
      x_home_invert: 0, // 0 = none, 1 = inverted
      y_home_invert: 0, // 0 = none, 1 = inverted
      z_home_invert: 0, // 0 = none, 1 = min, 2 = max
      x_dir: 0, // 0 = normal, 1 = inverted
      y_dir: 0, // 0 = normal, 1 = inverted
      z_dir: 0, // 0 = normal, 1 = inverted
      x_current: 0, // grbl-lpc and smoothie
      y_current: 0, // grbl-lpc and smoothie
      z_current: 0, // grbl-lpc and smoothie
      tools: {
        bed: true, // not really scoped to configure from here... but rather used in frontend to configure showing options related
        e0: true, // not really scoped to configure from here... but rather used in frontend to configure showing options related
        e1: false, // not really scoped to configure from here... but rather used in frontend to configure showing options related
        laser: false, // not really scoped to configure from here... but rather used in frontend to configure showing options related
        spindle: false // not really scoped to configure from here... but rather used in frontend to configure showing options related
      },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant