Skip to content

Commit

Permalink
extract list / print / delete commands according target and put in se…
Browse files Browse the repository at this point in the history
…ttings - WIP

Fix bug of dependencies in interfaces
Fix  Do not display TFT commands in status panel if no TFT target set
  • Loading branch information
luc-github committed Mar 1, 2024
1 parent a3713db commit 378aabe
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 78 deletions.
6 changes: 3 additions & 3 deletions languages/printerpack/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@
"P98": "Pause command",
"P99": "Resume command",
"P100": "Stop command",
"P101": "SD print commands",
"P102": "TFT SD print commands",
"P103": "TFT USB print commands",
"P101": "SD play commands",
"P102": "TFT SD play commands",
"P103": "TFT USB play commands",
"P104": "Preset values",
"P105": "Elapsed",
"P106": "Command",
Expand Down
4 changes: 2 additions & 2 deletions src/components/Helpers/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ const connectionDepend = (depend, settings) => {
}

//this is dynamic as it is depending on the preferences settings
const settingsDepend = (depend, settings, isOr) => {
const settingsDepend = (depend, settings, isOr=false) => {
if (typeof depend!="undefined"){
//console.log("settingsDepend", depend, settings, isOr)
console.log("settingsDepend", depend[0])
//console.log("settingsDepend", depend[0])
}
if (Array.isArray(depend)) {
return depend.reduce(
Expand Down
16 changes: 1 addition & 15 deletions src/tabs/interface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,7 @@ import { importPreferences, formatPreferences } from "./importHelper"

const isDependenciesMet = (depend) => {
const { interfaceSettings } = useSettingsContext()
let met = false
depend.forEach((d) => {
if (d.id) {
const element = useUiContextFn.getElement(
d.id,
interfaceSettings.current.settings
)
if (element.value == d.value) {
met = true
}
}
})
return met
return settingsDepend(depend, interfaceSettings.current.settings)
}

const InterfaceTab = () => {
Expand Down Expand Up @@ -388,8 +376,6 @@ const InterfaceTab = () => {
section[
subsectionId
]
// console.log(fieldData);

if (
fieldData.type ==
"group"
Expand Down
14 changes: 6 additions & 8 deletions src/targets/Printer3D/Marlin/DIRECTSD-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { h } from 'preact'
import { canProcessFile } from '../../helpers'
import { sortedFilesList, formatStatus } from '../../../components/Helpers'
import { useSettingsContextFn } from '../../../contexts'
import { useUiContextFn, useSettingsContextFn } from '../../../contexts'

const capabilities = {
Process: (path, filename) => {
Expand Down Expand Up @@ -125,17 +125,15 @@ const commands = {
'/sd' + path + (path.endsWith('/') ? '' : '/') + filename
return {
type: 'cmd',
cmd: '[ESP700]stream=' + fullpath.replaceAll(' ', ' '),
cmd: '[ESP700]stream=' + fullpath.replaceAll('//', '/'),
}
} else {
const spath =
(path + (path == '/' ? '' : '/') + filename).replaceAll('//', '/')
const cmd = useUiContextFn.getValue('sdplaycmd').replace("#", spath)
return {
type: 'cmd',
cmd:
'M23 ' +
path +
(path == '/' ? '' : '/') +
filename +
'\nM24',
cmd
}
}
},
Expand Down
6 changes: 4 additions & 2 deletions src/targets/Printer3D/Marlin/SD-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ const commands = {
return res
},
play: (path, filename) => {
let cmdstr = 'M23 ' + path + (path == '/' ? '' : '/') + filename + '\nM24'
const spath = (path + (path == '/' ? '' : '/') + filename).replaceAll('//', '/')
const cmd = useUiContextFn.getValue('sdplaycmd').replace('#', spath)
return {
type: 'cmd',
cmd: cmdstr.replace("//", "/"),
cmd,
}
},
delete: (path, filename) => {
//TODO: extract command from settings
return {
type: 'cmd',
cmd: 'M30 ' + path + (path == '/' ? '' : '/') + filename,
Expand Down
6 changes: 4 additions & 2 deletions src/targets/Printer3D/Marlin/SDEXT-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ const commands = {
return res
},
play: (path, filename) => {
let cmdstr = 'M23 ' + path + (path == '/' ? '' : '/') + filename + '\nM24'
const spath = (path + (path == '/' ? '' : '/') + filename).replaceAll('//', '/')
const cmd = useUiContextFn.getValue('sdextplaycmd').replace('#', spath)
return {
type: 'cmd',
cmd: cmdstr.replace("//", "/"),
cmd,
}
},
delete: (path, filename) => {
//TODO:: extract from settings
return {
type: 'cmd',
cmd: 'M30 ' + path + (path == '/' ? '' : '/') + filename,
Expand Down
36 changes: 18 additions & 18 deletions src/targets/Printer3D/Marlin/TFT-SD-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,19 @@ const capabilities = {

const commands = {
list: (path, filename) => {
if (useSettingsContextFn.getValue('SerialProtocol') == 'MKS') {
if (useSettingsContextFn.getValue('SerialProtocol') == 'MKS' || useUiContextFn.getValue('tftfs') == 'mks'){
const cmd = useUiContextFn.getValue('tftmkssdlistcmd').replace("#",path)
return {
type: 'cmd',
cmd: 'M998 1\r\nM20 1:' + path,
cmd,
}
} else
} else {
const cmd = useUiContextFn.getValue('tftbttsdlistcmd').replace("#",path)
return {
type: 'cmd',
cmd: 'M20 SD:' + path,
cmd,
}
}
},
upload: (path, filename) => {
if (useSettingsContextFn.getValue('SerialProtocol') == 'MKS')
Expand Down Expand Up @@ -167,30 +170,27 @@ const commands = {
res.status = formatStatus(data.status)
return res
},
play: (path, filename) => {
if (useSettingsContextFn.getValue('SerialProtocol') != 'MKS') {
play: (path, filename) => {
const spath = (path +
(path == '/' ? '' : '/') +
filename).replaceAll('//', '/')
if (useSettingsContextFn.getValue('SerialProtocol') == 'MKS' || useUiContextFn.getValue('tftfs') == 'mks')
{
const cmd = useUiContextFn.getValue('tftmkssdplaycmd').replace("#",spath)
return {
type: 'cmd',
cmd:
'M23 SD:' +
path +
(path == '/' ? '' : '/') +
filename +
'\nM24',
cmd,
}
} else {
const cmd = useUiContextFn.getValue('tftbttsdplaycmd').replace("#",spath)
return {
type: 'cmd',
cmd:
'M23 M998 1\r\n1:' +
path +
(path == '/' ? '' : '/') +
filename +
'\nM24',
cmd,
}
}
},
delete: (path, filename) => {
//TODO: extract command from settings
return {
type: 'cmd',
cmd: 'M30 SD:' + path + (path == '/' ? '' : '/') + filename,
Expand Down
36 changes: 18 additions & 18 deletions src/targets/Printer3D/Marlin/TFT-USB-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,19 @@ const capabilities = {

const commands = {
list: (path, filename) => {
if (useSettingsContextFn.getValue('SerialProtocol') == 'MKS') {
if (useSettingsContextFn.getValue('SerialProtocol') == 'MKS' || useUiContextFn.getValue('tftfs') == 'mks'){
const cmd = useUiContextFn.getValue('tftmksusblistcmd').replace("#",path)
return {
type: 'cmd',
cmd: 'M998 0\r\nM20 0:' + path,
cmd,
}
} else
} else {
const cmd = useUiContextFn.getValue('tftbttusblistcmd').replace("#",path)
return {
type: 'cmd',
cmd: 'M20 U:' + path,
cmd,
}
}
},
upload: (path, filename) => {
if (useSettingsContextFn.getValue('SerialProtocol') == 'MKS')
Expand Down Expand Up @@ -167,30 +170,27 @@ const commands = {
res.status = formatStatus(data.status)
return res
},
play: (path, filename) => {
if (useSettingsContextFn.getValue('SerialProtocol') != 'MKS') {
play: (path, filename) => {
const spath = (path +
(path == '/' ? '' : '/') +
filename).replaceAll('//', '/')
if (useSettingsContextFn.getValue('SerialProtocol') == 'MKS' || useUiContextFn.getValue('tftfs') == 'mks')
{
const cmd = useUiContextFn.getValue('tftmksusbplaycmd').replace("#",spath)
return {
type: 'cmd',
cmd:
'M23 U:' +
path +
(path == '/' ? '' : '/') +
filename +
'\nM24',
cmd,
}
} else {
const cmd = useUiContextFn.getValue('tftbttusbplaycmd').replace("#",spath)
return {
type: 'cmd',
cmd:
'M23 M998 0\r\n1:' +
path +
(path == '/' ? '' : '/') +
filename +
'\nM24',
cmd,
}
}
},
delete: (path, filename) => {
//TODO: extract command from settings
return {
type: 'cmd',
cmd: 'M30 U:' + path + (path == '/' ? '' : '/') + filename,
Expand Down
73 changes: 71 additions & 2 deletions src/targets/Printer3D/Marlin/preferences.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,32 @@
}
]
},
{
"id": "sdplaycmd",
"type": "text",
"label": "P119",
"value": "M21;M23 #;M24",
"help": "S97",
"depend": [
{
"id": "sd",
"value": true
}
]
},
{
"id": "sddeletecmd",
"type": "text",
"label": "P122",
"value": "M21;M30 #",
"help": "S97",
"depend": [
{
"id": "sd",
"value": true
}
]
},
{
"id": "sdext",
"type": "boolean",
Expand Down Expand Up @@ -117,6 +143,40 @@
"value": "!='none'"
}
]
},
{
"id": "sdextplaycmd",
"type": "text",
"label": "P119",
"value": "M21;M23 #;M24",
"help": "S97",
"depend": [
{
"id": "sdext",
"value": true
},
{
"connection_id": "SDConnection",
"value": "!='none'"
}
]
},
{
"id": "sdextdeletecmd",
"type": "text",
"label": "P122",
"value": "M21;M3 #",
"help": "S97",
"depend": [
{
"id": "sdext",
"value": true
},
{
"connection_id": "SDConnection",
"value": "!='none'"
}
]
}
],
"extruders": [
Expand Down Expand Up @@ -199,7 +259,16 @@
"id": "tftsdcommands",
"type": "group",
"label": "P102",
"depend": [{ "id": "tftsd", "value": true }],
"depend": [
{
"id": "tftfs",
"notvalue": "none"
},
{
"id": "tftsd",
"value": true
}
],
"value": [
{
"id": "tftsdpausecmd",
Expand Down Expand Up @@ -228,7 +297,7 @@
"id": "tftusbcommands",
"type": "group",
"label": "P103",
"depend": [{ "id": "tftusb", "value": true }],
"depend": [{ "id": "tftfs", "notvalue": "none"},{ "id": "tftusb", "value": true }],
"value": [
{
"id": "tftusbpausecmd",
Expand Down
Loading

0 comments on commit 378aabe

Please sign in to comment.