This repository was archived by the owner on Dec 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
WIP: shim design example #180
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
806576b
shim design example
andreamah deceeb7
some effort on image object design
andreamah 8ed9e5b
initial look at image class
andreamah 32060ce
fixes to image
andreamah ef6498c
finished first draft of most image methods
andreamah d2a7672
width and height modifications
andreamah 16beee3
more additions to image
andreamah 52ba07e
display microbit library
91352a0
resolve merge conflicts
cc0ac13
update dusplay
c761e8b
integrated image into display class
andreamah 4cbda2b
fixed LED array reference issue
andreamah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,135 +1,136 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| const gulp = require("gulp"); | ||
|
|
||
| const ts = require("gulp-typescript"); | ||
| const sourcemaps = require("gulp-sourcemaps"); | ||
| const typescript = require("typescript"); | ||
| const del = require("del"); | ||
| const es = require("event-stream"); | ||
| const vsce = require("vsce"); | ||
| const nls = require("vscode-nls-dev"); | ||
|
|
||
| const tsProject = ts.createProject("./tsconfig.json", { typescript }); | ||
|
|
||
| const inlineMap = true; | ||
| const inlineSource = false; | ||
| const outDest = "out"; | ||
|
|
||
| // A list of all locales supported by VSCode can be found here: https://code.visualstudio.com/docs/getstarted/locales | ||
| const languages = [{ folderName: "en", id: "en" }]; | ||
|
|
||
| gulp.task("clean", () => { | ||
| return del( | ||
| [ | ||
| "out/*", | ||
| "package.nls.*.json", | ||
| "../../dist/*0.0.0-UNTRACKEDVERSION.vsix" | ||
| ], | ||
| { force: true } | ||
| ); | ||
| }); | ||
|
|
||
| const pythonToMove = [ | ||
| "./src/adafruit_circuitplayground/*.*", | ||
| "./src/*.py", | ||
| "./src/requirements.txt", | ||
| ]; | ||
|
|
||
| gulp.task("python-compile", () => { | ||
| // the base option sets the relative root for the set of files, | ||
| // preserving the folder structure | ||
| return gulp.src(pythonToMove, { base: "./src/" }).pipe(gulp.dest("out")); | ||
| }); | ||
|
|
||
| gulp.task("internal-compile", () => { | ||
| return compile(false); | ||
| }); | ||
|
|
||
| gulp.task("internal-nls-compile", () => { | ||
| return compile(true); | ||
| }); | ||
|
|
||
| gulp.task("add-locales", () => { | ||
| return gulp | ||
| .src(["package.nls.json"]) | ||
| .pipe(nls.createAdditionalLanguageFiles(languages, "locales")) | ||
| .pipe(gulp.dest(".")); | ||
| }); | ||
|
|
||
| gulp.task("vsce:publish", () => { | ||
| return vsce.publish(); | ||
| }); | ||
|
|
||
| gulp.task("vsce:package", () => { | ||
| return vsce.createVSIX({ | ||
| packagePath: "../../dist/deviceSimulatorExpress-0.0.0-UNTRACKEDVERSION.vsix" | ||
| }); | ||
| }); | ||
|
|
||
| gulp.task( | ||
| "compile", | ||
| gulp.series("clean", "internal-compile", "python-compile", callback => { | ||
| callback(); | ||
| }) | ||
| ); | ||
|
|
||
| gulp.task( | ||
| "build", | ||
| gulp.series( | ||
| "clean", | ||
| "internal-nls-compile", | ||
| "python-compile", | ||
| "add-locales", | ||
| callback => { | ||
| callback(); | ||
| } | ||
| ) | ||
| ); | ||
|
|
||
| gulp.task( | ||
| "publish", | ||
| gulp.series("compile", "vsce:publish", callback => { | ||
| callback(); | ||
| }) | ||
| ); | ||
|
|
||
| gulp.task( | ||
| "package", | ||
| gulp.series("compile", "vsce:package", callback => { | ||
| callback(); | ||
| }) | ||
| ); | ||
|
|
||
| //---- internal | ||
|
|
||
| function compile(buildNls) { | ||
| var r = tsProject | ||
| .src() | ||
| .pipe(sourcemaps.init()) | ||
| .pipe(tsProject()) | ||
| .js.pipe(buildNls ? nls.rewriteLocalizeCalls() : es.through()) | ||
| .pipe( | ||
| buildNls | ||
| ? nls.createAdditionalLanguageFiles(languages, "locales", "out") | ||
| : es.through() | ||
| ); | ||
|
|
||
| if (inlineMap && inlineSource) { | ||
| r = r.pipe(sourcemaps.write()); | ||
| } else { | ||
| r = r.pipe( | ||
| sourcemaps.write("../out", { | ||
| // no inlined source | ||
| includeContent: inlineSource, | ||
| // Return relative source map root directories per file. | ||
| sourceRoot: "../src" | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| return r.pipe(gulp.dest(outDest)); | ||
| } | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| const gulp = require("gulp"); | ||
|
|
||
| const ts = require("gulp-typescript"); | ||
| const sourcemaps = require("gulp-sourcemaps"); | ||
| const typescript = require("typescript"); | ||
| const del = require("del"); | ||
| const es = require("event-stream"); | ||
| const vsce = require("vsce"); | ||
| const nls = require("vscode-nls-dev"); | ||
|
|
||
| const tsProject = ts.createProject("./tsconfig.json", { typescript }); | ||
|
|
||
| const inlineMap = true; | ||
| const inlineSource = false; | ||
| const outDest = "out"; | ||
|
|
||
| // A list of all locales supported by VSCode can be found here: https://code.visualstudio.com/docs/getstarted/locales | ||
| const languages = [{ folderName: "en", id: "en" }]; | ||
|
|
||
| gulp.task("clean", () => { | ||
| return del( | ||
| [ | ||
| "out/*", | ||
| "package.nls.*.json", | ||
| "../../dist/*0.0.0-UNTRACKEDVERSION.vsix" | ||
| ], | ||
| { force: true } | ||
| ); | ||
| }); | ||
|
|
||
| const pythonToMove = [ | ||
| "./src/adafruit_circuitplayground/*.*", | ||
| "./src/microbit/*.*", | ||
| "./src/*.py", | ||
| "./src/requirements.txt", | ||
| ]; | ||
|
|
||
| gulp.task("python-compile", () => { | ||
| // the base option sets the relative root for the set of files, | ||
| // preserving the folder structure | ||
| return gulp.src(pythonToMove, { base: "./src/" }).pipe(gulp.dest("out")); | ||
| }); | ||
|
|
||
| gulp.task("internal-compile", () => { | ||
| return compile(false); | ||
| }); | ||
|
|
||
| gulp.task("internal-nls-compile", () => { | ||
| return compile(true); | ||
| }); | ||
|
|
||
| gulp.task("add-locales", () => { | ||
| return gulp | ||
| .src(["package.nls.json"]) | ||
| .pipe(nls.createAdditionalLanguageFiles(languages, "locales")) | ||
| .pipe(gulp.dest(".")); | ||
| }); | ||
|
|
||
| gulp.task("vsce:publish", () => { | ||
| return vsce.publish(); | ||
| }); | ||
|
|
||
| gulp.task("vsce:package", () => { | ||
| return vsce.createVSIX({ | ||
| packagePath: "../../dist/deviceSimulatorExpress-0.0.0-UNTRACKEDVERSION.vsix" | ||
| }); | ||
| }); | ||
|
|
||
| gulp.task( | ||
| "compile", | ||
| gulp.series("clean", "internal-compile", "python-compile", callback => { | ||
| callback(); | ||
| }) | ||
| ); | ||
|
|
||
| gulp.task( | ||
| "build", | ||
| gulp.series( | ||
| "clean", | ||
| "internal-nls-compile", | ||
| "python-compile", | ||
| "add-locales", | ||
| callback => { | ||
| callback(); | ||
| } | ||
| ) | ||
| ); | ||
|
|
||
| gulp.task( | ||
| "publish", | ||
| gulp.series("compile", "vsce:publish", callback => { | ||
| callback(); | ||
| }) | ||
| ); | ||
|
|
||
| gulp.task( | ||
| "package", | ||
| gulp.series("compile", "vsce:package", callback => { | ||
| callback(); | ||
| }) | ||
| ); | ||
|
|
||
| //---- internal | ||
|
|
||
| function compile(buildNls) { | ||
| var r = tsProject | ||
| .src() | ||
| .pipe(sourcemaps.init()) | ||
| .pipe(tsProject()) | ||
| .js.pipe(buildNls ? nls.rewriteLocalizeCalls() : es.through()) | ||
| .pipe( | ||
| buildNls | ||
| ? nls.createAdditionalLanguageFiles(languages, "locales", "out") | ||
| : es.through() | ||
| ); | ||
|
|
||
| if (inlineMap && inlineSource) { | ||
| r = r.pipe(sourcemaps.write()); | ||
| } else { | ||
| r = r.pipe( | ||
| sourcemaps.write("../out", { | ||
| // no inlined source | ||
| includeContent: inlineSource, | ||
| // Return relative source map root directories per file. | ||
| sourceRoot: "../src" | ||
| }) | ||
| ); | ||
| } | ||
|
|
||
| return r.pipe(gulp.dest(outDest)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .code_processing_shim import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| from . import microbit_model | ||
| from . import image | ||
| from . import constants as CONSTANTS | ||
|
|
||
| # EXAMPLE | ||
| # can be called simply as "show_message("string")" | ||
| def show_message(message): | ||
| microbit_model.mb.show_message(message) | ||
|
|
||
|
|
||
| display = microbit_model.mb.display | ||
|
|
||
| microbit = microbit_model.mb | ||
| Image = image.Image | ||
|
|
||
| def repr(image): | ||
|
|
||
| ret_str = "Image(\'" | ||
| for index_y in range(0,image.height()): | ||
| ret_str += row_to_str(image, index_y) | ||
|
|
||
| ret_str = ret_str + "\')" | ||
|
|
||
| return ret_str | ||
|
|
||
|
|
||
| def str(image): | ||
| if type(image) is Image: | ||
| ret_str = "Image(\'\n" | ||
| for index_y in range(0,image.height()): | ||
| ret_str += "\t" + row_to_str(image,index_y) + "\n" | ||
|
|
||
| ret_str = ret_str + "\')" | ||
|
|
||
| return ret_str | ||
| else: | ||
| # if not image, call regular str class | ||
| return image.__str__() | ||
|
|
||
|
|
||
|
|
||
| # method to help with string formation | ||
| def row_to_str(image, y): | ||
| new_str = "" | ||
| for x in range(0, image.width()): | ||
| new_str = new_str + str(image.get_pixel(x, y)) | ||
|
|
||
| new_str = new_str + ":" | ||
|
|
||
| return new_str | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| INDEX_ERR = "index out of bounds" | ||
| BRIGHTNESS_ERR = "brightness out of bounds" | ||
| SAME_SIZE_ERR = "images must be the same size" | ||
| UNSUPPORTED_ADD_TYPE = "unsupported types for __add__:" | ||
| LED_WIDTH = 5 | ||
| LED_HEIGHT = 5 | ||
|
|
||
| NOT_IMPLEMENTED_ERROR = "This method is not implemented by the simulator" | ||
|
|
||
| BOAT = ( | ||
| [0, 5, 0, 5, 0], | ||
| [0, 5, 0, 5, 0], | ||
| [0, 5, 0, 5, 0], | ||
| [9, 9, 9, 9, 9], | ||
| [0, 9, 9, 9, 0], | ||
| ) | ||
|
|
||
| HEART = [ | ||
| [0, 9, 0, 9, 0], | ||
| [9, 9, 9, 9, 9], | ||
| [9, 9, 9, 9, 9], | ||
| [0, 9, 9, 9, 0], | ||
| [0, 0, 9, 0, 0], | ||
| ] | ||
|
|
||
| BLANK = [ | ||
| [0, 0, 0, 0, 0], | ||
| [0, 0, 0, 0, 0], | ||
| [0, 0, 0, 0, 0], | ||
| [0, 0, 0, 0, 0], | ||
| [0, 0, 0, 0, 0], | ||
| ] | ||
|
|
||
|
|
||
| COPY_ERR_MESSAGE = "please copy() first" | ||
|
|
||
| LED_MAX = 5 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's awesome, it was exactly what I was thinking as well :)