diff --git a/src/api/hardware-keyboardio-preonic/components/Keymap.js b/src/api/hardware-keyboardio-preonic/components/Keymap.js new file mode 100644 index 000000000..85022d23a --- /dev/null +++ b/src/api/hardware-keyboardio-preonic/components/Keymap.js @@ -0,0 +1,188 @@ +// -*- mode: js-jsx -*- +/* chrysalis-hardware-keyboardio-preonic -- Chrysalis Preonic support + * Copyright (C) 2019-2022 Keyboardio, Inc. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import KeymapDB from "@api/focus/keymap/db"; +import React from "react"; +import Preonic from "../data/preonic.png"; + +const db = new KeymapDB(); + +const Keymap = (props) => { + const keymap = + props.keymap || + Array(60) + .fill() + .map(() => 0); + const KeySpacingY = 54; + const keySpacingX = 54; + const colOffsetY = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + const colOffsetX = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + const rowOffsetX = [0, 0, 0, 0]; + const layer = props.index; + const onKeySelect = props.onKeySelect; + + const getKey = (row, col) => { + if (!props.keymap) return null; + const keyIndex = parseInt(row) * 12 + parseInt(col), + key = keymap[keyIndex]; + return key; + }; + + const isActive = (row, col) => { + const keyIndex = parseInt(row) * 12 + parseInt(col); + return props.selectedKey == keyIndex; + }; + + const getX = (row, col) => { + return rowOffsetX[row] + keySpacingX * col + colOffsetX[col]; + }; + + const getY = (row, col) => { + return colOffsetY[col] + KeySpacingY * row; + }; + + const Key = (props) => { + const { row, col } = props; + const x = getX(row, col), + y = getY(row, col), + active = isActive(row, col), + key = getKey(row, col), + onClick = onKeySelect; + const keyIndex = parseInt(row) * 12 + parseInt(col); + const strokeColor = "transparent" || "#b3b3b3"; + const stroke = active ? "#f3b3b3" : strokeColor; + const height = props.height || 44; + const width = props.width || 44; + const bottom = y + height - 5; + /* + const textColor = "#000000"; + const buttonColor = "#ffffff"; + */ + + let textColor = "#ffffff"; + const buttonColor = "transparent"; + let legendClass = ""; + let mainLegendClass = ""; + const legend = key && db.format(key, { layerNames: props.layerNames }); + if (key && (legend.main || "").length <= 1 && !legend.hint) legendClass = "short-legend"; + if (key && (legend.main || "").length <= 1) mainLegendClass = "short-legend"; + if (key && key.code == 0) textColor = "#888888"; + return ( + + + + {legend?.hint} + + + {legend?.main} + + + ); + }; + + const { classes, maxHeight } = props; + return ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; + +export default Keymap; diff --git a/src/api/hardware-keyboardio-preonic/data/atreus.png b/src/api/hardware-keyboardio-preonic/data/atreus.png new file mode 100644 index 000000000..ea6d60984 Binary files /dev/null and b/src/api/hardware-keyboardio-preonic/data/atreus.png differ diff --git a/src/api/hardware-keyboardio-preonic/data/preonic.png b/src/api/hardware-keyboardio-preonic/data/preonic.png new file mode 100644 index 000000000..1559a1034 Binary files /dev/null and b/src/api/hardware-keyboardio-preonic/data/preonic.png differ diff --git a/src/api/hardware-keyboardio-preonic/index.js b/src/api/hardware-keyboardio-preonic/index.js new file mode 100644 index 000000000..c3705ac4d --- /dev/null +++ b/src/api/hardware-keyboardio-preonic/index.js @@ -0,0 +1,57 @@ +/* chrysalis-hardware-keyboardio-atreus2 -- Chrysalis Preonic support + * Copyright (C) 2019-2022 Keyboardio, Inc. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +import Keymap from "./components/Keymap"; + +const Preonic = { + info: { + vendor: "Keyboardio", + product: "Preonic", + displayName: "Keyboardio Preonic", + urls: [ + { + name: "Homepage", + url: "https://shop.keyboard.io/products/keyboardio-atreus", + }, + { + name: "Forum", + url: "https://community.keyboard.io/", + }, + { + name: "Chat", + url: "https://keyboard.io/discord-invite", + }, + ], + }, + usb: { + vendorId: 0x1209, + productId: 0x2303, + bootloader: { + vendorId: 0x1209, + productId: 0x2302, + protocol: "avr109", + }, + }, + keyboard: { + rows: 4, + columns: 12, + }, + components: { + keymap: Keymap, + }, +}; + +export { Preonic };