Skip to content

Commit

Permalink
update: matrix pins
Browse files Browse the repository at this point in the history
  • Loading branch information
darakuneko committed Mar 27, 2023
1 parent c29a74c commit 865b20a
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 88 deletions.
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@
"dist:linux": "npm run build && electron-builder -l"
},
"name": "gpk_fwbuilder",
"version": "0.6.1",
"version": "0.6.2",
"description": "GPK FWBuilder",
"homepage": "https://github.com/darakuneko",
"author": {
"name": "darakuneko",
"email": "tvkids@gmail.com"
},
"devDependencies": {
"electron": "22.0.0",
"@electron/rebuild": "3.2.10",
"electron": "23.2.0",
"electron-builder": "23.6.0",
"electron-rebuild": "3.2.9",
"webpack-cli": "5.0.1"
},
"main": "./index.js",
"dependencies": {
"@babel/core": "7.20.5",
"@babel/core": "7.21.3",
"@babel/preset-env": "7.20.2",
"@babel/preset-react": "7.18.6",
"@emotion/babel-preset-css-prop": "11.10.0",
"@emotion/react": "11.10.5",
"@emotion/styled": "11.10.5",
"@mui/icons-material": "5.11.0",
"@mui/material": "5.11.0",
"@mui/styles": "5.11.0",
"ansi-to-html": "^0.7.2",
"axios": "^1.2.1",
"babel-loader": "9.1.0",
"@emotion/react": "11.10.6",
"@emotion/styled": "11.10.6",
"@mui/icons-material": "5.11.11",
"@mui/material": "5.11.14",
"@mui/styles": "5.11.13",
"ansi-to-html": "0.7.2",
"axios": "1.3.4",
"babel-loader": "9.1.2",
"electron-store": "8.1.0",
"form-data": "4.0.0",
"html-react-parser": "3.0.4",
"html-react-parser": "3.0.15",
"node-loader": "2.0.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"webpack": "5.75.0"
"webpack": "5.76.3"
},
"build": {
"productName": "GPK FWBuilder",
Expand Down
8 changes: 8 additions & 0 deletions src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export function StateProvider({children}) {
cols: '',
rows: '',
option: 0,
},
pins: {
rp2040: ["GP0","GP1","GP2","GP3","GP4","GP5","GP6","GP7","GP8","GP9","GP10","GP11","GP12","GP13","GP14","GP15","GP16","GP17","GP18","GP19","GP20","GP21","GP22","GP23","GP24","GP25","GP26","GP27","GP28","GP29"],
promicro: ["D3", "D2", "D1", "D0", "D4", "C6", "D7", "E6", "B4", "B5", "B6", "B2", "B3", "B1", "F7", "F6", "F5", "F4", "B0", "D5"]
}
},
logs: "",
Expand Down Expand Up @@ -81,6 +85,10 @@ export function StateProvider({children}) {
cols: obj.convert.kle.cols,
rows: obj.convert.kle.rows,
option: obj.convert.kle.option,
},
pins: {
rp2040: obj.convert.pins.rp2040,
promicro: obj.convert.pins.promicro,
}
},
version: obj.version,
Expand Down
170 changes: 97 additions & 73 deletions src/renderer/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import Checkbox from "@mui/material/Checkbox";
import FormControlLabel from "@mui/material/FormControlLabel";
import FormGroup from "@mui/material/FormGroup";
import FormHelperText from "@mui/material/FormHelperText";
import Chip from "@mui/material/Chip";
import OutlinedInput from "@mui/material/OutlinedInput";
import FormControl from "@mui/material/FormControl";

const {api} = window

const Convert = () => {
const {state, setState} = useStateContext()
const [viaJson, setViaJson] = useState({
const [viaObj, setViaObj] = useState({
info: {
name : "",
path : "",
Expand All @@ -26,10 +29,13 @@ const Convert = () => {
path : "",
},
})
const [kleJson, setKLEJson] = useState({
const [kleObj, setKleObj] = useState({
name : "",
path : "",
})
const [pinCols, setPinCols] = React.useState([]);
const [pinRows, setPinRows] = React.useState([]);

const [disabledViaCovertButton, setDisabledViaCovertButton] = useState(true)

const [keyboardError, setKeyboardError] = useState(false)
Expand All @@ -43,8 +49,6 @@ const Convert = () => {
const [usernameStrError, setUsernameStrError] = useState(false)
const [vidStrError, setVidStrError] = useState(false)
const [pidStrError, setPidStrError] = useState(false)
const [rowStrError, setRowsStrError] = useState(false)
const [colStrError, setColsStrError] = useState(false)

const [pidSameError, setPidSameError] = useState(false)

Expand All @@ -59,14 +63,11 @@ const Convert = () => {
const kle = state.convert.kle
const reg1 = /^[A-Za-z0-9 _/-]+$/
const reg2 = /^[A-Z0-9x]+$/
const reg3 = /^[A-Z0-9,]+$/
const isViaJson = state.convert.kle.option === 2
const isViaObj = state.convert.kle.option === 2
let validKeyboardStrError = false
let validUsernameStrError = false
let validVidStrError = false
let validPidStrError = false
let validRowsStrError = false
let validColsStrError = false
let validPidSameError = false

if(kle.kb.length > 0){
Expand All @@ -87,22 +88,15 @@ const Convert = () => {
validPidSameError = kle.pid !== "0x0000"
setPidSameError(!validPidSameError)
}
if(kle.rows.length > 0 || isViaJson){
validRowsStrError = isViaJson ? true : (reg3).test(kle.rows)
setRowsStrError(!validRowsStrError)
}
if(kle.cols.length > 0 || isViaJson){
validColsStrError = isViaJson ? true : (reg3).test(kle.cols)
setColsStrError(!validColsStrError)
}
const uploadedKleFile = kleJson.name.length > 0
const uploadedKleFile = kleObj.name.length > 0

const validDisableButton = (m2) => {
const m1 = kle.kb && kle.user && kle.vid && kle.pid && validKeyboardStrError && validUsernameStrError && validVidStrError && validPidStrError && validPidSameError &&
validRowsStrError && validColsStrError && uploadedKleFile
const m1 = kle.kb && kle.user && kle.vid && kle.pid && validKeyboardStrError && validUsernameStrError && validVidStrError
&& validPidStrError && validPidSameError && uploadedKleFile
return m1 && m2
}
setDisabledKleConvertButton(isViaJson ? !validDisableButton(true) : !validDisableButton(kle.rows && kle.cols))

setDisabledKleConvertButton(isViaObj ? !validDisableButton(true) : !validDisableButton(kle.rows && kle.cols))
}

const validKleEmpty = () => {
Expand All @@ -115,12 +109,19 @@ const Convert = () => {
}

const handleTextChange = (inputName) => (e) => {
if(inputName === 'kb') state.convert.kle.kb = e.target.value
if(inputName === 'user') state.convert.kle.user = e.target.value
if(inputName === 'vid') state.convert.kle.vid = e.target.value
if(inputName === 'pid') state.convert.kle.pid = e.target.value
if(inputName === 'rows') state.convert.kle.rows = e.target.value
if(inputName === 'cols') state.convert.kle.cols = e.target.value
const v =e.target.value
if(inputName === 'kb') state.convert.kle.kb = v
if(inputName === 'user') state.convert.kle.user = v
if(inputName === 'vid') state.convert.kle.vid = v
if(inputName === 'pid') state.convert.kle.pid = v
if(inputName === 'rows') {
state.convert.kle.rows = v.length > 0 ? v.join(',') : undefined
setPinRows(v)
}
if(inputName === 'cols') {
state.convert.kle.cols = v.length > 0 ? v.join(',') : undefined
setPinCols(v)
}

validKleEmpty()
validKleConvertButton()
Expand All @@ -130,6 +131,8 @@ const Convert = () => {
const handleSelectMCU = (e) => {
state.convert.kle.mcu = e.target.value
setState(state)
setPinRows([])
setPinCols([])
}

const convertMsg = "Convert...."
Expand All @@ -140,7 +143,7 @@ const Convert = () => {
state.tabDisabled = true
setState(state)

const logs = await api.convertKleJson({params: state.convert.kle, file: kleJson})
const logs = await api.convertKleJson({params: state.convert.kle, file: kleObj})

setDisabledKleConvertButton(false)
setDisabledConvertText(false)
Expand All @@ -152,9 +155,9 @@ const Convert = () => {
const handleKleFileUpload = async (e) => {
const file = e.target.files[0]
if (file){
kleJson.name = file.name
kleJson.path = file.path
setKLEJson({...kleJson, kleJson })
kleObj.name = file.name
kleObj.path = file.path
setKleObj({...kleObj, kleObj })

const json = await api.readJson(file.path)
const obj = json.filter(v => !Array.isArray(v))[0]
Expand Down Expand Up @@ -191,15 +194,14 @@ const Convert = () => {

const ValidKBUSRTextField = ValidTextField('A-Za-z0-9 _/- can used')
const ValidVidPidTextField = ValidTextField('A-Z0-9x can used')
const ValidRowColTextField = ValidTextField('A-Z0-9, can used')
const ValidPidSameTextField = ValidTextField('other than 0x0000')

const handleViaJsonSubmit = async () => {
const handleviaObjSubmit = async () => {
state.logs = convertMsg
state.tabDisabled = true
setState(state)
setDisabledViaCovertButton(true)
const log = await api.convertViaJson(viaJson)
const log = await api.convertviaObj(viaObj)
state.logs = log
state.tabDisabled = false
setState(state)
Expand All @@ -214,10 +216,10 @@ const Convert = () => {
name: file.name,
path: file.path
}
id === "info" ? viaJson.info = obj : viaJson.kle = obj
setViaJson({...viaJson, viaJson })
id === "info" ? viaObj.info = obj : viaObj.kle = obj
setViaObj({...viaObj, viaObj })
}
if (viaJson.info.name.length > 0 && viaJson.kle.name.length > 0) setDisabledViaCovertButton(false)
if (viaObj.info.name.length > 0 && viaObj.kle.name.length > 0) setDisabledViaCovertButton(false)
}

return (
Expand All @@ -243,7 +245,7 @@ const Convert = () => {
info json
<input id="info" type="file" accept=".json" hidden onChange={handleViaFileUpload} />
</Button>
<InputLabel sx={{ textAlign: "center", fontSize: inputLabelMiddleFontSize }} >{viaJson.info.name}</InputLabel>
<InputLabel sx={{ textAlign: "center", fontSize: inputLabelMiddleFontSize }} >{viaObj.info.name}</InputLabel>
</Box>
<Box>
<Button
Expand All @@ -254,7 +256,7 @@ const Convert = () => {
kle Json
<input id="kle" type="file" accept=".json" hidden onChange={handleViaFileUpload} />
</Button>
<InputLabel sx={{ textAlign: "center", fontSize: inputLabelMiddleFontSize }} >{viaJson.kle.name}</InputLabel>
<InputLabel sx={{ textAlign: "center", fontSize: inputLabelMiddleFontSize }} >{viaObj.kle.name}</InputLabel>
</Box>
<Box
sx={{
Expand All @@ -263,7 +265,7 @@ const Convert = () => {
alignItems: 'center'
}} >
<Button variant="contained"
onClick={handleViaJsonSubmit}
onClick={handleviaObjSubmit}
disabled={ disabledViaCovertButton }
>Convert</Button>
</Box>
Expand All @@ -278,7 +280,7 @@ const Convert = () => {
kle Json
<input id="kle" type="file" accept=".json" hidden onChange={handleKleFileUpload} />
</Button>
<InputLabel sx={{ textAlign: "center", fontSize: inputLabelMiddleFontSize }} >{kleJson.name}</InputLabel>
<InputLabel sx={{ textAlign: "center", fontSize: inputLabelMiddleFontSize }} >{kleObj.name}</InputLabel>
</Box>
<Box sx={{
display: 'flex',
Expand Down Expand Up @@ -372,46 +374,68 @@ const Convert = () => {
{pidSameError && ValidPidSameTextField}
</Box>
</Box>
<Box sx={{
</Box>
<Box
sx={{
pt: 4,
display: 'flex',
flexDirection: 'column',
}}>
<Box>
<TextField
id="convert-kle-row"
textAlign: "center",
alignItems: "center"
}} >
<Box>
<FormControl sx={{ m: 1, minWidth: 800 }}>
<InputLabel id="convert-kle-rows-label">matrix pins - rows</InputLabel>
<Select
labelId="convert-kle-rows-label"
id="convert-kle-rows"
label="matrix pins - rows"
required
onChange={handleTextChange("rows")}
error={rowsEmptyError}
disabled={state.convert.kle.option === 2 ? true : disabledConvertText }
onChange={handleTextChange("rows")}
variant="standard"
value={state.convert.kle.rows}
/>
{rowStrError && ValidRowColTextField}
</Box>
<Box>
<TextField
id="col"
label="matrix pins - cols"
required
error={colsEmptyError}
disabled={state.convert.kle.option === 2 ? true : disabledConvertText }
multiple
autoWidth
value={pinRows}
renderValue={(selected) => (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>
{pinRows.map((v) => ( <Chip key={v} label={v} />))}
</Box>
)}
>
{ state.convert.kle.mcu === 'promicro' ?
state.convert.pins.promicro.map((v) => ( <MenuItem key={v} value={v}>{v}</MenuItem> )) :
state.convert.pins.rp2040.map((v) => ( <MenuItem key={v} value={v}>{v}</MenuItem> ))
}
</Select>
</FormControl>
</Box>
<Box>
<FormControl sx={{ m: 1, minWidth: 800 }}>
<InputLabel id="convert-kle-cols-label">matrix pins - cols</InputLabel>
<Select
labelId="convert-kle-cols-label"
id="convert-kle-cols"
label="matrix pins - cols"
onChange={handleTextChange("cols")}
variant="standard"
value={state.convert.kle.cols}
/>
{colStrError && ValidRowColTextField}
</Box>
<Box>
<TextField
id="pin"
label="e.g."
variant="standard"
value={state.convert.kle.mcu === "RP2040" ? "GP0,GP1,GP2" : "D0,D1,D2"}
disabled={true}
/>
{colStrError && ValidRowColTextField}
</Box>
error={rowsEmptyError}
disabled={state.convert.kle.option === 2 ? true : disabledConvertText }
required
multiple
autoWidth
value={pinCols}
renderValue={(selected) => (
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 0.5 }}>
{pinCols.map((v) => ( <Chip key={v} label={v} />))}
</Box>
)}
>
{ state.convert.kle.mcu === 'promicro' ?
state.convert.pins.promicro.map((v) => ( <MenuItem key={v} value={v}>{v}</MenuItem> )) :
state.convert.pins.rp2040.map((v) => ( <MenuItem key={v} value={v}>{v}</MenuItem> ))
}
</Select>
</FormControl>
</Box>
</Box>
<Box
Expand Down
2 changes: 1 addition & 1 deletion src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const theme = createTheme({
})

export const buildBoxHeight = "230px"
export const convertBoxHeight = "690px"
export const convertBoxHeight = "820px"

export const inputLabelSmallFontSize = "12px"
export const inputLabelMiddleFontSize = "16px"
Expand Down

0 comments on commit 865b20a

Please sign in to comment.