diff --git a/package.json b/package.json index 3093381..418a0a5 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,8 @@ "@fortawesome/react-fontawesome": "^0.1.19", "@material-ui/core": "^4.12.4", "@monaco-editor/react": "^4.3.1", - "@sentry/react": "^6.19.7", - "@sentry/tracing": "^6.19.7", - "@testing-library/jest-dom": "^5.16.5", - "@testing-library/react": "^12.1.5", + "@testing-library/jest-dom": "^5.16.1", + "@testing-library/react": "^12.1.2", "@testing-library/user-event": "^7.2.1", "axios": "^0.22.0", "blockly": "^8.0.3", diff --git a/public/media/hardware/senseboxmcumini.png b/public/media/hardware/senseboxmcumini.png new file mode 100644 index 0000000..220caa6 Binary files /dev/null and b/public/media/hardware/senseboxmcumini.png differ diff --git a/src/actions/boardAction.js b/src/actions/boardAction.js new file mode 100644 index 0000000..f78cb82 --- /dev/null +++ b/src/actions/boardAction.js @@ -0,0 +1,10 @@ +import { + BOARD, + } from "./types"; + +export const setBoard = (board) => (dispatch) => { + dispatch({ + type: BOARD, + payload: board, + }); + }; \ No newline at end of file diff --git a/src/actions/types.js b/src/actions/types.js index 84e2580..c67ad2a 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -63,3 +63,6 @@ export const GET_PROJECT = "GET_PROJECT"; export const GET_PROJECTS = "GET_PROJECTS"; export const PROJECT_TYPE = "PROJECT_TYPE"; export const PROJECT_DESCRIPTION = "PROJECT_DESCRIPTION"; + +//board +export const BOARD = "BOARD"; diff --git a/src/components/Blockly/BlocklyWindow.js b/src/components/Blockly/BlocklyWindow.js index 4ff8341..bbab82d 100644 --- a/src/components/Blockly/BlocklyWindow.js +++ b/src/components/Blockly/BlocklyWindow.js @@ -43,8 +43,16 @@ class BlocklyWindow extends Component { componentDidUpdate(props) { const workspace = Blockly.getMainWorkspace(); - var xml = this.props.initialXml; + if (props.selectedBoard !== this.props.selectedBoard) { + // change board + if(!xml) xml = initialXml; + var xmlDom = Blockly.Xml.textToDom(xml); + Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace); + // var toolbox = workspace.getToolbox(); + // workspace.updateToolbox(toolbox.toolboxDef_); + } + // if svg is true, then the update process is done in the BlocklySvg component if (props.initialXml !== xml && !this.props.svg) { // guarantees that the current xml-code (this.props.initialXml) is rendered @@ -55,7 +63,7 @@ class BlocklyWindow extends Component { if (props.language !== this.props.language) { // change language if (!xml) xml = initialXml; - var xmlDom = Blockly.Xml.textToDom(xml); + xmlDom = Blockly.Xml.textToDom(xml); Blockly.Xml.clearWorkspaceAndLoadFromXml(xmlDom, workspace); // var toolbox = workspace.getToolbox(); // workspace.updateToolbox(toolbox.toolboxDef_); @@ -130,12 +138,14 @@ BlocklyWindow.propTypes = { renderer: PropTypes.string.isRequired, sounds: PropTypes.bool.isRequired, language: PropTypes.string.isRequired, + selectedBoard: PropTypes.string.isRequired, }; const mapStateToProps = (state) => ({ renderer: state.general.renderer, sounds: state.general.sounds, language: state.general.language, + selectedBoard: state.board.board, }); export default connect(mapStateToProps, { onChangeWorkspace, clearStats })( diff --git a/src/components/Blockly/blocks/sensebox-led.js b/src/components/Blockly/blocks/sensebox-led.js index 981133e..6810fcb 100644 --- a/src/components/Blockly/blocks/sensebox-led.js +++ b/src/components/Blockly/blocks/sensebox-led.js @@ -45,15 +45,11 @@ Blockly.Blocks['sensebox_rgb_led'] = { Blockly.Blocks['sensebox_ws2818_led_init'] = { init: function () { - - var dropdownOptions = [[Blockly.Msg.senseBox_ultrasonic_port_A, '1'], - [Blockly.Msg.senseBox_ultrasonic_port_B, '3'], [Blockly.Msg.senseBox_ultrasonic_port_C, '5']]; - this.setColour(getColour().sensebox); this.appendDummyInput() .appendField(Blockly.Msg.senseBox_ws2818_rgb_led_init) .appendField("Port:") - .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port") + .appendField(new Blockly.FieldDropdown(selectedBoard().digitalPinsRGB), "Port") this.appendValueInput("BRIGHTNESS", "brightness") .appendField((Blockly.Msg.senseBox_ws2818_rgb_led_brightness)); this.appendValueInput("NUMBER", "number") @@ -66,15 +62,11 @@ Blockly.Blocks['sensebox_ws2818_led_init'] = { Blockly.Blocks['sensebox_ws2818_led'] = { init: function () { - - var dropdownOptions = [[Blockly.Msg.senseBox_ultrasonic_port_A, '1'], - [Blockly.Msg.senseBox_ultrasonic_port_B, '3'], [Blockly.Msg.senseBox_ultrasonic_port_C, '5']]; - this.setColour(getColour().sensebox); this.appendDummyInput() .appendField(Blockly.Msg.senseBox_ws2818_rgb_led) .appendField("Port:") - .appendField(new Blockly.FieldDropdown(dropdownOptions), "Port") + .appendField(new Blockly.FieldDropdown(selectedBoard().digitalPinsRGB), "Port") this.appendValueInput("POSITION", "position") .appendField((Blockly.Msg.senseBox_ws2818_rgb_led_position)); this.appendValueInput("COLOR", 'Number') diff --git a/src/components/Blockly/blocks/sensebox-sensors.js b/src/components/Blockly/blocks/sensebox-sensors.js index 145a5e1..12929a7 100644 --- a/src/components/Blockly/blocks/sensebox-sensors.js +++ b/src/components/Blockly/blocks/sensebox-sensors.js @@ -114,10 +114,8 @@ Blockly.Blocks["sensebox_sensor_sds011"] = { ) .appendField(Blockly.Msg.senseBox_sds011_dimension) .appendField( - new Blockly.FieldDropdown([ - [Blockly.Msg.senseBox_sds011_serial1, "Serial1"], - [Blockly.Msg.senseBox_sds011_serial2, "Serial2"], - ]), + new Blockly.FieldDropdown( + selectedBoard().serial), "SERIAL" ); this.setOutput(true, Types.DECIMAL.typeName); diff --git a/src/components/Blockly/generator/sensebox-ble.js b/src/components/Blockly/generator/sensebox-ble.js index bd6ddd7..34a3a21 100644 --- a/src/components/Blockly/generator/sensebox-ble.js +++ b/src/components/Blockly/generator/sensebox-ble.js @@ -101,7 +101,6 @@ Blockly.Arduino.sensebox_phyphox_graph = function () { Blockly.Arduino.sensebox_phyphox_experiment_send = function () { var branch = Blockly.Arduino.statementToCode(this, "sendValues"); var blocks = this.getDescendants(); - console.log(blocks); var count = 0; if (blocks !== undefined) { for (var i = 0; i < blocks.length; i++) { @@ -115,7 +114,6 @@ Blockly.Arduino.sensebox_phyphox_experiment_send = function () { var string = ""; for (var j = 1; j <= count; j++) { - console.log("append"); if (string === "") { string += `channel${j}`; } else if (string !== "") { diff --git a/src/components/Blockly/generator/sensebox-sd.js b/src/components/Blockly/generator/sensebox-sd.js index ab54e47..419b76a 100644 --- a/src/components/Blockly/generator/sensebox-sd.js +++ b/src/components/Blockly/generator/sensebox-sd.js @@ -203,6 +203,5 @@ Blockly.Arduino.sensebox_sd_save_for_osem = function (block) { Blockly.Arduino.definitions_["SENSOR_ID" + id + ""] = "const char SENSOR_ID" + id + '[] PROGMEM = "' + sensor_id + '";'; code += "addMeasurement(SENSOR_ID" + id + "," + sensor_value + ");\n"; - console.log(code); return code; }; diff --git a/src/components/Blockly/generator/sensebox-web.js b/src/components/Blockly/generator/sensebox-web.js index a2cae3b..3d94af1 100644 --- a/src/components/Blockly/generator/sensebox-web.js +++ b/src/components/Blockly/generator/sensebox-web.js @@ -1,4 +1,12 @@ import Blockly from "blockly"; +//import store from "../../../store"; + +// preperations for the esp board +// var selectedBoard = store.getState().board.board; +// store.subscribe(() => { +// selectedBoard = store.getState().board.board; +// }); + /* Wifi connection and openSenseMap Blocks*/ Blockly.Arduino.sensebox_wifi = function (block) { @@ -110,3 +118,5 @@ Blockly.Arduino.sensebox_ethernetIp = function () { var code = "Ethernet.localIP()"; return [code, Blockly.Arduino.ORDER_ATOMIC]; }; + + diff --git a/src/components/Blockly/generator/variables.js b/src/components/Blockly/generator/variables.js index 2572b46..e8e4dd4 100644 --- a/src/components/Blockly/generator/variables.js +++ b/src/components/Blockly/generator/variables.js @@ -23,7 +23,6 @@ const setVariableFunction = function (defaultValue) { .getVariableMap() .getAllVariables(); const myVar = allVars.filter((v) => v.name === variableName)[0]; - console.log(myVar); var code = ""; if (myVar !== undefined) { Blockly.Arduino.variables_[variableName + myVar.type] = diff --git a/src/components/Blockly/helpers/board.js b/src/components/Blockly/helpers/board.js index 16e0165..12dd18d 100644 --- a/src/components/Blockly/helpers/board.js +++ b/src/components/Blockly/helpers/board.js @@ -23,6 +23,11 @@ const sensebox_mcu = { ["C5", "5"], ["C6", "6"], ], + digitalPinsRGB: [ + ["A", "1"], + ["B", "3"], + ["C", "5"], + ], digitalPinsButton: [ ["on Board", "0"], ["A1", "1"], @@ -126,6 +131,124 @@ const sensebox_mcu = { parseKey: "_*_", }; -export const selectedBoard = () => { - return sensebox_mcu; +//senseBox MCU mini +const sensebox_mini = { + description: "senseBox Mini", + compilerFlag: "arduino:samd", + digitalPins: [ + ["IO1", "1"], + ["IO2", "2"], + ], + digitalPinsLED: [ + ["BUILTIN_1", "7"], + ["BUILTIN_2", "8"], + ["IO1", "1"], + ["IO2", "2"], + ], + digitalPinsRGB: [ + ["on Board", "6"], + ["IO1", "1"], + ["IO2", "2"], + ], + digitalPinsButton: [ + ["on Board", "0"], + ["IO1", "1"], + ["IO2", "2"], + + ], + pwmPins: [ + ["IO1", "1"], + ["IO2", "2"], + ], + serial: [ + ["serial", "SerialUSB"], + ["serial_1", "Serial1"], + ], + serialPins: { + SerialUSB: [ + ["RX", ""], + ["TX", ""], + ], + Serial1: [ + ["RX", "11"], + ["TX", "10"], + ], + Serial2: [ + ["RX", "13"], + ["TX", "12"], + ], + }, + serialSpeed: [ + ["300", "300"], + ["600", "600"], + ["1200", "1200"], + ["2400", "2400"], + ["4800", "4800"], + ["9600", "9600"], + ["14400", "14400"], + ["19200", "19200"], + ["28800", "28800"], + ["31250", "31250"], + ["38400", "38400"], + ["57600", "57600"], + ["115200", "115200"], + ], + spi: [["SPI", "SPI"]], + spiPins: { + SPI: [ + ["MOSI", "19"], + ["MISO", "21"], + ["SCK", "20"], + ], + }, + spiClockDivide: [ + ["2 (8MHz)", "SPI_CLOCK_DIV2"], + ["4 (4MHz)", "SPI_CLOCK_DIV4"], + ["8 (2MHz)", "SPI_CLOCK_DIV8"], + ["16 (1MHz)", "SPI_CLOCK_DIV16"], + ["32 (500KHz)", "SPI_CLOCK_DIV32"], + ["64 (250KHz)", "SPI_CLOCK_DIV64"], + ["128 (125KHz)", "SPI_CLOCK_DIV128"], + ], + i2c: [["I2C", "Wire"]], + i2cPins: { + Wire: [ + ["SDA", "17"], + ["SCL", "16"], + ], + }, + i2cSpeed: [ + ["100kHz", "100000L"], + ["400kHz", "400000L"], + ], + builtinLed: [ + ["BUILTIN_1", "7"], + ["BUILTIN_2", "8"], + ], + interrupt: [ + ["interrupt1", "1"], + ["interrupt2", "2"], + ], + analogPins: [ + ["A1", "A1"], + ["A2", "A2"], + ], + serial_baud_rate: 9600, + parseKey: "_*_", +}; + +var board = sensebox_mcu + +export const setBoard = (selectedBoard) => { + if (selectedBoard === "mini"){ + board = sensebox_mini + } + else { + board = sensebox_mcu + } +} + + +export const selectedBoard = () => { + return board; }; diff --git a/src/components/Blockly/msg/de/ui.js b/src/components/Blockly/msg/de/ui.js index 904adad..85afe5e 100644 --- a/src/components/Blockly/msg/de/ui.js +++ b/src/components/Blockly/msg/de/ui.js @@ -141,6 +141,7 @@ export const UI = { button_cancel: "Abbrechen", button_close: "Schließen", + button_save: "Speichern", button_accept: "Bestätigen", button_compile: "Kompilieren", button_create_variableCreate: "Erstelle Variable", @@ -181,7 +182,8 @@ export const UI = { settings_sounds: "Töne", settings_sounds_text: "Aktiviere oder Deaktiviere Töne beim hinzufügen und löschen von Blöcken. Standardmäßig deaktiviert", - + settings_board: "Board", + settings_board_text: "Wähle dein verwendetes Board aus", /** * 404 */ @@ -301,4 +303,12 @@ export const UI = { codeeditor_blockly_code: "Lade Blockly Code", codeeditor_compile_progress: "Dein Code wird nun kompiliert und anschließend auf deinen Computer heruntergeladen", + + /** + * Device Selction + * */ + deviceselection_head: "Welches Board benutzt du?", + deviceselection_keep_selection: "Speichere meine Auswahl fürs nächste Mal (Du kannst das Board später in den Einstellungen wechseln)", + deviceselection_footnote: "Hier kommst du zur alten Blockly Version für den ", + deviceselection_footnote_02: "oder die" }; diff --git a/src/components/Blockly/msg/en/ui.js b/src/components/Blockly/msg/en/ui.js index fc49196..152042c 100644 --- a/src/components/Blockly/msg/en/ui.js +++ b/src/components/Blockly/msg/en/ui.js @@ -176,6 +176,8 @@ export const UI = { settings_sounds: "Sound", settings_sounds_text: "Enable or disable sounds when adding and deleting blocks. Disabled by default", + settings_board: "Board", + settings_board_text: "Choose your board", /** * 404 @@ -296,4 +298,14 @@ export const UI = { codeeditor_blockly_code: "Load blockly code", codeeditor_compile_progress: "Your code will now be compiled and then downloaded to your computer", + + /** + * Device Selction + * */ + deviceselection_head: "Which board are you using?", + deviceselection_keep_selection: "Save my choice (You can change the board later in the settings)", + deviceselection_footnote: "Here you can access the old blockly Version for the", + deviceselection_footnote_02: "or the", + + }; diff --git a/src/components/CodeEditor/CodeEditor.js b/src/components/CodeEditor/CodeEditor.js index dba6bdb..08e40f5 100644 --- a/src/components/CodeEditor/CodeEditor.js +++ b/src/components/CodeEditor/CodeEditor.js @@ -38,7 +38,6 @@ const CodeEditor = (props) => { }) .then((response) => response.json()) .then((data) => { - console.log(data); if (data.code === "Internal Server Error") { setProgress(false); setOpen(true); diff --git a/src/components/CodeEditor/Compile.js b/src/components/CodeEditor/Compile.js index b3d477e..26a9d4b 100644 --- a/src/components/CodeEditor/Compile.js +++ b/src/components/CodeEditor/Compile.js @@ -89,7 +89,6 @@ class Compile extends Component { }) .then((response) => response.json()) .then((data) => { - console.log(data); if (data.code === "Internal Server Error") { this.setState({ progress: false, diff --git a/src/components/CodeEditor/SerialMonitor.js b/src/components/CodeEditor/SerialMonitor.js index b40f10b..0636301 100644 --- a/src/components/CodeEditor/SerialMonitor.js +++ b/src/components/CodeEditor/SerialMonitor.js @@ -27,7 +27,6 @@ const SerialMonitor = () => { if (value) { // byte array to string: https://stackoverflow.com/a/37542820 const text = String.fromCharCode.apply(null, value); - console.log(text); setSerialPortContent((prevContent) => [ ...prevContent, [new Date(), text], diff --git a/src/components/Content.js b/src/components/Content.js index f4b7bef..a0a8d7a 100644 --- a/src/components/Content.js +++ b/src/components/Content.js @@ -10,6 +10,7 @@ import Navbar from './Navbar'; import Footer from './Footer'; import Routes from './Route/Routes'; import Cookies from './Cookies'; +import { setBoard } from './Blockly/helpers/board'; class Content extends Component { @@ -19,6 +20,7 @@ class Content extends Component { } else if (this.props.language === 'en_US') { Blockly.setLocale(En); } + setBoard(this.props.board) } componentDidUpdate(props) { @@ -29,6 +31,7 @@ class Content extends Component { Blockly.setLocale(En); } } + setBoard(this.props.board) } render() { @@ -48,7 +51,8 @@ Content.propTypes = { }; const mapStateToProps = state => ({ - language: state.general.language + language: state.general.language, + board: state.board.board }); export default connect(mapStateToProps, null)(Content); diff --git a/src/components/DeviceSelection.js b/src/components/DeviceSelection.js new file mode 100644 index 0000000..0ed7dbe --- /dev/null +++ b/src/components/DeviceSelection.js @@ -0,0 +1,162 @@ +import React, { Component } from "react"; +import PropTypes from "prop-types"; +import { connect } from "react-redux"; +import Dialog from "./Dialog"; + +import { withStyles } from "@material-ui/core/styles"; +import Checkbox from "@material-ui/core/Checkbox"; +import FormControlLabel from "@material-ui/core/FormControlLabel"; +import * as Blockly from "blockly"; +import { IconButton, Grid, Avatar, Typography } from "@material-ui/core"; +import { setBoard } from "../actions/boardAction"; + +const styles = (theme) => ({ + link: { + color: theme.palette.primary.main, + textDecoration: "none", + "&:hover": { + color: theme.palette.primary.main, + textDecoration: `underline`, + }, + }, + label: { + fontSize: "0.9rem", + color: "grey", + }, +}); + +class DeviceSeclection extends Component { + constructor(props) { + var previousPageWasAnotherDomain = props.pageVisits === 0; + var userWantToKeepBoard = window.localStorage.getItem("board") + ? true + : false; + super(props); + this.state = { + open: userWantToKeepBoard + ? !userWantToKeepBoard + : previousPageWasAnotherDomain, + selectedBoard : "", + saveSettings: false, + + }; + } + + toggleDialog = () => { + this.setState({ open: !this.state }); + if(this.state.saveSettings){ + window.localStorage.setItem("board", this.state.selectedBoard) + } + this.props.setBoard(this.state.selectedBoard) + + }; + + onChange = (e) => { + if (e.target.checked) { + this.setState({ saveSettings: true}); + } else { + this.setState({ saveSettings: false}); + } + }; + + onclick = (e, value) => { + console.log(e, value) + this.setState({selectedBoard: value}) + }; + + render() { + return ( + +
+ + + this.onclick(e, "mcu")}> + + +

senseBox MCU

+
+ + {/* + this.onclick(e, "esp")}> + + +

Sensebox ESP

+
*/} + + this.onclick(e, "mini")}> + + +

senseBox MCU:mini

+
+
+
+ this.onChange(e)} + name="dialog" + color="primary" + /> + } + label={Blockly.Msg.deviceselection_keep_selection} + /> + + {Blockly.Msg.deviceselection_footnote} Arduino UNO {Blockly.Msg.deviceselection_footnote_02} senseBox MCU + +
+ ); + } +} + +DeviceSeclection.propTypes = { + pageVisits: PropTypes.number.isRequired, +}; + +const mapStateToProps = (state) => ({ + pageVisits: state.general.pageVisits, + selectedBoard: state.board.board +}); + +export default connect( + mapStateToProps, + {setBoard} +)(withStyles(styles, { withTheme: true })(DeviceSeclection)); diff --git a/src/components/Dialog.js b/src/components/Dialog.js index 0dc7180..41d8aae 100644 --- a/src/components/Dialog.js +++ b/src/components/Dialog.js @@ -24,7 +24,7 @@ class Dialog extends Component { {this.props.actions ? this.props.actions : - } diff --git a/src/components/Home.js b/src/components/Home.js index a4c05d8..6904184 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -12,6 +12,7 @@ import BlocklyWindow from "./Blockly/BlocklyWindow"; import CodeViewer from "./CodeViewer"; import TrashcanButtons from "./Workspace/TrashcanButtons"; import HintTutorialExists from "./Tutorial/HintTutorialExists"; +import DeviceSelection from "./DeviceSelection"; import Grid from "@material-ui/core/Grid"; import IconButton from "@material-ui/core/IconButton"; @@ -186,6 +187,7 @@ class Home extends Component { ) : null} + {this.props.platform ? ( + {Blockly.Msg.settings_board} + {Blockly.Msg.settings_board_text} + + {Blockly.Msg.settings_board} + + + + ); + } +} + +DeviceSelector.propTypes = { + setBoard: PropTypes.func.isRequired, + selectedBoard: PropTypes.string.isRequired +}; + +const mapStateToProps = state => ({ + selectedBoard: state.board.board +}); + +export default connect(mapStateToProps, { setBoard })(DeviceSelector); diff --git a/src/components/Settings/Settings.js b/src/components/Settings/Settings.js index ad1dde6..a0f9361 100644 --- a/src/components/Settings/Settings.js +++ b/src/components/Settings/Settings.js @@ -12,6 +12,7 @@ import RenderSelector from "./RenderSelector"; import StatsSelector from "./StatsSelector"; import OtaSelector from "./OtaSelector"; import SoundsSelector from "./SoundsSelector"; +import DeviceSelector from "./DeviceSelector"; import Button from "@material-ui/core/Button"; import Paper from "@material-ui/core/Paper"; @@ -52,6 +53,9 @@ class Settings extends Component { + + +