diff --git a/.gitignore b/.gitignore index c2b7c44c..de5cca02 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,13 @@ build.properties ################# -## NetBeans +## Blockly Files ################# +# /src/main/**/logback.xml +################# +## NetBeans +################# nb-configuration.xml nbactions.xml target/ @@ -15,7 +19,7 @@ BlocklyProp.iml ################# .idea - +*.iml ################# ## Eclipse diff --git a/pom.xml b/pom.xml index ba680415..97a77be5 100644 --- a/pom.xml +++ b/pom.xml @@ -238,11 +238,25 @@ slf4j-api 1.7.21 + + + ch.qos.logback + logback-classic + 1.1.8 + + + ch.qos.logback + logback-core + 1.1.8 + + + @@ -382,15 +396,15 @@ - net.kencochrane.raven + com.getsentry.raven raven - 6.0.0 + 7.8.1 - net.kencochrane.raven - raven-log4j - 6.0.0 + com.getsentry.raven + raven-logback + 7.8.1 @@ -439,12 +453,19 @@ ${metrics-version} + + io.dropwizard.metrics + metrics-logback + 3.1.2 + + + io.dropwizard.metrics metrics-servlet @@ -517,5 +538,4 @@ --> - \ No newline at end of file diff --git a/src/main/config/default/log4j.xml b/src/main/config/default/log4j.xml deleted file mode 100644 index 7edfdbe0..00000000 --- a/src/main/config/default/log4j.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/java/com/parallax/server/blocklyprop/config/DaoModule.java b/src/main/java/com/parallax/server/blocklyprop/config/DaoModule.java index 6d6bd6ad..bd1f3dde 100644 --- a/src/main/java/com/parallax/server/blocklyprop/config/DaoModule.java +++ b/src/main/java/com/parallax/server/blocklyprop/config/DaoModule.java @@ -15,9 +15,26 @@ import com.parallax.server.blocklyprop.db.dao.impl.SessionDaoImpl; import com.parallax.server.blocklyprop.db.dao.impl.UserDaoImpl; + /** * * @author Michel + * + * AbstractModule: + * A support class for Modules which reduces repetition and results in a more + * readable configuration. Simply extend this class, implement configure(), + * and call the inherited methods which mirror those found in Binder. + * For example: + * + * public class MyModule extends AbstractModule { + * protected void configure() { + * bind(Service.class).to(ServiceImpl.class).in(Singleton.class); + * bind(CreditCardPaymentService.class); + * bind(PaymentService.class).to(CreditCardPaymentService.class); + * bindConstant().annotatedWith(Names.named("port")).to(8080); + * } + * } + * */ public class DaoModule extends AbstractModule { diff --git a/src/main/java/com/parallax/server/blocklyprop/config/PersistenceModule.java b/src/main/java/com/parallax/server/blocklyprop/config/PersistenceModule.java index 5fae250d..5311fe62 100644 --- a/src/main/java/com/parallax/server/blocklyprop/config/PersistenceModule.java +++ b/src/main/java/com/parallax/server/blocklyprop/config/PersistenceModule.java @@ -10,12 +10,13 @@ import com.google.inject.Provides; import com.parallax.server.blocklyprop.db.utils.DataSourceSetup; import java.sql.SQLException; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.sql.DataSource; import org.apache.commons.configuration.Configuration; import org.apache.commons.dbcp2.PoolingDataSource; import org.jooq.SQLDialect; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * @@ -37,6 +38,7 @@ protected void configure() { @Provides PoolingDataSource dataSource() throws ClassNotFoundException { + PoolingDataSource ds = DataSourceSetup.connect(configuration); try { ds.getConnection(); diff --git a/src/main/java/com/parallax/server/blocklyprop/config/SetupConfig.java b/src/main/java/com/parallax/server/blocklyprop/config/SetupConfig.java index b305c0f5..9cc46b07 100644 --- a/src/main/java/com/parallax/server/blocklyprop/config/SetupConfig.java +++ b/src/main/java/com/parallax/server/blocklyprop/config/SetupConfig.java @@ -21,6 +21,10 @@ import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.DefaultConfigurationBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import ch.qos.logback.classic.LoggerContext; + /** * @@ -29,6 +33,7 @@ public class SetupConfig extends GuiceServletContextListener { private Configuration configuration; + private final Logger LOG = LoggerFactory.getLogger(SetupConfig.class); @Override protected Injector getInjector() { @@ -60,15 +65,21 @@ protected void configure() { ); } + /* + * The application configuration is stored in the blocklyprop.properties + * file in user home directory. The config.xml contains the actual file + * name of the configuation file. If the file is not found, the app will + * use a set of default values. + */ private void readConfiguration() { try { - System.out.println("Looking for blocklyprop.properties in: " + System.getProperty("user.home")); + LOG.info("Looking for blocklyprop.properties in: {}", System.getProperty("user.home")); DefaultConfigurationBuilder configurationBuilder = new DefaultConfigurationBuilder(getClass().getResource("/config.xml")); configuration = configurationBuilder.getConfiguration(); } catch (ConfigurationException ce) { - ce.printStackTrace(); + LOG.error("{}", ce.getMessage()); } catch (Throwable t) { - t.printStackTrace(); + LOG.error(t.getMessage()); } } @@ -81,12 +92,20 @@ public void contextDestroyed(ServletContextEvent servletContextEvent) { Driver driver = drivers.nextElement(); try { DriverManager.deregisterDriver(driver); - // LOG.log(Level.INFO, String.format("deregistering jdbc driver: %s", driver)); + LOG.info("deregistering jdbc driver: {}",driver); } catch (SQLException sqlE) { - // LOG.log(Level.SEVERE, String.format("Error deregistering driver %s", driver), e); + LOG.error("Error deregistering driver %s", driver); + LOG.error("{}", sqlE.getSQLState()); } } + + // Shut down the loggers. Assume SLF4J is bound to logback-classic + // in the current environment + LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory(); + if (loggerContext != null) { + loggerContext.stop(); + } } } diff --git a/src/main/java/com/parallax/server/blocklyprop/converter/ProjectConverter.java b/src/main/java/com/parallax/server/blocklyprop/converter/ProjectConverter.java index 55ec6d4e..5df14e9a 100644 --- a/src/main/java/com/parallax/server/blocklyprop/converter/ProjectConverter.java +++ b/src/main/java/com/parallax/server/blocklyprop/converter/ProjectConverter.java @@ -107,7 +107,6 @@ public JsonObject toJson(ProjectRecord project) { } } - System.out.println("project to json" + result.get("name").getAsString()); return result; } diff --git a/src/main/java/com/parallax/server/blocklyprop/db/dao/ProjectDao.java b/src/main/java/com/parallax/server/blocklyprop/db/dao/ProjectDao.java index 7e46d0b3..60334cc7 100644 --- a/src/main/java/com/parallax/server/blocklyprop/db/dao/ProjectDao.java +++ b/src/main/java/com/parallax/server/blocklyprop/db/dao/ProjectDao.java @@ -73,10 +73,19 @@ List getSharedProjects( Integer offset, Long idUser); + List getSharedProjectsByUser( + TableSort sort, + TableOrder order, + Integer limit, + Integer offset, + Long idUser); + int countUserProjects(Long idUser); int countSharedProjects(Long idUser); + int countSharedProjectsByUser(Long idUser); + ProjectRecord cloneProject(Long idProject); boolean deleteProject(Long idProject); diff --git a/src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java b/src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java index 481f90e3..3f46d017 100644 --- a/src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java +++ b/src/main/java/com/parallax/server/blocklyprop/db/dao/impl/ProjectDaoImpl.java @@ -20,14 +20,18 @@ import org.jooq.Condition; import org.jooq.DSLContext; import org.jooq.SortField; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * * @author Michel + * + * TODO: add details. */ @Singleton public class ProjectDaoImpl implements ProjectDao { - + private static final Logger LOG = LoggerFactory.getLogger(ProjectDao.class); private DSLContext create; @Inject @@ -35,122 +39,244 @@ public void setDSLContext(DSLContext dsl) { this.create = dsl; } - private ProjectRecord alterReadRecord(ProjectRecord record) { - - String newCode = record.getCode(); - if (record.getType() == ProjectType.SPIN) { - newCode = newCode.replaceAll("block type=\"controls_if\"", "block type=\"controls_boolean_if\""); - newCode = newCode.replaceAll("block type=\"logic_compare\"", "block type=\"logic_boolean_compare\""); - newCode = newCode.replaceAll("block type=\"logic_operation\"", "block type=\"logic_boolean_operation\""); - newCode = newCode.replaceAll("block type=\"logic_negate\"", "block type=\"logic_boolean_negate\""); - newCode = newCode.replaceAll("block type=\"math_number\"", "block type=\"spin_integer\""); - - } else if (record.getType() == ProjectType.PROPC){ - newCode = newCode.replaceAll("field name=\"OP\">ADD + MINUS - MULTIPLY * DIVIDE / MODULUS % AND && AND_NOT && !LT<GT>LTE<=GTE>=EQ==NEQ!=INCHES_inchesCM_cm getUserProjects(Long idUser, TableSort sort, TableOrder order, Integer limit, Integer offset) { + LOG.info("Retreive projects for user {}.", idUser); + SortField orderField = Tables.PROJECT.NAME.asc(); if (TableOrder.desc == order) { orderField = Tables.PROJECT.NAME.desc(); } - return create.selectFrom(Tables.PROJECT).where(Tables.PROJECT.ID_USER.equal(idUser)).orderBy(orderField).limit(limit).offset(offset).fetch(); + + return create.selectFrom(Tables.PROJECT) + .where(Tables.PROJECT.ID_USER.equal(idUser)) + .orderBy(orderField).limit(limit).offset(offset) + .fetch(); } + /** + * TODO: add details. + * + * @param sort + * @param order + * @param limit + * @param offset + * @param idUser + * @return + */ @Override public List getSharedProjects(TableSort sort, TableOrder order, Integer limit, Integer offset, Long idUser) { + LOG.info("Retreive shared projects."); + SortField orderField = sort == null ? Tables.PROJECT.NAME.asc() : sort.getField().asc(); if (TableOrder.desc == order) { orderField = sort == null ? Tables.PROJECT.NAME.desc() : sort.getField().desc(); @@ -200,16 +371,64 @@ public List getSharedProjects(TableSort sort, TableOrder order, I if (idUser != null) { conditions = conditions.or(Tables.PROJECT.ID_USER.eq(idUser)); } - return create.selectFrom(Tables.PROJECT).where(conditions).orderBy(orderField).limit(limit).offset(offset).fetch(); + return create.selectFrom(Tables.PROJECT) + .where(conditions) + .orderBy(orderField).limit(limit).offset(offset) + .fetch(); } + /** + * TODO: add details. + * + * @param sort + * @param order + * @param limit + * @param offset + * @param idUser + * @return + */ + @Override + public List getSharedProjectsByUser(TableSort sort, TableOrder order, Integer limit, Integer offset, Long idUser) { + LOG.info("Retreive shared projects."); + + SortField orderField = sort == null ? Tables.PROJECT.NAME.asc() : sort.getField().asc(); + if (TableOrder.desc == order) { + orderField = sort == null ? Tables.PROJECT.NAME.desc() : sort.getField().desc(); + } + Condition conditions = Tables.PROJECT.SHARED.eq(Boolean.TRUE); + if (idUser != null) { + conditions = conditions.and(Tables.PROJECT.ID_USER.eq(idUser)); + } + return create.selectFrom(Tables.PROJECT) + .where(conditions) + .orderBy(orderField).limit(limit).offset(offset) + .fetch(); + } + + /** + * TODO: add details. + * + * @param idUser + * @return + */ @Override public int countUserProjects(Long idUser) { + LOG.info("Count project for user {}.", idUser); + return create.fetchCount(Tables.PROJECT, Tables.PROJECT.ID_USER.equal(idUser)); } + /** + * + * TODO: add details. + * + * @param idUser + * @return + */ @Override public int countSharedProjects(Long idUser) { + LOG.info("Count shared projects for user {}.", idUser); + Condition conditions = Tables.PROJECT.SHARED.equal(Boolean.TRUE); if (idUser != null) { conditions = conditions.or(Tables.PROJECT.ID_USER.eq(idUser)); @@ -217,8 +436,34 @@ public int countSharedProjects(Long idUser) { return create.fetchCount(Tables.PROJECT, conditions); } + /** + * + * TODO: add details. + * + * @param idUser + * @return + */ + @Override + public int countSharedProjectsByUser(Long idUser) { + LOG.info("Count shared projects for user {}.", idUser); + + Condition conditions = Tables.PROJECT.SHARED.equal(Boolean.TRUE); + if (idUser != null) { + conditions = conditions.and(Tables.PROJECT.ID_USER.eq(idUser)); + } + return create.fetchCount(Tables.PROJECT, conditions); + } + + /** + * TODO: add details. + * + * @param idProject + * @return + */ @Override public ProjectRecord cloneProject(Long idProject) { + LOG.info("Clone existing project {} to a new project.", idProject); + ProjectRecord original = getProject(idProject); if (original == null) { throw new NullPointerException("Project doesn't exist"); @@ -230,35 +475,30 @@ public ProjectRecord cloneProject(Long idProject) { return null; } - private ProjectRecord doProjectClone(ProjectRecord original) { - ProjectRecord cloned = createProject( - original.getName(), - original.getDescription(), - original.getDescriptionHtml(), - original.getCode(), - original.getType(), - original.getBoard(), - original.getPrivate(), - original.getShared()); - - cloned.setBasedOn(original.getId()); - cloned.update(); - - create.update(Tables.PROJECT) - .set(Tables.PROJECT.BASED_ON, original.getId()) - .where(Tables.PROJECT.ID.equal(cloned.getId())); - return cloned; - } - + /** + * TODO: add details. + * + * @param idProject + * @return + */ @Override public boolean deleteProject(Long idProject) { + LOG.info("Delete project {}.", idProject); return create.deleteFrom(Tables.PROJECT) .where(Tables.PROJECT.ID.equal(idProject)) .execute() > 0; } + /** + * TODO: add details. + * + * @param idProject + * @param code + * @return + */ @Override public ProjectRecord updateProjectCode(Long idProject, String code) { + LOG.info("Update code for project {}.", idProject); ProjectRecord record = create.selectFrom(Tables.PROJECT) .where(Tables.PROJECT.ID.equal(idProject)) .fetchOne(); @@ -281,19 +521,33 @@ public ProjectRecord updateProjectCode(Long idProject, String code) { cloned.update(); return cloned; } + LOG.error("User {} tried and failed to update project {}.", idUser, idProject); throw new UnauthorizedException(); } } else { + LOG.warn("Unable to project {}. Unknown reason.", idProject); return null; } } + /** + * TODO: add details. + * + * @param idProject + * @param code + * @param newName + * @return + */ @Override public ProjectRecord saveProjectCodeAs(Long idProject, String code, String newName) { + LOG.info("Saving project code as '{}'", newName); + ProjectRecord original = getProject(idProject); if (original == null) { + LOG.error("Original project {} is missing. Unable to save code as...", idProject); throw new NullPointerException("Project doesn't exist"); } + Long idUser = BlocklyPropSecurityUtils.getCurrentUserId(); if (original.getIdUser().equals(idUser) || original.getShared()) { // TODO check if friends ProjectRecord cloned = createProject( @@ -312,4 +566,197 @@ public ProjectRecord saveProjectCodeAs(Long idProject, String code, String newNa return null; } + // Private over-ride of the public getProject() + // + // + private ProjectRecord getProject(Long idProject, boolean toEdit) { + LOG.info("Retreiving project {}.", idProject); + ProjectRecord record = create + .selectFrom(Tables.PROJECT) + .where(Tables.PROJECT.ID.equal(idProject)) + .fetchOne(); + + if (record != null) { + Long idUser = BlocklyPropSecurityUtils.getCurrentUserId(); + + // Return a project if the edit flag is off or the edit flag is + // on and the project owner is the current user + if (!toEdit || record.getIdUser().equals(idUser)) { + + // Todo: Verify that the record was fetched - it sometimes is not. + return alterReadRecord(record); + } else { + LOG.error("User {} attempted to edit project {} without authorization.", + idUser, idProject); + throw new UnauthorizedException(); + } + } + + // Return the project after checking if for depricated blocks + // + // Todo: Verify that the record was fetched - it sometimes is not. + return alterReadRecord(record); + } + + private ProjectRecord doProjectClone(ProjectRecord original) { + ProjectRecord cloned = createProject( + original.getName(), + original.getDescription(), + original.getDescriptionHtml(), + original.getCode(), + original.getType(), + original.getBoard(), + original.getPrivate(), + original.getShared()); + + cloned.setBasedOn(original.getId()); + cloned.update(); + + create.update(Tables.PROJECT) + .set(Tables.PROJECT.BASED_ON, original.getId()) + .where(Tables.PROJECT.ID.equal(cloned.getId())); + return cloned; + } + + + // Evaluate project code and replace any depricated or updated blocks + // + // Return a ProjectRecord object. The code field may be altered to correct + // any old, depricated or updated blocks. The method will throw an + // exception if the ProjectRecord parameter is null or something has gone + // horribly wrong with the string conversions. + // + private ProjectRecord alterReadRecord(ProjectRecord record) { + LOG.info("Verify project block characteristics"); + String currentCode, newCode; + + if (record == null) { + LOG.error("Null project record detected."); + throw new NullPointerException("Cannot alter a null project record."); + } + + try { + currentCode = record.getCode(); + + // Return immediately if there is no code to adjust + if (currentCode == null) { + LOG.warn("Project () code block is empty.", record.getId()); + return record; + } + + /* + * Make a copy of the project. We will use this after the updates + * to determine if anything was changed. This ensures that we do + * not do any database I/O unless we actually changed something. + */ + newCode = currentCode; + + if (record.getType() == ProjectType.SPIN) { + newCode = fixSpinProjectBlocks(newCode); + + } else if (record.getType() == ProjectType.PROPC){ + newCode = fixPropcProjectBlocks(newCode); + } + + // Check for any difference from the original code + if (! currentCode.equals(newCode)) { + LOG.info("Updated depricated project code blocks in project {}.", record.getId()); + record.setCode(newCode); + } + } + + catch (Exception ex) { + LOG.error("Exception trapped. Message is: {}", ex.getMessage()); + } + + return record; + } + + // Correct depricated block details related to Spin blocks + private String fixSpinProjectBlocks(String newCode) { + LOG.info("Looking for depricated Spin blocks."); + + newCode = newCode.replaceAll("block type=\"controls_if\"", + "block type=\"controls_boolean_if\""); + + newCode = newCode.replaceAll("block type=\"logic_compare\"", + "block type=\"logic_boolean_compare\""); + + newCode = newCode.replaceAll("block type=\"logic_operation\"", + "block type=\"logic_boolean_operation\""); + + newCode = newCode.replaceAll("block type=\"logic_negate\"", + "block type=\"logic_boolean_negate\""); + + newCode = newCode.replaceAll("block type=\"math_number\"", + "block type=\"spin_integer\""); + return newCode; + } + + private String fixPropcProjectBlocks(String newCode) { + LOG.info("Looking for depricated PropC blocks."); + + newCode = newCode.replaceAll("field name=\"OP\">ADD + MINUS - MULTIPLY * DIVIDE / MODULUS % AND && AND_NOT && !LT<GT>LTE<=GTE>=EQ==NEQ!=INCHES_inchesCM_cmInternal Server Error,200>Success Response") public class RestSharedProject { + private static final Logger LOG = LoggerFactory.getLogger(RestSharedProject.class); private ProjectService projectService; @@ -55,7 +59,7 @@ public void setProjectConverter(ProjectConverter projectConverter) { @Name("Get all shared projects") @Produces("application/json") public Response get(@QueryParam("sort") TableSort sort, @QueryParam("order") TableOrder order, @QueryParam("limit") Integer limit, @QueryParam("offset") Integer offset) { - System.out.println("Sort: " + sort); + LOG.info("Sort: {}", sort); List projects = projectService.getSharedProjects(sort, order, limit, offset); int projectCount = projectService.countSharedProjects(); @@ -72,21 +76,51 @@ public Response get(@QueryParam("sort") TableSort sort, @QueryParam("order") Tab return Response.ok(result.toString()).build(); } + @GET + @Path("/list/user/{id}") + @Detail("Get shared projects by user") + @Name("Get shared projects by user") + @Produces("application/json") + public Response get(@QueryParam("sort") TableSort sort, @QueryParam("order") TableOrder order, @QueryParam("limit") Integer limit, @QueryParam("offset") Integer offset, @PathParam("id") Long idUser) { + LOG.info("Sort: {}", sort); + + List projects = projectService.getSharedProjectsByUser(sort, order, limit, offset, idUser); + int projectCount = projectService.countSharedProjectsByUser(idUser); + + JsonObject result = new JsonObject(); + JsonArray jsonProjects = new JsonArray(); + for (ProjectRecord project : projects) { + jsonProjects.add(projectConverter.toListJson(project)); + } + + result.add("rows", jsonProjects); + result.addProperty("total", projectCount); + + return Response.ok(result.toString()).build(); + } + + @GET @Path("/get/{id}") @Detail("Get project by id") @Name("Get project by id") @Produces("application/json") public Response get(@HeaderParam("X-Authorization") String authorization, @HeaderParam("X-Timestamp") Long timestamp, @PathParam("id") Long idProject) { - ProjectRecord project = projectService.getProject(idProject); - - if (project == null) { + + try { + ProjectRecord project = projectService.getProject(idProject); + + if (project == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } + + JsonObject result = projectConverter.toJson(project); + return Response.ok(result.toString()).build(); + } + catch (Exception e) { + LOG.error("Exception in {} detected. Message is: {}", e.getClass(), e.getLocalizedMessage()); return Response.status(Response.Status.NOT_FOUND).build(); } - - JsonObject result = projectConverter.toJson(project); - - return Response.ok(result.toString()).build(); } @GET @@ -95,18 +129,24 @@ public Response get(@HeaderParam("X-Authorization") String authorization, @Heade @Name("Get project by id for editor") @Produces("application/json") public Response getEditor(@HeaderParam("X-Authorization") String authorization, @HeaderParam("X-Timestamp") Long timestamp, @PathParam("id") Long idProject) { - System.out.println("Authorization: " + authorization); + LOG.info("Authorization: {}", authorization); - ProjectRecord project = projectService.getProject(idProject); + try { + ProjectRecord project = projectService.getProject(idProject); - if (project == null) { - return Response.status(Response.Status.NOT_FOUND).build(); - } + if (project == null) { + return Response.status(Response.Status.NOT_FOUND).build(); + } - JsonObject result = projectConverter.toJson(project); - result.addProperty("code", project.getCode()); + JsonObject result = projectConverter.toJson(project); + result.addProperty("code", project.getCode()); - return Response.ok(result.toString()).build(); + return Response.ok(result.toString()).build(); + } + catch (Exception e) { + LOG.error("Exception in {} detected. Message is: {}", e.getClass(), e.getLocalizedMessage()); + return Response.status(Response.Status.NOT_FOUND).build(); + } } } diff --git a/src/main/java/com/parallax/server/blocklyprop/services/ProjectService.java b/src/main/java/com/parallax/server/blocklyprop/services/ProjectService.java index 9c617f62..692e5587 100644 --- a/src/main/java/com/parallax/server/blocklyprop/services/ProjectService.java +++ b/src/main/java/com/parallax/server/blocklyprop/services/ProjectService.java @@ -25,9 +25,13 @@ public interface ProjectService { List getSharedProjects(TableSort tablesSort, TableOrder order, Integer limit, Integer offset); + List getSharedProjectsByUser(TableSort tablesSort, TableOrder order, Integer limit, Integer offset, Long idUser); + int countUserProjects(Long idUser); int countSharedProjects(); + + int countSharedProjectsByUser(Long idUser); ProjectRecord saveProject(Long idProject, String name, String description, String descriptionHtml, boolean privateProject, boolean sharedProject, ProjectType type, String board); diff --git a/src/main/java/com/parallax/server/blocklyprop/services/impl/ProjectServiceImpl.java b/src/main/java/com/parallax/server/blocklyprop/services/impl/ProjectServiceImpl.java index 45fb8c45..69fcca98 100644 --- a/src/main/java/com/parallax/server/blocklyprop/services/impl/ProjectServiceImpl.java +++ b/src/main/java/com/parallax/server/blocklyprop/services/impl/ProjectServiceImpl.java @@ -86,6 +86,11 @@ public List getSharedProjects(TableSort sort, TableOrder order, I return projectDao.getSharedProjects(sort, order, limit, offset, BlocklyPropSecurityUtils.getCurrentUserId()); } + @Override + public List getSharedProjectsByUser(TableSort sort, TableOrder order, Integer limit, Integer offset, Long idUser) { + return projectDao.getSharedProjectsByUser(sort, order, limit, offset, idUser); + } + @Override public int countUserProjects(Long idUser) { return projectDao.countUserProjects(idUser); @@ -95,6 +100,11 @@ public int countUserProjects(Long idUser) { public int countSharedProjects() { return projectDao.countSharedProjects(BlocklyPropSecurityUtils.getCurrentUserId()); } + + @Override + public int countSharedProjectsByUser(Long idUser) { + return projectDao.countSharedProjectsByUser(idUser); + } @Override public ProjectRecord saveProject(Long idProject, String name, String description, String descriptionHtml, boolean privateProject, boolean sharedProject, ProjectType type, String board) { diff --git a/src/main/java/com/parallax/server/blocklyprop/servlets/PingServlet.java b/src/main/java/com/parallax/server/blocklyprop/servlets/PingServlet.java index 60e3f863..5aa71aa9 100644 --- a/src/main/java/com/parallax/server/blocklyprop/servlets/PingServlet.java +++ b/src/main/java/com/parallax/server/blocklyprop/servlets/PingServlet.java @@ -20,7 +20,7 @@ public class PingServlet extends HttpServlet { /* - * Get user information + * Respond to a ping request */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { diff --git a/src/main/java/com/parallax/server/blocklyprop/utils/HttpServletRequestImpl.java b/src/main/java/com/parallax/server/blocklyprop/utils/HttpServletRequestImpl.java index a51703bf..7255be5e 100644 --- a/src/main/java/com/parallax/server/blocklyprop/utils/HttpServletRequestImpl.java +++ b/src/main/java/com/parallax/server/blocklyprop/utils/HttpServletRequestImpl.java @@ -152,9 +152,12 @@ public boolean isRequestedSessionIdFromURL() { throw new UnsupportedOperationException("Not supported."); } + /* + * Depricated as of Java Servlet API version 2.1 + */ @Override public boolean isRequestedSessionIdFromUrl() { - throw new UnsupportedOperationException("Not supported."); + return this.isRequestedSessionIdFromURL(); } @Override @@ -277,9 +280,16 @@ public RequestDispatcher getRequestDispatcher(String path) { throw new UnsupportedOperationException("Not supported."); } + /* + * Depricated as of Java Servlet API version 2.1 + * + * Consider using this in it's place: + * + * servletRequest.getSession().getServletContext().getRealPath("/") + */ @Override public String getRealPath(String path) { - throw new UnsupportedOperationException("Not supported."); + return this.getSession().getServletContext().getRealPath(path); } @Override diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f3cd4ee1..aa0dd28a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,7 +7,36 @@ database.dialect = MYSQL cdnfiles.baseurl = http://localhost:8080/cdn downloadfiles.baseurl = http://localhost:8080/download +offline.enabled = false +offline.downloadfiles.baseurl = http://localhost/downloads + cloudsession.baseurl = http://localhost:5011 cloudsession.server = blocklyprop -cloudcompiler.baseurl = http://localhost:5000 \ No newline at end of file +# OAuth support for Google users +oauth.google.enabled = false +oauth.google.key = hash_key_assigned_by_Google.apps.googleusercontent.com +oauth.google.secret = secret_key_hash_assigned_by_Google + +cloudcompiler.baseurl = http://localhost:5000 + +# Send monitor output to the console. Default: false +monitor.console.enabled = false + +# Console update interval (in seconds). Default: 300 +monitor.console.interval = 15 + +# : default: false (set to true to send to graphite) +monitor.graphite.enabled = false + +# : default: blocklyprop (prefix for the keys) +monitor.graphite.prefix = blocklyprop + +# : default: localhost (location of the graphite carbon server) +monitor.graphite.address = localhost + +# : default: 2003 (graphite carbon server port) +monitor.graphite.port = 2003 + +# : default: 30 (send every x seconds to graphite carbon server) +monitor.graphite.interval = 16 diff --git a/src/main/resources/com/parallax/server/blocklyprop/internationalization/translations.properties b/src/main/resources/com/parallax/server/blocklyprop/internationalization/translations.properties index 9994e8c7..8551b839 100644 --- a/src/main/resources/com/parallax/server/blocklyprop/internationalization/translations.properties +++ b/src/main/resources/com/parallax/server/blocklyprop/internationalization/translations.properties @@ -29,8 +29,8 @@ footer.clientdownloadlink = BlocklyProp-client # Application version numbers. application.major = 0 -application.minor = 94 -application.build = 304 +application.minor = 95 +application.build = 338 html.content_missing = Content missing @@ -121,7 +121,7 @@ project.create.previouslink = Previous project.board.activity-board = Propeller Activity Board WX project.board.s3 = Scribbler Robot project.board.heb = Hackable Electronic Badge -project.board.flip = Propeller Flip +project.board.flip = Propeller FLiP or Project Board project.board.other = Other confirm.request.title = Email confirm request @@ -247,6 +247,7 @@ category.control = Control category.operators = Operators category.operators.numbers = Numbers category.operators.strings = Strings +category.operators.arrays = Arrays category.values = Values category.input-output = Input/Output category.input-output.pin-states = Pin states @@ -264,6 +265,7 @@ category.communicate.WS2812B = RGB LEDs category.sensor-input = Sensor category.sensor-input.LSM9DS1 = LSM9DS1 IMU category.sensor-input.etape = ETape liquid level +category.sensor-input.fingerprint = Fingerprint Scanner category.sensor-input.hmc5883l = HMC5883L category.sensor-input.2axis-joystick = 2-axis Joystick category.sensor-input.memsic-2axis = Memsic 2-axis @@ -295,11 +297,12 @@ category.robot.activitybot = ActivityBot category.robot.servo-diff-drive = Servo Differential Drive category.hackable-electronic-badge = Hackable Electronic Badge category.hackable-electronic-badge.led_control = LED Control -category.hackable-electronic-badge.oled = OLED +category.hackable-electronic-badge.oled = Display category.hackable-electronic-badge.ir-communication = IR Communication -category.hackable-electronic-badge.eeprom = EEPROM +category.hackable-electronic-badge.eeprom = Memory category.hackable-electronic-badge.accelerometer = Accelerometer category.hackable-electronic-badge.touchpad-control = Touchpad Control +category.hackable-electronic-badge.text-to-speech = Text to Speech category.functions = Functions category.variables = Variables category.s3-simple = Simple Scribbler diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 00000000..3d19c558 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + ${APP_LOG_PATH}/${APP_LOG_FILE_BASE}.log + + %date %level [%thread] %logger{10} [%file:%line] %msg%n + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/includes/pageparts/editor-menu.jsp b/src/main/webapp/WEB-INF/includes/pageparts/editor-menu.jsp index 96dff12b..b855f30f 100644 --- a/src/main/webapp/WEB-INF/includes/pageparts/editor-menu.jsp +++ b/src/main/webapp/WEB-INF/includes/pageparts/editor-menu.jsp @@ -28,16 +28,22 @@ + +
-
+
- + diff --git a/src/main/webapp/WEB-INF/properties.tld b/src/main/webapp/WEB-INF/properties.tld index de0dd926..13c238a7 100644 --- a/src/main/webapp/WEB-INF/properties.tld +++ b/src/main/webapp/WEB-INF/properties.tld @@ -9,15 +9,24 @@ 1.0 http://blocklyprop.parallax.com/properties + downloadfiles com.parallax.server.blocklyprop.jsp.Properties String getDownloadFilesBaseUrl(java.lang.String) + oauth com.parallax.server.blocklyprop.jsp.Properties boolean isOauthEnabled(java.lang.String) - \ No newline at end of file + + + + experimentalmenu + com.parallax.server.blocklyprop.jsp.Properties + boolean isExperimentalMenu(java.lang.Boolean) + + diff --git a/src/main/webapp/WEB-INF/servlet/public-profile.jsp b/src/main/webapp/WEB-INF/servlet/public-profile.jsp index 0b3a6970..14909bbf 100644 --- a/src/main/webapp/WEB-INF/servlet/public-profile.jsp +++ b/src/main/webapp/WEB-INF/servlet/public-profile.jsp @@ -20,15 +20,97 @@

: <%= request.getAttribute("screenname")%>

+ + +
-
+

-
+

+
+
    +
    + Projects: + + +
    @@ -37,7 +119,9 @@
    + <%@ include file="/WEB-INF/includes/pageparts/footer.jsp"%> + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index d13a7f16..0904df89 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -1,8 +1,30 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + ShiroFilter org.apache.shiro.web.servlet.ShiroFilter @@ -17,7 +39,9 @@ ERROR - + + + GuiceFilter com.google.inject.servlet.GuiceFilter @@ -59,6 +83,7 @@ com.cuubez.visualizer.servlet.VzHttpServletDispatcher + vapi_servlet /apidoc diff --git a/src/main/webapp/cdn/blockly/generators/propc.js b/src/main/webapp/cdn/blockly/generators/propc.js index 02f83099..5e757f63 100644 --- a/src/main/webapp/cdn/blockly/generators/propc.js +++ b/src/main/webapp/cdn/blockly/generators/propc.js @@ -28,14 +28,13 @@ */ var quotes = { - /** * Create an image of an open or closed quote. * @param {boolean} open True if open quote, false if closed. * @return {!Blockly.FieldImage} The field image of the quote. * @this Blockly.Block */ - newQuote_: function(open) { + newQuote_: function (open) { if (open === this.RTL) { var file = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAKCAQAAAAqJXdxAAAAqUlEQVQI1z3KvUpCcRiA8ef9E4JNHhI0aFEacm1o0BsI0Slx8wa8gLauoDnoBhq7DcfWhggONDmJJgqCPA7neJ7p934EOOKOnM8Q7PDElo/4x4lFb2DmuUjcUzS3URnGib9qaPNbuXvBO3sGPHJDRG6fGVdMSeWDP2q99FQdFrz26Gu5Tq7dFMzUvbXy8KXeAj57cOklgA+u1B5AoslLtGIHQMaCVnwDnADZIFIrXsoXrgAAAABJRU5ErkJggg=='; } else { @@ -140,7 +139,9 @@ var profile = { ["78", "32846"], ["79", "32847"], ["80", "32848"], ["81", "32849"], ["82", "32850"], ["83", "32851"], ["84", "32852"], ["85", "32853"], ["86", "32854"], ["87", "32855"], ["88", "32856"], ["89", "32857"], ["90", "32858"], ["91", "32859"], ["92", "32860"], ["92", "32861"], ["93", "32862"], ["94", "32863"], ["95", "32864"], ["96", "32865"], ["97", "32866"], ["98", "32867"], ["99", "32868"], ["100", "32869"]], - baudrate: 115200 + baudrate: 115200, + contiguous_pins_start: 0, + contiguous_pins_end: 17 }, "s3": { description: "Scribbler Robot", @@ -157,12 +158,14 @@ var profile = { ["78", "32846"], ["79", "32847"], ["80", "32848"], ["81", "32849"], ["82", "32850"], ["83", "32851"], ["84", "32852"], ["85", "32853"], ["86", "32854"], ["87", "32855"], ["88", "32856"], ["89", "32857"], ["90", "32858"], ["91", "32859"], ["92", "32860"], ["92", "32861"], ["93", "32862"], ["94", "32863"], ["95", "32864"], ["96", "32865"], ["97", "32866"], ["98", "32867"], ["99", "32868"], ["100", "32869"]], - baudrate: 9600 + baudrate: 9600, + contiguous_pins_start: 0, + contiguous_pins_end: 5 }, "heb": { description: "Hackable Electronic Badge", - digital: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"], ["13", "13"], ["14", "14"], ["15", "15"], ["16", "16"], ["17", "17"], ["18", "18"], ["19", "19"], ["20", "20"], ["21", "21"], ["22", "22"], ["23", "23"], ["24", "24"], ["25", "25"], ["26", "26"], ["27", "27"], ["28", "28"], ["29", "29"], ["30", "30"], ["31", "31"]], - servo: [["12", "12"], ["13", "13"], ["14", "14"], ["15", "15"], ["16", "16"]], + digital: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"]], + servo: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"]], analog: [["A0", "A0"], ["A1", "A1"], ["A2", "A2"], ["A3", "A3"], ["A4", "A4"], ["A5", "A5"]], eeprom: [["0", "32768"], ["1", "32769"], ["2", "32770"], ["3", "32771"], ["4", "32772"], ["5", "32773"], ["6", "32774"], ["7", "32775"], ["8", "32776"], ["9", "32777"], ["10", "32778"], ["11", "32779"], ["12", "32780"], ["13", "32781"], ["14", "32782"], ["15", "32783"], ["16", "32784"], ["17", "32785"], ["18", "32786"], ["19", "32787"], ["20", "32788"], ["21", "32789"], ["22", "32790"], @@ -174,10 +177,12 @@ var profile = { ["78", "32846"], ["79", "32847"], ["80", "32848"], ["81", "32849"], ["82", "32850"], ["83", "32851"], ["84", "32852"], ["85", "32853"], ["86", "32854"], ["87", "32855"], ["88", "32856"], ["89", "32857"], ["90", "32858"], ["91", "32859"], ["92", "32860"], ["92", "32861"], ["93", "32862"], ["94", "32863"], ["95", "32864"], ["96", "32865"], ["97", "32866"], ["98", "32867"], ["99", "32868"], ["100", "32869"]], - baudrate: 115200 + baudrate: 115200, + contiguous_pins_start: 0, + contiguous_pins_end: 11 }, "flip": { - description: "Propeller Flip Board", + description: "Propeller FLiP or Project Board", digital: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"], ["13", "13"], ["14", "14"], ["15", "15"], ["16", "16"], ["17", "17"], ["18", "18"], ["19", "19"], ["20", "20"], ["21", "21"], ["22", "22"], ["23", "23"], ["24", "24"], ["25", "25"], ["26", "26"], ["27", "27"], ["28", "28"], ["29", "29"], ["30", "30"], ["31", "31"]], servo: [["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"], ["13", "13"], ["14", "14"], ["15", "15"], ["16", "16"], ["17", "17"], ["18", "18"], ["19", "19"], ["20", "20"], ["21", "21"], ["22", "22"], ["23", "23"], ["24", "24"], ["25", "25"], ["26", "26"], ["27", "27"], ["28", "28"], ["29", "29"], ["30", "30"], ["31", "31"]], analog: [["A0", "A0"], ["A1", "A1"], ["A2", "A2"], ["A3", "A3"], ["A4", "A4"], ["A5", "A5"]], @@ -191,7 +196,9 @@ var profile = { ["78", "32846"], ["79", "32847"], ["80", "32848"], ["81", "32849"], ["82", "32850"], ["83", "32851"], ["84", "32852"], ["85", "32853"], ["86", "32854"], ["87", "32855"], ["88", "32856"], ["89", "32857"], ["90", "32858"], ["91", "32859"], ["92", "32860"], ["92", "32861"], ["93", "32862"], ["94", "32863"], ["95", "32864"], ["96", "32865"], ["97", "32866"], ["98", "32867"], ["99", "32868"], ["100", "32869"]], - baudrate: 115200 + baudrate: 115200, + contiguous_pins_start: 0, + contiguous_pins_end: 27 }, "other": { description: "Other Propeller Boards", @@ -208,7 +215,9 @@ var profile = { ["78", "32846"], ["79", "32847"], ["80", "32848"], ["81", "32849"], ["82", "32850"], ["83", "32851"], ["84", "32852"], ["85", "32853"], ["86", "32854"], ["87", "32855"], ["88", "32856"], ["89", "32857"], ["90", "32858"], ["91", "32859"], ["92", "32860"], ["92", "32861"], ["93", "32862"], ["94", "32863"], ["95", "32864"], ["96", "32865"], ["97", "32866"], ["98", "32867"], ["99", "32868"], ["100", "32869"]], - baudrate: 115200 + baudrate: 115200, + contiguous_pins_start: 0, + contiguous_pins_end: 27 } }; function setProfile(profileName) { @@ -311,7 +320,11 @@ Blockly.propc.finish = function (code) { // Convert the setups dictionary into a list. var setups = []; for (var name in Blockly.propc.setups_) { - setups.push(' ' + Blockly.propc.setups_[name]); + if (name !== 's3_setup') { + setups.push(' ' + Blockly.propc.setups_[name]); + } else { + setups.unshift(' ' + Blockly.propc.setups_[name]); + } } for (var method in Blockly.propc.methods_) { @@ -382,4 +395,48 @@ Blockly.propc.scrub_ = function (block, code) { var nextBlock = block.nextConnection && block.nextConnection.targetBlock(); var nextCode = this.blockToCode(nextBlock); return commentCode + code + nextCode; +}; + +// Provides backward compatibility for some older browsers: +// From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys + +if (!Object.keys) { + Object.keys = (function() { + 'use strict'; + var hasOwnProperty = Object.prototype.hasOwnProperty, + hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'), + dontEnums = [ + 'toString', + 'toLocaleString', + 'valueOf', + 'hasOwnProperty', + 'isPrototypeOf', + 'propertyIsEnumerable', + 'constructor' + ], + dontEnumsLength = dontEnums.length; + + return function(obj) { + if (typeof obj !== 'function' && (typeof obj !== 'object' || obj === null)) { + throw new TypeError('Object.keys called on non-object'); + } + + var result = [], prop, i; + + for (prop in obj) { + if (hasOwnProperty.call(obj, prop)) { + result.push(prop); + } + } + + if (hasDontEnumBug) { + for (i = 0; i < dontEnumsLength; i++) { + if (hasOwnProperty.call(obj, dontEnums[i])) { + result.push(dontEnums[i]); + } + } + } + return result; + }; + }()); }; \ No newline at end of file diff --git a/src/main/webapp/cdn/blockly/generators/propc/base.js b/src/main/webapp/cdn/blockly/generators/propc/base.js index ac01cdce..be662944 100644 --- a/src/main/webapp/cdn/blockly/generators/propc/base.js +++ b/src/main/webapp/cdn/blockly/generators/propc/base.js @@ -34,8 +34,8 @@ if (!Blockly.Blocks) Blockly.Blocks.math_number = { helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MATH_NUMBER_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MATH_NUMBER_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() .appendField(new Blockly.FieldTextInput('0', @@ -44,7 +44,7 @@ Blockly.Blocks.math_number = { } }; -Blockly.propc.math_number = function() { +Blockly.propc.math_number = function () { // Numeric value. var code = window.parseInt(this.getFieldValue('NUM')); // -4.abs() returns -4 in Dart due to strange order of operation choices. @@ -55,13 +55,13 @@ Blockly.propc.math_number = function() { }; Blockly.Blocks.math_arithmetic = { - init: function() { - if(profile.default.description === "Scribbler Robot") { + init: function () { + if (profile.default.description === "Scribbler Robot") { this.setHelpUrl(Blockly.MSG_S3_MATH_HELPURL); } else { this.setHelpUrl(Blockly.MSG_NUMBERS_HELPURL); } - this.setTooltip(Blockly.MSG_MATH_ARITHMETIC_TOOLTIP); + this.setTooltip(Blockly.MSG_MATH_ARITHMETIC_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.setOutput(true, 'Number'); this.appendValueInput('A') @@ -69,26 +69,26 @@ Blockly.Blocks.math_arithmetic = { this.appendValueInput('B') .setCheck('Number') .appendField(new Blockly.FieldDropdown([ - ["+", ' + '], - ["-", ' - '], - ["×", ' * '], - ["÷", ' / '], - ["% (remainder after division)", ' % '], - ["^ (raise to the power of)", ' p ']]), 'OP'); + ["+", ' + '], + ["-", ' - '], + ["×", ' * '], + ["÷", ' / '], + ["% (remainder after division)", ' % '], + ["^ (raise to the power of)", ' p ']]), 'OP'); this.setInputsInline(true); } }; -Blockly.propc.math_arithmetic = function() { +Blockly.propc.math_arithmetic = function () { var operator = this.getFieldValue('OP'); var order = Blockly.propc.ORDER_MULTIPLICATIVE; - if(operator === ' + ' || operator === ' - ') { + if (operator === ' + ' || operator === ' - ') { order = Blockly.propc.ORDER_ADDITIVE; } var argument0 = Blockly.propc.valueToCode(this, 'A', order) || '0'; var argument1 = Blockly.propc.valueToCode(this, 'B', order) || '0'; var code; - if(operator === ' p ') { + if (operator === ' p ') { code = 'pow(' + argument0 + ', ' + argument1 + ')'; } else { code = argument0 + operator + argument1; @@ -98,8 +98,8 @@ Blockly.propc.math_arithmetic = function() { Blockly.Blocks.math_limit = { helpUrl: Blockly.MSG_NUMBERS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MATH_LIMIT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MATH_LIMIT_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput('A') .setCheck('Number') @@ -115,7 +115,7 @@ Blockly.Blocks.math_limit = { } }; -Blockly.propc.math_limit = function() { +Blockly.propc.math_limit = function () { var operator = this.getFieldValue('OP'); var argument0 = Blockly.propc.valueToCode(this, 'A', Blockly.propc.ORDER_ASSIGNMENT) || '0'; var argument1 = Blockly.propc.valueToCode(this, 'B', Blockly.propc.ORDER_ASSIGNMENT) || '0'; @@ -125,21 +125,21 @@ Blockly.propc.math_limit = function() { return [code, Blockly.propc.ORDER_ASSIGNMENT]; }; -Blockly.Blocks.math_crement = { +Blockly.Blocks.math_crement = { // Increment/decrement helpUrl: Blockly.MSG_NUMBERS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MATH_CREMENT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MATH_CREMENT_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput('VAR') - .setCheck('Number') - .appendField(new Blockly.FieldDropdown([["decrement", "--"], ["increment", "++"]]), "OP"); + .setCheck('Number') + .appendField(new Blockly.FieldDropdown([["decrement", "--"], ["increment", "++"]]), "OP"); this.setPreviousStatement(true); this.setNextStatement(true); } }; -Blockly.propc.math_crement = function() { +Blockly.propc.math_crement = function () { var operator = this.getFieldValue('OP'); var variable = Blockly.propc.valueToCode(this, 'VAR', Blockly.propc.ORDER_UNARY_PREFIX) || '0'; @@ -149,15 +149,15 @@ Blockly.propc.math_crement = function() { Blockly.Blocks.math_random = { helpUrl: Blockly.MSG_NUMBERS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MATH_RANDOM_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MATH_RANDOM_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput("A") - .setCheck("Number") - .appendField("random number from"); + .setCheck("Number") + .appendField("random number from"); this.appendValueInput("B") - .setCheck("Number") - .appendField("to"); + .setCheck("Number") + .appendField("to"); this.setInputsInline(true); this.setPreviousStatement(false, null); this.setNextStatement(false, null); @@ -165,7 +165,7 @@ Blockly.Blocks.math_random = { } }; -Blockly.propc.math_random = function() { +Blockly.propc.math_random = function () { Blockly.propc.setups_["random_seed"] = "srand(INA + CNT);\n"; var arg1 = Blockly.propc.valueToCode(this, 'A', Blockly.propc.ORDER_ATOMIC) || '0'; var arg2 = Blockly.propc.valueToCode(this, 'B', Blockly.propc.ORDER_ATOMIC) || '99'; @@ -176,26 +176,26 @@ Blockly.propc.math_random = function() { Blockly.Blocks.math_bitwise = { helpUrl: Blockly.MSG_NUMBERS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MATH_BITWISE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MATH_BITWISE_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput('A'); this.appendDummyInput() - .appendField(new Blockly.FieldDropdown([ - ["& (bitwise AND)", " & "], - ["| (bitwise OR)", " | "], - ["^ (bitwise XOR)", " ^ "], - [">> (bitwise right shift)", " >> "], - ["<< (bitwise left shift)", " << "]]), "OP"); + .appendField(new Blockly.FieldDropdown([ + ["& (bitwise AND)", " & "], + ["| (bitwise OR)", " | "], + ["^ (bitwise XOR)", " ^ "], + [">> (bitwise right shift)", " >> "], + ["<< (bitwise left shift)", " << "]]), "OP"); this.appendValueInput('B'); - + this.setOutput(true, 'Number'); this.setPreviousStatement(false, null); this.setNextStatement(false, null); } }; -Blockly.propc.math_bitwise = function() { +Blockly.propc.math_bitwise = function () { var argument0 = Blockly.propc.valueToCode(this, 'A', Blockly.propc.ORDER_NONE); var argument1 = Blockly.propc.valueToCode(this, 'B', Blockly.propc.ORDER_NONE); var operator = this.getFieldValue('OP'); @@ -206,8 +206,8 @@ Blockly.propc.math_bitwise = function() { Blockly.Blocks.base_delay = { helpUrl: Blockly.MSG_CONTROL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_BASE_DELAY_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_BASE_DELAY_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendValueInput("DELAY_TIME", 'Number') .appendField("pause (ms)") @@ -226,8 +226,8 @@ Blockly.propc.base_delay = function () { Blockly.Blocks.string_type_block = { helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_STRING_TYPE_BLOCK_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_STRING_TYPE_BLOCK_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() .appendField(new Blockly.FieldTextInput('Hello'), "TEXT"); @@ -238,7 +238,7 @@ Blockly.Blocks.string_type_block = { } }; -Blockly.propc.string_type_block = function() { +Blockly.propc.string_type_block = function () { var text = this.getFieldValue("TEXT"); var code = '"' + text + '"'; @@ -247,8 +247,8 @@ Blockly.propc.string_type_block = function() { Blockly.Blocks.char_type_block = { helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CHAR_TYPE_BLOCK_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_CHAR_TYPE_BLOCK_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() .appendField("character") @@ -358,7 +358,7 @@ Blockly.Blocks.char_type_block = { } }; -Blockly.propc.char_type_block = function() { +Blockly.propc.char_type_block = function () { var code = this.getFieldValue("CHAR"); return [code, Blockly.propc.ORDER_NONE]; @@ -366,24 +366,24 @@ Blockly.propc.char_type_block = function() { Blockly.Blocks.system_counter = { helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SYSTEM_COUNTER_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SYSTEM_COUNTER_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() - .appendField("system counter"); + .appendField("system counter"); this.setOutput(true, "Number"); - } + } }; -Blockly.propc.system_counter = function() { - var code = 'CNT'; - return [code, Blockly.propc.ORDER_NONE]; +Blockly.propc.system_counter = function () { + var code = 'CNT'; + return [code, Blockly.propc.ORDER_NONE]; }; Blockly.Blocks.string_length = { helpUrl: Blockly.MSG_STRINGS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_STRING_LENGTH_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_STRING_LENGTH_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput('VALUE') .setCheck('String') @@ -395,15 +395,15 @@ Blockly.Blocks.string_length = { } }; -Blockly.propc.string_length = function() { - var text = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_NONE); - return ['strlen(' + text + ')', Blockly.propc.ORDER_NONE]; +Blockly.propc.string_length = function () { + var text = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_NONE); + return ['strlen(' + text + ')', Blockly.propc.ORDER_NONE]; }; Blockly.Blocks.high_low_value = { helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_HIGH_LOW_VALUE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_HIGH_LOW_VALUE_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() .appendField(new Blockly.FieldDropdown([["high", "1"], ["low", "0"]]), 'VALUE'); @@ -414,15 +414,15 @@ Blockly.Blocks.high_low_value = { } }; -Blockly.propc.high_low_value = function() { +Blockly.propc.high_low_value = function () { var code = this.getFieldValue('VALUE'); return [code, Blockly.propc.ORDER_ATOMIC]; }; Blockly.Blocks.comment = { helpUrl: Blockly.MSG_CONTROL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_COMMENT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_COMMENT_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() .appendField("add comment") @@ -433,7 +433,7 @@ Blockly.Blocks.comment = { } }; -Blockly.propc.comment = function() { +Blockly.propc.comment = function () { var text = this.getFieldValue("COMMENT_TEXT"); return '// ' + text + '\n'; @@ -441,35 +441,35 @@ Blockly.propc.comment = function() { /* * Casting Blocks are not currently used (Everything is a string or an int) - -Blockly.Blocks.cast = { - init: function() { - this.setColour(colorPalette.getColor('math')); - this.appendValueInput('ITEM_TO_CAST') - .appendField("cast"); - this.appendDummyInput() - .appendField("to") - .appendField(new Blockly.FieldDropdown([["int", "(int) "], ["float", "(float) "], ["char", "(char) "], ["char[128]", "(char[]) "]]), "CAST_TYPE"); - - this.setPreviousStatement(false, null); - this.setNextStatement(false, null); - this.setOutput(true, 'Number'); - } -}; - -Blockly.propc.cast = function() { - var type = this.getFieldValue("CAST_TYPE"); - var item = Blockly.propc.valueToCode(this, 'ITEM_TO_CAST', Blockly.propc.ORDER_NONE); - - var code = "" + type + item; - return [code, Blockly.propc.ORDER_NONE]; -}; -*/ + + Blockly.Blocks.cast = { + init: function() { + this.setColour(colorPalette.getColor('math')); + this.appendValueInput('ITEM_TO_CAST') + .appendField("cast"); + this.appendDummyInput() + .appendField("to") + .appendField(new Blockly.FieldDropdown([["int", "(int) "], ["float", "(float) "], ["char", "(char) "], ["char[128]", "(char[]) "]]), "CAST_TYPE"); + + this.setPreviousStatement(false, null); + this.setNextStatement(false, null); + this.setOutput(true, 'Number'); + } + }; + + Blockly.propc.cast = function() { + var type = this.getFieldValue("CAST_TYPE"); + var item = Blockly.propc.valueToCode(this, 'ITEM_TO_CAST', Blockly.propc.ORDER_NONE); + + var code = "" + type + item; + return [code, Blockly.propc.ORDER_NONE]; + }; + */ Blockly.Blocks.color_picker = { helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_COLOR_PICKER_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_COLOR_PICKER_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() .appendField("color") @@ -481,7 +481,7 @@ Blockly.Blocks.color_picker = { } }; -Blockly.propc.color_picker = function() { +Blockly.propc.color_picker = function () { var color = this.getFieldValue('COLOR'); color = "0x" + color.substr(1); @@ -490,17 +490,17 @@ Blockly.propc.color_picker = function() { Blockly.Blocks.color_value_from = { helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_COLOR_VALUE_FROM_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_COLOR_VALUE_FROM_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() - .appendField("color value from:"); + .appendField("color value from:"); this.appendValueInput("RED_VALUE") - .appendField("red"); + .appendField("red"); this.appendValueInput("GREEN_VALUE") - .appendField("green"); + .appendField("green"); this.appendValueInput("BLUE_VALUE") - .appendField("blue"); + .appendField("blue"); this.setOutput(true, "Number"); this.setInputsInline(true); @@ -509,7 +509,7 @@ Blockly.Blocks.color_value_from = { } }; -Blockly.propc.color_value_from = function() { +Blockly.propc.color_value_from = function () { var red = Blockly.propc.valueToCode(this, 'RED_VALUE', Blockly.propc.ORDER_NONE) || '0'; var green = Blockly.propc.valueToCode(this, 'GREEN_VALUE', Blockly.propc.ORDER_NONE) || '0'; var blue = Blockly.propc.valueToCode(this, 'BLUE_VALUE', Blockly.propc.ORDER_NONE) || '0'; @@ -522,14 +522,14 @@ Blockly.propc.color_value_from = function() { Blockly.Blocks.get_channel_from = { helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_GET_CHANNEL_FROM_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_GET_CHANNEL_FROM_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() - .appendField("get") - .appendField(new Blockly.FieldDropdown([["Red", "R"], ["Green", "G"], ["Blue", "B"]]), "CHANNEL"); + .appendField("get") + .appendField(new Blockly.FieldDropdown([["Red", "R"], ["Green", "G"], ["Blue", "B"]]), "CHANNEL"); this.appendValueInput('COLOR') - .appendField("value from"); + .appendField("value from"); this.setOutput(true, 'Number'); this.setInputsInline(true); @@ -538,7 +538,7 @@ Blockly.Blocks.get_channel_from = { } }; -Blockly.propc.get_channel_from = function() { +Blockly.propc.get_channel_from = function () { var channel = this.getFieldValue("CHANNEL"); var color = Blockly.propc.valueToCode(this, 'COLOR', Blockly.propc.ORDER_NONE); @@ -549,15 +549,15 @@ Blockly.propc.get_channel_from = function() { Blockly.Blocks.compare_colors = { helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_COMPARE_COLORS_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_COMPARE_COLORS_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() - .appendField("compare"); + .appendField("compare"); this.appendValueInput('COLOR1') - .appendField("color 1:"); + .appendField("color 1:"); this.appendValueInput('COLOR2') - .appendField("color 2:"); + .appendField("color 2:"); this.setOutput(true, 'Number'); this.setInputsInline(true); @@ -566,7 +566,7 @@ Blockly.Blocks.compare_colors = { } }; -Blockly.propc.compare_colors = function() { +Blockly.propc.compare_colors = function () { var color1 = Blockly.propc.valueToCode(this, 'COLOR1', Blockly.propc.ORDER_NONE) || '0'; var color2 = Blockly.propc.valueToCode(this, 'COLOR2', Blockly.propc.ORDER_NONE) || '0'; @@ -579,25 +579,25 @@ Blockly.propc.compare_colors = function() { Blockly.Blocks.logic_compare = { // Comparison operator. category: Blockly.LANG_CATEGORY_LOGIC, - init: function() { - if(profile.default.description === "Scribbler Robot") { + init: function () { + if (profile.default.description === "Scribbler Robot") { this.setHelpUrl(Blockly.MSG_S3_MATH_HELPURL); } else { this.setHelpUrl(Blockly.MSG_NUMBERS_HELPURL); } - this.setTooltip(Blockly.MSG_LOGIC_COMPARE_TOOLTIP); + this.setTooltip(Blockly.MSG_LOGIC_COMPARE_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.setOutput(true, 'Number'); this.appendValueInput('A') - .setCheck("Number"); + .setCheck("Number"); this.appendValueInput('B') - .setCheck("Number") - .appendField(new Blockly.FieldDropdown([['=', '=='], ['\u2260', '!='], ['<', '<'], ['\u2264', '<='], ['>', '>'], ['\u2265', '>=']]), 'OP'); + .setCheck("Number") + .appendField(new Blockly.FieldDropdown([['=', '=='], ['\u2260', '!='], ['<', '<'], ['\u2264', '<='], ['>', '>'], ['\u2265', '>=']]), 'OP'); this.setInputsInline(true); } }; -Blockly.propc.logic_compare = function() { +Blockly.propc.logic_compare = function () { // Comparison operator. var operator = this.getFieldValue('OP'); var order = (operator === '==' || operator === '!=') ? @@ -611,13 +611,13 @@ Blockly.propc.logic_compare = function() { Blockly.Blocks.logic_operation = { // Logical operations: 'and', 'or'. category: Blockly.LANG_CATEGORY_LOGIC, - init: function() { - if(profile.default.description === "Scribbler Robot") { + init: function () { + if (profile.default.description === "Scribbler Robot") { this.setHelpUrl(Blockly.MSG_S3_MATH_HELPURL); } else { this.setHelpUrl(Blockly.MSG_NUMBERS_HELPURL); } - this.setTooltip(Blockly.MSG_LOGIC_OPERATION_TOOLTIP); + this.setTooltip(Blockly.MSG_LOGIC_OPERATION_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.setOutput(true, 'Number'); this.appendValueInput('A') @@ -629,11 +629,11 @@ Blockly.Blocks.logic_operation = { } }; -Blockly.propc.logic_operation = function() { +Blockly.propc.logic_operation = function () { // Operations 'and', 'or'. var operator = this.getFieldValue('OP'); var order = Blockly.propc.ORDER_LOGICAL_AND; - if(operator === ' || ' || operator === ' || !') { + if (operator === ' || ' || operator === ' || !') { order = Blockly.propc.ORDER_LOGICAL_OR; } var argument0 = Blockly.propc.valueToCode(this, 'A', order) || '0'; @@ -645,13 +645,13 @@ Blockly.propc.logic_operation = function() { Blockly.Blocks.logic_negate = { // Negation. //category: Blockly.LANG_CATEGORY_LOGIC, - init: function() { - if(profile.default.description === "Scribbler Robot") { + init: function () { + if (profile.default.description === "Scribbler Robot") { this.setHelpUrl(Blockly.MSG_S3_MATH_HELPURL); } else { this.setHelpUrl(Blockly.MSG_NUMBERS_HELPURL); } - this.setTooltip(Blockly.MSG_LOGIC_NEGATE_TOOLTIP); + this.setTooltip(Blockly.MSG_LOGIC_NEGATE_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.setOutput(true, 'Number'); this.appendValueInput('BOOL') @@ -660,16 +660,16 @@ Blockly.Blocks.logic_negate = { } }; -Blockly.propc.logic_negate = function() { +Blockly.propc.logic_negate = function () { // Negation. var order = Blockly.propc.ORDER_UNARY_PREFIX; var operator = this.getFieldValue('OP'); var argument0 = Blockly.propc.valueToCode(this, 'BOOL', order) || '0'; var code = operator + argument0; - if(operator === 'abs(') { + if (operator === 'abs(') { code += ')'; order = Blockly.propc.ORDER_NONE; - } + } return [code, order]; }; @@ -677,8 +677,8 @@ Blockly.Blocks.logic_boolean = { // Boolean data type: true and false. //category: Blockly.LANG_CATEGORY_LOGIC, helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_LOGIC_BOOLEAN_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_LOGIC_BOOLEAN_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.setOutput(true, 'Number'); this.appendDummyInput() @@ -686,7 +686,7 @@ Blockly.Blocks.logic_boolean = { } }; -Blockly.propc.logic_boolean = function() { +Blockly.propc.logic_boolean = function () { // Boolean values true and false. var code = (this.getFieldValue('BOOL') === 'TRUE') ? '1' : '0'; return [code, Blockly.propc.ORDER_ATOMIC]; @@ -694,13 +694,13 @@ Blockly.propc.logic_boolean = function() { Blockly.Blocks.cog_new = { helpUrl: Blockly.MSG_CONTROL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_COG_NEW_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_COG_NEW_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() - .appendField("new processor"); + .appendField("new processor"); this.appendStatementInput("METHOD") - .appendField("function"); + .appendField("function"); this.setInputsInline(true); this.setPreviousStatement(true, null); @@ -708,7 +708,7 @@ Blockly.Blocks.cog_new = { } }; -Blockly.propc.cog_new = function() { +Blockly.propc.cog_new = function () { var method = Blockly.propc.statementToCode(this, 'METHOD'); method = method.replace(" ", "").replace("\n", "").replace("()", "").replace(";", ""); @@ -718,27 +718,25 @@ Blockly.propc.cog_new = function() { Blockly.Blocks.combine_strings = { helpUrl: Blockly.MSG_STRINGS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_COMBINE_STRINGS_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_COMBINE_STRINGS_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput("STRA") - .setCheck("String") - .appendField("combine string"); + .setCheck("String") + .appendField("combine string"); this.appendValueInput("STRB") - .setCheck("String") - .appendField("with string"); + .setCheck("String") + .appendField("with string"); this.appendDummyInput() - .appendField("store in") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VALUE'); + .appendField("store in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VALUE'); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); }, - getVars: function () { return [this.getFieldValue('VALUE')]; }, - renameVar: function (oldName, newName) { if (Blockly.Names.equals(oldName, this.getFieldValue('VALUE'))) { this.setTitleValue(newName, 'VALUE'); @@ -754,16 +752,16 @@ Blockly.propc.combine_strings = function () { Blockly.propc.vartype_[data] = 'char *'; - if(strA !== '' && strB !== '') { + if (strA !== '' && strB !== '') { Blockly.propc.definitions_['str_Buffer'] = 'char *__scBfr;'; - code += 'sprint(__scBfr, "%s%s", ' + strA + ', ' + strB + ');\n'; - code += 'strcpy(' + data + ', __scBfr);\n'; - } else if(strA !== ''){ - code += 'strcpy(' + data + ', ' + strB + ');\n'; - } else if(strB !== ''){ - code += 'strcpy(' + data + ', ' + strA + ');\n'; - } else { + code += 'sprint(__scBfr, "%s%s", ' + strA + ', ' + strB + ');\n'; + code += 'strcpy(' + data + ', __scBfr);\n'; + } else if (strA !== '') { + code += 'strcpy(' + data + ', ' + strB + ');\n'; + } else if (strB !== '') { + code += 'strcpy(' + data + ', ' + strA + ');\n'; + } else { code += '// Both of the strings to combine are blank!\n'; } return code; @@ -771,18 +769,18 @@ Blockly.propc.combine_strings = function () { Blockly.Blocks.find_substring = { helpUrl: Blockly.MSG_STRINGS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_FIND_SUBSTRING_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_FIND_SUBSTRING_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput("SUBSTR") - .setCheck("String") - .appendField("find location of text"); + .setCheck("String") + .appendField("find location of text"); this.appendValueInput("STR") - .setCheck("String") - .appendField("in string"); + .setCheck("String") + .appendField("in string"); this.setInputsInline(true); this.setOutput(true, "Number"); - } + } }; Blockly.propc.find_substring = function () { @@ -790,42 +788,40 @@ Blockly.propc.find_substring = function () { var strs = Blockly.propc.valueToCode(this, 'STR', Blockly.propc.ORDER_ATOMIC) || ''; Blockly.propc.definitions_['find_sub'] = 'int find_sub(char *__strS, char *__subS) { char* __pos = strstr(__strS, __subS); return (__pos - __strS + 1); }\n'; - + var code = ''; - if(subs !== '' && strs !== '') { - code += 'find_sub(' + strs + ', ' + subs + ')'; - } else { - code += '0'; + if (subs !== '' && strs !== '') { + code += 'find_sub(' + strs + ', ' + subs + ')'; + } else { + code += '0'; } - + return [code, Blockly.propc.ORDER_NONE]; }; Blockly.Blocks.get_char_at_position = { helpUrl: Blockly.MSG_STRINGS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_GET_CHAR_AT_POSITION_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_GET_CHAR_AT_POSITION_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput("POSITION") - .setCheck("Number") - .appendField("get character at position"); + .setCheck("Number") + .appendField("get character at position"); this.appendDummyInput() - .appendField("of") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VALUE'); + .appendField("of") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VALUE'); this.setInputsInline(true); this.setOutput(true, "Number"); - }, - - getVars: function () { - return [this.getFieldValue('VALUE')]; - }, - - renameVar: function (oldName, newName) { - if (Blockly.Names.equals(oldName, this.getFieldValue('VALUE'))) { - this.setTitleValue(newName, 'VALUE'); - } - } + }, + getVars: function () { + return [this.getFieldValue('VALUE')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('VALUE'))) { + this.setTitleValue(newName, 'VALUE'); + } + } }; Blockly.propc.get_char_at_position = function () { @@ -833,32 +829,40 @@ Blockly.propc.get_char_at_position = function () { var data = Blockly.propc.variableDB_.getName(this.getFieldValue('VALUE'), Blockly.Variables.NAME_TYPE); var code = '0'; - - if(Blockly.propc.vartype_[data] === 'char *') + + if (Blockly.propc.vartype_[data] === 'char *') { code = data + '[(' + pos + '>strlen(' + data + ')?strlen(' + data + '):' + pos + ')-1]'; } - + return [code, Blockly.propc.ORDER_NONE]; }; Blockly.Blocks.set_char_at_position = { helpUrl: Blockly.MSG_STRINGS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SET_CHAR_AT_POSITION_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SET_CHAR_AT_POSITION_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput("POSITION") - .setCheck("Number") - .appendField("set character at position"); + .setCheck("Number") + .appendField("set character at position"); this.appendDummyInput() - .appendField("of string") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VALUE'); + .appendField("of string") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VALUE'); this.appendValueInput("CHAR") - .setCheck("Number") - .appendField("to"); + .setCheck("Number") + .appendField("to"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); + }, + getVars: function () { + return [this.getFieldValue('VALUE')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('VALUE'))) { + this.setTitleValue(newName, 'VALUE'); + } } }; @@ -872,24 +876,33 @@ Blockly.propc.set_char_at_position = function () { Blockly.Blocks.get_substring = { helpUrl: Blockly.MSG_STRINGS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_GET_SUBSTRING_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_GET_SUBSTRING_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendDummyInput() - .appendField("get part of string") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'FROM_STR'); + .appendField("get part of string") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'FROM_STR'); this.appendValueInput("START") - .setCheck("Number") - .appendField("from position"); + .setCheck("Number") + .appendField("from position"); this.appendValueInput("END") - .setCheck("Number") - .appendField("to position"); + .setCheck("Number") + .appendField("to position"); this.appendDummyInput() - .appendField("store in") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'TO_STR'); + .appendField("store in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'TO_STR'); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); + }, + getVars: function () { + return [this.getFieldValue('FROM_STR'), this.getFieldValue('TO_STR')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('FROM_STR'))) + this.setTitleValue(newName, 'FROM_STR'); + if (Blockly.Names.equals(oldName, this.getFieldValue('TO_STR'))) + this.setTitleValue(newName, 'TO_STR'); } }; @@ -903,30 +916,30 @@ Blockly.propc.get_substring = function () { Blockly.propc.definitions_['str_Buffer'] = 'char *__scBfr;'; var code = ''; - - if(Blockly.propc.vartype_[frStr] === 'char *') + + if (Blockly.propc.vartype_[frStr] === 'char *') { Blockly.propc.definitions_['__ssIdx'] = 'int __ssIdx, __stIdx;'; - code += '__stIdx = 0;\nfor(__ssIdx = (' + sst + '-1); __ssIdx <= (' + snd +' <= strlen(' + frStr + ')?' + snd +':strlen(' + frStr + '))-1; __ssIdx++) {\n__scBfr[__stIdx] = ' + frStr + '[__ssIdx]; __stIdx++; }\n'; + code += '__stIdx = 0;\nfor(__ssIdx = (' + sst + '-1); __ssIdx <= (' + snd + ' <= strlen(' + frStr + ')?' + snd + ':strlen(' + frStr + '))-1; __ssIdx++) {\n__scBfr[__stIdx] = ' + frStr + '[__ssIdx]; __stIdx++; }\n'; code += '__scBfr[__stIdx] = 0;\n'; code += 'strcpy(' + toStr + ', __scBfr);\n'; } - + return code; }; Blockly.Blocks.string_compare = { helpUrl: Blockly.MSG_STRINGS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_STRING_COMPARE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_STRING_COMPARE_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput("STRA") - .setCheck("String") - .appendField("string"); + .setCheck("String") + .appendField("string"); this.appendValueInput("STRB") - .setCheck("String") - .appendField(new Blockly.FieldDropdown([["is the same as", "=="], ["is not the same as", "!="], ["is alphabetically before", "<"], ["is alphabetically after", ">"]]), "COMP"); + .setCheck("String") + .appendField(new Blockly.FieldDropdown([["is the same as", "=="], ["is not the same as", "!="], ["is alphabetically before", "<"], ["is alphabetically after", ">"]]), "COMP"); this.setInputsInline(true); this.setOutput(true, "Number"); } @@ -938,34 +951,42 @@ Blockly.propc.string_compare = function () { var comp = this.getFieldValue('COMP'); Blockly.propc.definitions_['str_comp'] = 'int str_comp(char *__strA, char *__strB) { return strcmp(__strA, __strB); }'; - + var code = ''; - if(strA !== '' && strB !== '') { + if (strA !== '' && strB !== '') { code += 'str_comp(' + strA + ', ' + strB + ') ' + comp + ' 0'; - } else { - code += '0'; + } else { + code += '0'; } - + return [code, Blockly.propc.ORDER_NONE]; }; Blockly.Blocks.string_to_number = { helpUrl: Blockly.MSG_STRINGS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_STRING_TO_NUMBER_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_STRING_TO_NUMBER_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput("STRING") - .setCheck("String") - .appendField("string"); + .setCheck("String") + .appendField("string"); this.appendDummyInput() - .appendField(new Blockly.FieldDropdown([["in decimal", "%d"], ["in hexadecimal", "%x"], ["in binary", "%b"]]), "TYPE") - .appendField("to integer store in") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), "VAR"); + .appendField(new Blockly.FieldDropdown([["in decimal", "%d"], ["in hexadecimal", "%x"], ["in binary", "%b"]]), "TYPE") + .appendField("to integer store in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), "VAR"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); - } + }, + getVars: function () { + return [this.getFieldValue('VAR')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) { + this.setTitleValue(newName, 'VAR'); + } + } }; Blockly.propc.string_to_number = function () { @@ -978,27 +999,35 @@ Blockly.propc.string_to_number = function () { var code = ''; code += 'strcpy(__s2iBfr, ' + str + ');\n'; code += 'sscan(__s2iBfr, "' + type + '", &' + store + ');\n'; - + return code; }; Blockly.Blocks.number_to_string = { helpUrl: Blockly.MSG_STRINGS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_NUMBER_TO_STRING_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_NUMBER_TO_STRING_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput("NUMBER") - .setCheck("Number") - .appendField("integer"); + .setCheck("Number") + .appendField("integer"); this.appendDummyInput() - .appendField("to string in") - .appendField(new Blockly.FieldDropdown([["decimal", "%d"], ["hexadecimal", "%x"], ["binary", "%b"]]), "TYPE") - .appendField("store in") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), "VAR"); + .appendField("to string in") + .appendField(new Blockly.FieldDropdown([["decimal", "%d"], ["hexadecimal", "%x"], ["binary", "%b"]]), "TYPE") + .appendField("store in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), "VAR"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); - } + }, + getVars: function () { + return [this.getFieldValue('VAR')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) { + this.setTitleValue(newName, 'VAR'); + } + } }; Blockly.propc.number_to_string = function () { @@ -1006,24 +1035,24 @@ Blockly.propc.number_to_string = function () { var type = this.getFieldValue('TYPE'); var store = Blockly.propc.variableDB_.getName(this.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE); - Blockly.propc.vartype_[str] = 'char *'; - + Blockly.propc.vartype_[store] = 'char *'; + return 'sprint(' + store + ', "' + type + '", ' + str + ');\n'; }; Blockly.Blocks.number_binary = { helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_NUMBER_BINARY_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_NUMBER_BINARY_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() - .appendField(new Blockly.FieldTextInput("0101"), "NUMBER") - .appendField("binary"); + .appendField(new Blockly.FieldTextInput("0101"), "NUMBER") + .appendField("binary"); this.setOutput(true, "Number"); - } + } }; -Blockly.propc.number_binary = function() { +Blockly.propc.number_binary = function () { var code = '0b' + this.getFieldValue("NUMBER"); return [code, Blockly.propc.ORDER_NONE]; @@ -1031,17 +1060,17 @@ Blockly.propc.number_binary = function() { Blockly.Blocks.number_hex = { helpUrl: Blockly.MSG_VALUES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_NUMBER_HEX_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_NUMBER_HEX_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() - .appendField(new Blockly.FieldTextInput("7F"), "NUMBER") - .appendField("hexadecimal"); + .appendField(new Blockly.FieldTextInput("7F"), "NUMBER") + .appendField("hexadecimal"); this.setOutput(true, "Number"); - } + } }; -Blockly.propc.number_hex = function() { +Blockly.propc.number_hex = function () { var code = '0x' + this.getFieldValue("NUMBER"); return [code, Blockly.propc.ORDER_NONE]; @@ -1049,24 +1078,24 @@ Blockly.propc.number_hex = function() { Blockly.Blocks.constrain_value = { helpUrl: Blockly.MSG_NUMBERS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CONSTRAIN_VALUE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_CONSTRAIN_VALUE_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput("NUMBER") - .setCheck("Number") - .appendField("constrain"); + .setCheck("Number") + .appendField("constrain"); this.appendDummyInput() - .appendField("from") - .appendField(new Blockly.FieldTextInput("0"), "MIN") - .appendField("(min) to") - .appendField(new Blockly.FieldTextInput("100"), "MAX") - .appendField("(max)"); + .appendField("from") + .appendField(new Blockly.FieldTextInput("0"), "MIN") + .appendField("(min) to") + .appendField(new Blockly.FieldTextInput("100"), "MAX") + .appendField("(max)"); this.setInputsInline(true); this.setOutput(true, "Number"); - } + } }; -Blockly.propc.constrain_value = function() { +Blockly.propc.constrain_value = function () { var num = Blockly.propc.valueToCode(this, 'NUMBER', Blockly.propc.ORDER_ATOMIC) || '0'; var min = window.parseInt(this.getFieldValue('MIN')); var max = window.parseInt(this.getFieldValue('MAX')); @@ -1082,24 +1111,24 @@ Blockly.propc.constrain_value = function() { Blockly.Blocks.math_advanced = { helpUrl: Blockly.MSG_NUMBERS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MATH_ADVANCED_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MATH_ADVANCED_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput("ARG1") - .setCheck("Number"); + .setCheck("Number"); this.appendValueInput("ARG2") - .setCheck("Number") - .appendField(new Blockly.FieldDropdown([ - ["× the cosine of", "cos"], - ["× the sine of", "sin"], - ["× the tangent of", "tan"], - ["× the square root of", "sqrt"], - ["× e raised to the power of", "exp"], - ["× the logarithm (base 10) of", "log10"], - ["× the natural logarithm of", "log"]]), "OP"); + .setCheck("Number") + .appendField(new Blockly.FieldDropdown([ + ["× the cosine of", "cos"], + ["× the sine of", "sin"], + ["× the tangent of", "tan"], + ["× the square root of", "sqrt"], + ["× e raised to the power of", "exp"], + ["× the logarithm (base 10) of", "log10"], + ["× the natural logarithm of", "log"]]), "OP"); this.appendDummyInput("") - .appendField("store in") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'STORE'); + .appendField("store in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'STORE'); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -1114,36 +1143,37 @@ Blockly.Blocks.math_advanced = { } }; -Blockly.propc.math_advanced = function() { +Blockly.propc.math_advanced = function () { var store = Blockly.propc.variableDB_.getName(this.getFieldValue('STORE'), Blockly.Variables.NAME_TYPE); var arg1 = Blockly.propc.valueToCode(this, 'ARG1', Blockly.propc.ORDER_ATOMIC) || '1'; var arg2 = Blockly.propc.valueToCode(this, 'ARG2', Blockly.propc.ORDER_ATOMIC) || '1'; var operator = this.getFieldValue('OP'); var opTrig = ''; - if(operator === 'sin' || operator === 'cos' || operator === 'tan') opTrig = ' * PI/180.0'; + if (operator === 'sin' || operator === 'cos' || operator === 'tan') + opTrig = ' * PI/180.0'; var code = store + ' = (int) (((float)' + arg1 + ') * ' + operator + '(((float) ' + arg2 + ')' + opTrig + ') + 0.5);\n'; - + return code; }; Blockly.Blocks.math_inv_trig = { helpUrl: Blockly.MSG_NUMBERS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MATH_INV_TRIG_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MATH_INV_TRIG_TOOLTIP); this.setColour(colorPalette.getColor('math')); this.appendValueInput("ARG1") - .setCheck("Number") - .appendField(new Blockly.FieldDropdown([ - ["arcsine of (", "asin"], - ["arccosine of (", "acos"], - ["arctangent of (", "atan2"]]), "OP"); + .setCheck("Number") + .appendField(new Blockly.FieldDropdown([ + ["arcsine of (", "asin"], + ["arccosine of (", "acos"], + ["arctangent of (", "atan2"]]), "OP"); this.appendValueInput("ARG2") - .setCheck("Number") - .appendField("÷"); + .setCheck("Number") + .appendField("÷"); this.appendDummyInput() - .appendField(") store in") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'STORE'); + .appendField(") store in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'STORE'); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -1158,15 +1188,16 @@ Blockly.Blocks.math_inv_trig = { } }; -Blockly.propc.math_inv_trig = function() { +Blockly.propc.math_inv_trig = function () { var store = Blockly.propc.variableDB_.getName(this.getFieldValue('STORE'), Blockly.Variables.NAME_TYPE); var arg1 = Blockly.propc.valueToCode(this, 'ARG1', Blockly.propc.ORDER_ATOMIC) || '1'; var arg2 = Blockly.propc.valueToCode(this, 'ARG2', Blockly.propc.ORDER_ATOMIC) || '1'; var operator = this.getFieldValue('OP'); var opTrig = '/'; - if(operator === 'atan2') opTrig = ','; + if (operator === 'atan2') + opTrig = ','; var code = store + ' = (int) (180.0 * ' + operator + '(((float) ' + arg1 + ')' + opTrig + '((float) ' + arg2 + ')) / PI + 0.5);\n'; - + return code; }; \ No newline at end of file diff --git a/src/main/webapp/cdn/blockly/generators/propc/communicate.js b/src/main/webapp/cdn/blockly/generators/propc/communicate.js index 608fb791..f01f489a 100644 --- a/src/main/webapp/cdn/blockly/generators/propc/communicate.js +++ b/src/main/webapp/cdn/blockly/generators/propc/communicate.js @@ -35,15 +35,15 @@ if (!Blockly.Blocks) // ------------------ Terminal Console Blocks ---------------------------------- Blockly.Blocks.console_print = { helpUrl: Blockly.MSG_TERMINAL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CONSOLE_PRINT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_CONSOLE_PRINT_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendValueInput('MESSAGE') - .setCheck('String') - .appendField("Terminal print text"); + .setCheck('String') + .appendField("Terminal print text"); this.appendDummyInput() - .appendField("then a new line") - .appendField(new Blockly.FieldCheckbox("FALSE"), "ck_nl"); + .appendField("then a new line") + .appendField(new Blockly.FieldCheckbox("FALSE"), "ck_nl"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -55,30 +55,32 @@ Blockly.propc.console_print = function () { var checkbox = this.getFieldValue('ck_nl'); Blockly.propc.serial_terminal_ = true; - - var code = 'print(' + text.replace("%","%%") + ');\n'; - if (checkbox === 'TRUE') { code += 'print("\\r");\n'; } + + var code = 'print(' + text.replace("%", "%%") + ');\n'; + if (checkbox === 'TRUE') { + code += 'print("\\r");\n'; + } return code; }; Blockly.Blocks.console_print_variables = { helpUrl: Blockly.MSG_TERMINAL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CONSOLE_PRINT_VARIABLES_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_CONSOLE_PRINT_VARIABLES_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendValueInput('VALUE') - .appendField("Terminal print number"); + .appendField("Terminal print number"); this.appendDummyInput() - .appendField("as") - .appendField(new Blockly.FieldDropdown([ - ['Decimal','DEC'], - ['Hexadecimal','HEX'], - ['Binary', 'BIN'], - ['ASCII Character', 'CHAR'] - ]), "FORMAT"); + .appendField("as") + .appendField(new Blockly.FieldDropdown([ + ['Decimal', 'DEC'], + ['Hexadecimal', 'HEX'], + ['Binary', 'BIN'], + ['ASCII Character', 'CHAR'] + ]), "FORMAT"); this.appendDummyInput() - .appendField("then a new line") - .appendField(new Blockly.FieldCheckbox("FALSE"), "ck_nl"); + .appendField("then a new line") + .appendField(new Blockly.FieldCheckbox("FALSE"), "ck_nl"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -96,7 +98,7 @@ Blockly.propc.console_print_variables = function () { if (format === 'BIN') { code += '"%b"'; } else if (format === 'HEX') { - code += '"%x"'; + code += '"%x"'; } else if (format === 'DEC') { code += '"%d"'; } else { @@ -106,7 +108,7 @@ Blockly.propc.console_print_variables = function () { if (format === 'BIN') { code += '"%b\\r"'; } else if (format === 'HEX') { - code += '"%x\\r"'; + code += '"%x\\r"'; } else if (format === 'DEC') { code += '"%d\\r"'; } else { @@ -116,15 +118,15 @@ Blockly.propc.console_print_variables = function () { if (format === 'CHAR') { code += ', (' + value + ' & 0xFF));\n'; } else { - code += ', ' + value + ');\n'; + code += ', ' + value + ');\n'; } return code; }; Blockly.Blocks.console_scan_text = { helpUrl: Blockly.MSG_TERMINAL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CONSOLE_SCAN_TEXT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_CONSOLE_SCAN_TEXT_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() .appendField("Terminal receive text store in") @@ -145,11 +147,11 @@ Blockly.Blocks.console_scan_text = { }; Blockly.propc.console_scan_text = function () { - var data = Blockly.propc.variableDB_.getName(this.getFieldValue('VALUE'), Blockly.Variables.NAME_TYPE); - Blockly.propc.vartype_[data] = 'char *'; + var data = Blockly.propc.variableDB_.getName(this.getFieldValue('VALUE'), Blockly.Variables.NAME_TYPE); + Blockly.propc.vartype_[data] = 'char *'; Blockly.propc.serial_terminal_ = true; - if(data !== '') { + if (data !== '') { var code = 'getStr(' + data + ', 128);\n'; return code; @@ -160,8 +162,8 @@ Blockly.propc.console_scan_text = function () { Blockly.Blocks.console_scan_number = { helpUrl: Blockly.MSG_TERMINAL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CONSOLE_SCAN_NUMBER_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_CONSOLE_SCAN_NUMBER_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() .appendField("Terminal receive") @@ -185,12 +187,12 @@ Blockly.Blocks.console_scan_number = { Blockly.propc.console_scan_number = function () { var type = this.getFieldValue('TYPE'); - var data = Blockly.propc.variableDB_.getName(this.getFieldValue('VALUE'), Blockly.Variables.NAME_TYPE); + var data = Blockly.propc.variableDB_.getName(this.getFieldValue('VALUE'), Blockly.Variables.NAME_TYPE); Blockly.propc.serial_terminal_ = true; var code = ''; - if(data !== '') { + if (data !== '') { if (type === 'NUMBER') { code += 'scan("%d\\n", &' + data + ');\n'; } else { @@ -204,11 +206,11 @@ Blockly.propc.console_scan_number = function () { Blockly.Blocks.console_newline = { helpUrl: Blockly.MSG_TERMINAL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CONSOLE_NEWLINE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_CONSOLE_NEWLINE_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("Terminal new line"); + .appendField("Terminal new line"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -222,11 +224,11 @@ Blockly.propc.console_newline = function () { Blockly.Blocks.console_clear = { helpUrl: Blockly.MSG_TERMINAL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CONSOLE_CLEAR_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_CONSOLE_CLEAR_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("Terminal clear screen"); + .appendField("Terminal clear screen"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -240,17 +242,17 @@ Blockly.propc.console_clear = function () { Blockly.Blocks.console_move_to_position = { helpUrl: Blockly.MSG_TERMINAL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CONSOLE_MOVE_TO_POSITION_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_CONSOLE_MOVE_TO_POSITION_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("Terminal set cursor to row"); + .appendField("Terminal set cursor to row"); this.appendValueInput('ROW') - .setCheck('Number'); + .setCheck('Number'); this.appendDummyInput() - .appendField("column"); + .appendField("column"); this.appendValueInput('COLUMN') - .setCheck('Number'); + .setCheck('Number'); this.setInputsInline(true); this.setPreviousStatement(true, null); @@ -281,8 +283,8 @@ Blockly.propc.console_move_to_position = function () { // ----------------------- Serial Protocol Blocks ------------------------------ Blockly.Blocks.serial_open = { helpUrl: Blockly.MSG_PROTOCOLS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SERIAL_OPEN_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SERIAL_OPEN_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() .appendField("Serial initialize RX") @@ -313,15 +315,15 @@ Blockly.propc.serial_open = function () { Blockly.Blocks.serial_tx = { helpUrl: Blockly.MSG_PROTOCOLS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SERIAL_TX_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SERIAL_TX_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() .appendField("Serial transmit") .appendField(new Blockly.FieldDropdown([ - ["number (32-bit integer)", "INT"], - ["byte (ASCII character)", "BYTE"] - ]), "TYPE"); + ["number (32-bit integer)", "INT"], + ["byte (ASCII character)", "BYTE"] + ]), "TYPE"); this.appendValueInput('VALUE', Number) .setCheck(null); this.setInputsInline(true); @@ -338,10 +340,10 @@ Blockly.propc.serial_tx = function () { { return '//Missing serial port initialize block\n'; } else { - if(type === "BYTE") { + if (type === "BYTE") { return 'fdserial_txChar(fdser, (' + data + ' & 0xFF) );\n'; } else { - var code = 'fdserial_txChar(fdser, (' + data + ' >> 24) & 255);\n'; + var code = 'fdserial_txChar(fdser, (' + data + ' >> 24) & 255);\n'; code += 'fdserial_txChar(fdser, (' + data + ' >> 16) & 255);\n'; code += 'fdserial_txChar(fdser, (' + data + ' >> 8 ) & 255);\n'; code += 'fdserial_txChar(fdser, ' + data + ' & 255);\n'; @@ -353,8 +355,8 @@ Blockly.propc.serial_tx = function () { Blockly.Blocks.serial_send_text = { helpUrl: Blockly.MSG_PROTOCOLS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SERIAL_SEND_TEXT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SERIAL_SEND_TEXT_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendValueInput('VALUE') .appendField("Serial transmit text") @@ -367,11 +369,11 @@ Blockly.Blocks.serial_send_text = { Blockly.propc.serial_send_text = function () { var text = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_NONE); - + if (Blockly.propc.setups_['setup_fdserial'] === undefined) { return '//Missing serial port initialize block\n'; } else { - var code = 'dprint(fdser, ' + text.replace("%","%%") + ');\n'; + var code = 'dprint(fdser, ' + text.replace("%", "%%") + ');\n'; code += 'while(!fdserial_txEmpty(fdser));\n'; code += 'pause(5);\n'; @@ -381,15 +383,15 @@ Blockly.propc.serial_send_text = function () { Blockly.Blocks.serial_rx = { helpUrl: Blockly.MSG_PROTOCOLS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SERIAL_RX_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SERIAL_RX_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() .appendField("Serial receive") .appendField(new Blockly.FieldDropdown([ - ["number (32-bit integer)", "INT"], - ["byte (ASCII character)", "BYTE"] - ]), "TYPE") + ["number (32-bit integer)", "INT"], + ["byte (ASCII character)", "BYTE"] + ]), "TYPE") .appendField("store in") .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VALUE'); this.setInputsInline(true); @@ -408,14 +410,14 @@ Blockly.Blocks.serial_rx = { Blockly.propc.serial_rx = function () { var type = this.getFieldValue('TYPE'); - var data = Blockly.propc.variableDB_.getName(this.getFieldValue('VALUE'), Blockly.Variables.NAME_TYPE); + var data = Blockly.propc.variableDB_.getName(this.getFieldValue('VALUE'), Blockly.Variables.NAME_TYPE); if (Blockly.propc.setups_["setup_fdserial"] === undefined) { return '//Missing serial port initialize block\n'; } else { - if(data !== '') { - if(type === "BYTE") { + if (data !== '') { + if (type === "BYTE") { return data + ' = fdserial_rxChar(fdser);\n'; } else { return data + ' = (fdserial_rxChar(fdser) << 24) | (fdserial_rxChar(fdser) << 16) | (fdserial_rxChar(fdser) << 8) | fdserial_rxChar(fdser);\n'; @@ -428,8 +430,8 @@ Blockly.propc.serial_rx = function () { Blockly.Blocks.serial_receive_text = { helpUrl: Blockly.MSG_PROTOCOLS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SERIAL_RECEIVE_TEXT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SERIAL_RECEIVE_TEXT_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() .appendField("Serial receive text store in") @@ -449,21 +451,21 @@ Blockly.Blocks.serial_receive_text = { }; Blockly.propc.serial_receive_text = function () { - var data = Blockly.propc.variableDB_.getName(this.getFieldValue('VALUE'), Blockly.Variables.NAME_TYPE); + var data = Blockly.propc.variableDB_.getName(this.getFieldValue('VALUE'), Blockly.Variables.NAME_TYPE); Blockly.propc.global_vars_["ser_rx"] = "int __idx;"; Blockly.propc.vartype_[data] = 'char *'; - + if (Blockly.propc.setups_["setup_fdserial"] === undefined) { return '//Missing serial port initialize block\n'; } else { - if(data !== '') { + if (data !== '') { var code = '__idx = 0;\n'; code += 'do {\n'; code += ' ' + data + '[__idx] = fdserial_rxChar(fdser);\n'; code += ' __idx++;\n'; - code += '} while(fdserial_rxPeek(fdser) != 0);\n'; + code += '} while(fdserial_rxPeek(fdser) != 0);\n'; code += data + '[__idx] = 0;\nfdserial_rxFlush(fdser);\n'; return code; @@ -473,11 +475,138 @@ Blockly.propc.serial_receive_text = function () { } }; + +//--------------- Shift In/Out Blocks ------------------------------------------ +Blockly.Blocks.shift_in = { + helpUrl: Blockly.MSG_PROTOCOLS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_SHIFT_IN_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField("shift in") + .appendField(new Blockly.FieldDropdown( + [['2', '2'], + ['3', '3'], + ['4', '4'], + ['5', '5'], + ['6', '6'], + ['7', '7'], + ['8', '8'], + ['9', '9'], + ['10', '10'], + ['11', '11'], + ['12', '12'], + ['13', '13'], + ['14', '14'], + ['15', '15'], + ['16', '16'], + ['17', '17'], + ['18', '18'], + ['19', '19'], + ['20', '20'], + ['21', '21'], + ['22', '22'], + ['23', '23'], + ['24', '24'], + ['25', '25'], + ['26', '26'], + ['27', '27'], + ['28', '28'], + ['29', '29'], + ['30', '30'], + ['31', '31'], + ['32', '32']]), "BITS") + .appendField("bits") + .appendField(new Blockly.FieldDropdown([["MSB first", "MSB"], ["LSB first", "LSB"]]), "MODE") + .appendField(new Blockly.FieldDropdown([["before clock", "PRE"], ["after clock", "POST"]]), "ORDER") + .appendField("DATA") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "DATA") + .appendField("CLK") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "CLK"); + this.setInputsInline(true); + this.setOutput(true, null); + } +}; + +Blockly.propc.shift_in = function () { + var bits = this.getFieldValue('BITS'); + var mode = this.getFieldValue('MODE'); + var ord = this.getFieldValue('ORDER'); + var dat = this.getFieldValue('DATA'); + var clk = this.getFieldValue('CLK'); + + return ['shift_in(' + dat + ', ' + clk + ', ' + mode + ord + ', ' + bits + ')', Blockly.propc.ORDER_NONE]; +}; + +Blockly.Blocks.shift_out = { + helpUrl: Blockly.MSG_PROTOCOLS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_SHIFT_OUT_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendValueInput("VALUE") + .setCheck("Number") + .appendField("shift out the") + .appendField(new Blockly.FieldDropdown( + [['2', '2'], + ['3', '3'], + ['4', '4'], + ['5', '5'], + ['6', '6'], + ['7', '7'], + ['8', '8'], + ['9', '9'], + ['10', '10'], + ['11', '11'], + ['12', '12'], + ['13', '13'], + ['14', '14'], + ['15', '15'], + ['16', '16'], + ['17', '17'], + ['18', '18'], + ['19', '19'], + ['20', '20'], + ['21', '21'], + ['22', '22'], + ['23', '23'], + ['24', '24'], + ['25', '25'], + ['26', '26'], + ['27', '27'], + ['28', '28'], + ['29', '29'], + ['30', '30'], + ['31', '31'], + ['32', '32']]), "BITS") + .appendField("lowest bits of"); + this.appendDummyInput() + .appendField(new Blockly.FieldDropdown([["MSB first", "MSBFIRST"], ["LSB first", "LSBFIRST"]]), "MODE") + .appendField("DATA") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "DATA") + .appendField("CLK") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "CLK"); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.propc.shift_out = function () { + var bits = this.getFieldValue('BITS'); + var mode = this.getFieldValue('MODE'); + var dat = this.getFieldValue('DATA'); + var clk = this.getFieldValue('CLK'); + var val = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_NONE) || '0'; + + return 'shift_out(' + dat + ', ' + clk + ', ' + mode + ', ' + bits + ', ' + val + ');\n'; +}; + + //--------------- Serial LCD Blocks -------------------------------------------- Blockly.Blocks.debug_lcd_init = { helpUrl: Blockly.MSG_SERIAL_LCD_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_DEBUG_LCD_INIT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_DEBUG_LCD_INIT_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() .appendField("LCD initialize PIN") @@ -504,16 +633,16 @@ Blockly.propc.debug_lcd_init = function () { Blockly.Blocks.debug_lcd_music_note = { helpUrl: Blockly.MSG_SERIAL_LCD_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_DEBUG_LCD_MUSIC_NOTE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_DEBUG_LCD_MUSIC_NOTE_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("LCD play note") - .appendField(new Blockly.FieldDropdown([["C", "223"], ["C#", "224"], ["D", "225"], ["D#", "226"], ["E", "227"], ["F", "228"], ["F#", "229"], ["G", "230"], ["G#", "231"], ["A", "220"], ["A#", "221"], ["B", "222"], ["no note (rest)", "232"]]), "NOTE") - .appendField("octave") - .appendField(new Blockly.FieldDropdown([["3rd", "215"], ["4th", "216"], ["5th", "217"], ["6th", "218"], ["7th", "219"]]), "OCTAVE") - .appendField("length") - .appendField(new Blockly.FieldDropdown([["whole (2 s)", "214"], ["half (1 s)", "213"], ["quarter (500 ms)", "212"], ["eigth (250 ms)", "211"], ["sixteenth (125 ms)", "210"], ["thirty-second (63 ms)", "209"], ["sixty-fourth (31 ms)", "208"]]), "LENGTH"); + .appendField("LCD play note") + .appendField(new Blockly.FieldDropdown([["C", "223"], ["C#", "224"], ["D", "225"], ["D#", "226"], ["E", "227"], ["F", "228"], ["F#", "229"], ["G", "230"], ["G#", "231"], ["A", "220"], ["A#", "221"], ["B", "222"], ["no note (rest)", "232"]]), "NOTE") + .appendField("octave") + .appendField(new Blockly.FieldDropdown([["3rd", "215"], ["4th", "216"], ["5th", "217"], ["6th", "218"], ["7th", "219"]]), "OCTAVE") + .appendField("length") + .appendField(new Blockly.FieldDropdown([["whole (2 s)", "214"], ["half (1 s)", "213"], ["quarter (500 ms)", "212"], ["eigth (250 ms)", "211"], ["sixteenth (125 ms)", "210"], ["thirty-second (63 ms)", "209"], ["sixty-fourth (31 ms)", "208"]]), "LENGTH"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -526,25 +655,25 @@ Blockly.propc.debug_lcd_music_note = function () { var dropdown_length = this.getFieldValue('LENGTH'); var code = ''; - - if(Blockly.propc.setups_['setup_debug_lcd'] === undefined) { + + if (Blockly.propc.setups_['setup_debug_lcd'] === undefined) { code += '//Missing Serial LCD initialize block\n'; } else { code += 'writeChar(debug_lcd, ' + dropdown_octave + ');\n'; code += 'writeChar(debug_lcd, ' + dropdown_length + ');\n'; code += 'writeChar(debug_lcd, ' + dropdown_note + ');\n'; - } - + } + return code; }; Blockly.Blocks.debug_lcd_print = { helpUrl: Blockly.MSG_SERIAL_LCD_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_DEBUG_LCD_PRINT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_DEBUG_LCD_PRINT_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendValueInput('MESSAGE') - .setCheck('String') + .setCheck('String') .appendField("LCD print text "); this.setInputsInline(true); this.setPreviousStatement(true, null); @@ -554,24 +683,24 @@ Blockly.Blocks.debug_lcd_print = { Blockly.propc.debug_lcd_print = function () { var msg = Blockly.propc.valueToCode(this, 'MESSAGE', Blockly.propc.ORDER_NONE); - - if(Blockly.propc.setups_['setup_debug_lcd'] === undefined) { + + if (Blockly.propc.setups_['setup_debug_lcd'] === undefined) { return '//Missing Serial LCD initialize block\n'; } else { - return 'dprint(debug_lcd, ' + msg.replace("%","%%") + ');\n'; + return 'dprint(debug_lcd, ' + msg.replace("%", "%%") + ');\n'; } }; Blockly.Blocks.debug_lcd_number = { helpUrl: Blockly.MSG_SERIAL_LCD_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_DEBUG_LCD_NUMBER_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_DEBUG_LCD_NUMBER_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendValueInput('VALUE') - .appendField("LCD print number"); + .appendField("LCD print number"); this.appendDummyInput() - .appendField("as") - .appendField(new Blockly.FieldDropdown([['Decimal','DEC'], ['Hexadecimal','HEX'], ['Binary', 'BIN']]), "FORMAT"); + .appendField("as") + .appendField(new Blockly.FieldDropdown([['Decimal', 'DEC'], ['Hexadecimal', 'HEX'], ['Binary', 'BIN']]), "FORMAT"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -583,18 +712,18 @@ Blockly.propc.debug_lcd_number = function () { var format = this.getFieldValue('FORMAT'); var code = ''; - - if(Blockly.propc.setups_['setup_debug_lcd'] === undefined) { + + if (Blockly.propc.setups_['setup_debug_lcd'] === undefined) { code += '//Missing Serial LCD initialize block\n'; } else { code += 'dprint(debug_lcd, '; if (format === 'BIN') { code += '"%b"'; - }else if (format === 'HEX') { - code += '"%x"'; - }else { + } else if (format === 'HEX') { + code += '"%x"'; + } else { code += '"%d"'; - } + } code += ', ' + value + ');'; } @@ -603,8 +732,8 @@ Blockly.propc.debug_lcd_number = function () { Blockly.Blocks.debug_lcd_action = { helpUrl: Blockly.MSG_SERIAL_LCD_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_DEBUG_LCD_ACTION_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_DEBUG_LCD_ACTION_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() .appendField("LCD command") @@ -630,13 +759,13 @@ Blockly.Blocks.debug_lcd_action = { Blockly.propc.debug_lcd_action = function () { var action = this.getFieldValue('ACTION'); var code = ''; - - if(Blockly.propc.setups_['setup_debug_lcd'] === undefined) { + + if (Blockly.propc.setups_['setup_debug_lcd'] === undefined) { code += '//Missing Serial LCD initialization\n'; } else { code += 'writeChar(debug_lcd, ' + action + ');\n'; //if(action === '12') { - code += 'pause(5);\n'; + code += 'pause(5);\n'; //} } return code; @@ -644,15 +773,15 @@ Blockly.propc.debug_lcd_action = function () { Blockly.Blocks.debug_lcd_set_cursor = { helpUrl: Blockly.MSG_SERIAL_LCD_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_DEBUG_LCD_SET_CURSOR_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_DEBUG_LCD_SET_CURSOR_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendValueInput('ROW') - .appendField("LCD set cursor row") - .setCheck('Number'); + .appendField("LCD set cursor row") + .setCheck('Number'); this.appendValueInput('COLUMN') - .appendField("column") - .setCheck('Number'); + .appendField("column") + .setCheck('Number'); this.setInputsInline(true); this.setPreviousStatement(true, null); @@ -669,7 +798,7 @@ Blockly.propc.debug_lcd_set_cursor = function () { setup_code += 'if(__cVal > __cMax) __cVal = __cMax;\nreturn __cVal;\n}\n'; Blockly.propc.global_vars_["constrain_function"] = setup_code; - if(Blockly.propc.setups_['setup_debug_lcd'] === undefined) { + if (Blockly.propc.setups_['setup_debug_lcd'] === undefined) { return '//Missing Serial LCD initialize block\n'; } else { return 'writeChar(debug_lcd, (128 + (constrain(' + row + ', 0, 3) * 20) + constrain(' + column + ', 0, 19)));\n'; @@ -679,8 +808,8 @@ Blockly.propc.debug_lcd_set_cursor = function () { //--------------- XBee Blocks -------------------------------------------------- Blockly.Blocks.xbee_setup = { helpUrl: Blockly.MSG_XBEE_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_XBEE_SETUP_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_XBEE_SETUP_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() .appendField("XBee initialize DI") @@ -711,8 +840,8 @@ Blockly.propc.xbee_setup = function () { Blockly.Blocks.xbee_transmit = { helpUrl: Blockly.MSG_XBEE_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_XBEE_TRANSMIT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_XBEE_TRANSMIT_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() .appendField("XBee transmit") @@ -733,12 +862,12 @@ Blockly.propc.xbee_transmit = function () { { return '//Missing xbee initialize block\n'; } else { - if(type === "BYTE") { + if (type === "BYTE") { return 'fdserial_txChar(xbee, (' + data + ' & 0xFF) );\n'; - } else if(type === "INT") { + } else if (type === "INT") { return 'dprint(xbee, "%d\\r", ' + data + ');\n'; - } else { - var code = 'dprint(xbee, "%s\\r", ' + data.replace("%","%%") + ');\n'; + } else { + var code = 'dprint(xbee, "%s\\r", ' + data.replace("%", "%%") + ');\n'; code += 'while(!fdserial_txEmpty(xbee));\n'; code += 'pause(5);\n'; @@ -749,8 +878,8 @@ Blockly.propc.xbee_transmit = function () { Blockly.Blocks.xbee_receive = { helpUrl: Blockly.MSG_XBEE_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_XBEE_RECEIVE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_XBEE_RECEIVE_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() .appendField("XBee receive") @@ -779,11 +908,11 @@ Blockly.propc.xbee_receive = function () { { return '//Missing xbee initialize block\n'; } else { - if(type === "BYTE") { + if (type === "BYTE") { return data + ' = fdserial_rxChar(xbee);\n'; - } else if(type === "INT") { + } else if (type === "INT") { return 'dscan(xbee, "%d", &' + data + ');\n'; - } else { + } else { Blockly.propc.global_vars_["xbee_rx"] = "int __XBidx;"; Blockly.propc.vartype_[data] = 'char *'; @@ -792,7 +921,7 @@ Blockly.propc.xbee_receive = function () { code += ' ' + data + '[__XBidx] = fdserial_rxChar(xbee);\n'; code += ' if(' + data + '[__XBidx] == 13 || ' + data + '[__XBidx] == 10) break;\n'; code += ' __XBidx++;\n'; - code += '}\n'; + code += '}\n'; code += data + '[__XBidx] = 0;\nfdserial_rxFlush(xbee);\n'; return code; } @@ -802,22 +931,22 @@ Blockly.propc.xbee_receive = function () { // -------------- OLED Display blocks ------------------------------------------ Blockly.Blocks.oled_initialize = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_INITIALIZE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_INITIALIZE_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); // Field order DIN, CLK, CS, D/C, RES this.appendDummyInput() - .appendField("OLED initialize") - .appendField("DIN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "DIN") - .appendField("CLK") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "CLK") - .appendField("CS") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "CS") - .appendField("D/C") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "DC") - .appendField("RES") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "RES"); + .appendField("OLED initialize") + .appendField("DIN") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "DIN") + .appendField("CLK") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "CLK") + .appendField("CS") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "CS") + .appendField("D/C") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "DC") + .appendField("RES") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "RES"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -839,11 +968,11 @@ Blockly.propc.oled_initialize = function () { Blockly.Blocks.oled_font_loader = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_FONT_LOADER_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_FONT_LOADER_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("OLED font loader (EEPROM only)"); + .appendField("OLED font loader (EEPROM only)"); } }; @@ -857,33 +986,33 @@ Blockly.propc.oled_font_loader = function () { Blockly.Blocks.oled_clear_screen = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_CLEAR_SCREEN_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_CLEAR_SCREEN_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("OLED command") - .appendField(new Blockly.FieldDropdown([["clear screen", "CLS"], ["sleep", "SLEEP"], ["wake", "WAKE"], ["invert", "INV"]]), "CMD"); + .appendField("OLED command") + .appendField(new Blockly.FieldDropdown([["clear screen", "CLS"], ["sleep", "SLEEP"], ["wake", "WAKE"], ["invert", "INV"]]), "CMD"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.oled_clear_screen = function() { +Blockly.propc.oled_clear_screen = function () { var cmd = this.getFieldValue("CMD"); var code = ''; if (Blockly.propc.setups_["oled"] === undefined) { code += '//Missing OLED initialize block\n'; - } else { - if(cmd === 'CLS') { + } else { + if (cmd === 'CLS') { code += 'oledc_clear(0, 0, oledc_getWidth(), oledc_getHeight() );\n'; - } else if(cmd === 'WAKE') { + } else if (cmd === 'WAKE') { code += 'oledc_wake();\n'; - } else if(cmd === 'SLEEP') { + } else if (cmd === 'SLEEP') { code += 'oledc_sleep();\n'; - } else if(cmd === 'INV') { + } else if (cmd === 'INV') { code += 'oledc_invertDisplay();\n'; } } @@ -892,29 +1021,29 @@ Blockly.propc.oled_clear_screen = function() { Blockly.Blocks.oled_draw_circle = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_DRAW_CIRCLE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_DRAW_CIRCLE_TOOLTIP); // First x/y coordinates this.appendValueInput("POINT_X") - .setCheck("Number") - .appendField("OLED draw circle at (x)"); + .setCheck("Number") + .appendField("OLED draw circle at (x)"); this.appendValueInput("POINT_Y") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("(y)"); + .setCheck(null) + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("(y)"); this.appendValueInput("RADIUS") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("radius"); + .setCheck("Number") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("radius"); // Color picker control this.appendValueInput('COLOR') - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck('Number') - .appendField("color"); + .setAlign(Blockly.ALIGN_RIGHT) + .setCheck('Number') + .appendField("color"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("fill") - .appendField(new Blockly.FieldCheckbox("TRUE"), "ck_fill"); + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("fill") + .appendField(new Blockly.FieldCheckbox("TRUE"), "ck_fill"); // Other details this.setInputsInline(false); @@ -924,7 +1053,7 @@ Blockly.Blocks.oled_draw_circle = { } }; -Blockly.propc.oled_draw_circle = function() { +Blockly.propc.oled_draw_circle = function () { // Ensure header file is included Blockly.propc.definitions_["colormath"] = '#include "colormath.h"'; @@ -955,28 +1084,28 @@ Blockly.propc.oled_draw_circle = function() { Blockly.Blocks.oled_draw_line = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_DRAW_LINE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_DRAW_LINE_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendValueInput("X_ONE") - .setCheck('Number') - .appendField("OLED draw line from 1 (x)"); + .setCheck('Number') + .appendField("OLED draw line from 1 (x)"); this.appendValueInput("Y_ONE") - .setCheck('Number') - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("(y)"); + .setCheck('Number') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("(y)"); this.appendValueInput("X_TWO") - .setCheck('Number') - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("to 2 (x)"); + .setCheck('Number') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("to 2 (x)"); this.appendValueInput("Y_TWO") - .setCheck('Number') - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("(y)"); + .setCheck('Number') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("(y)"); this.appendValueInput('COLOR') - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck('Number') - .appendField("color"); + .setAlign(Blockly.ALIGN_RIGHT) + .setCheck('Number') + .appendField("color"); this.setInputsInline(false); this.setPreviousStatement(true, null); @@ -1007,18 +1136,18 @@ Blockly.propc.oled_draw_line = function () { Blockly.Blocks.oled_draw_pixel = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_DRAW_PIXEL_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_DRAW_PIXEL_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendValueInput("X_AXIS") - .setCheck('Number') - .appendField("OLED draw pixel at"); + .setCheck('Number') + .appendField("OLED draw pixel at"); this.appendValueInput("Y_AXIS") - .setCheck('Number') - .appendField(","); + .setCheck('Number') + .appendField(","); this.appendValueInput('COLOR') - .setCheck('Number') - .appendField("color"); + .setCheck('Number') + .appendField("color"); this.setInputsInline(true); this.setPreviousStatement(true, null); @@ -1026,7 +1155,7 @@ Blockly.Blocks.oled_draw_pixel = { } }; -Blockly.propc.oled_draw_pixel = function() { +Blockly.propc.oled_draw_pixel = function () { Blockly.propc.definitions_["colormath"] = '#include "colormath.h"'; var point_x = Blockly.propc.valueToCode(this, 'X_AXIS', Blockly.propc.ORDER_ATOMIC); @@ -1046,44 +1175,44 @@ Blockly.propc.oled_draw_pixel = function() { Blockly.Blocks.oled_draw_triangle = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_DRAW_TRIANGLE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_DRAW_TRIANGLE_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); // First x/y coordinates this.appendValueInput("POINT_X0") - .setCheck(null) - .appendField("OLED draw triangle at 1 (x)"); + .setCheck(null) + .appendField("OLED draw triangle at 1 (x)"); this.appendValueInput("POINT_Y0") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("(y)"); + .setCheck(null) + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("(y)"); // Second x/y coordinates this.appendValueInput("POINT_X1") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("2 (x)"); + .setCheck(null) + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("2 (x)"); this.appendValueInput("POINT_Y1") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("(y)"); + .setCheck(null) + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("(y)"); // Third x/y coordinates this.appendValueInput("POINT_X2") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("3 (x)"); + .setCheck(null) + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("3 (x)"); this.appendValueInput("POINT_Y2") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("(y)"); + .setCheck(null) + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("(y)"); // Color picker control this.appendValueInput('COLOR') - .setCheck('Number') - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("color"); + .setCheck('Number') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("color"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("fill") - .appendField(new Blockly.FieldCheckbox("TRUE"), "ck_fill"); + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("fill") + .appendField(new Blockly.FieldCheckbox("TRUE"), "ck_fill"); // Other details this.setInputsInline(false); @@ -1092,7 +1221,7 @@ Blockly.Blocks.oled_draw_triangle = { } }; -Blockly.propc.oled_draw_triangle = function() { +Blockly.propc.oled_draw_triangle = function () { Blockly.propc.definitions_["colormath"] = '#include "colormath.h"'; var point_x0 = Blockly.propc.valueToCode(this, 'POINT_X0', Blockly.propc.ORDER_NONE); @@ -1125,36 +1254,36 @@ Blockly.propc.oled_draw_triangle = function() { Blockly.Blocks.oled_draw_rectangle = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_DRAW_RECTANGLE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_DRAW_RECTANGLE_TOOLTIP); this.appendValueInput("POINT_X") - .setCheck("Number") - .appendField("OLED draw rectangle at (x)"); + .setCheck("Number") + .appendField("OLED draw rectangle at (x)"); this.appendValueInput("POINT_Y") - .setCheck("Number") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("(y)"); + .setCheck("Number") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("(y)"); this.appendValueInput("RECT_WIDTH") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("width"); + .setCheck(null) + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("width"); this.appendValueInput("RECT_HEIGHT") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("height"); + .setCheck(null) + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("height"); this.appendValueInput("RECT_ROUND") - .setCheck(null) - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("roundness"); + .setCheck(null) + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("roundness"); // Color picker control this.appendValueInput('COLOR') - .setAlign(Blockly.ALIGN_RIGHT) - .setCheck('Number') - .appendField("color"); + .setAlign(Blockly.ALIGN_RIGHT) + .setCheck('Number') + .appendField("color"); this.appendDummyInput() - .setAlign(Blockly.ALIGN_RIGHT) - .appendField("fill") - .appendField(new Blockly.FieldCheckbox("TRUE"), "ck_fill"); + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("fill") + .appendField(new Blockly.FieldCheckbox("TRUE"), "ck_fill"); // Other details this.setInputsInline(false); @@ -1164,7 +1293,7 @@ Blockly.Blocks.oled_draw_rectangle = { } }; -Blockly.propc.oled_draw_rectangle = function() { +Blockly.propc.oled_draw_rectangle = function () { Blockly.propc.definitions_["colormath"] = '#include "colormath.h"'; var point_x = Blockly.propc.valueToCode(this, 'POINT_X', Blockly.propc.ORDER_NONE); @@ -1188,12 +1317,11 @@ Blockly.propc.oled_draw_rectangle = function() { code = 'oledc_drawRect('; } code += point_x + ', ' + point_y + ', ' + width + ', ' + height + ', '; - } else { + } else { // Rounded rectangle if (checkbox === 'TRUE') { code = 'oledc_fillRoundRect('; - } - else { + } else { code = 'oledc_drawRoundRect('; } code += point_x + ', ' + point_y + ', ' + width + ', ' + height + ', ' + corners + ', '; @@ -1205,20 +1333,20 @@ Blockly.propc.oled_draw_rectangle = function() { Blockly.Blocks.oled_text_size = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_TEXT_SIZE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_TEXT_SIZE_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("OLED text size") - .appendField(new Blockly.FieldDropdown([["small", "SMALL"], ["medium", "MEDIUM"], ["large", "LARGE"]]), "size_select") - .appendField("font") - .appendField(new Blockly.FieldDropdown([["sans", "FONT_SANS"], ["serif", "FONT_SERIF"], ["script", "FONT_SCRIPT"], ["bubble", "FONT_BUBBLE"]]), "font_select"); + .appendField("OLED text size") + .appendField(new Blockly.FieldDropdown([["small", "SMALL"], ["medium", "MEDIUM"], ["large", "LARGE"]]), "size_select") + .appendField("font") + .appendField(new Blockly.FieldDropdown([["sans", "FONT_SANS"], ["serif", "FONT_SERIF"], ["script", "FONT_SCRIPT"], ["bubble", "FONT_BUBBLE"]]), "font_select"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.oled_text_size = function() { +Blockly.propc.oled_text_size = function () { var size = this.getFieldValue('size_select'); var font = this.getFieldValue('font_select'); @@ -1236,22 +1364,22 @@ Blockly.propc.oled_text_size = function() { Blockly.Blocks.oled_text_color = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_TEXT_COLOR_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_TEXT_COLOR_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendValueInput('FONT_COLOR') - .setCheck('Number') - .appendField("OLED font color"); + .setCheck('Number') + .appendField("OLED font color"); this.appendValueInput('BACKGROUND_COLOR') - .setCheck('Number') - .appendField("font background color"); + .setCheck('Number') + .appendField("font background color"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.oled_text_color = function() { +Blockly.propc.oled_text_color = function () { Blockly.propc.definitions_["colormath"] = '#include "colormath.h"'; var font_color = Blockly.propc.valueToCode(this, 'FONT_COLOR', Blockly.propc.ORDER_NONE); @@ -1264,8 +1392,8 @@ Blockly.propc.oled_text_color = function() { } else { code += 'oledc_setTextColor('; - // TO DO: Try this - it's shorter but slightly slower: - // code += 'remapColor(' + font_color + ', "8R8G8B", "5R6G5B"), remapColor(' + background_color + ', "8R8G8B", "5R6G5B"));\n'; + // TO DO: Try this - it's shorter but slightly slower: + // code += 'remapColor(' + font_color + ', "8R8G8B", "5R6G5B"), remapColor(' + background_color + ', "8R8G8B", "5R6G5B"));\n'; code += 'oledc_color565(get8bitColor(' + font_color + ', "RED"), get8bitColor(' + font_color + ', "GREEN"), get8bitColor(' + font_color + ', "BLUE")), '; code += 'oledc_color565(get8bitColor(' + background_color + ', "RED"), get8bitColor(' + background_color + ', "GREEN"), get8bitColor(' + background_color + ', "BLUE")));'; @@ -1275,11 +1403,11 @@ Blockly.propc.oled_text_color = function() { Blockly.Blocks.oled_get_max_height = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_GET_MAX_HEIGHT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_GET_MAX_HEIGHT_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("OLED max height"); + .appendField("OLED max height"); this.setPreviousStatement(false, null); this.setNextStatement(false, null); @@ -1287,7 +1415,7 @@ Blockly.Blocks.oled_get_max_height = { } }; -Blockly.propc.oled_get_max_height = function() { +Blockly.propc.oled_get_max_height = function () { if (Blockly.propc.setups_["oled"] === undefined) { return ['0', Blockly.propc.ORDER_NONE]; @@ -1298,11 +1426,11 @@ Blockly.propc.oled_get_max_height = function() { Blockly.Blocks.oled_get_max_width = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_GET_MAX_WIDTH_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_GET_MAX_WIDTH_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("OLED max width"); + .appendField("OLED max width"); this.setPreviousStatement(false, null); this.setNextStatement(false, null); @@ -1310,7 +1438,7 @@ Blockly.Blocks.oled_get_max_width = { } }; -Blockly.propc.oled_get_max_width = function() { +Blockly.propc.oled_get_max_width = function () { if (Blockly.propc.setups_["oled"] === undefined) { return ['0', Blockly.propc.ORDER_NONE]; @@ -1321,14 +1449,14 @@ Blockly.propc.oled_get_max_width = function() { Blockly.Blocks.oled_set_cursor = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_SET_CURSOR_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_SET_CURSOR_TOOLTIP); this.appendValueInput('X_POS') - .setCheck('Number') - .appendField("OLED set cursor at (x)"); + .setCheck('Number') + .appendField("OLED set cursor at (x)"); this.appendValueInput('Y_POS') - .setCheck('Number') - .appendField("(y)"); + .setCheck('Number') + .appendField("(y)"); this.setInputsInline(true); this.setPreviousStatement(true, null); @@ -1337,7 +1465,7 @@ Blockly.Blocks.oled_set_cursor = { } }; -Blockly.propc.oled_set_cursor = function() { +Blockly.propc.oled_set_cursor = function () { // Get user input var x = Blockly.propc.valueToCode(this, 'X_POS', Blockly.propc.ORDER_NONE); @@ -1353,11 +1481,11 @@ Blockly.propc.oled_set_cursor = function() { Blockly.Blocks.oled_print_text = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_PRINT_TEXT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_PRINT_TEXT_TOOLTIP); this.appendValueInput('MESSAGE') - .setCheck('String') - .appendField("OLED print text "); + .setCheck('String') + .appendField("OLED print text "); this.setInputsInline(true); this.setPreviousStatement(true, null); @@ -1366,9 +1494,9 @@ Blockly.Blocks.oled_print_text = { } }; -Blockly.propc.oled_print_text = function() { +Blockly.propc.oled_print_text = function () { var msg = Blockly.propc.valueToCode(this, 'MESSAGE', Blockly.propc.ORDER_NONE); - + if (Blockly.propc.setups_["oled"] === undefined) { return '//Missing OLED initialize block\n'; } else { @@ -1378,13 +1506,13 @@ Blockly.propc.oled_print_text = function() { Blockly.Blocks.oled_print_number = { helpUrl: Blockly.MSG_OLED_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_OLED_PRINT_NUMBER_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_OLED_PRINT_NUMBER_TOOLTIP); this.appendValueInput('NUMIN') - .setCheck('Number') - .appendField("OLED print number "); + .setCheck('Number') + .appendField("OLED print number "); this.appendDummyInput() - .appendField(new Blockly.FieldDropdown([["Decimal", "DEC"], ["Hexadecimal", "HEX"], ["Binary", "BIN"]]), "type"); + .appendField(new Blockly.FieldDropdown([["Decimal", "DEC"], ["Hexadecimal", "HEX"], ["Binary", "BIN"]]), "type"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -1392,10 +1520,10 @@ Blockly.Blocks.oled_print_number = { } }; -Blockly.propc.oled_print_number = function() { +Blockly.propc.oled_print_number = function () { var num = Blockly.propc.valueToCode(this, 'NUMIN', Blockly.propc.ORDER_NONE); var type = this.getFieldValue('type'); - + if (Blockly.propc.setups_["oled"] === undefined) { return '//Missing OLED initialize block\n'; } else { @@ -1406,54 +1534,56 @@ Blockly.propc.oled_print_number = function() { // -------------- RGB LEDs (WS2812B module) blocks ----------------------------- Blockly.Blocks.ws2812b_init = { helpUrl: Blockly.MSG_WS2812B_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_WS2812B_INIT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_WS2812B_INIT_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("RGB-LED initialize PIN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN") - .appendField("number of LEDs") - .appendField(new Blockly.FieldTextInput('4', Blockly.FieldTextInput.numberValidator), "LEDNUM") - .appendField("type") - .appendField(new Blockly.FieldDropdown([["WS2812", "WS2812"]]), "TYPE"); + .appendField("RGB-LED initialize PIN") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN") + .appendField("number of LEDs") + .appendField(new Blockly.FieldTextInput('4', Blockly.FieldTextInput.numberValidator), "LEDNUM") + .appendField("type") + .appendField(new Blockly.FieldDropdown([["WS2812", "WS2812"]]), "TYPE"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.ws2812b_init = function() { +Blockly.propc.ws2812b_init = function () { var pin = this.getFieldValue('PIN'); var num = window.parseInt(this.getFieldValue('LEDNUM')); - - if(num < 1) num = 1; - if(num > 1500) num = 1500; - Blockly.propc.definitions_["ws2812b_def"] = '#include "ws2812.h"\n\n#define LED_PIN ' + pin + '\n#define LED_COUNT ' + num + '\n'; + if (num < 1) + num = 1; + if (num > 1500) + num = 1500; + + Blockly.propc.definitions_["ws2812b_def"] = '#include "ws2812.h"\n\n#define LED_PIN ' + pin + '\n#define LED_COUNT ' + num + '\n'; Blockly.propc.global_vars_["ws2812b_array"] = 'ws2812 *__ws2812b;\nint RGBleds[' + num + '];\nint __rgbTemp;\n'; Blockly.propc.setups_["ws2812b_init"] = '__ws2812b = ws2812b_open();\n'; - + return ''; }; Blockly.Blocks.ws2812b_set = { helpUrl: Blockly.MSG_WS2812B_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_WS2812B_SET_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_WS2812B_SET_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendValueInput("LED") - .setCheck("Number") - .appendField("RGB-LED set LED number"); + .setCheck("Number") + .appendField("RGB-LED set LED number"); this.appendValueInput("COLOR") - .setCheck("Number") - .appendField("to color"); + .setCheck("Number") + .appendField("to color"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.ws2812b_set = function() { +Blockly.propc.ws2812b_set = function () { var led = Blockly.propc.valueToCode(this, 'LED', Blockly.propc.ORDER_NONE); var color = Blockly.propc.valueToCode(this, 'COLOR', Blockly.propc.ORDER_NONE); @@ -1463,24 +1593,24 @@ Blockly.propc.ws2812b_set = function() { } else { code += '__rgbTemp = ' + led + ';\nif(__rgbTemp < 1) __rgbTemp = 1;\nif(__rgbTemp > LED_COUNT) __rgbTemp = LED_COUNT;\n'; code += 'RGBleds[(__rgbTemp - 1)] = ' + color + ';\n'; - } + } return code; }; Blockly.Blocks.ws2812b_update = { helpUrl: Blockly.MSG_WS2812B_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_WS2812B_UPDATE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_WS2812B_UPDATE_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("RGB-LED update LEDs"); + .appendField("RGB-LED update LEDs"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.ws2812b_update = function() { +Blockly.propc.ws2812b_update = function () { if (Blockly.propc.setups_["ws2812b_init"] === undefined) { return '//Missing RGB-LED initialize block\n'; } else { @@ -1489,36 +1619,135 @@ Blockly.propc.ws2812b_update = function() { }; // --------------------- Simple WX Module -------------------------------------- +Blockly.Blocks.wx_init = { + helpUrl: Blockly.MSG_SWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_SWX_INIT_TOOLTIP); + var bkg_colors = new Blockly.FieldColour("#FFFFFF"); + bkg_colors.setColours(['#FFFFFF', '#000000']).setColumns(2); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField('Simple WX initialize') + .appendField("mode") + .appendField(new Blockly.FieldDropdown([['Terminal on USB', 'USB_PGM_TERM'], ['Terminal on WX', 'USB_PGM'], ['Term & Programming on WX', 'WX_ALL_COM']]), "MODE") // .concat(profile.default.digital) + .appendField(" DO") + .appendField(new Blockly.FieldDropdown([['WX Socket', '31']].concat(profile.default.digital), function (pin) { + this.sourceBlock_.updateShape_({"PIN": pin}); + }), "DO"); + this.appendDummyInput('DIPIN') + .appendField("DI") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "DI"); + this.getInput('DIPIN').setVisible(false); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + }, + mutationToDom: function () { + var container = document.createElement('mutation'); + var pin = this.getFieldValue('DO'); + container.setAttribute('pin', pin); + return container; + }, + domToMutation: function (xmlElement) { + var pin = xmlElement.getAttribute('pin'); + this.updateShape_({"PIN": pin}); + }, + updateShape_: function (details) { + if (details['PIN'] === '31') + this.getInput('DIPIN').setVisible(false); + else + this.getInput('DIPIN').setVisible(true); + } +}; + +Blockly.propc.wx_init = function () { + var pin_do = this.getFieldValue('DO'); + var pin_di = this.getFieldValue('DI'); + if (pin_do === '31') + pin_di = '30'; + var bkg = (this.getFieldValue('BKG') === '#FFFFFF') ? '1' : '0'; + var title = this.getFieldValue('TITLE'); + var mode = this.getFieldValue('MODE'); + //if(pin_do === '31' && pin_di === '30' && mode === 'USB_PGM') mode = 'WX_ALL_COM'; + var code = ''; + code += 'wifi_start(' + pin_do + ', ' + pin_di + ', 115200, ' + mode + ');\n'; + code += 'wifi_setBuffer(__wxBffr, sizeof(__wxBffr));\n'; + code += '__wsId = wifi_listen(WS, "/ws/a");\n'; + code += 'while(!__wsHandle) {\n wifi_poll(&__wxEvent, &__wxId, &__wxHandle);\n'; + code += ' if(__wxEvent == \'W\' && __wxId == __wsId) __wsHandle = __wxHandle;\n}'; + + var vars = ''; + vars += 'int __wxEvent, __wxId, __wxHandle, __wsId, __wv[13], __wsHandle = 0;\n'; + vars += 'char __wxBffr[136];\n'; + + Blockly.propc.definitions_["wx_def"] = '#include "wifi.h"'; + Blockly.propc.global_vars_["wx_vars"] = vars; + Blockly.propc.setups_["wx_init"] = code; + + return ''; +}; + +Blockly.Blocks.wx_config_page = { + helpUrl: Blockly.MSG_SWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_SWX_CONFIG_PAGE_TOOLTIP); + var bkg_colors = new Blockly.FieldColour("#FFFFFF"); + bkg_colors.setColours(['#FFFFFF', '#000000']).setColumns(2); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField("Simple WX configure page title") + .appendField(new Blockly.FieldTextInput('title'), 'TITLE') + .appendField(" background color") + .appendField(bkg_colors, "BKG"); + this.setInputsInline(false); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.propc.wx_config_page = function () { + var bkg = (this.getFieldValue('BKG') === '#FFFFFF') ? '1' : '0'; + var title = this.getFieldValue('TITLE'); + + var code = 'wifi_print(WS, __wsHandle, "S,' + bkg + ',' + title + '");\n'; + + return code; +}; + Blockly.Blocks.wx_set_widget = { - init: function() { + helpUrl: Blockly.MSG_SWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_SWX_SET_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput("SET_1") - .appendField("Simple WX set widget") - .appendField(new Blockly.FieldDropdown([["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"]]), "WIDGET") - .appendField("to a") - .appendField(new Blockly.FieldDropdown([ - ["Button \u2794", '0'], - ["Switch \u2794", '1'], - ["Slider \u2794", '2'], - ["Send Value \u2794", '3'], - ["Pick Color \u2794", '4'], - ["\u2794 Show Value", '5'], - ["\u2794 Gauge", '6'], - ["\u2794 Bar Graph", '7'], - ["\u2794 Show Color", '8'], - ["\u2794 Light Bulb", '9'], - ["Clear Widget", '10']], function (type) { + .appendField("Simple WX configure widget") + .appendField(new Blockly.FieldDropdown([["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"]]), "WIDGET") + .appendField("to a") + .appendField(new Blockly.FieldDropdown([ + ["Button \u2794", '0'], + ["Switch \u2794", '1'], + ["Slider \u2794", '2'], + ["Send Value \u2794", '3'], + ["Pick Color \u2794", '4'], + ["\u2794 Show Value", '5'], + ["\u2794 Gauge", '6'], + ["\u2794 Bar Graph", '7'], + ["\u2794 Show Color", '8'], + ["\u2794 Light Bulb", '9'], + ["Clear Widget", '10']], function (type) { this.sourceBlock_.updateShape_({"TYPE": type}); - }), "TYPE"); + }), "TYPE") + .appendField(" label") + .appendField(new Blockly.FieldTextInput('label'), 'LABEL'); this.appendDummyInput("SET_2") - .appendField("widget color") - .appendField(new Blockly.FieldColour("#ffffff"), "COLOR") - .appendField(" minimum") - .appendField(new Blockly.FieldTextInput('0', Blockly.FieldTextInput.numberValidator), 'MIN') - .appendField(" maximum") - .appendField(new Blockly.FieldTextInput('10', Blockly.FieldTextInput.numberValidator), 'MAX') - .appendField(" initial value") - .appendField(new Blockly.FieldTextInput('5', Blockly.FieldTextInput.numberValidator), 'INITIAL'); + .appendField("widget color") + .appendField(new Blockly.FieldColour("#ffffff"), "COLOR") + .appendField(" minimum") + .appendField(new Blockly.FieldTextInput('0', Blockly.FieldTextInput.numberValidator), 'MIN') + .appendField(" maximum") + .appendField(new Blockly.FieldTextInput('10', Blockly.FieldTextInput.numberValidator), 'MAX') + .appendField(" initial value") + .appendField(new Blockly.FieldTextInput('5', Blockly.FieldTextInput.numberValidator), 'INITIAL'); this.setInputsInline(false); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -1526,12 +1755,25 @@ Blockly.Blocks.wx_set_widget = { mutationToDom: function () { var container = document.createElement('mutation'); var type = this.getFieldValue('TYPE'); - container.setAttribute('TYPE', type); + container.setAttribute('w_type', type); + var color = this.getFieldValue('COLOR'); + container.setAttribute('w_color', color); + var min = this.getFieldValue('MIN'); + container.setAttribute('w_min', min); + var max = this.getFieldValue('MAX'); + container.setAttribute('w_max', max); + var initial = this.getFieldValue('INITIAL'); + container.setAttribute('w_init', initial); + return container; }, domToMutation: function (xmlElement) { - var type = xmlElement.getAttribute('TYPE'); - this.updateShape_({"TYPE": type}); + var type = xmlElement.getAttribute('w_type'); + var color = xmlElement.getAttribute('w_color'); + var min = xmlElement.getAttribute('w_min'); + var max = xmlElement.getAttribute('w_max'); + var initial = xmlElement.getAttribute('w_init'); + this.updateShape_({"TYPE": type, "COLOR": color, "MIN": min, "MAX": max, "INITIAL": initial}); }, updateShape_: function (details) { var type = details['TYPE']; @@ -1539,6 +1781,23 @@ Blockly.Blocks.wx_set_widget = { type = this.getFieldValue('TYPE'); } + var min = details['MIN']; + if (details['MIN'] === undefined) { + min = this.getFieldValue('MIN'); + } + var max = details['MAX']; + if (details['MAX'] === undefined) { + max = this.getFieldValue('MAX'); + } + var color = details['COLOR']; + if (details['COLOR'] === undefined) { + color = this.getFieldValue('COLOR'); + } + var initial = details['INITIAL']; + if (details['INITIAL'] === undefined) { + initial = this.getFieldValue('INITIAL'); + } + if (this.getInput('SET_2') !== undefined) { this.removeInput('SET_2'); } @@ -1549,107 +1808,1305 @@ Blockly.Blocks.wx_set_widget = { } if (type === '2' || type === '6' || type === '7') { inputPins.appendField("widget color") - .appendField(new Blockly.FieldColour("#ffffff"), "COLOR") - .appendField(" minimum") - .appendField(new Blockly.FieldTextInput('0', Blockly.FieldTextInput.numberValidator), 'MIN') - .appendField(" maximum") - .appendField(new Blockly.FieldTextInput('10', Blockly.FieldTextInput.numberValidator), 'MAX') - .appendField(" initial value") - .appendField(new Blockly.FieldTextInput('5', Blockly.FieldTextInput.numberValidator), 'INITIAL'); + .appendField(new Blockly.FieldColour("#ffffff"), "COLOR") + .appendField(" minimum") + .appendField(new Blockly.FieldTextInput('0', Blockly.FieldTextInput.numberValidator), 'MIN') + .appendField(" maximum") + .appendField(new Blockly.FieldTextInput('10', Blockly.FieldTextInput.numberValidator), 'MAX') + .appendField(" initial value") + .appendField(new Blockly.FieldTextInput('5', Blockly.FieldTextInput.numberValidator), 'INITIAL'); } else if (type === '1') { inputPins.appendField("widget color") - .appendField(new Blockly.FieldColour("#ffffff"), "COLOR") - .appendField(" minimum") - .appendField(new Blockly.FieldTextInput('0', Blockly.FieldTextInput.numberValidator), 'MIN') - .appendField(" maximum") - .appendField(new Blockly.FieldTextInput('10', Blockly.FieldTextInput.numberValidator), 'MAX'); + .appendField(new Blockly.FieldColour("#ffffff"), "COLOR") + .appendField(" off value") + .appendField(new Blockly.FieldTextInput('0', Blockly.FieldTextInput.numberValidator), 'MIN') + .appendField(" on value") + .appendField(new Blockly.FieldTextInput('10', Blockly.FieldTextInput.numberValidator), 'MAX') + .appendField(" initial state") + .appendField(new Blockly.FieldDropdown([['on', 'on'], ['off', 'off']]), 'INITIAL'); } else if (type === '0' || type === '5' || type === '9') { inputPins.appendField("widget color") - .appendField(new Blockly.FieldColour("#ffffff"), "COLOR") - .appendField(" initial value") - .appendField(new Blockly.FieldTextInput('5', Blockly.FieldTextInput.numberValidator), 'INITIAL'); + .appendField(new Blockly.FieldColour("#ffffff"), "COLOR") + .appendField(" initial value") + .appendField(new Blockly.FieldTextInput('5', Blockly.FieldTextInput.numberValidator), 'INITIAL'); } else if (type === '8') { inputPins.appendField("widget color") - .appendField(new Blockly.FieldColour("#ffffff"), "COLOR") - .appendField(" initial color shown") - .appendField(new Blockly.FieldColour("#ffffff"), "INITIAL_COLOR"); + .appendField(new Blockly.FieldColour("#ffffff"), "COLOR") + .appendField(" initial color shown") + .appendField(new Blockly.FieldColour("#ffffff"), "INITIAL"); } else if (type === '3' || type === '4') { inputPins.appendField("widget color") - .appendField(new Blockly.FieldColour("#ffffff"), "COLOR"); + .appendField(new Blockly.FieldColour("#ffffff"), "COLOR"); + } + + if (this.getField('TYPE') && type !== null) { + this.setFieldValue(type, 'TYPE'); } + if (this.getField('MIN') && min !== null) { + this.setFieldValue(min, 'MIN'); + } + if (this.getField('MAX') && max !== null) { + this.setFieldValue(max, 'MAX'); + } + if (this.getField('COLOR') && color !== null) { + this.setFieldValue(color, 'COLOR'); + } + if (this.getField('INITIAL') && initial !== null) { + this.setFieldValue(initial, 'INITIAL'); + if (type === '1' && initial === min) + this.setFieldValue('off', 'INITIAL'); + if (type === '1' && initial === max) + this.setFieldValue('on', 'INITIAL'); + } + } }; -Blockly.propc.wx_set_widget = function() { +Blockly.propc.wx_set_widget = function () { var widget = this.getFieldValue('WIDGET'); + var label = this.getFieldValue('LABEL'); var type = this.getFieldValue('TYPE'); var color = this.getFieldValue('COLOR').substr(1).toUpperCase(); var min = window.parseInt(this.getFieldValue('MIN') || '0'); var max = window.parseInt(this.getFieldValue('MAX') || '10'); var initial; - if (type !== '8') { - initial = window.parseInt(this.getFieldValue('INITIAL') || '5'); - } else { - initial = window.parseInt((this.getFieldValue('INITIAL_COLOR') || '#FFFFFF').substr(1), 16); + if (type === '8') { + initial = (window.parseInt((this.getFieldValue('INITIAL') || '#FFFFFF').substr(1), 16)).toString(10); + } else if (this.getFieldValue('INITIAL') === 'on') { + initial = max; + } else if (this.getFieldValue('INITIAL') === 'off') { + initial = min; + } else { + initial = (window.parseInt(this.getFieldValue('INITIAL') || '5')).toString(10); } - + var code = ''; - code += 'wx_print("s' + widget + ',' + type + ',' + color + ','; - code += min + ',' + max + ',' + initial + '");\n'; - - return code; + code += 'wifi_print(WS, __wsHandle, "W,' + widget + ',' + type + ',' + label + ','; + code += min + ',' + max + ',' + initial + ',' + color + '");\n'; + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } }; Blockly.Blocks.wx_send_widget = { - init: function() { + helpUrl: Blockly.MSG_SWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_SWX_SEND_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendValueInput("NUM") - .setCheck(null) - .appendField("Simple WX send"); + .setCheck(null) + .appendField("Simple WX send"); this.appendDummyInput() - .appendField(new Blockly.FieldDropdown([["as text", "%s"], ["as an ASCII character", "%c"], ["as a decimal integer", "%d"], ["as a hexadecimal integer", "%x"], ["as a binary integer", "%b"]]), "TYPE") - .appendField("to widget") - .appendField(new Blockly.FieldDropdown([["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"]]), "WIDGET"); + .appendField("to widget") + .appendField(new Blockly.FieldDropdown([["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"]]), "WIDGET"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.wx_send_widget = function() { +Blockly.propc.wx_send_widget = function () { var num = Blockly.propc.valueToCode(this, 'NUM', Blockly.propc.ORDER_NONE); var widget = this.getFieldValue('WIDGET'); var type = this.getFieldValue('TYPE'); - - var code = ''; - code += 'wx_print("t' + widget + ',' + type + '", ' + num + ');\n'; - - return code; + + var code = 'wifi_print(WS, __wsHandle, "D,' + widget + ',%d", ' + num + ');\n'; + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } + }; -Blockly.Blocks.wx_read_widget = { - init: function() { +Blockly.Blocks.wx_read_widgets = { + helpUrl: Blockly.MSG_SWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_SWX_READ_TOOLTIP); this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField("Simple WX read") - .appendField(new Blockly.FieldDropdown([["text", "%s"], ["an ASCII character", "%c"], ["a decimal integer", "%d"], ["a hexadecimal integer", "%x"], ["a binary integer", "%b"]]), "TYPE") - .appendField("from widget") - .appendField(new Blockly.FieldDropdown([["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"]]), "WIDGET") - .appendField("store in") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), "VAR"); + .appendField("Simple WX read widgets"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.wx_read_widget = function() { - var value = Blockly.propc.valueToCode(this, 'VAR', Blockly.propc.ORDER_NONE); - var widget = this.getFieldValue('WIDGET'); - var type = this.getFieldValue('TYPE'); - +Blockly.propc.wx_read_widgets = function () { var code = ''; - code += 'wx_scan("r' + widget + ',' + type + '", &' + value + ');\n'; - - return code; + code += 'wifi_print(WS, __wsHandle, "U,0");\n__wv[0] = 0;\n'; + code += 'while(__wv[0] != \'V\') { __wv[0]++;\n wifi_poll(&__wxEvent, &__wxId,'; + code += '&__wxHandle);\n if(__wxEvent == \'W\' && __wxId == __wsId)'; + code += '__wsHandle = __wxHandle;\n if(__wxEvent == \'D\') '; + code += 'wifi_scan(WS, __wxHandle, "%c%d%d%d%d%d%d%d%d%d%d%d%d", '; + code += '&__wv[0], &__wv[1], &__wv[2], &__wv[3], &__wv[4], &__wv[5], &__wv[6], '; + code += '&__wv[7], &__wv[8], &__wv[9], &__wv[10], &__wv[11], &__wv[12]);\n'; + code += 'if(__wxEvent == \'X\') {__wsHandle = 0;\nwhile (!__wsHandle)'; + code += '{wifi_poll( & __wxEvent, & __wxId, & __wxHandle);\nif (__wxEvent == \'W\' '; + code += '&& __wxId == __wsId) __wsHandle = __wxHandle;}break;}}'; + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +Blockly.Blocks.wx_get_widget = { + helpUrl: Blockly.MSG_SWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_SWX_GET_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField("Simple WX widget") + .appendField(new Blockly.FieldDropdown([["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"]]), "WIDGET") + .appendField("value"); + this.setOutput(true, "Number"); + this.setPreviousStatement(false, null); + this.setNextStatement(false, null); + } +}; + +Blockly.propc.wx_get_widget = function () { + var widget = this.getFieldValue('WIDGET'); + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return ['__wv[' + widget + ']', Blockly.propc.ORDER_ATOMIC]; + } else { + return '// Missing Simple WX initialize block!\n'; + } + +}; + +Blockly.Blocks.wx_evt_connected = { + helpUrl: Blockly.MSG_SWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_SWX_GET_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField("Simple WX connected"); + this.setOutput(true, "Number"); + this.setPreviousStatement(false, null); + this.setNextStatement(false, null); + } +}; + +Blockly.propc.wx_evt_connected = function () { + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return ['(__wxEvent != \'X\')', Blockly.propc.ORDER_ATOMIC]; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +// ---------------- Advanced WX Blocks ----------------------------------------- + +Blockly.Blocks.wx_init_adv = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_INIT_ADV_TOOLTIP); + var bkg_colors = new Blockly.FieldColour("#FFFFFF"); + bkg_colors.setColours(['#FFFFFF', '#000000']).setColumns(2); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField('WX initialize') + .appendField("mode") + .appendField(new Blockly.FieldDropdown([['Terminal on USB', 'USB_PGM_TERM'], ['Terminal on WX', 'USB_PGM'], ['Term & Programming on WX', 'WX_ALL_COM']]), "MODE") // .concat(profile.default.digital) + .appendField(" DO") + .appendField(new Blockly.FieldDropdown([['WX Socket', '31']].concat(profile.default.digital), function (pin) { + this.sourceBlock_.updateShape_({"PIN": pin}); + }), "DO"); + this.appendDummyInput('DIPIN') + .appendField("DI") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "DI"); + this.getInput('DIPIN').setVisible(false); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + }, + mutationToDom: function () { + var container = document.createElement('mutation'); + var pin = this.getFieldValue('DO'); + container.setAttribute('pin', pin); + return container; + }, + domToMutation: function (xmlElement) { + var pin = xmlElement.getAttribute('pin'); + this.updateShape_({"PIN": pin}); + }, + updateShape_: function (details) { + if (details['PIN'] === '31') + this.getInput('DIPIN').setVisible(false); + else + this.getInput('DIPIN').setVisible(true); + } +}; + +Blockly.propc.wx_init_adv = function () { + var pin_do = this.getFieldValue('DO'); + var pin_di = this.getFieldValue('DI'); + if (pin_do === '31') + pin_di = '30'; + var bkg = (this.getFieldValue('BKG') === '#FFFFFF') ? '1' : '0'; + var title = this.getFieldValue('TITLE'); + var mode = this.getFieldValue('MODE'); + + var code = 'wifi_start(' + pin_do + ', ' + pin_di + ', 115200, ' + mode + ');\n'; + + Blockly.propc.definitions_["wx_def"] = '#include "wifi.h"'; + Blockly.propc.setups_["wx_init"] = code; + + return ''; +}; + +Blockly.Blocks.wx_scan_multiple = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_SCAN_MULTIPLE_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('WX scan') + .appendField(new Blockly.FieldDropdown([["POST", "POST"], ["Websocket", "WS"], ["Command", "CMD"]], function (action) { + this.sourceBlock_.setPrefix_({"ACTION": action}); + }), "CONNECTION") + .appendField('from handle') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'HANDLE'); + this.appendDummyInput('PREFIX') + .appendField('string starts with') + .appendField(new Blockly.FieldTextInput('txt'), 'START'); + this.optionList_ = ['dec', 'dec']; + this.updateShape_(); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.setMutator(new Blockly.Mutator(['wx_scan_dec', 'wx_scan_char'])); + }, + mutationToDom: function (workspace) { + // Create XML to represent menu options. + var container = document.createElement('mutation'); + container.setAttribute('options', JSON.stringify(this.optionList_)); + return container; + }, + domToMutation: function (container) { + // Parse XML to restore the menu options. + var value = JSON.parse(container.getAttribute('options')); + this.optionList_ = value; + this.updateShape_(); + }, + decompose: function (workspace) { + // Populate the mutator's dialog with this block's components. + var containerBlock = workspace.newBlock('wx_scan_container'); + containerBlock.initSvg(); + var connection = containerBlock.getInput('STACK').connection; + for (var i = 0; i < this.optionList_.length; i++) { + var optionBlock = workspace.newBlock( + 'wx_scan_' + this.optionList_[i]); + optionBlock.initSvg(); + connection.connect(optionBlock.previousConnection); + connection = optionBlock.nextConnection; + } + return containerBlock; + }, + compose: function (containerBlock) { + // Reconfigure this block based on the mutator dialog's components. + var optionBlock = containerBlock.getInputTargetBlock('STACK'); + // Count number of inputs. + this.optionList_.length = 0; + var data = []; + while (optionBlock) { + if (optionBlock.type === 'wx_scan_dec') { + this.optionList_.push('dec'); + } else if (optionBlock.type === 'wx_scan_char') { + this.optionList_.push('char'); + } + data.push([optionBlock.userData_, optionBlock.cpuData_]); + optionBlock = optionBlock.nextConnection && + optionBlock.nextConnection.targetBlock(); + } + this.updateShape_(); + // Restore any data. + for (var i = 0; i < this.optionList_.length; i++) { + var userData = data[i][0]; + if (userData !== undefined) { + this.setFieldValue(data[i][1], 'CPU' + i); + } + } + }, + saveConnections: function (containerBlock) { + // Store all data for each option. + var optionBlock = containerBlock.getInputTargetBlock('STACK'); + var i = 0; + while (optionBlock) { + optionBlock.cpuData_ = this.getFieldValue('CPU' + i) || Blockly.LANG_VARIABLES_GET_ITEM; + i++; + optionBlock.userData_ = this.getFieldValue('CPU' + i); + optionBlock = optionBlock.nextConnection && + optionBlock.nextConnection.targetBlock(); + } + }, + updateShape_: function () { + // Delete everything. + var i = 0; + while (this.getInput('OPTION' + i)) { + this.removeInput('OPTION' + i); + i++; + } + // Rebuild block. + + + for (var i = 0; i < this.optionList_.length; i++) { + var type = this.optionList_[i]; + var label = 'store character in'; + if (type === 'dec') + label = 'store integer in'; + this.appendDummyInput('OPTION' + i) + .appendField(label, 'TYPE' + i) + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'CPU' + i); + } + }, + setPrefix_: function (details) { + var prefixVisible = false; + if (details['ACTION'] === 'POST') + prefixVisible = true; + this.getInput('PREFIX').setVisible(prefixVisible); + var data = []; + var x = 0; + while (this.getInput('OPTION' + x)) { + data[x] = this.getFieldValue('CPU' + x); + this.removeInput('OPTION' + x); + x++; + } + + for (var i = 0; i < x; i++) { + var type = this.optionList_[i]; + var label = 'store character in'; + if (type === 'dec') + label = 'store integer in'; + this.appendDummyInput('OPTION' + i) + .appendField(label, 'TYPE' + i) + .appendField(new Blockly.FieldVariable(data[i]), 'CPU' + i); + } + }, + onchange: function () { + if (this.workspace && this.optionList_.length < 1) { + this.setWarningText('WX scan must have at least one search term.'); + } else { + this.setWarningText(null); + } + }, + getVars: function () { + + var theVars = [this.getFieldValue('HANDLE')]; + for (var i = 0; i < this.optionList_.length; i++) { + theVars.push(this.getFieldValue('CPU' + i)); + } + return theVars; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('HANDLE'))) + this.setTitleValue(newName, 'VALUE'); + for (var i = 0; i < this.optionList_.length; i++) { + if (Blockly.Names.equals(oldName, this.getFieldValue('CPU' + i))) + this.setTitleValue(newName, 'CPU' + i); + + } + } +}; + +Blockly.Blocks.wx_scan_container = { + // Container. + init: function () { + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField('scan'); + this.appendStatementInput('STACK'); + this.contextMenu = false; + } +}; + +Blockly.Blocks.wx_scan_dec = { + // Add text option. + init: function () { + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField('integer'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.contextMenu = false; + } +}; + +Blockly.Blocks.wx_scan_char = { + // Add image option. + init: function () { + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField('character'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.contextMenu = false; + } }; + +Blockly.propc.wx_scan_multiple = function () { + var handle = this.getFieldValue('HANDLE'); + var conn = this.getFieldValue('CONNECTION'); + var start = this.getFieldValue('START'); + start.replace(/['"]+/g, ''); + + if (conn !== 'POST') + start = ''; + + var code = 'wifi_scan(' + conn + ', ' + handle + ', "' + start; + var varList = ''; + var i = 0; + while (this.getFieldValue('CPU' + i)) { + if (this.getFieldValue('TYPE' + i).includes('integer')) { + code += '%d'; + } else { + code += '%c'; + } + varList += ', &' + this.getFieldValue('CPU' + i); + i++; + } + code += '"' + varList + ');\n'; + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + + +Blockly.Blocks.wx_print_multiple = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_PRINT_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('WX print to') + .appendField(new Blockly.FieldDropdown([["GET", "GET"], ["TCP", "TCP"], ["Websocket", "WS"], ["Command", "CMD"]]), "CONNECTION") + .appendField('handle') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'HANDLE'); + this.appendValueInput('PRINTa') + .setAlign(Blockly.ALIGN_RIGHT) + .setCheck('String') + .appendField('string'); + this.appendValueInput('PRINTb') + .setAlign(Blockly.ALIGN_RIGHT) + .setCheck('Number') + .appendField('integer'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.setMutator(new Blockly.Mutator(['wx_print_dec', 'wx_print_char', 'wx_print_str'])); + this.optionList_ = ['str', 'dec']; + }, + mutationToDom: function (workspace) { + // Create XML to represent menu options. + var container = document.createElement('mutation'); + container.setAttribute('options', JSON.stringify(this.optionList_)); + return container; + }, + domToMutation: function (container) { + // Parse XML to restore the menu options. + var value = JSON.parse(container.getAttribute('options')); + this.optionList_ = value; + for (var i = 0; i < this.optionList_.length; i++) { + var label = 'integer'; + if (this.optionList_[i] === 'str') + label = 'string'; + if (this.optionList_[i] === 'char') + label = 'character'; + this.appendValueInput('PRINT' + i) + .setAlign(Blockly.ALIGN_RIGHT) + .appendField(label, 'TYPE' + i); + } + }, + decompose: function (workspace) { + var containerBlock = Blockly.Block.obtain(workspace, 'wx_print_container'); + containerBlock.initSvg(); + var connection = containerBlock.getInput('STACK').connection; + for (var i = 0; i < this.optionList_.length; i++) { + var optionBlock = workspace.newBlock( + 'wx_print_' + this.optionList_[i]); + optionBlock.initSvg(); + connection.connect(optionBlock.previousConnection); + connection = optionBlock.nextConnection; + } + return containerBlock; + + }, + compose: function (containerBlock) { + // Delete everything. + var i = 0; + while (this.getInput('PRINT' + i)) { + this.removeInput('PRINT' + i); + i++; + } + + i = 0; + this.optionList_.length = 0; + // Rebuild the block's optional inputs. + var clauseBlock = containerBlock.getInputTargetBlock('STACK'); + var label = ''; + var chk = ''; + while (clauseBlock) { + if (clauseBlock.type === 'wx_print_dec') { + this.optionList_.push('dec'); + chk = 'Number'; + label = 'integer'; + } else if (clauseBlock.type === 'wx_print_char') { + this.optionList_.push('char'); + chk = 'Number'; + label = 'character'; + } else if (clauseBlock.type === 'wx_print_str') { + this.optionList_.push('str'); + chk = 'String'; + label = 'string'; + } + // Reconnect any child blocks. + + var printInput = this.appendValueInput('PRINT' + i) + .setAlign(Blockly.ALIGN_RIGHT) + .setCheck(chk) + .appendField(label, 'TYPE' + i); + + if (clauseBlock.valueConnection_) { + printInput.connection.connect(clauseBlock.valueConnection_); + } + i++; + + clauseBlock = clauseBlock.nextConnection && + clauseBlock.nextConnection.targetBlock(); + } + + + + }, + saveConnections: function (containerBlock) { + // Store a pointer to any connected child blocks. + var clauseBlock = containerBlock.getInputTargetBlock('STACK'); + var x = 0; + while (clauseBlock) { + var printInput = this.getInput('PRINT' + x); + clauseBlock.valueConnection_ = + printInput && printInput.connection.targetConnection; + x++; + break; + clauseBlock = clauseBlock.nextConnection && + clauseBlock.nextConnection.targetBlock(); + } + }, + onchange: function () { + if (this.workspace && this.optionList_.length < 1) { + this.setWarningText('WX print must have at least one term.'); + } else { + this.setWarningText(null); + } + if (this.getInput('PRINT0') && this.getInput('PRINTa')) { + this.removeInput('PRINTa'); + this.removeInput('PRINTb'); + } + }, + getVars: function () { + return [this.getFieldValue('HANDLE')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('HANDLE'))) { + this.setTitleValue(newName, 'HANDLE'); + } + } +}; + +Blockly.Blocks.wx_print_container = { + init: function () { + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField('print'); + this.appendStatementInput('STACK'); + this.contextMenu = false; + } +}; + +Blockly.Blocks.wx_print_dec = { + init: function () { + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField('integer'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.contextMenu = false; + } +}; + +Blockly.Blocks.wx_print_str = { + init: function () { + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField('string'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.contextMenu = false; + } +}; + +Blockly.Blocks.wx_print_char = { + init: function () { + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField('character'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.contextMenu = false; + } +}; + +Blockly.propc.wx_print_multiple = function () { + var handle = this.getFieldValue('HANDLE'); + var conn = this.getFieldValue('CONNECTION'); + + var code = 'wifi_print(' + conn + ', ' + handle + ', "'; + var varList = ''; + var i = 0; + var orIt = ''; + while (Blockly.propc.valueToCode(this, 'PRINT' + i, Blockly.propc.ORDER_NONE)) { + if (this.getFieldValue('TYPE' + i).includes('integer')) { + code += '%d'; + orIt = '0'; + } else if (this.getFieldValue('TYPE' + i).includes('string')) { + code += '%s'; + orIt = '" "'; + } else { + code += '%c'; + code = '32'; + } + varList += ', ' + Blockly.propc.valueToCode(this, 'PRINT' + i, Blockly.propc.NONE || orIt); + i++; + } + code += '"' + varList + ');\n'; + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +Blockly.Blocks.wx_scan_string = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_SCAN_STRING_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('WX scan') + .appendField(new Blockly.FieldDropdown([["POST", "POST"], ["Websocket", "WS"], ["Command", "CMD"]], function (action) { + this.sourceBlock_.setPrefix_({"ACTION": action}); + }), "CONNECTION") + .appendField('from handle') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'HANDLE'); + this.appendDummyInput('PREFIX') + .appendField('string starts with') + .appendField(new Blockly.FieldTextInput('txt'), 'START'); + this.appendDummyInput('STORE') + .appendField('store string in') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VARNAME'); + this.setPreviousStatement(true); + this.setNextStatement(true); + }, + setPrefix_: function (details) { + var prefixVisible = false; + if (details['ACTION'] === 'POST') + prefixVisible = true; + this.getInput('PREFIX').setVisible(prefixVisible); + var data = this.getFieldValue('VARNAME'); + this.removeInput('STORE'); + + this.appendDummyInput('STORE') + .appendField('store string in') + .appendField(new Blockly.FieldVariable(data), 'VARNAME'); + }, + getVars: function () { + return [this.getFieldValue('HANDLE'), this.getFieldValue('HANDLE')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('HANDLE'))) + this.setTitleValue(newName, 'HANDLE'); + if (Blockly.Names.equals(oldName, this.getFieldValue('VARNAME'))) + this.setTitleValue(newName, 'VARNAME'); + } +}; + +Blockly.propc.wx_scan_string = function () { + var handle = this.getFieldValue('HANDLE'); + var conn = this.getFieldValue('CONNECTION'); + var start = this.getFieldValue('START'); + start.replace(/['"]+/g, ''); + var store = this.getFieldValue('VARNAME'); + + Blockly.propc.vartype_[store] = 'char *'; + + if (conn !== 'POST') + start = ''; + + var code = 'wifi_scan(' + conn + ', ' + handle + ', "' + start + '%s", &' + store + ');\n'; + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +Blockly.Blocks.wx_send_string = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_SEND_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendValueInput("DATA") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("WX send string") + .setCheck("String"); + this.appendDummyInput() + .appendField("handle") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'HANDLE'); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + }, + getVars: function () { + return [this.getFieldValue('HANDLE')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('HANDLE'))) { + this.setTitleValue(newName, 'HANDLE'); + } + } +}; + +Blockly.propc.wx_send_string = function () { + var data = Blockly.propc.valueToCode(this, 'DATA', Blockly.propc.ORDER_NONE); + var handle = this.getFieldValue('HANDLE'); + + var code = 'wifi_send(' + handle + ', ' + data + ', sizeof(' + data + '));\n'; + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +Blockly.Blocks.wx_receive_string = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_RECEIVE_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("WX receive store string in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'DATA') + .appendField("byte count in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'BYTES'); + this.appendValueInput("MAX") + .appendField("handle") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'HANDLE') + .setAlign(Blockly.ALIGN_RIGHT) + .setCheck("Number") + .appendField("max bytes"); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setInputsInline(false); + }, + getVars: function () { + return [this.getFieldValue('DATA'), this.getFieldValue('BYTES'), this.getFieldValue('HANDLE')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('DATA'))) + this.setTitleValue(newName, 'DATA'); + if (Blockly.Names.equals(oldName, this.getFieldValue('BYTES'))) + this.setTitleValue(newName, 'BYTES'); + if (Blockly.Names.equals(oldName, this.getFieldValue('HANDLE'))) + this.setTitleValue(newName, 'HANDLE'); + } +}; + +Blockly.propc.wx_receive_string = function () { + var data = this.getFieldValue('DATA'); + var handle = this.getFieldValue('HANDLE'); + var max = Blockly.propc.valueToCode(this, 'MAX', Blockly.propc.NONE) || '64'; + var bytes = this.getFieldValue('BYTES'); + + Blockly.propc.vartype_[data] = 'char *'; + + var code = bytes + ' = wifi_recv(' + handle + ', ' + data + ', ' + max + ');\n'; + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +Blockly.Blocks.wx_poll = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_POLL_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .appendField("WX poll store event in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'EVENT') + .appendField("ID in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'ID') + .appendField("handle in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'HANDLE'); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + }, + getVars: function () { + return [this.getFieldValue('ID'), this.getFieldValue('EVENT'), this.getFieldValue('HANDLE')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('ID'))) + this.setTitleValue(newName, 'ID'); + if (Blockly.Names.equals(oldName, this.getFieldValue('EVENT'))) + this.setTitleValue(newName, 'EVENT'); + if (Blockly.Names.equals(oldName, this.getFieldValue('HANDLE'))) + this.setTitleValue(newName, 'HANDLE'); + } +}; + +Blockly.propc.wx_poll = function () { + var id = this.getFieldValue('ID'); + var event = this.getFieldValue('EVENT'); + var handle = this.getFieldValue('HANDLE'); + + var code = 'wifi_poll(&' + event + ', &' + id + ', &' + handle + ');\n'; + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +Blockly.Blocks.wx_listen = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_LISTEN_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendValueInput("PATH") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("WX connect") + .appendField(new Blockly.FieldDropdown([['HTTP', 'HTTP'], ['Websocket', 'WS'], ['TCP', 'TCP']], function (action) { + this.sourceBlock_.setPrefix_({"ACTION": action}); + }), 'PROTOCOL') + .appendField("store ID in", 'TEXT') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'ID') + .appendField("path", "LABEL") + .setCheck("String"); + this.appendValueInput("PORT") + .appendField("port") + .setCheck("Number"); + this.appendDummyInput('CONNVARS') + .appendField(new Blockly.FieldVariable('wxConnId1'), 'ID1') + .appendField(new Blockly.FieldVariable('wxConnId2'), 'ID2') + .appendField(new Blockly.FieldVariable('wxConnId3'), 'ID3') + .appendField(new Blockly.FieldVariable('wxConnId4'), 'ID4'); + this.getInput('PORT').setVisible(false); + this.getInput('CONNVARS').setVisible(false); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + }, + mutationToDom: function () { + var container = document.createElement('mutation'); + var action = this.getFieldValue('PROTOCOL'); + container.setAttribute('action', action); + return container; + }, + domToMutation: function (xmlElement) { + var action = xmlElement.getAttribute('action'); + this.setPrefix_({"ACTION": action}); + }, + setPrefix_: function (details) { + var prefixVisible = false; + this.removeInput('CONNVARS'); + if (details['ACTION'] === 'TCP') { + prefixVisible = true; + this.setFieldValue('URL', 'LABEL'); + this.setFieldValue('wxHandle', 'ID'); + this.setFieldValue('store handle in', 'TEXT'); + } else { + this.setFieldValue('path', 'LABEL'); + this.setFieldValue('wxConnId1', 'ID'); + this.setFieldValue('store ID in', 'TEXT'); + this.appendDummyInput('CONNVARS') + .appendField(new Blockly.FieldVariable('wxConnId1'), 'ID1') + .appendField(new Blockly.FieldVariable('wxConnId2'), 'ID2') + .appendField(new Blockly.FieldVariable('wxConnId3'), 'ID3') + .appendField(new Blockly.FieldVariable('wxConnId4'), 'ID4'); + this.getInput('CONNVARS').setVisible(false); + } + this.getInput('PORT').setVisible(prefixVisible); + }, + getVars: function () { + return [this.getFieldValue('ID'), this.getFieldValue('ID1'), this.getFieldValue('ID2'), this.getFieldValue('ID3'), this.getFieldValue('ID4')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('ID'))) + this.setTitleValue(newName, 'ID'); + if (Blockly.Names.equals(oldName, this.getFieldValue('ID1'))) + this.setTitleValue(newName, 'ID1'); + if (Blockly.Names.equals(oldName, this.getFieldValue('ID2'))) + this.setTitleValue(newName, 'ID2'); + if (Blockly.Names.equals(oldName, this.getFieldValue('ID3'))) + this.setTitleValue(newName, 'ID3'); + if (Blockly.Names.equals(oldName, this.getFieldValue('ID4'))) + this.setTitleValue(newName, 'ID4'); + } +}; + +Blockly.propc.wx_listen = function () { + var path = Blockly.propc.valueToCode(this, 'PATH', Blockly.propc.ORDER_NONE); + var protocol = this.getFieldValue('PROTOCOL'); + var id = this.getFieldValue('ID'); + var port = Blockly.propc.valueToCode(this, 'PORT', Blockly.propc.ORDER_NONE) || '80'; + + var code = ''; + if (protocol === 'TCP') { + code += id + ' = wifi_connect(' + path + ', ' + port + ');\n'; + } else { + code += id + ' = wifi_listen(' + protocol + ', ' + path + ');\n'; + } + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +Blockly.Blocks.wx_code = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_CODE_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("WX code") + .appendField(new Blockly.FieldDropdown( + [['ARG', '0xE6'], + ['Connect', '0xE4'], + ['Close', '0xE8'], + ['Check', '0xEE'], + ['Join', '0xEF'], + ['Listen', '0xE7'], + ['Path', '0xEB'], + ['Poll', '0xEC'], + ['Receive', '0xE9'], + ['Reply', '0xE5'], + ['Send', '0xEA'], + ['Set', '0xED'], + ['AP Mode', '0xF3'], + ['CMD', '0xFE'], + ['GET', '71'], + ['HTTP', '0xF7'], + ['POST', '80'], + ['Station Mode', '0xF4'], + ['Station+AP Mode', '0xF2'], + ['TCP', '0xF5'], + ['Websocket', '0xF6'], + ['GPIO_DI', '1'], + ['GPIO_DO', '3'], + ['GPIO_RTS', '15'], + ['GPIO_CTS', '13'], + ['GPIO_ASC', '5'], + ['GPIO_DBG', '2'], + ['GPIO_PGM', '0'], + ['Invalid Request', '1'], + ['Invalid Argument', '2'], + ['Wrong Argument', '3'], + ['No free listeners', '4'], + ['No free connection', '5'], + ['Lookup failed', '6'], + ['Connection failed', '7'], + ['Send failed', '8'], + ['Invalid state', '9'], + ['Invalid size', '10'], + ['Disconnected', '11'], + ['Not implemented', '12'], + ['Busy', '13'], + ['Internal error', '14'], + ['No error', '0'], + ['Out of memory', '-1'], + ['Undefined (NEG2)', '-2'], + ['Timeout', '-3'], + ['Routing problem', '-4'], + ['Operation in progress', '-5'], + ['Undefined (NEG6)', '-6'], + ['Number too large', '-7'], + ['Connection aborted', '-8'], + ['Connection reset', '-9'], + ['Connection closed', '-10'], + ['Not connected', '-11'], + ['Illegal argument', '-12'], + ['Undefined (NEG13)', '-13'], + ['UDP send error', '-14'], + ['Already connected', '-15'], + ['SSL handshake failed', '-28'], + ['SSL application invalid', '-61']]), 'CODE'); + this.setOutput(true, "Number"); + } +}; + +Blockly.propc.wx_code = function () { + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return [this.getFieldValue('CODE'), Blockly.propc.ORDER_NONE]; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +Blockly.Blocks.wx_mode = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_MODE_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("WX ") + .appendField(new Blockly.FieldDropdown([['Set', 'SET'], ['Leave and set', 'LEAVE'], ['Check', 'CHECK']], function (action) { + this.sourceBlock_.setPrefix_({"ACTION": action}); + }), 'ACTION') + .appendField("mode"); + this.appendDummyInput("CHECK") + .appendField("to") + .appendField(new Blockly.FieldDropdown([['AP', 'AP'], ['Station', 'STA'], ['Station + AP', 'STA_AP']]), 'MODE'); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setInputsInline(true); + }, + mutationToDom: function () { + var container = document.createElement('mutation'); + var action = this.getFieldValue('ACTION'); + container.setAttribute('action', action); + return container; + }, + domToMutation: function (xmlElement) { + var action = xmlElement.getAttribute('action'); + this.setPrefix_({"ACTION": action}); + }, + setPrefix_: function (details) { + this.removeInput('CHECK'); + if (details['ACTION'] === 'LEAVE') { + this.appendDummyInput("CHECK") + .appendField("to") + .appendField(new Blockly.FieldDropdown([['AP', 'AP'], ['Station + AP', 'STA_AP']]), 'MODE'); + } else { + this.appendDummyInput("CHECK") + .appendField("to") + .appendField(new Blockly.FieldDropdown([['AP', 'AP'], ['Station', 'STA'], ['Station + AP', 'STA_AP']]), 'MODE'); + } + if (details['ACTION'] === 'CHECK') { + this.getInput('CHECK').setVisible(false); + this.setPreviousStatement(false, null); + this.setNextStatement(false, null); + this.setOutput(true, "Number"); + } else { + this.getInput('CHECK').setVisible(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + this.setOutput(false); + } + } +}; + +Blockly.propc.wx_mode = function () { + var mode = this.getFieldValue('MODE'); + var action = this.getFieldValue('ACTION'); + + var code; + + if (action === 'CHECK') { + code = ['wifi_mode(CHECK)', Blockly.propc.ORDER_NONE]; + } else if (mode === 'LEAVE') { + code = 'wifi_leave(' + mode + ');\n'; + } else { + code = 'wifi_mode(' + mode + ');\n'; + } + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +Blockly.Blocks.wx_buffer = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_BUFFER_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendValueInput("SIZE") + .setCheck('Number') + .appendField("WX buffer use default") + .appendField(new Blockly.FieldCheckbox("TRUE", function (action) { + this.sourceBlock_.setPrefix_({"ACTION": action}); + }), "DEFAULT") + .appendField("size"); + this.appendDummyInput('BUF') + .appendField("set") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), "BUFFER") + .appendField("as buffer"); + this.getInput('BUF').setVisible(false); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + }, + mutationToDom: function () { + var container = document.createElement('mutation'); + var action = this.getFieldValue('DEFAULT'); + container.setAttribute('action', action); + return container; + }, + domToMutation: function (xmlElement) { + var action = xmlElement.getAttribute('action'); + this.setPrefix_({"ACTION": action}); + }, + setPrefix_: function (details) { + var data = this.getFieldValue('BUFFER'); + this.removeInput('BUF'); + if (details["ACTION"] === 'FALSE' || details["ACTION"] === false || details["ACTION"] === 'false') { + this.appendDummyInput('BUF') + .appendField("set") + .appendField(new Blockly.FieldVariable(data || Blockly.LANG_VARIABLES_GET_ITEM), "BUFFER") + .appendField("as buffer"); + this.getInput('BUF').setVisible(true); + } + }, + getVars: function () { + return [this.getFieldValue('BUFFER')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('BUFFER'))) { + this.setTitleValue(newName, 'BUFFER'); + } + } +}; + +Blockly.propc.wx_buffer = function () { + var size = Blockly.propc.valueToCode(this, 'SIZE', Blockly.propc.NONE) || '64'; + var def = this.getFieldValue('DEFAULT'); + var buffer = this.getFieldValue('BUFFER'); + + Blockly.propc.vartype_[buffer] = 'char *'; + + var code = ''; + if (def === "TRUE") { + code += 'wifi_bufferSize(' + size + ');\n'; + } else { + code += 'wifi_setBuffer(' + buffer + ',' + size + ');\n'; + } + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +Blockly.Blocks.wx_disconnect = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_DISCONNECT_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("WX disconnect") + .appendField(new Blockly.FieldDropdown([['HTTP', 'HTTP'], ['Websocket', 'WS'], ['TCP', 'TCP']], function (action) { + this.sourceBlock_.setPrefix_({"ACTION": action}); + }), 'PROTOCOL') + .appendField("ID", 'TEXT') + .appendField(new Blockly.FieldVariable('wxId'), 'ID'); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + }, + mutationToDom: function () { + var container = document.createElement('mutation'); + var action = this.getFieldValue('PROTOCOL'); + container.setAttribute('action', action); + return container; + }, + domToMutation: function (xmlElement) { + var action = xmlElement.getAttribute('action'); + this.setPrefix_({"ACTION": action}); + }, + setPrefix_: function (details) { + if (details['ACTION'] === 'TCP') { + this.setFieldValue('wxHandle', 'ID'); + this.setFieldValue('handle', 'TEXT'); + } else { + this.setFieldValue('wxId', 'ID'); + this.setFieldValue('ID', 'TEXT'); + } + }, + getVars: function () { + return [this.getFieldValue('ID')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('ID'))) { + this.setTitleValue(newName, 'ID'); + } + } +}; + +Blockly.propc.wx_disconnect = function () { + var code = 'wifi_disconnect(' + this.getFieldValue('ID') + ');\n'; + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + return code; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; + +Blockly.Blocks.wx_ip = { + helpUrl: Blockly.MSG_AWX_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_AWX_GET_IP_TOOLTIP); + this.setColour(colorPalette.getColor('protocols')); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("WX") + .appendField(new Blockly.FieldDropdown([['Station', 'STA'], ['AP', 'AP']]), 'MODE') + .appendField("IP address"); + this.setInputsInline(true); + this.setOutput(true, "String"); + } +}; + +Blockly.propc.wx_ip = function () { + var mode = this.getFieldValue('MODE'); + + var func = 'char* wifi_ip_string(int __mode) {int __ip[4]; __result = '; + func += 'wifi_ip(__mode, __ip); char ipStr[16]; if(__result = \'E\') '; + func += '{ipStr = "Error \0"} else {sprint(ipStr, "%03d.%03d'; + func += '.%03d.%03d", __ip[0], __ip[1], __ip[2], __ip[3]);} return ipStr;}'; + + if (Blockly.propc.definitions_["wx_def"] === '#include "wifi.h"') { + Blockly.propc.global_vars_['ip_address_func'] = func; + return ['wifi_ip_string(' + mode + ')', Blockly.propc.ORDER_NONE]; + } else { + return '// Missing Simple WX initialize block!\n'; + } +}; \ No newline at end of file diff --git a/src/main/webapp/cdn/blockly/generators/propc/control.js b/src/main/webapp/cdn/blockly/generators/propc/control.js index 247d0f4e..9978b9ca 100644 --- a/src/main/webapp/cdn/blockly/generators/propc/control.js +++ b/src/main/webapp/cdn/blockly/generators/propc/control.js @@ -32,13 +32,13 @@ if (!Blockly.Blocks) Blockly.Blocks.controls_repeat = { - init: function() { - if(profile.default.description === "Scribbler Robot") { + init: function () { + if (profile.default.description === "Scribbler Robot") { this.setHelpUrl(Blockly.MSG_S3_CONTROL_HELPURL); } else { this.setHelpUrl(Blockly.MSG_CONTROL_HELPURL); } - this.setTooltip(Blockly.MSG_CONTROLS_REPEAT_TOOLTIP); + this.setTooltip(Blockly.MSG_CONTROLS_REPEAT_TOOLTIP); this.setColour(colorPalette.getColor('programming')); // ["with", "WITH"] var PROPERTIES = [["forever", "FOREVER"], ["x times", "TIMES"], ["until", "UNTIL"], ["while", "WHILE"]]; @@ -95,7 +95,7 @@ Blockly.Blocks.controls_repeat = { } }; -Blockly.propc.controls_repeat = function() { +Blockly.propc.controls_repeat = function () { var type = this.getFieldValue('TYPE'); var branch = Blockly.propc.statementToCode(this, 'DO'); if (Blockly.propc.INFINITE_LOOP_TRAP) { @@ -130,13 +130,13 @@ Blockly.propc.controls_repeat = function() { Blockly.Blocks.controls_if = { // If/elseif/else condition. category: Blockly.LANG_CATEGORY_CONTROLS, - init: function() { - if(profile.default.description === "Scribbler Robot") { + init: function () { + if (profile.default.description === "Scribbler Robot") { this.setHelpUrl(Blockly.MSG_S3_CONTROL_HELPURL); } else { this.setHelpUrl(Blockly.MSG_CONTROL_HELPURL); } - this.setTooltip(Blockly.MSG_CONTROLS_IF_TOOLTIP); + this.setTooltip(Blockly.MSG_CONTROLS_IF_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendValueInput('IF0') .setCheck('Number') @@ -309,7 +309,7 @@ Blockly.Blocks.controls_if_else = { } }; -Blockly.propc.controls_if = function() { +Blockly.propc.controls_if = function () { // If/elseif/else condition. var n = 0; var argument = Blockly.propc.valueToCode(this, 'IF' + n, @@ -331,51 +331,51 @@ Blockly.propc.controls_if = function() { /* * Disabled/Unused - -Blockly.Blocks.controls_if_return = { - init: function () { - this.setColour(colorPalette.getColor('programming')); - this.appendValueInput('CONDITION') - .appendField("if"); - this.appendDummyInput() - .appendField("return"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - } -}; - -Blockly.propc.controls_if_return = function () { - var argument = Blockly.propc.valueToCode(this, 'CONDITION', Blockly.propc.ORDER_NONE) || '0'; - - return 'if (' + argument + ') {return;}\n'; -}; -*/ + + Blockly.Blocks.controls_if_return = { + init: function () { + this.setColour(colorPalette.getColor('programming')); + this.appendValueInput('CONDITION') + .appendField("if"); + this.appendDummyInput() + .appendField("return"); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } + }; + + Blockly.propc.controls_if_return = function () { + var argument = Blockly.propc.valueToCode(this, 'CONDITION', Blockly.propc.ORDER_NONE) || '0'; + + return 'if (' + argument + ') {return;}\n'; + }; + */ Blockly.Blocks.control_repeat_for_loop = { //helpUrl: Blockly.MSG_CONTROL_HELPURL, - init: function() { - if(profile.default.description === "Scribbler Robot") { + init: function () { + if (profile.default.description === "Scribbler Robot") { this.setHelpUrl(Blockly.MSG_S3_CONTROL_HELPURL); } else { this.setHelpUrl(Blockly.MSG_CONTROL_HELPURL); } - this.setTooltip(Blockly.MSG_CONTROL_REPEAT_FOR_LOOP_TOOLTIP); + this.setTooltip(Blockly.MSG_CONTROL_REPEAT_FOR_LOOP_TOOLTIP); this.setColour(colorPalette.getColor('programming')); this.appendDummyInput() - .appendField("repeat") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR'); + .appendField("repeat") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR'); this.appendValueInput('START') - .setCheck('Number') - .appendField("from"); + .setCheck('Number') + .appendField("from"); this.appendValueInput('END') - .setCheck('Number') - .appendField("to"); + .setCheck('Number') + .appendField("to"); this.appendValueInput('STEP') - .setCheck('Number') - .appendField("by"); + .setCheck('Number') + .appendField("by"); this.appendStatementInput("DO") - .appendField("do"); + .appendField("do"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -402,41 +402,258 @@ Blockly.propc.control_repeat_for_loop = function () { var code = 'for (' + loop_counter + ' = ' + start + '; ' + loop_counter + ' <= ' + end + '; ' + loop_counter + ' += abs(' + step + ')) {\n' + repeat_code + '\n}'; return code; } else { - var code = 'for (' + loop_counter + ' = ' + start + '; ' + loop_counter + ' >= ' + end + '; ' + loop_counter + ' -= abs(' + step + ')) {\n' + repeat_code + '\n}'; - return code; + var code = 'for (' + loop_counter + ' = ' + start + '; ' + loop_counter + ' >= ' + end + '; ' + loop_counter + ' -= abs(' + step + ')) {\n' + repeat_code + '\n}'; + return code; } }; Blockly.Blocks.controls_return = { - helpUrl: Blockly.MSG_CONTROL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CONTROLS_RETURN_TOOLTIP); - this.appendDummyInput() - .appendField("return"); + helpUrl: Blockly.MSG_CONTROL_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_CONTROLS_RETURN_TOOLTIP); + this.appendDummyInput() + .appendField("return"); - this.setInputsInline(false); - this.setPreviousStatement(true, null); - this.setColour(colorPalette.getColor('programming')); - } + this.setInputsInline(false); + this.setPreviousStatement(true, null); + this.setColour(colorPalette.getColor('programming')); + } }; -Blockly.propc.controls_return = function() { +Blockly.propc.controls_return = function () { return 'return;'; }; Blockly.Blocks.controls_break = { - helpUrl: Blockly.MSG_CONTROL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CONTROLS_BREAK_TOOLTIP); - this.appendDummyInput() - .appendField("break"); + helpUrl: Blockly.MSG_CONTROL_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_CONTROLS_BREAK_TOOLTIP); + this.appendDummyInput() + .appendField("break"); - this.setInputsInline(false); - this.setPreviousStatement(true, null); - this.setColour(colorPalette.getColor('programming')); - } + this.setInputsInline(false); + this.setPreviousStatement(true, null); + this.setColour(colorPalette.getColor('programming')); + } }; -Blockly.propc.controls_break = function() { +Blockly.propc.controls_break = function () { return 'break;'; }; + +Blockly.Blocks.controls_select = { + // If/elseif/else condition. + category: Blockly.LANG_CATEGORY_CONTROLS, + init: function () { + if (profile.default.description === "Scribbler Robot") { + this.setHelpUrl(Blockly.MSG_S3_CONTROL_HELPURL); + } else { + this.setHelpUrl(Blockly.MSG_CONTROL_HELPURL); + } + this.setTooltip(Blockly.MSG_CONTROLS_SELECT_TOOLTIP); + this.setColour(colorPalette.getColor('programming')); + this.appendValueInput('SWITCH') + .appendField('switch'); + this.appendValueInput('SEL1') + .setCheck('Number') + .appendField('case'); + this.appendStatementInput('CASE1') + .appendField('do (then break') + .appendField(new Blockly.FieldCheckbox("TRUE"), 'BREAK1') + .appendField(')'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.setMutator(new Blockly.Mutator(['controls_select_case', + 'controls_select_default'])); + this.elseifCount_ = 1; + this.elseCount_ = 0; + }, + mutationToDom: function () { + if (!this.elseifCount_ && !this.elseCount_) { + return null; + } + var container = document.createElement('mutation'); + if (this.elseifCount_) { + container.setAttribute('case', this.elseifCount_); + } + if (this.elseCount_) { + container.setAttribute('default', 1); + } + return container; + }, + domToMutation: function (xmlElement) { + this.elseifCount_ = window.parseInt(xmlElement.getAttribute('case'), 10); + this.elseCount_ = window.parseInt(xmlElement.getAttribute('default'), 10); + for (var x = 1; x <= this.elseifCount_; x++) { + var theInput = this.getInput('SEL' + x); + if (!theInput) { + this.appendValueInput('SEL' + x) + .setCheck('Number') + .appendField('case'); + this.appendStatementInput('CASE' + x) + .appendField('do (then break') + .appendField(new Blockly.FieldCheckbox("TRUE"), 'BREAK' + x) + .appendField(')'); + } + } + if (this.elseCount_) { + this.appendStatementInput('DEFAULT') + .appendField('default'); + } + }, + decompose: function (workspace) { + var containerBlock = Blockly.Block.obtain(workspace, 'controls_select_select'); + containerBlock.initSvg(); + var connection = containerBlock.getInput('STACK').connection; + for (var x = 1; x <= this.elseifCount_; x++) { + var elseifBlock = Blockly.Block.obtain(workspace, 'controls_select_case'); + elseifBlock.initSvg(); + connection.connect(elseifBlock.previousConnection); + connection = elseifBlock.nextConnection; + } + if (this.elseCount_) { + var elseBlock = Blockly.Block.obtain(workspace, 'controls_select_default'); + elseBlock.initSvg(); + connection.connect(elseBlock.previousConnection); + } + return containerBlock; + }, + compose: function (containerBlock) { + // Disconnect the else input blocks and remove the inputs. + if (this.elseCount_) { + this.removeInput('DEFAULT'); + } + this.elseCount_ = 0; + // Disconnect all the elseif input blocks and remove the inputs. + for (var x = this.elseifCount_; x > 0; x--) { + this.removeInput('SEL' + x); + this.removeInput('CASE' + x); + } + this.elseifCount_ = 0; + // Rebuild the block's optional inputs. + var clauseBlock = containerBlock.getInputTargetBlock('STACK'); + while (clauseBlock) { + switch (clauseBlock.type) { + case 'controls_select_case': + this.elseifCount_++; + var ifInput = this.appendValueInput('SEL' + this.elseifCount_) + .setCheck('Number') + .appendField('case'); + var doInput = this.appendStatementInput('CASE' + this.elseifCount_); + doInput.appendField('do (then break') + .appendField(new Blockly.FieldCheckbox("TRUE"), 'BREAK' + this.elseifCount_) + .appendField(')'); + // Reconnect any child blocks. + if (clauseBlock.valueConnection_) { + ifInput.connection.connect(clauseBlock.valueConnection_); + } + if (clauseBlock.statementConnection_) { + doInput.connection.connect(clauseBlock.statementConnection_); + } + break; + case 'controls_select_default': + this.elseCount_++; + var elseInput = this.appendStatementInput('DEFAULT'); + elseInput.appendField('default'); + // Reconnect any child blocks. + if (clauseBlock.statementConnection_) { + elseInput.connection.connect(clauseBlock.statementConnection_); + } + break; + default: + throw 'Unknown block type.'; + } + clauseBlock = clauseBlock.nextConnection && + clauseBlock.nextConnection.targetBlock(); + } + }, + saveConnections: function (containerBlock) { + // Store a pointer to any connected child blocks. + var clauseBlock = containerBlock.getInputTargetBlock('STACK'); + var x = 1; + while (clauseBlock) { + switch (clauseBlock.type) { + case 'controls_select_case': + var inputIf = this.getInput('SEL' + x); + var inputDo = this.getInput('CASE' + x); + clauseBlock.valueConnection_ = + inputIf && inputIf.connection.targetConnection; + clauseBlock.statementConnection_ = + inputDo && inputDo.connection.targetConnection; + x++; + break; + case 'controls_select_default': + var inputDo = this.getInput('DEFAULT'); + clauseBlock.statementConnection_ = + inputDo && inputDo.connection.targetConnection; + break; + default: + throw 'Unknown block type.'; + } + clauseBlock = clauseBlock.nextConnection && + clauseBlock.nextConnection.targetBlock(); + } + } +}; + + +Blockly.Blocks.controls_select_select = { + // If condition. + init: function () { + this.setColour(colorPalette.getColor('programming')); + this.appendDummyInput() + .appendField('switch'); + this.appendStatementInput('STACK'); + this.setInputsInline(false); + this.contextMenu = false; + } +}; + +Blockly.Blocks.controls_select_case = { + // Else-If condition. + init: function () { + this.setColour(colorPalette.getColor('programming')); + this.appendDummyInput() + .appendField('case'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.contextMenu = false; + } +}; + +Blockly.Blocks.controls_select_default = { + // Else condition. + init: function () { + this.setColour(colorPalette.getColor('programming')); + this.appendDummyInput() + .appendField('default'); + this.setPreviousStatement(true); + this.contextMenu = false; + } +}; + +Blockly.propc.controls_select = function () { + // If/elseif/else condition. + var n = 0; + var start = Blockly.propc.valueToCode(this, 'SWITCH', Blockly.propc.ORDER_NONE) || '0'; + var argument = ''; //Blockly.propc.valueToCode(this, 'SEL' + n, Blockly.propc.ORDER_NONE) || '0'; + var breaking = ''; //this.getFieldValue('BREAK' + n); + var branch = ''; //Blockly.propc.statementToCode(this, 'CASE' + n); + var code = 'switch(' + start + ') {\n'; + //code += 'case ' + argument + ':\n' + branch; + if (breaking === true || breaking === 'TRUE' || breaking === 'true') + code += 'break;\n'; + for (n = 1; n <= this.elseifCount_; n++) { + argument = Blockly.propc.valueToCode(this, 'SEL' + n, Blockly.propc.ORDER_NONE) || '0'; + branch = Blockly.propc.statementToCode(this, 'CASE' + n); + code += 'case ' + argument + ':\n' + branch; + breaking = this.getFieldValue('BREAK' + n); + if (breaking === true || breaking === 'TRUE' || breaking === 'true') + code += 'break;\n'; + } + if (this.elseCount_) { + branch = Blockly.propc.statementToCode(this, 'DEFAULT'); + code += 'default: \n' + branch + '\n'; + } + return code + '}\n'; +}; diff --git a/src/main/webapp/cdn/blockly/generators/propc/gpio.js b/src/main/webapp/cdn/blockly/generators/propc/gpio.js index 68ee6880..9120b3b9 100644 --- a/src/main/webapp/cdn/blockly/generators/propc/gpio.js +++ b/src/main/webapp/cdn/blockly/generators/propc/gpio.js @@ -32,8 +32,8 @@ if (!Blockly.Blocks) Blockly.Blocks.make_pin = { helpUrl: Blockly.MSG_PINS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MAKE_PIN_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MAKE_PIN_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -63,8 +63,8 @@ Blockly.propc.make_pin = function () { Blockly.Blocks.make_pin_input = { helpUrl: Blockly.MSG_PINS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MAKE_PIN_INPUT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MAKE_PIN_INPUT_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -96,8 +96,8 @@ Blockly.propc.make_pin_input = function () { Blockly.Blocks.check_pin = { helpUrl: Blockly.MSG_PINS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CHECK_PIN_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_CHECK_PIN_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput("") .appendField("check PIN") @@ -115,8 +115,8 @@ Blockly.propc.check_pin = function () { Blockly.Blocks.check_pin_input = { helpUrl: Blockly.MSG_PINS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_CHECK_PIN_INPUT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_CHECK_PIN_INPUT_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput("") .appendField("check PIN"); @@ -136,17 +136,17 @@ Blockly.propc.check_pin_input = function () { Blockly.Blocks.set_pins = { helpUrl: Blockly.MSG_PINS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SET_PINS_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SET_PINS_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.setPreviousStatement(true, null); this.setNextStatement(true, null); var start_pin = []; - for (var i = 0; i < 14; i++) { + for (var i = profile.default.contiguous_pins_start; i <= profile.default.contiguous_pins_end; i++) { start_pin.push([i.toString(), i.toString()]); } var pin_count = []; - for (var i = 0; i < 14; i++) { + for (var i = profile.default.contiguous_pins_start; i <= profile.default.contiguous_pins_end; i++) { pin_count.push([i.toString(), i.toString()]); } this.appendDummyInput("") @@ -154,11 +154,11 @@ Blockly.Blocks.set_pins = { .appendField(new Blockly.FieldDropdown([["states", "STATE"], ["directions", "DIRECTION"]], function (action) { this.sourceBlock_.updateShape_({"ACTION": action}); }), "ACTION") - .appendField("from PIN") + .appendField("from lowest PIN") .appendField(new Blockly.FieldDropdown(pin_count, function (startPin) { this.sourceBlock_.updateShape_({"START_PIN": startPin}); }), "START_PIN") - .appendField("to PIN") + .appendField("to highest PIN") .appendField(new Blockly.FieldDropdown(start_pin, function (pinCount) { this.sourceBlock_.updateShape_({"PIN_COUNT": pinCount}); }), "PIN_COUNT"); @@ -239,7 +239,7 @@ Blockly.propc.set_pins = function () { code = 'set_directions('; } //var highestPin = dropdown_start_pin + dropdown_pin_count - 1; - + code += dropdown_pin_count; code += ', '; code += dropdown_start_pin; @@ -250,10 +250,102 @@ Blockly.propc.set_pins = function () { return code + ');\n'; }; +Blockly.Blocks.get_pins = { + helpUrl: Blockly.MSG_PINS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_GET_PINS_TOOLTIP); + this.setColour(colorPalette.getColor('io')); + this.setPreviousStatement(false, null); + this.setNextStatement(false, null); + this.setOutput(true, 'Number'); + var start_pin = []; + for (var i = profile.default.contiguous_pins_start; i <= profile.default.contiguous_pins_end; i++) { + start_pin.push([i.toString(), i.toString()]); + } + var pin_count = []; + for (var i = profile.default.contiguous_pins_start; i <= profile.default.contiguous_pins_end; i++) { + pin_count.push([i.toString(), i.toString()]); + } + this.appendDummyInput("") + .appendField("get the") + .appendField(new Blockly.FieldDropdown([["states", "STATE"], ["directions", "DIRECTION"]]), "ACTION") + .appendField("to highest PIN") + .appendField(new Blockly.FieldDropdown(start_pin), "PIN_COUNT") + .appendField("from lowest PIN") + .appendField(new Blockly.FieldDropdown(pin_count), "START_PIN"); + } +}; + +Blockly.propc.get_pins = function () { + var code = ''; + var action = this.getFieldValue('ACTION'); + var dropdown_pin_count = Number(this.getFieldValue('PIN_COUNT')); + var dropdown_start_pin = Number(this.getFieldValue('START_PIN')); + if (action === 'STATE') { + code = 'get_states('; + } else if (action === 'DIRECTION') { + code = 'get_outputs('; + } + + code += dropdown_pin_count; + code += ', '; + code += dropdown_start_pin; + code += ')'; + return [code, Blockly.propc.ORDER_NONE]; +}; + +Blockly.Blocks.set_pins_binary = { + helpUrl: Blockly.MSG_PINS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_SET_PINS_BINARY_TOOLTIP); + this.setColour(colorPalette.getColor('io')); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + + var start_pin = []; + for (var i = profile.default.contiguous_pins_start; i <= profile.default.contiguous_pins_end; i++) { + start_pin.push([i.toString(), i.toString()]); + } + var pin_count = []; + for (var i = profile.default.contiguous_pins_start; i <= profile.default.contiguous_pins_end; i++) { + pin_count.push([i.toString(), i.toString()]); + } + this.appendValueInput("VALUE") + .appendField("set the") + .appendField(new Blockly.FieldDropdown([["states", "STATE"], ["directions", "DIRECTION"]]), "ACTION") + .appendField("to highest PIN") + .appendField(new Blockly.FieldDropdown(start_pin), "PIN_COUNT") + .appendField("from lowest PIN") + .appendField(new Blockly.FieldDropdown(pin_count), "START_PIN") + .appendField("using bits from") + .setCheck('Number'); + } +}; + +Blockly.propc.set_pins_binary = function () { + var code = ''; + var value = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_NONE) || '0b0000'; + var action = this.getFieldValue('ACTION'); + var dropdown_pin_count = Number(this.getFieldValue('PIN_COUNT')); + var dropdown_start_pin = Number(this.getFieldValue('START_PIN')); + if (action === 'STATE') { + code = 'set_outputs('; + } else if (action === 'DIRECTION') { + code = 'set_directions('; + } + + code += dropdown_pin_count; + code += ', '; + code += dropdown_start_pin; + code += ', ' + value + ');\n'; + + return code; +}; + Blockly.Blocks.base_freqout = { helpUrl: Blockly.MSG_AUDIO_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_BASE_FREQOUT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_BASE_FREQOUT_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput("") .appendField("frequency PIN") @@ -282,8 +374,8 @@ Blockly.propc.base_freqout = function () { Blockly.Blocks.base_count = { helpUrl: Blockly.MSG_ANALOG_PULSE_IN_OUT_HELPURL, - init: function() { - //this.setTooltip(Blockly.MSG_BASE_FREQOUT_TOOLTIP); + init: function () { + //this.setTooltip(Blockly.MSG_BASE_FREQOUT_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput("") .appendField("count pulses PIN") @@ -309,15 +401,15 @@ Blockly.propc.base_count = function () { Blockly.Blocks.pulse_in = { helpUrl: Blockly.MSG_ANALOG_PULSE_IN_OUT_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_PULSE_IN_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_PULSE_IN_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput() - .appendField("pulse-in PIN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); + .appendField("pulse-in PIN") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); this.appendDummyInput() - .appendField("read") - .appendField(new Blockly.FieldDropdown([["negative/low pulses", "0"], ["positive/high pulses", "1"]]), "STATE"); + .appendField("read") + .appendField(new Blockly.FieldDropdown([["negative/low pulses", "0"], ["positive/high pulses", "1"]]), "STATE"); this.setInputsInline(true); this.setPreviousStatement(false, null); @@ -326,7 +418,7 @@ Blockly.Blocks.pulse_in = { } }; -Blockly.propc.pulse_in = function() { +Blockly.propc.pulse_in = function () { var pin = this.getFieldValue("PIN"); var state = this.getFieldValue("STATE"); @@ -336,21 +428,21 @@ Blockly.propc.pulse_in = function() { Blockly.Blocks.pulse_out = { helpUrl: Blockly.MSG_ANALOG_PULSE_IN_OUT_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_PULSE_OUT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_PULSE_OUT_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput() - .appendField("pulse-out PIN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); + .appendField("pulse-out PIN") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); this.appendValueInput('PULSE_LENGTH') - .appendField("pulse length (" + "\u00B5" + "s)"); + .appendField("pulse length (" + "\u00B5" + "s)"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.pulse_out = function() { +Blockly.propc.pulse_out = function () { var pin = this.getFieldValue("PIN"); var pulse_length = Blockly.propc.valueToCode(this, 'PULSE_LENGTH', Blockly.propc.ORDER_ATOMIC); @@ -359,15 +451,15 @@ Blockly.propc.pulse_out = function() { Blockly.Blocks.rc_charge_discharge = { helpUrl: Blockly.MSG_ANALOG_RC_TIME_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_RC_CHARGE_DISCHARGE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_RC_CHARGE_DISCHARGE_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput("") - .appendField("RC") - .appendField(new Blockly.FieldDropdown([["charge", "0"], ["discharge", "1"]]), "STATE"); + .appendField("RC") + .appendField(new Blockly.FieldDropdown([["charge", "0"], ["discharge", "1"]]), "STATE"); this.appendDummyInput("") - .appendField("PIN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); + .appendField("PIN") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); this.setInputsInline(true); this.setPreviousStatement(false, null); this.setNextStatement(false, null); @@ -375,7 +467,7 @@ Blockly.Blocks.rc_charge_discharge = { } }; -Blockly.propc.rc_charge_discharge = function() { +Blockly.propc.rc_charge_discharge = function () { var pin = this.getFieldValue("PIN"); var state = this.getFieldValue("STATE"); @@ -386,16 +478,16 @@ Blockly.propc.rc_charge_discharge = function() { // --------------- EEPROM Memory Blocks ---------------------------------------- Blockly.Blocks.eeprom_write = { helpUrl: Blockly.MSG_EEPROM_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_EEPROM_WRITE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_EEPROM_WRITE_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendValueInput("DATA") - .setCheck(null) - .appendField("EEPROM write") - .appendField(new Blockly.FieldDropdown([["number", "NUMBER"], ["text", "TEXT"], ["byte", "BYTE"]]), "TYPE"); + .setCheck(null) + .appendField("EEPROM write") + .appendField(new Blockly.FieldDropdown([["number", "NUMBER"], ["text", "TEXT"], ["byte", "BYTE"]]), "TYPE"); this.appendValueInput("ADDRESS") - .setCheck("Number") - .appendField("to address"); + .setCheck("Number") + .appendField("to address"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -406,36 +498,36 @@ Blockly.propc.eeprom_write = function () { var type = this.getFieldValue('TYPE'); var address = Blockly.propc.valueToCode(this, 'ADDRESS', Blockly.propc.ORDER_ATOMIC); var data = Blockly.propc.valueToCode(this, 'DATA', Blockly.propc.ORDER_ATOMIC) || ''; - + var setup_code = '// Constrain Function\nint constrain(int __cVal, int __cMin, int __cMax) {'; setup_code += 'if(__cVal < __cMin) __cVal = __cMin;\n'; setup_code += 'if(__cVal > __cMax) __cVal = __cMax;\nreturn __cVal;\n}\n'; Blockly.propc.global_vars_["constrain_function"] = setup_code; - + var code = ''; - if(data !== '') { + if (data !== '') { if (type === 'BYTE') { code += 'ee_putByte((' + data + ' & 255), (32768 + constrain(' + address + ', 0, 7675)) );\n'; } else if (type === 'NUMBER') { code += 'ee_putInt(' + data + ', (32768 + constrain(' + address + ', 0, 7675)) );\n'; } else { - code += 'ee_putStr(' + data + ', (strlen(' + data + ') + 1), (32768 + constrain(' + address + ', 0, 7675)) );\n'; + code += 'ee_putStr(' + data + ', (strlen(' + data + ') + 1), (32768 + constrain(' + address + ', 0, 7675)) );\n'; } } - + return code; }; Blockly.Blocks.eeprom_read = { helpUrl: Blockly.MSG_EEPROM_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_EEPROM_READ_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_EEPROM_READ_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendValueInput("ADDRESS") - .setCheck("Number") - .appendField("EEPROM read") - .appendField(new Blockly.FieldDropdown([["number", "NUMBER"], ["text", "TEXT"], ["byte", "BYTE"]]), "TYPE") - .appendField("from address"); + .setCheck("Number") + .appendField("EEPROM read") + .appendField(new Blockly.FieldDropdown([["number", "NUMBER"], ["text", "TEXT"], ["byte", "BYTE"]]), "TYPE") + .appendField("from address"); this.appendDummyInput() .appendField("store in") .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VALUE'); @@ -456,15 +548,15 @@ Blockly.Blocks.eeprom_read = { Blockly.propc.eeprom_read = function () { var type = this.getFieldValue('TYPE'); var address = Blockly.propc.valueToCode(this, 'ADDRESS', Blockly.propc.ORDER_ATOMIC); - var data = Blockly.propc.variableDB_.getName(this.getFieldValue('VALUE'), Blockly.Variables.NAME_TYPE); + var data = Blockly.propc.variableDB_.getName(this.getFieldValue('VALUE'), Blockly.Variables.NAME_TYPE); Blockly.propc.global_vars_["i2c_eepromAddr"] = 'int __eeAddr;'; - + var code = '__eeAddr = ' + address + ';\n'; code += 'if(__eeAddr < 0) __eeAddr = 0;\n'; code += 'if(__eeAddr > 7675) __eeAddr = 7675;\n'; - - if(data !== '') { + + if (data !== '') { if (type === 'BYTE') { code += data + ' = ee_getByte( 32768 + __eeAddr ) & 255;\n'; } else if (type === 'NUMBER') { @@ -472,7 +564,7 @@ Blockly.propc.eeprom_read = function () { } else { Blockly.propc.global_vars_["i2c_eeBffr"] = 'char __eeBffr[1];'; Blockly.propc.global_vars_["i2c_eeIdx"] = 'int __eeIdx = 0;'; - Blockly.propc.vartype_[data] = 'char *'; + Blockly.propc.vartype_[data] = 'char *'; code += '// Get the string from EEPROM one character at a time until it finds the end of the string.\n'; code += '__eeIdx = 0;\n'; code += 'while(__eeIdx < 128) {\n ee_getStr(__eeBffr, 1, (32768 + __eeAddr) + __eeIdx);\n'; @@ -481,23 +573,23 @@ Blockly.propc.eeprom_read = function () { code += ' if(__eeIdx >= 128) ' + data + '[127] = 0;\n'; } } - + return code; }; // ------------------ Servo motor blocks --------------------------------------- Blockly.Blocks.servo_move = { helpUrl: Blockly.MSG_SERVO_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SERVO_MOVE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SERVO_MOVE_TOOLTIP); this.setColour(colorPalette.getColor('output')); this.appendDummyInput() - .appendField("Servo PIN") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); + .appendField("Servo PIN") + .setAlign(Blockly.ALIGN_RIGHT) + .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); this.appendValueInput("ANGLE") - .appendField("set angle (0-180\u00B0)") - .setCheck("Number"); + .appendField("set angle (0-180\u00B0)") + .setCheck("Number"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -521,8 +613,8 @@ Blockly.propc.servo_move = function () { Blockly.Blocks.servo_speed = { helpUrl: Blockly.MSG_SERVO_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SERVO_SPEED_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SERVO_SPEED_TOOLTIP); this.setColour(colorPalette.getColor('output')); this.appendDummyInput() .appendField("CR Servo PIN") @@ -547,8 +639,8 @@ Blockly.propc.servo_speed = function () { Blockly.Blocks.servo_set_ramp = { helpUrl: Blockly.MSG_SERVO_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SERVO_SET_RAMP_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SERVO_SET_RAMP_TOOLTIP); this.setColour(colorPalette.getColor('output')); this.appendDummyInput() .appendField("CR Servo set ramp PIN") @@ -568,9 +660,9 @@ Blockly.propc.servo_set_ramp = function () { var ramp_step = Blockly.propc.valueToCode(this, 'RAMPSTEP', Blockly.propc.ORDER_NONE); if (Number(ramp_step) < 0) { - ramp_step = "0"; + ramp_step = "0"; } else if (Number(ramp_step) > 100) { - ramp_step = "100"; + ramp_step = "100"; } Blockly.propc.definitions_["include servo"] = '#include "servo.h"'; @@ -581,20 +673,20 @@ Blockly.propc.servo_set_ramp = function () { // --------- ActivityBoard A/D and D/A voltage measurement/generation blocks --- Blockly.Blocks.ab_volt_in = { helpUrl: Blockly.MSG_ANALOG_PULSES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_AB_VOLT_IN_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_AB_VOLT_IN_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput() - .appendField("A/D channel") - .appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"]]), "CHANNEL") - .appendField("read (0-5V) in volt-100ths"); + .appendField("A/D channel") + .appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"]]), "CHANNEL") + .appendField("read (0-5V) in volt-100ths"); this.setOutput(true, 'Number'); this.setPreviousStatement(false, null); this.setNextStatement(false, null); } }; -Blockly.propc.ab_volt_in = function() { +Blockly.propc.ab_volt_in = function () { var dropdown_channel = this.getFieldValue('CHANNEL'); Blockly.propc.definitions_["include abvolt"] = '#include "abvolts.h"'; @@ -608,14 +700,14 @@ Blockly.propc.ab_volt_in = function() { Blockly.Blocks.ab_volt_out = { helpUrl: Blockly.MSG_ANALOG_PULSES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_AB_VOLT_OUT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_AB_VOLT_OUT_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput() .appendField("D/A channel") .appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"]]), "CHANNEL") .appendField("output (0-3.3V)"); - this.appendValueInput("VALUE") + this.appendValueInput("VALUE") .setCheck('Number') .setAlign(Blockly.ALIGN_RIGHT) .appendField("volt-100ths"); @@ -625,7 +717,7 @@ Blockly.Blocks.ab_volt_out = { } }; -Blockly.propc.ab_volt_out = function() { +Blockly.propc.ab_volt_out = function () { var dropdown_channel = this.getFieldValue('CHANNEL'); var value = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_NONE) || '0'; @@ -641,8 +733,8 @@ Blockly.propc.ab_volt_out = function() { // ------------- PWM (Pulse-width modulation) Blocks --------------------------- Blockly.Blocks.pwm_start = { helpUrl: Blockly.MSG_ANALOG_PWM_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_PWM_START_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_PWM_START_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput() .appendField("PWM initialize"); @@ -659,8 +751,8 @@ Blockly.propc.pwm_start = function () { Blockly.Blocks.pwm_set = { helpUrl: Blockly.MSG_ANALOG_PWM_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_PWM_SET_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_PWM_SET_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput() .appendField("PWM set PIN") @@ -695,8 +787,8 @@ Blockly.propc.pwm_set = function () { Blockly.Blocks.pwm_stop = { helpUrl: Blockly.MSG_ANALOG_PWM_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_PWM_STOP_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_PWM_STOP_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput() .appendField("PWM stop"); @@ -714,12 +806,12 @@ Blockly.propc.pwm_stop = function () { // ----------------- .WAV file audio player blocks ----------------------------- Blockly.Blocks.wav_play = { helpUrl: Blockly.MSG_AUDIO_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_WAV_PLAY_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_WAV_PLAY_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput() - .appendField("WAV play file") - .appendField(new Blockly.FieldTextInput('File_name'), 'FILENAME'); + .appendField("WAV play file") + .appendField(new Blockly.FieldTextInput('File_name'), 'FILENAME'); this.setInputsInline(true); this.setPreviousStatement(true, null); @@ -727,7 +819,7 @@ Blockly.Blocks.wav_play = { } }; -Blockly.propc.wav_play = function() { +Blockly.propc.wav_play = function () { var filename = this.getFieldValue('FILENAME'); Blockly.propc.definitions_["include wavplayer"] = '#include "wavplayer.h"'; @@ -739,11 +831,11 @@ Blockly.propc.wav_play = function() { Blockly.Blocks.wav_status = { helpUrl: Blockly.MSG_AUDIO_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_WAV_STATUS_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_WAV_STATUS_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput() - .appendField("WAV status"); + .appendField("WAV status"); this.setPreviousStatement(false, null); this.setNextStatement(false, null); @@ -751,7 +843,7 @@ Blockly.Blocks.wav_status = { } }; -Blockly.propc.wav_status = function() { +Blockly.propc.wav_status = function () { Blockly.propc.definitions_["include wavplayer"] = '#include "wavplayer.h"'; var code = 'wav_playing()'; @@ -760,18 +852,18 @@ Blockly.propc.wav_status = function() { Blockly.Blocks.wav_volume = { helpUrl: Blockly.MSG_AUDIO_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_WAV_VOLUME_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_WAV_VOLUME_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendValueInput('VOLUME') - .appendField("WAV volume (0 - 10)"); + .appendField("WAV volume (0 - 10)"); this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.wav_volume = function() { +Blockly.propc.wav_volume = function () { var volume = Blockly.propc.valueToCode(this, 'VOLUME', Blockly.propc.ORDER_NONE) || '0'; Blockly.propc.definitions_["include wavplayer"] = '#include "wavplayer.h"'; @@ -788,18 +880,18 @@ Blockly.propc.wav_volume = function() { Blockly.Blocks.wav_stop = { helpUrl: Blockly.MSG_AUDIO_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_WAV_STOP_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_WAV_STOP_TOOLTIP); this.setColour(colorPalette.getColor('io')); this.appendDummyInput() - .appendField("WAV stop"); + .appendField("WAV stop"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.wav_stop = function() { +Blockly.propc.wav_stop = function () { var code = 'wav_stop();\n'; return code; }; @@ -807,15 +899,15 @@ Blockly.propc.wav_stop = function() { // ----------------- Robot (drive) blocks -------------------------------------- Blockly.Blocks.ab_drive_init = { helpUrl: Blockly.MSG_ROBOT_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_ROBOT_DRIVE_INIT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_ROBOT_DRIVE_INIT_TOOLTIP); this.setColour(colorPalette.getColor('robot')); this.appendDummyInput() .appendField("Robot") .appendField(new Blockly.FieldDropdown([["ActivityBot", "abdrive.h"], ["Arlo", "arlodrive.h"], ["Servo Differential Drive", "servodiffdrive.h"]], function (bot) { this.sourceBlock_.updateShape_({"BOT": bot}); }), "BOT") - .appendField("initialize"); + .appendField("initialize"); this.appendDummyInput("PINS") .appendField(" ramping") .appendField(new Blockly.FieldDropdown([["none", "64"], ["light", "8"], ["medium", "4"], ["heavy", "2"], ["maximum", "1"]]), "RAMPING"); @@ -847,19 +939,19 @@ Blockly.Blocks.ab_drive_init = { var inputPins = this.getInput('PINS'); if (bot === 'servodiffdrive.h') { inputPins.appendField(" left PIN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "LEFT") - .appendField("right PIN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "RIGHT") - .appendField(" ramping") - .appendField(new Blockly.FieldDropdown([["none", "64"], ["light", "8"], ["medium", "4"], ["heavy", "2"], ["maximum", "1"]]), "RAMPING"); + .appendField(new Blockly.FieldDropdown(profile.default.digital), "LEFT") + .appendField("right PIN") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "RIGHT") + .appendField(" ramping") + .appendField(new Blockly.FieldDropdown([["none", "64"], ["light", "8"], ["medium", "4"], ["heavy", "2"], ["maximum", "1"]]), "RAMPING"); } else { inputPins.appendField(" ramping") - .appendField(new Blockly.FieldDropdown([["none", "64"], ["light", "8"], ["medium", "4"], ["heavy", "2"], ["maximum", "1"]]), "RAMPING"); + .appendField(new Blockly.FieldDropdown([["none", "64"], ["light", "8"], ["medium", "4"], ["heavy", "2"], ["maximum", "1"]]), "RAMPING"); } } }; -Blockly.propc.ab_drive_init = function() { +Blockly.propc.ab_drive_init = function () { var bot = this.getFieldValue('BOT'); var left = Number(this.getFieldValue('LEFT')); var right = Number(this.getFieldValue('RIGHT')); @@ -867,20 +959,20 @@ Blockly.propc.ab_drive_init = function() { Blockly.propc.definitions_["include abdrive"] = '#include "' + bot + '"'; - if(Blockly.propc.definitions_["include abdrive"] === '#include "servodiffdrive.h"') { + if (Blockly.propc.definitions_["include abdrive"] === '#include "servodiffdrive.h"') { Blockly.propc.setups_["servodiffdrive"] = 'drive_pins(' + left + ',' + right + ');\n'; - Blockly.propc.setups_["sdd_ramping"] = 'drive_setramp(' + ramping + ',' + ramping + ');\n'; + Blockly.propc.setups_["sdd_ramping"] = 'drive_setramp(' + ramping + ',' + ramping + ');\n'; } else { Blockly.propc.setups_["abd_ramping"] = 'drive_setRampStep(' + ramping + ');\n'; } - + return ''; }; Blockly.Blocks.ab_drive_goto = { helpUrl: Blockly.MSG_ROBOT_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_ROBOT_DRIVE_DISTANCE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_ROBOT_DRIVE_DISTANCE_TOOLTIP); this.setColour(colorPalette.getColor('robot')); this.appendDummyInput() .appendField('Robot drive distance in') @@ -898,35 +990,35 @@ Blockly.Blocks.ab_drive_goto = { } }; -Blockly.propc.ab_drive_goto = function() { +Blockly.propc.ab_drive_goto = function () { var left = Blockly.propc.valueToCode(this, 'LEFT', Blockly.propc.ORDER_NONE); var right = Blockly.propc.valueToCode(this, 'RIGHT', Blockly.propc.ORDER_NONE); var units = this.getFieldValue('UNITS'); var bot = Blockly.propc.definitions_["include abdrive"]; var code = ''; - - if(bot === '#include "servodiffdrive.h"') { + + if (bot === '#include "servodiffdrive.h"') { code += '// Servo Differential Drive does not support "Drive Distance"\n'; - } else if(bot === '#include "abdrive.h"') { - if(units === 'TICK') { + } else if (bot === '#include "abdrive.h"') { + if (units === 'TICK') { code += 'drive_goto(' + left + ', ' + right + ');\n'; - } else if(units === 'CM') { + } else if (units === 'CM') { code += 'drive_goto((' + left + ' * 40)/13, (' + right + ' * 40)/13);\n'; } else { - code += 'drive_goto((' + left + ' * 508)/65, (' + right + ' * 508)/65);\n'; + code += 'drive_goto((' + left + ' * 508)/65, (' + right + ' * 508)/65);\n'; } } else { - if(units === 'TICK') { + if (units === 'TICK') { code += 'drive_goto(' + left + ', ' + right + ');\n'; - } else if(units === 'CM') { - code += 'drive_goto((' + left + ' * 253)/90, (' + right + ' * 253)/90);\n'; + } else if (units === 'CM') { + code += 'drive_goto((' + left + ' * 253)/90, (' + right + ' * 253)/90);\n'; } else { - code += 'drive_goto((' + left + ' * 50)/7, (' + right + ' * 50)/7);\n'; - } + code += 'drive_goto((' + left + ' * 50)/7, (' + right + ' * 50)/7);\n'; + } } - - if(bot === undefined) { + + if (bot === undefined) { return '// Robot drive system is not initialized!\n'; } else { return code; @@ -935,8 +1027,8 @@ Blockly.propc.ab_drive_goto = function() { Blockly.Blocks.ab_drive_speed = { helpUrl: Blockly.MSG_ROBOT_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_ROBOT_DRIVE_SPEED_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_ROBOT_DRIVE_SPEED_TOOLTIP); this.setColour(colorPalette.getColor('robot')); this.appendValueInput("LEFT") .setCheck('Number') @@ -951,24 +1043,24 @@ Blockly.Blocks.ab_drive_speed = { } }; -Blockly.propc.ab_drive_speed = function() { +Blockly.propc.ab_drive_speed = function () { var left = Blockly.propc.valueToCode(this, 'LEFT', Blockly.propc.ORDER_NONE); var right = Blockly.propc.valueToCode(this, 'RIGHT', Blockly.propc.ORDER_NONE); var bot = Blockly.propc.definitions_["include abdrive"]; - + var code = ''; - - if(bot === '#include "servodiffdrive.h"') { + + if (bot === '#include "servodiffdrive.h"') { code = 'drive_speeds(' + left + ', ' + right + ');\n'; } else { - if(Blockly.propc.setups_["abd_ramping"] === 'drive_setRampStep(64);\n') { + if (Blockly.propc.setups_["abd_ramping"] === 'drive_setRampStep(64);\n') { code = 'drive_speed(' + left + ', ' + right + ');\n'; } else { code = 'drive_ramp(' + left + ', ' + right + ');\n'; } } - if(bot === undefined) { + if (bot === undefined) { return '// Robot drive system is not initialized!\n'; } else { return code; @@ -977,8 +1069,8 @@ Blockly.propc.ab_drive_speed = function() { Blockly.Blocks.ab_drive_stop = { helpUrl: Blockly.MSG_ROBOT_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_ROBOT_DRIVE_STOP_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_ROBOT_DRIVE_STOP_TOOLTIP); this.setColour(colorPalette.getColor('robot')); this.appendDummyInput() .appendField("Robot drive stop"); @@ -988,24 +1080,24 @@ Blockly.Blocks.ab_drive_stop = { } }; -Blockly.propc.ab_drive_stop = function() { +Blockly.propc.ab_drive_stop = function () { var left = Blockly.propc.valueToCode(this, 'LEFT', Blockly.propc.ORDER_NONE); var right = Blockly.propc.valueToCode(this, 'RIGHT', Blockly.propc.ORDER_NONE); var bot = Blockly.propc.definitions_["include abdrive"]; - + var code = ''; - - if(bot === '#include "servodiffdrive.h"') { + + if (bot === '#include "servodiffdrive.h"') { code = 'drive_speeds(0, 0);\n'; } else { - if(Blockly.propc.setups_["abd_ramping"] === 'drive_setRampStep(64);\n') { + if (Blockly.propc.setups_["abd_ramping"] === 'drive_setRampStep(64);\n') { code = 'drive_speed(0, 0);\n'; } else { code = 'drive_ramp(0, 0);\n'; } } - if(bot === undefined) { + if (bot === undefined) { return '// Robot drive system is not initialized!\n'; } else { return code; @@ -1014,15 +1106,15 @@ Blockly.propc.ab_drive_stop = function() { Blockly.Blocks.activitybot_calibrate = { helpUrl: Blockly.MSG_ROBOT_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_ACTIVITYBOT_CALIBRATE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_ACTIVITYBOT_CALIBRATE_TOOLTIP); this.setColour(colorPalette.getColor('robot')); this.appendDummyInput() - .appendField("ActivityBot calibrate"); + .appendField("ActivityBot calibrate"); } }; -Blockly.propc.activitybot_calibrate = function() { +Blockly.propc.activitybot_calibrate = function () { Blockly.propc.definitions_["activitybot_calibrate"] = '#include "abcalibrate.h"'; Blockly.propc.setups_["activitybot_calibrate"] = 'cal_servoPins(12, 13);\n\tcal_encoderPins(14, 15);'; @@ -1031,19 +1123,19 @@ Blockly.propc.activitybot_calibrate = function() { Blockly.Blocks.activitybot_display_calibration = { helpUrl: Blockly.MSG_ROBOT_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_ACTIVITYBOT_DISPLAY_CALIBRATION_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_ACTIVITYBOT_DISPLAY_CALIBRATION_TOOLTIP); this.setColour(colorPalette.getColor('robot')); this.appendDummyInput() - .appendField("ActivityBot display calibration"); + .appendField("ActivityBot display calibration"); } }; -Blockly.propc.activitybot_display_calibration = function() { +Blockly.propc.activitybot_display_calibration = function () { Blockly.propc.definitions_["include abdrive"] = '#include "abdrive.h"'; Blockly.propc.serial_terminal_ = true; - + var code = ''; code += 'int abd_intTabSetup;\n'; code += 'volatile int abd_elCntL, abd_elCntR, abd_elCntL, abd_elCntR, abd_cntrLidx, abd_cntrRidx;\n'; @@ -1053,14 +1145,128 @@ Blockly.propc.activitybot_display_calibration = function() { code = ''; code += 'if(!abd_intTabSetup) interpolation_table_setup();\n'; - code += 'print("=== LEFT SERVO ===\\n");\n'; - code += 'print("Table Entries = %d, Zero Speed Index = %d\\n\\n", abd_elCntL, abd_cntrLidx);\n'; - code += 'print("Index, Servo Drive, Encoder Ticks/Second\\n");\n'; - code += 'for(int __rIdx = 0; __rIdx < abd_elCntL; __rIdx++) print("%d, %d, %d\\n", __rIdx, abd_spdrL[__rIdx], abd_spdmL[__rIdx]);\n'; - code += 'print("\\n\\n=== RIGHT SERVO ===\\n");\n'; - code += 'print("Table Entries = %d, Zero Speed Index = %d\\n\\n", abd_elCntR, abd_cntrRidx);\n'; + code += 'print("=== LEFT SERVO ===\\r");\n'; + code += 'print("Table Entries = %d, Zero Speed Index = %d\\r\\r", abd_elCntL, abd_cntrLidx);\n'; code += 'print("Index, Servo Drive, Encoder Ticks/Second\\n");\n'; - code += 'for(int __rIdx = 0; __rIdx < abd_elCntR; __rIdx++) print("%d, %d, %d\\n", __rIdx, abd_spdrR[__rIdx], abd_spdmR[__rIdx]);\n'; + code += 'for(int __rIdx = 0; __rIdx < abd_elCntL; __rIdx++) print("%d, %d, %d\\r", __rIdx, abd_spdrL[__rIdx], abd_spdmL[__rIdx]);\n'; + code += 'print("\\r\\r=== RIGHT SERVO ===\\r");\n'; + code += 'print("Table Entries = %d, Zero Speed Index = %d\\r\\r", abd_elCntR, abd_cntrRidx);\n'; + code += 'print("Index, Servo Drive, Encoder Ticks/Second\\r");\n'; + code += 'for(int __rIdx = 0; __rIdx < abd_elCntR; __rIdx++) print("%d, %d, %d\\r", __rIdx, abd_spdrR[__rIdx], abd_spdmR[__rIdx]);\n'; return code; }; + +Blockly.Blocks.mcp320x_read = { + helpUrl: Blockly.MSG_ANALOG_PULSES_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_MCP320X_READ_TOOLTIP); + this.setColour(colorPalette.getColor('io')); + this.appendDummyInput() + .appendField(new Blockly.FieldDropdown([["MCP3202", "2"], ["MCP3204", "4"], ["MCP8208", "8"]], function (ch_c) { + this.sourceBlock_.updateShape_({"CH_C": ch_c}); + }), "CHIP") + .appendField("CS") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "CS_PIN") + .appendField("CLK") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "CLK_PIN") + .appendField("DO") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "DO_PIN") + .appendField("DI") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "DI_PIN"); + this.appendDummyInput('CHANNELS') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("channel") + .appendField(new Blockly.FieldDropdown([["1", "1"], ["2", "2"]]), "CHAN") + .appendField("read (0-3.3V) in volt-100ths"); + this.setInputsInline(false); + this.setOutput(true, null); + }, + mutationToDom: function () { + var container = document.createElement('mutation'); + var ch_c = this.getFieldValue('CHIP'); + container.setAttribute('chip', ch_c); + return container; + }, + domToMutation: function (xmlElement) { + var ch_c = xmlElement.getAttribute('chip'); + this.updateShape_({"CH_C": ch_c}); + }, + updateShape_: function (details) { + + var num = details['CH_C']; + if (details['CH_C'] === undefined) { + num = this.getFieldValue('CH_C'); + } + + var chan_count = []; + + for (var i = 1; i <= num; i++) { + chan_count.push([i.toString(), i.toString()]); + } + + this.removeInput('CHANNELS'); + this.appendDummyInput('CHANNELS') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField("channel") + .appendField(new Blockly.FieldDropdown(chan_count), "CHAN") + .appendField("read (0-3.3V) in volt-100ths"); + } +}; + +Blockly.propc.mcp320x_read = function () { + var chip = parseInt(this.getFieldValue('CHIP')); + var cs_pin = this.getFieldValue('CS_PIN'); + var clk_pin = this.getFieldValue('CLK_PIN'); + var do_pin = this.getFieldValue('DO_PIN'); + var di_pin = this.getFieldValue('DI_PIN'); + var channel = '000' + parseInt(this.getFieldValue('CHANNEL')).toString(2) + "1"; + + if (chip < 4) { + channel = "11" + channel.substr(0, 1) + "1"; + } else { + channel = "11" + channel.substr(0, 3) + "0"; + } + + var func = ''; + func += 'int __Mvref = 330;'; + func += 'int read_mcp320x(int __McsPin, int __MclkPin, int __MdoPin, int __MdiPin, int __Mbits, int __Mdata, int __MVr) {\n'; + func += ' high(__McsPin); low(__MclkPin); low(__McsPin);\n'; + func += ' shift_out(__MdiPin, __MclkPin, MSBFIRST, __Mbits, __Mdata);\n'; + func += ' int __Mvolts = shift_in(__MdiPin, __MclkPin, MSBPOST, 12);\n'; + func += ' high(__McsPin); high(__MclkPin);\n return ((__Mvolts * __MVr) / 4096);}'; + Blockly.propc.global_vars_["mcp320x_read"] = func; + + + var code = ''; + code += 'read_mcp320x(' + cs_pin + ', ' + clk_pin + ', ' + do_pin; + code += ', ' + di_pin + ', ' + channel.length + ', 0b' + channel + ', __Mvref)'; + + return [code, Blockly.propc.ORDER_NONE]; +}; + +Blockly.Blocks.mcp320x_set_vref = { + helpUrl: Blockly.MSG_ANALOG_PULSES_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_MCP320X_SET_VREF_TOOLTIP); + this.setColour(colorPalette.getColor('io')); + this.appendDummyInput() + .appendField("MCP320X set Vref to") + .appendField(new Blockly.FieldTextInput('330', + Blockly.FieldTextInput.numberValidator), "VREF") + .appendField("volt 100ths"); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.propc.mcp320x_set_vref = function () { + var vref = parseInt(this.getFieldValue('VREF')); + + var code = ''; + if (Blockly.propc.global_vars_["mcp320x_read"] !== undefined) { + code += '__Mvref = ' + vref + ';\n'; + } + return code; +}; \ No newline at end of file diff --git a/src/main/webapp/cdn/blockly/generators/propc/heb.js b/src/main/webapp/cdn/blockly/generators/propc/heb.js index 62e1f399..b2381eca 100644 --- a/src/main/webapp/cdn/blockly/generators/propc/heb.js +++ b/src/main/webapp/cdn/blockly/generators/propc/heb.js @@ -30,7 +30,7 @@ if (!Blockly.Blocks) Blockly.Blocks.heb_toggle_led = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('functions')); this.appendDummyInput() .appendField('LED set state of') .appendField(new Blockly.FieldDropdown([["0 - P27", "0"], ["1 - P26", "1"], ["2 - P25", "2"], ["3 - P15", "3"], ["4 - P16", "4"], ["5 - P17", "5"]]), "LED_#") @@ -55,7 +55,7 @@ Blockly.propc.heb_toggle_led = function () { Blockly.Blocks.heb_toggle_led_open = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('functions')); this.appendDummyInput() .appendField('LED set state of'); this.appendValueInput('LED_NUM') @@ -80,15 +80,34 @@ Blockly.propc.heb_toggle_led_open = function () { return code; }; -Blockly.Blocks.heb_set_led_rgb = { +Blockly.Blocks.heb_color_val = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('programming')); + var rgb_led_colors = new Blockly.FieldColour("#FFFFFF"); + rgb_led_colors.setColours(['#FFFFFF', '#FFFF00', '#00FFFF', '#FF00FF', '#000000', '#00FF00', '#0000FF', '#FF0000']).setColumns(4); this.appendDummyInput() - .appendField('RGB LED set state of') - .appendField(new Blockly.FieldDropdown([["left LED", "L"], ["right LED", "R"]]), "SIDE") - .appendField('color') - .appendField(new Blockly.FieldDropdown([["BLUE", "BLUE"], ["GREEN", "GREEN"], ["CYAN", "CYAN"], ["RED", "RED"], ["MAGENTA", "MAGENTA"], ["YELLOW", "YELLOW"], ["WHITE", "WHITE"], ["OFF", "OFF"]]), "RGB"); + .appendField('color (Badge)') + .appendField(rgb_led_colors, "RGB"); + this.setOutput(true, 'Number'); + this.setPreviousStatement(false, null); + this.setNextStatement(false, null); + } +}; + +Blockly.propc.heb_color_val = function () { + var led_rgb = this.getFieldValue("RGB").replace(/F/g, '1').replace(/f/g, '1').replace('#', ''); + var code = '0b' + led_rgb[0] + led_rgb[2] + led_rgb[4]; + + return [code, Blockly.propc.ORDER_NONE]; +}; +Blockly.Blocks.heb_set_led_rgb = { + init: function () { + this.setColour(colorPalette.getColor('functions')); + this.appendValueInput('RGB') + .appendField('RGB LED set state of') + .appendField(new Blockly.FieldDropdown([["left LED", "L"], ["right LED", "R"], ["both LEDs", "B"]]), "SIDE") + .appendField('to'); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } @@ -96,21 +115,26 @@ Blockly.Blocks.heb_set_led_rgb = { Blockly.propc.heb_set_led_rgb = function () { var led_side = this.getFieldValue("SIDE"); - var led_rgb = this.getFieldValue("RGB"); + var led_rgb = Blockly.propc.valueToCode(this, "RGB", Blockly.propc.ORDER_NONE); + + var both_leds = ''; + if (led_side === "B") { + led_side = led_rgb; + both_leds = 's'; + } Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; Blockly.propc.setups_["badgetools"] = 'badge_setup();'; - var code = 'rgb(' + led_side + ', ' + led_rgb + ');\n'; + var code = 'rgb' + both_leds + '(' + led_side + ', ' + led_rgb + ');\n'; return code; }; Blockly.Blocks.heb_print_numeric_var = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('protocols')); this.appendValueInput('VALUE') - .appendField("OLED print number"); - + .appendField("Display print number"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } @@ -133,10 +157,9 @@ Blockly.propc.heb_print_numeric_var = function () { Blockly.Blocks.heb_print_string_var = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('protocols')); this.appendValueInput('VALUE') - .appendField("OLED print text"); - + .appendField("Display print text"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } @@ -154,13 +177,10 @@ Blockly.propc.heb_print_string_var = function () { Blockly.Blocks.heb_cursor_position_large = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField('Setup to print LARGE text. Cursor at:') - .appendField('Column') - .appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"]]), "COLS") - .appendField('Row') - .appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"]]), "ROWS"); + .appendField('Display set font size') + .appendField(new Blockly.FieldDropdown([["Large", "LARGE"], ["Small", "SMALL"]]), "SIZE"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -168,47 +188,292 @@ Blockly.Blocks.heb_cursor_position_large = { }; Blockly.propc.heb_cursor_position_large = function () { - var columns = this.getFieldValue("COLS"); - var rows = this.getFieldValue("ROWS"); + var size = this.getFieldValue("SIZE"); Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; Blockly.propc.setups_["badgetools"] = 'badge_setup();'; - var code = 'text_size(LARGE);\n' + 'cursor(' + columns + ', ' + rows + ');\n'; + var code = 'text_size(' + size + ');\n'; return code; }; Blockly.Blocks.heb_cursor_position_small = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('protocols')); + this.appendValueInput('COLS') + .appendField('Display set cursor column'); + this.appendValueInput('ROWS') + .appendField('row'); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.propc.heb_cursor_position_small = function () { + var columns = Blockly.propc.valueToCode(this, "COLS", Blockly.propc.ORDER_NONE); + var rows = Blockly.propc.valueToCode(this, "ROWS", Blockly.propc.ORDER_NONE); + + Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; + Blockly.propc.setups_["badgetools"] = 'badge_setup();'; + + var code = 'cursor(' + columns + ', ' + rows + ');\n'; + return code; +}; + +Blockly.Blocks.heb_oled_point = { + init: function () { + var oled_colors = new Blockly.FieldColour("#FFFFFF"); + oled_colors.setColours(['#FFFFFF', '#000000']).setColumns(2); + this.setColour(colorPalette.getColor('protocols')); + this.appendValueInput('X0') + .appendField('Display draw pixel at (x)'); + this.appendValueInput('Y0') + .appendField('(y)'); this.appendDummyInput() - .appendField('Setup to print SMALL text. Cursor at:') - .appendField('Column') - .appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"], ["8", "8"], ["9", "9"], ["10", "10"], ["11", "11"], ["12", "12"], ["13", "13"], ["14", "14"], ["15", "15"]]), "COLS") - .appendField('Row') - .appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"], ["4", "4"], ["5", "5"], ["6", "6"], ["7", "7"]]), "ROWS"); + .appendField('color') + .appendField(oled_colors, 'COLOR'); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.propc.heb_oled_point = function () { + var x = Blockly.propc.valueToCode(this, "X0", Blockly.propc.ORDER_NONE); + var y = Blockly.propc.valueToCode(this, "Y0", Blockly.propc.ORDER_NONE); + var c = this.getFieldValue('COLOR'); + //var c = Blockly.propc.valueToCode(this, "COLOR", Blockly.propc.ORDER_NONE); + if (c === '#000000') + c = '0'; + else + c = '1'; + + Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; + Blockly.propc.setups_["badgetools"] = 'badge_setup();'; + var code = 'point(' + x + ', ' + y + ', ' + c + ');\n'; + return code; +}; + +Blockly.Blocks.heb_oled_line = { + init: function () { + var oled_colors = new Blockly.FieldColour("#FFFFFF"); + oled_colors.setColours(['#FFFFFF', '#000000']).setColumns(2); + this.setColour(colorPalette.getColor('protocols')); + this.appendValueInput('X0') + .appendField('Display draw line from 1 (x)'); + this.appendValueInput('Y0') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('(y)'); + this.appendValueInput('X1') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('to 2 (x)'); + this.appendValueInput('Y1') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('(y)'); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('color') + .appendField(oled_colors, 'COLOR'); + this.setInputsInline(false); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.heb_cursor_position_small = function () { - var columns = this.getFieldValue("COLS"); - var rows = this.getFieldValue("ROWS"); +Blockly.propc.heb_oled_line = function () { + var x0 = Blockly.propc.valueToCode(this, "X0", Blockly.propc.ORDER_NONE); + var y0 = Blockly.propc.valueToCode(this, "Y0", Blockly.propc.ORDER_NONE); + var x1 = Blockly.propc.valueToCode(this, "X1", Blockly.propc.ORDER_NONE); + var y1 = Blockly.propc.valueToCode(this, "Y1", Blockly.propc.ORDER_NONE); + var c = this.getFieldValue('COLOR'); + //var c = Blockly.propc.valueToCode(this, "COLOR", Blockly.propc.ORDER_NONE); + if (c === '#000000') + c = '0'; + else + c = '1'; + + Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; + Blockly.propc.setups_["badgetools"] = 'badge_setup();'; + + var code = 'line(' + x0 + ', ' + y0 + ', ' + x1 + ', ' + y1 + ', ' + c + ');\n'; + return code; +}; + +Blockly.Blocks.heb_oled_circle = { + init: function () { + var oled_colors = new Blockly.FieldColour("#FFFFFF"); + oled_colors.setColours(['#FFFFFF', '#000000']).setColumns(2); + this.setColour(colorPalette.getColor('protocols')); + this.appendValueInput('X0') + .appendField('Display draw circle at (x)'); + this.appendValueInput('Y0') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('(y)'); + this.appendValueInput('R') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('radius'); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('filled') + .appendField(new Blockly.FieldCheckbox('TRUE'), 'FILL'); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('color') + .appendField(oled_colors, 'COLOR'); + this.setInputsInline(false); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.propc.heb_oled_circle = function () { + var x = Blockly.propc.valueToCode(this, "X0", Blockly.propc.ORDER_NONE); + var y = Blockly.propc.valueToCode(this, "Y0", Blockly.propc.ORDER_NONE); + var r = Blockly.propc.valueToCode(this, "R", Blockly.propc.ORDER_NONE); + var f = this.getFieldValue('FILL'); + var c = this.getFieldValue('COLOR'); + //var c = Blockly.propc.valueToCode(this, "COLOR", Blockly.propc.ORDER_NONE); + if (c === '#000000') + c = '0'; + else + c = '1'; + if (f === 'TRUE') + f = 'Filled'; + else + f = ''; + + Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; + Blockly.propc.setups_["badgetools"] = 'badge_setup();'; + + var code = 'circle' + f + '(' + x + ', ' + y + ', ' + r + ', ' + c + ');\n'; + return code; +}; + +Blockly.Blocks.heb_oled_box = { + init: function () { + var oled_colors = new Blockly.FieldColour("#FFFFFF"); + oled_colors.setColours(['#FFFFFF', '#000000']).setColumns(2); + this.setColour(colorPalette.getColor('protocols')); + this.appendValueInput('X0') + .appendField('Display draw rectangle at 1 (x)'); + this.appendValueInput('Y0') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('(y)'); + this.appendValueInput('W') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('width'); + this.appendValueInput('H') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('height'); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('filled') + .appendField(new Blockly.FieldCheckbox('TRUE'), 'FILL'); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('color') + .appendField(oled_colors, 'COLOR'); + this.setInputsInline(false); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.propc.heb_oled_box = function () { + var x0 = Blockly.propc.valueToCode(this, "X0", Blockly.propc.ORDER_NONE); + var y0 = Blockly.propc.valueToCode(this, "Y0", Blockly.propc.ORDER_NONE); + var w = Blockly.propc.valueToCode(this, "W", Blockly.propc.ORDER_NONE); + var h = Blockly.propc.valueToCode(this, "H", Blockly.propc.ORDER_NONE); + var f = this.getFieldValue('FILL'); + var c = this.getFieldValue('COLOR'); + //var c = Blockly.propc.valueToCode(this, "COLOR", Blockly.propc.ORDER_NONE); + if (c === '#000000') + c = '0'; + else + c = '1'; + if (f === 'TRUE') + f = 'Filled'; + else + f = ''; Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; Blockly.propc.setups_["badgetools"] = 'badge_setup();'; - var code = 'text_size(SMALL);\n' + 'cursor(' + columns + ', ' + rows + ');\n'; + var code = 'box' + f + '(' + x0 + ', ' + y0 + ', (' + x0 + '+' + w + '-1),'; + code += '(' + y0 + '+' + h + '-1), ' + c + ');\n'; + return code; +}; + +Blockly.Blocks.heb_oled_triangle = { + init: function () { + var oled_colors = new Blockly.FieldColour("#FFFFFF"); + oled_colors.setColours(['#FFFFFF', '#000000']).setColumns(2); + this.setColour(colorPalette.getColor('protocols')); + this.appendValueInput('X0') + .appendField('Display draw triangle from 1 (x)'); + this.appendValueInput('Y0') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('(y)'); + this.appendValueInput('X1') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('to 2 (x)'); + this.appendValueInput('Y1') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('(y)'); + this.appendValueInput('X2') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('to 3 (x)'); + this.appendValueInput('Y2') + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('(y)'); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('filled') + .appendField(new Blockly.FieldCheckbox('TRUE'), 'FILL'); + this.appendDummyInput() + .setAlign(Blockly.ALIGN_RIGHT) + .appendField('color') + .appendField(oled_colors, 'COLOR'); + this.setInputsInline(false); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.propc.heb_oled_triangle = function () { + var x0 = Blockly.propc.valueToCode(this, "X0", Blockly.propc.ORDER_NONE); + var y0 = Blockly.propc.valueToCode(this, "Y0", Blockly.propc.ORDER_NONE); + var x1 = Blockly.propc.valueToCode(this, "X1", Blockly.propc.ORDER_NONE); + var y1 = Blockly.propc.valueToCode(this, "Y1", Blockly.propc.ORDER_NONE); + var x2 = Blockly.propc.valueToCode(this, "X2", Blockly.propc.ORDER_NONE); + var y2 = Blockly.propc.valueToCode(this, "Y2", Blockly.propc.ORDER_NONE); + var f = this.getFieldValue('FILL'); + var c = this.getFieldValue('COLOR'); + //var c = Blockly.propc.valueToCode(this, "COLOR", Blockly.propc.ORDER_NONE); + if (c === '#000000') + c = '0'; + else + c = '1'; + if (f === 'TRUE') + f = 'Filled'; + else + f = ''; + + Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; + Blockly.propc.setups_["badgetools"] = 'badge_setup();'; + + var code = 'triangle' + f + '(' + x0 + ', ' + y0 + ', ' + x1 + ', '; + code += y1 + ', ' + x2 + ', ' + y2 + ', ' + c + ');\n'; return code; }; Blockly.Blocks.heb_clear_screen = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField('OLED Clear screen'); + .appendField('Display clear screen'); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -225,9 +490,9 @@ Blockly.propc.heb_clear_screen = function () { Blockly.Blocks.heb_rotate = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField('OLED Rotate 180'); + .appendField('Display rotate 180\u00B0'); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -244,67 +509,64 @@ Blockly.propc.heb_rotate = function () { Blockly.Blocks.heb_ir_send_signal = { init: function () { - this.setColour(colorPalette.getColor('heb')); - this.appendDummyInput() - .appendField('IR send text') - .appendField(new Blockly.FieldTextInput(''), "MESSAGE"); - + this.setColour(colorPalette.getColor('protocols')); + this.appendValueInput('MESSAGE') + .appendField('IR send text'); + this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; Blockly.propc.heb_ir_send_signal = function () { - var message = this.getFieldValue("MESSAGE"); + var message = Blockly.propc.valueToCode(this, "MESSAGE", Blockly.propc.ORDER_NONE); Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; Blockly.propc.setups_["badgetools"] = 'badge_setup();'; - var code = 'send("' + message + '");\n'; + var code = 'send(' + message + ');\n'; return code; }; Blockly.Blocks.heb_ir_read_signal = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() - .appendField('number of characters received'); - this.appendDummyInput() - .appendField('Receive an array of characters'); - this.appendDummyInput() - .appendField('Message contents:') - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'BUFFER'); - - this.setInputsInline(false); - this.setPreviousStatement(false, null); - this.setNextStatement(false, null); - this.setOutput(true, 'Number'); + .appendField('IR receive store message in') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'BUFFER') + .appendField('length in') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'LENGTH'); + this.setPreviousStatement(true); + this.setNextStatement(true); + this.setInputsInline(true); }, getVars: function () { - return [this.getFieldValue('BUFFER')]; + return [this.getFieldValue('BUFFER'), this.getFieldValue('LENGTH')]; }, renameVar: function (oldName, newName) { - if (Blockly.Names.equals(oldName, this.getFieldValue('BUFFER'))) { + if (Blockly.Names.equals(oldName, this.getFieldValue('BUFFER'))) this.setTitleValue(newName, 'BUFFER'); - } + if (Blockly.Names.equals(oldName, this.getFieldValue('LENGTH'))) + this.setTitleValue(newName, 'LENGTH'); } }; Blockly.propc.heb_ir_read_signal = function () { - var buffer = Blockly.propc.variableDB_.getName(this.getFieldValue('BUFFER'), Blockly.Variables.NAME_TYPE); + var buffer = this.getFieldValue('BUFFER'); + var len = this.getFieldValue('LENGTH'); Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; Blockly.propc.setups_["badgetools"] = 'badge_setup();'; Blockly.propc.vartype_[buffer] = 'char'; Blockly.propc.varlength_[buffer] = 128; - var code = 'receive(' + buffer + ')'; - return [code, Blockly.propc.ORDERN_NONE]; + var code = len + '= receive(' + buffer + ');\n'; + return code; }; Blockly.Blocks.heb_ir_clear_buffer = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('protocols')); this.appendDummyInput() // @TODO : Should the title be something else? This might be confusing for beginners... .appendField("IR clear buffer"); @@ -324,18 +586,16 @@ Blockly.propc.heb_ir_clear_buffer = function () { Blockly.Blocks.heb_badge_eeprom_store = { init: function () { - this.setColour(colorPalette.getColor('heb')); - this.appendDummyInput() - .appendField("EEPROM store a contact") - .appendField(new Blockly.FieldTextInput(''), "CONTACT"); - + this.setColour(colorPalette.getColor('input')); + this.appendValueInput('CONTACT') + .appendField("EEPROM store contact"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; Blockly.propc.heb_badge_eeprom_store = function () { - var contact = this.getFieldValue("CONTACT"); + var contact = Blockly.propc.valueToCode(this, "CONTACT", Blockly.propc.ORDER_NONE); Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; Blockly.propc.setups_["badgetools"] = 'badge_setup();'; @@ -346,20 +606,20 @@ Blockly.propc.heb_badge_eeprom_store = function () { Blockly.Blocks.heb_badge_eeprom_is_stored = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('input')); + this.appendValueInput('CONTACT') + .appendField("EEPROM contact"); this.appendDummyInput() - .appendField("EEPROM is") - .appendField(new Blockly.FieldTextInput(''), "CONTACT") - .appendField("already stored?"); - + .appendField("already stored"); this.setOutput(true, 'Number'); + this.setInputsInline(true); this.setPreviousStatement(false, null); this.setNextStatement(false, null); } }; Blockly.propc.heb_badge_eeprom_is_stored = function () { - var contact = this.getFieldValue("CONTACT"); + var contact = Blockly.propc.valueToCode(this, "CONTACT", Blockly.propc.ORDER_NONE); Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; Blockly.propc.setups_["badgetools"] = 'badge_setup();'; @@ -370,34 +630,44 @@ Blockly.propc.heb_badge_eeprom_is_stored = function () { Blockly.Blocks.heb_badge_eeprom_retrieve = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('input')); + this.appendValueInput('INDEX') + .appendField("EEPROM get contact at index"); this.appendDummyInput() - .appendField("EEPROM retrieve value from index") - // @TODO : Get proper EEPROM index values ( THESE ARE FOR TESTING PURPOSES ONLY ) - .appendField(new Blockly.FieldDropdown([["1", "0"], ["2", "1"], ["3", "2"]]), "INDEX"); - this.appendValueInput("BUFFER") - .setAlign(Blockly.ALIGN_RIGHT) - .appendField('store in'); - + .appendField('store in') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_SET_ITEM), 'BUFFER'); this.setPreviousStatement(true, null); this.setNextStatement(true, null); + }, + getVars: function () { + return [this.getFieldValue('BUFFER')]; + }, + renameVar: function (oldName, newName) { + if (Blockly.Names.equals(oldName, this.getFieldValue('BUFFER'))) { + this.setTitleValue(newName, 'BUFFER'); + } } }; Blockly.propc.heb_badge_eeprom_retrieve = function () { - var buffer = Blockly.propc.valueToCode(this, "BUFFER", Blockly.propc.ORDER_NONE); - var index = this.getFieldValue("INDEX"); + var index = Blockly.propc.valueToCode(this, "INDEX", Blockly.propc.ORDER_NONE); + var buffer = this.getFieldValue("BUFFER"); + + var setup_code = '// Constrain Function\nint constrain(int __cVal, int __cMin, int __cMax) {'; + setup_code += 'if(__cVal < __cMin) __cVal = __cMin;\n'; + setup_code += 'if(__cVal > __cMax) __cVal = __cMax;\nreturn __cVal;\n}\n'; + Blockly.propc.global_vars_["constrain_function"] = setup_code; Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; Blockly.propc.setups_["badgetools"] = 'badge_setup();'; - var code = 'retrieve(' + buffer + ', ' + index + ');\n'; + var code = 'retrieve(' + buffer + ', constrain(' + index + ', 0, contacts_count() - 1));\n'; return code; }; Blockly.Blocks.heb_count_contacts = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("EEPROM count contacts"); @@ -417,7 +687,7 @@ Blockly.propc.heb_count_contacts = function () { Blockly.Blocks.heb_erase_all_contacts = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("EEPROM erase all contacts"); @@ -436,7 +706,7 @@ Blockly.propc.heb_erase_all_contacts = function () { Blockly.Blocks.heb_badge_axis_acceleration = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('io')); this.appendDummyInput() .appendField("Accelerometer get") .appendField(new Blockly.FieldDropdown([["x-axis", "AX"], ["y-axis", "AY"], ["z-axis", "AZ"]]), "AXIS"); @@ -459,7 +729,7 @@ Blockly.propc.heb_badge_axis_acceleration = function () { Blockly.Blocks.heb_badge_was_shaken = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('io')); this.appendDummyInput() .appendField("Accelerometer was shaken?"); @@ -479,7 +749,7 @@ Blockly.propc.heb_badge_was_shaken = function () { Blockly.Blocks.heb_touchpad_status = { init: function () { - this.setColour(colorPalette.getColor('heb')); + this.setColour(colorPalette.getColor('io')); this.appendDummyInput() .appendField("Touchpad is") .appendField(new Blockly.FieldDropdown([["0 - P27", "0"], ["1 - P26", "1"], ["2 - P25", "2"], ["3 - P15", "3"], ["4 - P16", "4"], ["5 - P17", "5"], ["6 - Center Button", "6"], ["Any button", "-1"]]), "TOUCHPAD") @@ -497,10 +767,58 @@ Blockly.propc.heb_touchpad_status = function () { Blockly.propc.setups_["badgetools"] = 'badge_setup();'; var code = ''; - if(touchpad === "-1") { + if (touchpad === "-1") { code += 'buttons()'; } else { code += 'button(' + touchpad + ')'; } return [code, Blockly.propc.ORDER_NONE]; }; + +Blockly.Blocks.heb_text_to_speech_say = { + init: function () { + this.setColour(colorPalette.getColor('heb')); + this.appendValueInput('STRING') + .appendField("TTS say"); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.propc.heb_text_to_speech_say = function () { + var str = Blockly.propc.valueToCode(this, "STRING", Blockly.propc.ORDER_NONE); + + Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; + Blockly.propc.setups_["badgetools"] = 'badge_setup();'; + + Blockly.propc.definitions_["TTS"] = '#include "text2speech.h"'; + Blockly.propc.global_vars_["TTS"] = 'talk *tts_talk;'; + Blockly.propc.setups_["TTS"] = 'tts_talk = talk_run(9, 10);\ntalk_set_speaker(tts_talk, 1, 100);'; + + var code = 'talk_say(tts_talk, ' + str + ');\n'; + return code; +}; + +Blockly.Blocks.heb_text_to_speech_spell = { + init: function () { + this.setColour(colorPalette.getColor('heb')); + this.appendValueInput('STRING') + .appendField("TTS spell"); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.propc.heb_text_to_speech_spell = function () { + var str = Blockly.propc.valueToCode(this, "STRING", Blockly.propc.ORDER_NONE); + + Blockly.propc.definitions_["badgetools"] = '#include "badgetools.h"'; + Blockly.propc.setups_["badgetools"] = 'badge_setup();'; + + Blockly.propc.definitions_["TTS"] = '#include "text2speech.h"'; + Blockly.propc.global_vars_["TTS"] = 'talk *tts_talk;'; + Blockly.propc.setups_["TTS"] = 'tts_talk = talk_run(9, 10);\ntalk_set_speaker(tts_talk, 1, 100);'; + + var code = 'talk_spell(tts_talk, ' + str + ');\n'; + return code; +}; \ No newline at end of file diff --git a/src/main/webapp/cdn/blockly/generators/propc/s3.js b/src/main/webapp/cdn/blockly/generators/propc/s3.js index bdedcdd6..5d0d00c9 100644 --- a/src/main/webapp/cdn/blockly/generators/propc/s3.js +++ b/src/main/webapp/cdn/blockly/generators/propc/s3.js @@ -139,7 +139,7 @@ Blockly.Blocks.scribbler_if_line = { Blockly.propc.scribbler_if_line = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var line_condition = this.getFieldValue('LINE_CONDITION'); var line_position = this.getFieldValue('LINE_POSITION'); @@ -168,7 +168,7 @@ Blockly.Blocks.scribbler_if_obstacle = { Blockly.propc.scribbler_if_obstacle = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var obstacle_condition = this.getFieldValue('OBSTACLE_CONDITION'); var obstacle_position = this.getFieldValue('OBSTACLE_POSITION'); @@ -196,7 +196,7 @@ Blockly.Blocks.scribbler_if_light = { Blockly.propc.scribbler_if_light = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var light_condition = this.getFieldValue('LIGHT_CONDITION'); var light_position = this.getFieldValue('LIGHT_POSITION'); @@ -223,7 +223,7 @@ Blockly.Blocks.scribbler_if_stalled = { Blockly.propc.scribbler_if_stalled = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var code = 'if(s3_simpleStalled(S3_' + this.getFieldValue('STALLED_CONDITION') + ')) {\n'; return code + Blockly.propc.statementToCode(this, 'IF_STALLED') + '\n}'; @@ -245,7 +245,7 @@ Blockly.Blocks.scribbler_if_button = { Blockly.propc.scribbler_if_button = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var code = 'if(s3_simpleButton(S3_' + this.getFieldValue('BUTTON_CONDITION') + ')) {\n'; return code + Blockly.propc.statementToCode(this, 'IF_BUTTON') + '\n}'; @@ -269,7 +269,7 @@ Blockly.Blocks.scribbler_if_random = { Blockly.propc.scribbler_if_random = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var code = 'if(s3_simpleRandom(S3_' + this.getFieldValue('RANDOM_CONDITION') + this.getFieldValue('RANDOM_INVERT') + ')) {\n'; return code + Blockly.propc.statementToCode(this, 'IF_RANDOM') + '\n}'; @@ -295,7 +295,7 @@ Blockly.Blocks.scribbler_drive = { Blockly.propc.scribbler_drive = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var drive_direction = this.getFieldValue('DRIVE_DIRECTION'); var drive_angle = this.getFieldValue('DRIVE_ANGLE'); @@ -323,7 +323,7 @@ Blockly.Blocks.scribbler_spin = { Blockly.propc.scribbler_spin = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var spin_direction = this.getFieldValue('SPIN_DIRECTION'); var spin_angle = this.getFieldValue('SPIN_ANGLE'); @@ -345,7 +345,7 @@ Blockly.Blocks.scribbler_stop = { Blockly.propc.scribbler_stop = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; return 's3_simpleStop();\n'; }; @@ -384,7 +384,7 @@ Blockly.Blocks.scribbler_LED = { Blockly.propc.scribbler_LED = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var left_color = this.getFieldValue('LEFT_COLOR'); var center_color = this.getFieldValue('CENTER_COLOR'); @@ -408,7 +408,7 @@ Blockly.Blocks.scribbler_play = { init: function () { this.appendDummyInput() .appendField("play a") - .appendField(new Blockly.FieldDropdown([['double high', '2'], ['soprano', '4'], ['tenor', '8'], ['middle', '16'], ['low', '32'], ['deep', '64'], ['pedal', '128']]), 'NOTE_OCTAVE') + .appendField(new Blockly.FieldDropdown([['soprano', '4'], ['tenor', '8'], ['middle', '16'], ['low', '32'], ['deep', '64']]), 'NOTE_OCTAVE') //.appendField(new Blockly.FieldDropdown([['double high', '1'], ['soprano', '2'], ['tenor', '3'], ['middle', '4'], ['low', '5'], ['deep', '6'], ['pedal', '7']]), 'NOTE_OCTAVE') .appendField(new Blockly.FieldDropdown([['A\u266D', '3322'], ['A', '3520'], ['A\u266F/B\u266D', '3729'], ['B', '3951'], ['C', '4186'], ['C\u266F/D\u266D', '4435'], ['D', '4699'], ['D\u266F/E\u266D', '4978'], ['E', '5274'], ['F', '5588'], ['F\u266F/G\u266D', '5920'], ['G', '6272'], ['G\u266F', '6645']]), 'NOTE_FREQUENCY') .appendField("for a") @@ -427,7 +427,7 @@ Blockly.Blocks.scribbler_play = { Blockly.propc.scribbler_play = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var note_octave = this.getFieldValue('NOTE_OCTAVE'); var note_frequency = this.getFieldValue('NOTE_FREQUENCY'); @@ -465,7 +465,7 @@ Blockly.Blocks.move_motors = { Blockly.propc.move_motors = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var left_speed = Blockly.propc.valueToCode(this, 'LEFT_MOTOR_SPEED', Blockly.propc.ORDER_ATOMIC) || '0'; var right_speed = Blockly.propc.valueToCode(this, 'RIGHT_MOTOR_SPEED', Blockly.propc.ORDER_ATOMIC) || '0'; @@ -501,7 +501,7 @@ Blockly.Blocks.move_motors_distance = { Blockly.propc.move_motors_distance = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var distance_multiplier = this.getFieldValue('MULTIPLIER'); var left_distance = Blockly.propc.valueToCode(this, 'LEFT_MOTOR_DISTANCE', Blockly.propc.ORDER_ATOMIC) || '0'; @@ -537,7 +537,7 @@ Blockly.Blocks.move_motors_xy = { //TODO - This function appears to be missing. Blockly.propc.move_motors_xy = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var distance_multiplier = this.getFieldValue('MULTIPLIER'); var x_distance = Blockly.propc.valueToCode(this, 'X_DISTANCE', Blockly.propc.ORDER_ATOMIC) || '0'; @@ -571,7 +571,7 @@ Blockly.Blocks.move_motors_angle = { Blockly.propc.move_motors_angle = function () { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var radius_multiplier = this.getFieldValue('RADIUS_MULTIPLIER'); var angle = Blockly.propc.valueToCode(this, 'ROTATE_ANGLE', Blockly.propc.ORDER_ATOMIC); @@ -584,10 +584,10 @@ Blockly.Blocks.play_polyphony = { init: function () { this.appendValueInput("FREQUENCY_1") .setCheck("Number") - .appendField("play a tone of (1 to 10,000) Hz"); + .appendField("play a tone of (1 to 2,000) Hz"); this.appendValueInput("FREQUENCY_2") .setCheck("Number") - .appendField("and a tone of (1 to 10,000) Hz"); + .appendField("and a tone of (1 to 2,000) Hz"); this.appendValueInput("POLYPHONY_DURATION") .setCheck("Number") .appendField("for a duration of (1 to 8,000) ms"); @@ -606,10 +606,10 @@ Blockly.Blocks.play_polyphony = { Blockly.propc.play_polyphony = function() { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; - var fq1 = Blockly.propc.valueToCode(this, 'FREQUENCY_1', Blockly.propc.ORDER_ATOMIC) || 1000; - var fq2 = Blockly.propc.valueToCode(this, 'FREQUENCY_2', Blockly.propc.ORDER_ATOMIC) || 2000; + var fq1 = Blockly.propc.valueToCode(this, 'FREQUENCY_1', Blockly.propc.ORDER_ATOMIC) || 522; + var fq2 = Blockly.propc.valueToCode(this, 'FREQUENCY_2', Blockly.propc.ORDER_ATOMIC) || 784; var dur = Blockly.propc.valueToCode(this, 'POLYPHONY_DURATION', Blockly.propc.ORDER_ATOMIC) || 250; var vol = Blockly.propc.valueToCode(this, 'POLYPHONY_VOLUME', Blockly.propc.ORDER_ATOMIC) || 50; @@ -632,7 +632,7 @@ Blockly.Blocks.line_sensor = { Blockly.propc.line_sensor = function() { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var dir = this.getFieldValue("LINE_SENSOR_CHOICE"); return ['s3_lineSensor(S3_' + dir + ')', Blockly.propc.ORDER_NONE]; @@ -654,7 +654,7 @@ Blockly.Blocks.obstacle_sensor = { Blockly.propc.obstacle_sensor = function() { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var dir = this.getFieldValue("OBSTACLE_SENSOR_CHOICE"); return ['s3_readObstacle(S3_' + dir + ')', Blockly.propc.ORDER_NONE]; @@ -674,7 +674,7 @@ Blockly.Blocks.stall_sensor = { Blockly.propc.stall_sensor = function() { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; return ['s3_stalled()', Blockly.propc.ORDER_NONE]; }; @@ -705,7 +705,7 @@ Blockly.Blocks.spinning_sensor = { Blockly.propc.spinning_sensor = function() { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var dir = this.getFieldValue("LGHT_SENSOR_CHOICE"); return ['!s3_motorsMoving()', Blockly.propc.ORDER_NONE]; @@ -726,7 +726,7 @@ Blockly.Blocks.light_sensor = { Blockly.propc.light_sensor = function() { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; var dir = this.getFieldValue("LGHT_SENSOR_CHOICE"); return ['s3_lightSensor(S3_' + dir + ')', Blockly.propc.ORDER_NONE]; @@ -745,7 +745,7 @@ Blockly.Blocks.reset_button_presses = { Blockly.propc.reset_button_presses = function() { Blockly.propc.definitions_[ "include_scribbler" ] = '#include "s3.h"'; - Blockly.propc.setups_[ 'setup_scribbler' ] = 's3_setup();'; + Blockly.propc.setups_[ 's3_setup' ] = 's3_setup();pause(1000);'; return ['s3_resetButtonCount()', Blockly.propc.ORDER_NONE]; }; diff --git a/src/main/webapp/cdn/blockly/generators/propc/sensors.js b/src/main/webapp/cdn/blockly/generators/propc/sensors.js index 11b06422..00be270e 100644 --- a/src/main/webapp/cdn/blockly/generators/propc/sensors.js +++ b/src/main/webapp/cdn/blockly/generators/propc/sensors.js @@ -34,12 +34,12 @@ if (!Blockly.Blocks) // ---------------- 2-axis Joystick Blocks ------------------------------------- Blockly.Blocks.joystick_input_yaxis = { helpUrl: Blockly.MSG_JOYSTICK_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_JOYSTICK_INPUT_YAXIS_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_JOYSTICK_INPUT_YAXIS_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("Joystick y-axis A/D") - .appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"]]), "PINY"); + .appendField("Joystick y-axis A/D") + .appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"]]), "PINY"); this.setOutput(true, 'Number'); this.setPreviousStatement(false, null); @@ -47,7 +47,7 @@ Blockly.Blocks.joystick_input_yaxis = { } }; -Blockly.propc.joystick_input_yaxis = function() { +Blockly.propc.joystick_input_yaxis = function () { var pin_number_yaxis = this.getFieldValue('PINY'); Blockly.propc.definitions_["include abvolts"] = '#include "abvolts.h"'; @@ -58,12 +58,12 @@ Blockly.propc.joystick_input_yaxis = function() { Blockly.Blocks.joystick_input_xaxis = { helpUrl: Blockly.MSG_JOYSTICK_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_JOYSTICK_INPUT_XAXIS_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_JOYSTICK_INPUT_XAXIS_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("Joystick x-axis A/D") - .appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"]]), "PINX"); + .appendField("Joystick x-axis A/D") + .appendField(new Blockly.FieldDropdown([["0", "0"], ["1", "1"], ["2", "2"], ["3", "3"]]), "PINX"); this.setOutput(true, 'Number'); this.setPreviousStatement(false, null); @@ -71,7 +71,7 @@ Blockly.Blocks.joystick_input_xaxis = { } }; -Blockly.propc.joystick_input_xaxis = function() { +Blockly.propc.joystick_input_xaxis = function () { var pin_number_xaxis = this.getFieldValue('PINX'); Blockly.propc.definitions_["include abvolts"] = '#include "abvolts.h"'; @@ -83,14 +83,14 @@ Blockly.propc.joystick_input_xaxis = function() { // ---------------- Ping))) Sensor Blocks -------------------------------------- Blockly.Blocks.sensor_ping = { helpUrl: Blockly.MSG_PING_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SENSOR_PING_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SENSOR_PING_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("Ping))) distance in") - .appendField(new Blockly.FieldDropdown([["inches", "_inches"], ["cm", "_cm"]]), "UNIT") - .appendField("PIN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); + .appendField("Ping))) distance in") + .appendField(new Blockly.FieldDropdown([["inches", "_inches"], ["cm", "_cm"]]), "UNIT") + .appendField("PIN") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); this.setOutput(true, 'Number'); this.setPreviousStatement(false, null); @@ -98,7 +98,7 @@ Blockly.Blocks.sensor_ping = { } }; -Blockly.propc.sensor_ping = function() { +Blockly.propc.sensor_ping = function () { var dropdown_pin = this.getFieldValue('PIN'); var unit = this.getFieldValue('UNIT'); @@ -111,8 +111,8 @@ Blockly.propc.sensor_ping = function() { // ---------------- PIR Sensor Blocks ------------------------------------------ Blockly.Blocks.PIR_Sensor = { helpUrl: Blockly.MSG_PIR_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_PIR_SENSOR_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_PIR_SENSOR_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("PIR Sensor PIN") @@ -133,39 +133,39 @@ Blockly.propc.PIR_Sensor = function () { // ---------------- SF02 Laser Rangefinder Blocks ------------------------------ /* -Blockly.Blocks.SF02_Laser_Rangefinder = { - init: function () { - this.setColour(colorPalette.getColor('input')); - this.appendDummyInput() - .appendField("SF02 Laser Rangefinder PIN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); - - this.setOutput(true, 'Number'); - this.setPreviousStatement(false, null); - this.setNextStatement(false, null); - } -}; - -Blockly.propc.SF02_Laser_Rangefinder = function() { - var pin = this.getFieldValue('PIN'); - - Blockly.propc.definitions_["include abvolt"] = '#include "abvolts.h"'; - Blockly.propc.setups_['setup_abvolt'] = 'ad_init(21, 20, 19, 18);'; - - var code = 'ad_volts(' + pin + ')'; - return [code, Blockly.propc.ORDER_ATOMIC]; -}; -*/ + Blockly.Blocks.SF02_Laser_Rangefinder = { + init: function () { + this.setColour(colorPalette.getColor('input')); + this.appendDummyInput() + .appendField("SF02 Laser Rangefinder PIN") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); + + this.setOutput(true, 'Number'); + this.setPreviousStatement(false, null); + this.setNextStatement(false, null); + } + }; + + Blockly.propc.SF02_Laser_Rangefinder = function() { + var pin = this.getFieldValue('PIN'); + + Blockly.propc.definitions_["include abvolt"] = '#include "abvolts.h"'; + Blockly.propc.setups_['setup_abvolt'] = 'ad_init(21, 20, 19, 18);'; + + var code = 'ad_volts(' + pin + ')'; + return [code, Blockly.propc.ORDER_ATOMIC]; + }; + */ // ---------------- Sound Impact Sensor Blocks --------------------------------- Blockly.Blocks.sound_impact_run = { helpUrl: Blockly.MSG_SOUND_IMPACT_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SOUND_IMPACT_RUN_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SOUND_IMPACT_RUN_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("Sound Impact initialize PIN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); + .appendField("Sound Impact initialize PIN") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); this.setInputsInline(true); this.setNextStatement(true, null); @@ -173,7 +173,7 @@ Blockly.Blocks.sound_impact_run = { } }; -Blockly.propc.sound_impact_run = function() { +Blockly.propc.sound_impact_run = function () { var pin = this.getTitleValue('PIN'); Blockly.propc.definitions_["sound_impact"] = '#include "soundimpact.h"'; @@ -184,11 +184,11 @@ Blockly.propc.sound_impact_run = function() { Blockly.Blocks.sound_impact_get = { helpUrl: Blockly.MSG_SOUND_IMPACT_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SOUND_IMPACT_GET_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SOUND_IMPACT_GET_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("Sound Impact get count"); + .appendField("Sound Impact get count"); this.setNextStatement(false, null); this.setPreviousStatement(false, null); @@ -196,7 +196,7 @@ Blockly.Blocks.sound_impact_get = { } }; -Blockly.propc.sound_impact_get = function() { +Blockly.propc.sound_impact_get = function () { Blockly.propc.definitions_["sound_impact"] = '#include "soundimpact.h"'; if (Blockly.propc.setups_["sound_impact"] === undefined) @@ -210,18 +210,18 @@ Blockly.propc.sound_impact_get = function() { Blockly.Blocks.sound_impact_end = { helpUrl: Blockly.MSG_SOUND_IMPACT_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SOUND_IMPACT_END_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SOUND_IMPACT_END_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("Sound Impact close"); + .appendField("Sound Impact close"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.sound_impact_end = function() { +Blockly.propc.sound_impact_end = function () { Blockly.propc.definitions_["sound_impact"] = '#include "soundimpact.h"'; if (Blockly.propc.setups_["sound_impact"] === undefined) { @@ -234,8 +234,8 @@ Blockly.propc.sound_impact_end = function() { // ---------------- ColorPal Color Sensor Blocks ------------------------------- Blockly.Blocks.colorpal_enable = { helpUrl: Blockly.MSG_COLORPAL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_COLORPAL_ENABLE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_COLORPAL_ENABLE_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("ColorPal initialize PIN") @@ -249,8 +249,8 @@ Blockly.propc.colorpal_enable = function () { Blockly.propc.global_vars_["colorpal"] = 'colorPal *cpal;'; Blockly.propc.definitions_["colorpal"] = '#include "colorpal.h"'; - var pin = this.getFieldValue('IO_PIN'); - + var pin = this.getFieldValue('IO_PIN'); + Blockly.propc.setups_["colorpal"] = 'cpal = colorPal_open(' + pin + ');'; return ''; @@ -258,8 +258,8 @@ Blockly.propc.colorpal_enable = function () { Blockly.Blocks.colorpal_get_colors_raw = { helpUrl: Blockly.MSG_COLORPAL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_COLORPAL_GET_COLORS_RAW_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_COLORPAL_GET_COLORS_RAW_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("ColorPal raw colors store R in") @@ -299,8 +299,8 @@ Blockly.propc.colorpal_get_colors_raw = function () { Blockly.Blocks.colorpal_get_colors = { helpUrl: Blockly.MSG_COLORPAL_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_COLORPAL_GET_COLORS_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_COLORPAL_GET_COLORS_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("ColorPal store color in") @@ -331,10 +331,170 @@ Blockly.propc.colorpal_get_colors = function () { return code; }; +// -------------- Fingerprint Scanner Blocks ----------------------------------- +Blockly.Blocks.fp_scanner_init = { + helpUrl: Blockly.MSG_FPS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_FPS_INIT_TOOLTIP); + this.setColour(colorPalette.getColor('input')); + this.appendDummyInput() + .appendField("Fingerprint Scanner initialize RX") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "RXPIN") + .appendField("TX") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "TXPIN"); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + } +}; + +Blockly.propc.fp_scanner_init = function () { + var rxpin = this.getFieldValue('RXPIN'); + var txpin = this.getFieldValue('TXPIN'); + + Blockly.propc.global_vars_["fpScannerObj"] = 'fpScanner *fpScan;'; + Blockly.propc.definitions_["fpScannerDef"] = '#include "fingerprint.h"'; + + Blockly.propc.setups_["fpScanner"] = 'fpScan = fingerprint_open(' + rxpin + ', ' + txpin + ');'; + + return ''; +}; + +Blockly.Blocks.fp_scanner_add = { + helpUrl: Blockly.MSG_FPS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_FPS_ADD_TOOLTIP); + this.setColour(colorPalette.getColor('input')); + this.appendDummyInput() + .appendField("Fingerprint Scanner") + .appendField(new Blockly.FieldDropdown([["capture and save to", "ADD"], ["delete capture for", "DEL"], ["delete all captures", "ALL"]], function (action) { + this.sourceBlock_.setAction_({"ACTION": action}); + }), "ACTION"); + this.appendValueInput("USER") + .setCheck("Number") + .appendField("ID"); + this.setInputsInline(true); + this.setPreviousStatement(true, null); + this.setNextStatement(true, null); + }, + mutationToDom: function () { + var container = document.createElement('mutation'); + var action = this.getFieldValue('ACTION'); + container.setAttribute('action', action); + return container; + }, + domToMutation: function (xmlElement) { + var action = xmlElement.getAttribute('action'); + this.setAction_({"ACTION": action}); + }, + setAction_: function (details) { + var inputIs = this.getInput('USER'); + if (details['ACTION'] !== 'ALL') { + if (!inputIs) { + this.appendValueInput("USER") + .setCheck("Number") + .appendField("ID"); + } + } else { + if (inputIs) + this.removeInput('USER'); + } + } +}; + +Blockly.propc.fp_scanner_add = function () { + var act = this.getFieldValue('ACTION'); + var usr = '1'; + if (act !== "ALL") + usr = Blockly.propc.valueToCode(this, 'USER', Blockly.propc.NONE) || '1'; + + var code = ''; + + if (Blockly.propc.global_vars_["fpScannerObj"] === 'fpScanner *fpScan;') { + if (act === 'ADD') + code = 'fingerprint_add(fpScan, ' + usr + ', 3, 0);\n'; + if (act === 'DEL') + code = 'fingerprint_deleteUser(fpScan, ' + usr + ');\n'; + if (act === 'ALL') + code = 'fingerprint_deleteUser(fpScan, 0);\n'; + } else { + code = '// ERROR: Fingerprint Scanner is not initialized!\n'; + } + + return code; +}; + +Blockly.Blocks.fp_scanner_scan = { + helpUrl: Blockly.MSG_FPS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_FPS_SCAN_TOOLTIP); + this.setColour(colorPalette.getColor('input')); + this.appendDummyInput() + .appendField("Fingerprint Scanner") + .appendField(new Blockly.FieldDropdown([["scan and identify", "SCAN"], ["scan and compare", "COMP"], ["count number of IDs", "COUNT"]], function (action) { + this.sourceBlock_.setAction_({"ACTION": action}); + }), "ACTION"); + this.setInputsInline(true); + this.setOutput(true, 'Number'); + }, + mutationToDom: function () { + var container = document.createElement('mutation'); + var action = this.getFieldValue('ACTION'); + container.setAttribute('action', action); + return container; + }, + domToMutation: function (xmlElement) { + var action = xmlElement.getAttribute('action'); + this.setAction_({"ACTION": action}); + }, + setAction_: function (details) { + var inputIs = this.getInput('USER'); + if (details['ACTION'] === 'COMP') { + if (!inputIs) { + this.appendValueInput("USER") + .setCheck("Number") + .appendField("to ID"); + } + } else { + if (inputIs) + this.removeInput('USER'); + } + } +}; + +Blockly.propc.fp_scanner_scan = function () { + var act = this.getFieldValue('ACTION'); + var usr = '1'; + if (act === "COMP") + usr = Blockly.propc.valueToCode(this, 'USER', Blockly.propc.NONE) || '1'; + + var func = 'int fingerScanner(int __u) {'; + func += 'int r;\nfingerprint_scan(fpScan, __u, &r);\n'; + func += 'if (__u != 0 && r != 0) return 1;\n else return r;}'; + + var code = '0'; + + if (Blockly.propc.global_vars_["fpScannerObj"] === 'fpScanner *fpScan;') { + if (act === 'SCAN') { + Blockly.propc.global_vars_["fpScannerFunc"] = func; + code = 'fingerScanner(0)'; + } + if (act === 'COMP') { + Blockly.propc.global_vars_["fpScannerFunc"] = func; + code = 'fingerScanner(' + usr + ')'; + } + if (act === 'COUNT') + code = 'fingerprint_countUsers(fpScan)'; + } + //code = 'toast'; + return [code, Blockly.propc.ORDER_ATOMIC]; +}; + + // -------------Memsic Tilt/Accel (MX2125 Module) ------------------------------ Blockly.Blocks.MX2125_acceleration_xaxis = { helpUrl: Blockly.MSG_MEMSIC_HELPURL, - init: function() { + init: function () { this.setTooltip(Blockly.MSG_MX2125_ACCELERATION_XAXIS_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() @@ -358,7 +518,7 @@ Blockly.propc.MX2125_acceleration_xaxis = function () { Blockly.Blocks.MX2125_acceleration_yaxis = { helpUrl: Blockly.MSG_MEMSIC_HELPURL, - init: function() { + init: function () { this.setTooltip(Blockly.MSG_MX2125_ACCELERATION_YAXIS_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() @@ -382,7 +542,7 @@ Blockly.propc.MX2125_acceleration_yaxis = function () { Blockly.Blocks.MX2125_rotation = { helpUrl: Blockly.MSG_MEMSIC_HELPURL, - init: function() { + init: function () { this.setTooltip(Blockly.MSG_MX2125_ROTATION_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() @@ -410,8 +570,8 @@ Blockly.propc.MX2125_rotation = function () { Blockly.Blocks.MX2125_tilt_xaxis = { helpUrl: Blockly.MSG_MEMSIC_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MX2125_TILT_XAXIS_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MX2125_TILT_XAXIS_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("Memsic tilt x-axis PIN") @@ -434,8 +594,8 @@ Blockly.propc.MX2125_tilt_xaxis = function () { Blockly.Blocks.MX2125_tilt_yaxis = { helpUrl: Blockly.MSG_MEMSIC_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MX2125_TILT_YAXIS_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MX2125_TILT_YAXIS_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("Memsic tilt y-axis PIN") @@ -459,8 +619,8 @@ Blockly.propc.MX2125_tilt_yaxis = function () { // --------------Accelerometer (MMA7455 Module) Blocks-------------------------- Blockly.Blocks.MMA7455_init = { helpUrl: Blockly.MSG_ACCELEROMETER_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MMA7455_INIT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MMA7455_INIT_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("Accelerometer initialize CS") @@ -489,8 +649,8 @@ Blockly.propc.MMA7455_init = function () { Blockly.Blocks.MMA7455_acceleration = { helpUrl: Blockly.MSG_ACCELEROMETER_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_MMA7455_ACCELERATION_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_MMA7455_ACCELERATION_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("Accelerometer store x-axis in") @@ -530,8 +690,8 @@ Blockly.propc.MMA7455_acceleration = function () { //-----------------------Compass (HMC5883L Module) Blocks ---------------------- Blockly.Blocks.HMC5883L_init = { helpUrl: Blockly.MSG_COMPASS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_HMC5883L_INIT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_HMC5883L_INIT_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("Compass initialize SCL") @@ -558,8 +718,8 @@ Blockly.propc.HMC5883L_init = function () { Blockly.Blocks.HMC5883L_read = { helpUrl: Blockly.MSG_COMPASS_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_HMC5883L_READ_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_HMC5883L_READ_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("Compass heading store in") @@ -582,21 +742,21 @@ Blockly.Blocks.HMC5883L_read = { Blockly.propc.HMC5883L_read = function () { var storage = Blockly.propc.variableDB_.getName(this.getFieldValue('HEADING'), Blockly.Variables.NAME_TYPE); Blockly.propc.global_vars_["compass_vars"] = 'int __compX, __compY, __compZ;\nfloat __compH;\n'; - + var code = ''; code += 'compass_read(bus, &__compX, &__compY, &__compZ);\n'; code += '\t__compH = atan2(((float) __compY), (((float) __compX)) * 180.0/PI;\n'; code += '\tif(__compH < 0.0) __compH = (360.0 + __compH);\n'; code += '\t' + storage + ' = (int) __compH;\n'; - + return code; }; // ------------------ IMU (LSM9DS1 module) Blocks ------------------------------ Blockly.Blocks.lsm9ds1_init = { helpUrl: Blockly.MSG_IMU_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_LSM9DS1_INIT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_LSM9DS1_INIT_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("IMU initialize SCL") @@ -627,14 +787,32 @@ Blockly.propc.lsm9ds1_init = function () { return ''; }; +Blockly.Blocks.lsm9ds1_mag_calibrate = { + helpUrl: Blockly.MSG_IMU_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_LSM9DS1_INIT_TOOLTIP); + this.setColour(colorPalette.getColor('input')); + this.appendDummyInput() + .appendField("IMU calibrate magnetometer"); + + this.setInputsInline(true); + this.setNextStatement(true, null); + this.setPreviousStatement(true, null); + } +}; + +Blockly.propc.lsm9ds1_mag_calibrate = function () { + return 'high(26);high(27);imu_calibrateMag();low(26);low(27);'; +}; + Blockly.Blocks.lsm9ds1_read = { helpUrl: Blockly.MSG_IMU_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_LSM9DS1_READ_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_LSM9DS1_READ_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("IMU read") - .appendField(new Blockly.FieldDropdown([["accelerometer (g-100ths)", "Accel"], ["gyroscope (DPS-100ths)", "Gyro"], ["magnetometer (gauss-100ths)", "Mag"]]), "SENSOR") + .appendField(new Blockly.FieldDropdown([["accelerometer (100ths of g's)", "Accel"], ["gyroscope (100ths of deg/s)", "Gyro"], ["magnetometer (100ths of gauss)", "Mag"]]), "SENSOR") .appendField("store X-axis in") .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'X_VAR') .appendField(" y-axis in") @@ -666,7 +844,7 @@ Blockly.propc.lsm9ds1_read = function () { var zstorage = Blockly.propc.variableDB_.getName(this.getFieldValue('Z_VAR'), Blockly.Variables.NAME_TYPE); var code = ''; - if(Blockly.propc.definitions_["include_lsm9ds1"] === '#include "lsm9ds1.h"') { + if (Blockly.propc.definitions_["include_lsm9ds1"] === '#include "lsm9ds1.h"') { code += 'imu_read' + sensor + 'Calculated(&__imuX, &__imuY, &__imuZ);\n'; code += xstorage + ' = (int) (100.0 * __imuX);\n'; code += ystorage + ' = (int) (100.0 * __imuY);\n'; @@ -674,67 +852,181 @@ Blockly.propc.lsm9ds1_read = function () { } else { code += "// LSM9DS1 IMU is not initialized!\n"; } - + return code; }; Blockly.Blocks.lsm9ds1_tilt = { helpUrl: Blockly.MSG_IMU_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_LSM9DS1_TILT_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_LSM9DS1_TILT_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("IMU tilt along ") - .appendField(new Blockly.FieldDropdown([["x-axis", "__imuX"], ["y-axis", "__imuY"], ["z-axis", "__imuZ"]]), "T_AXIS") - .appendField("gravity pulls along ") - .appendField(new Blockly.FieldDropdown([["z-axis", "__imuZ"], ["x-axis", "__imuX"], ["y-axis", "__imuY"]]), "G_AXIS") - .appendField("store in") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR'); - this.setInputsInline(false); + .appendField("IMU tilt") + .appendField(new Blockly.FieldDropdown([["x-axis", "X"], ["y-axis", "Y"], ["z-axis", "Z"]], function (action) { + this.sourceBlock_.setAxes_({"ACTION": action}); + }), "G_AXIS") + .appendField("points up/down"); + this.appendDummyInput('TILT1') + .appendField("store y-tilt in", 'A1') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR1'); + this.appendDummyInput('TILT2') + .appendField("z-tilt in", 'A2') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR2'); + this.setInputsInline(true); this.setNextStatement(true, null); this.setPreviousStatement(true, null); }, + mutationToDom: function () { + var container = document.createElement('mutation'); + var action = this.getFieldValue('G_AXIS'); + container.setAttribute('action', action); + return container; + }, + domToMutation: function (xmlElement) { + var action = xmlElement.getAttribute('action'); + this.setAxes_({"ACTION": action}); + }, + setAxes_: function (details) { + var theVar1 = this.getFieldValue('VAR1'); + var theVar2 = this.getFieldValue('VAR2'); + this.removeInput('TILT1'); + this.removeInput('TILT2'); + if (details['ACTION'] === 'X') { + this.appendDummyInput('TILT1') + .appendField("store y-tilt in", 'A1') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR1'); + this.appendDummyInput('TILT2') + .appendField("z-tilt in", 'A2') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR2'); + } else if (details['ACTION'] === 'Y') { + this.appendDummyInput('TILT1') + .appendField("store x-tilt in", 'A1') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR1'); + this.appendDummyInput('TILT2') + .appendField("z-tilt in", 'A2') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR2'); + } else { + this.appendDummyInput('TILT1') + .appendField("store x-tilt in", 'A1') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR1'); + this.appendDummyInput('TILT2') + .appendField("y-tilt in", 'A2') + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR2'); + } + this.setFieldValue(theVar1, 'VAR1'); + this.setFieldValue(theVar2, 'VAR2'); + }, getVars: function () { - return [this.getFieldValue('VAR')]; + return [this.getFieldValue('VAR1'), this.getFieldValue('VAR2')]; }, renameVar: function (oldName, newName) { - if (Blockly.Names.equals(oldName, this.getFieldValue('VAR'))) { - this.setTitleValue(newName, 'VAR'); - } + if (Blockly.Names.equals(oldName, this.getFieldValue('VAR1'))) + this.setTitleValue(newName, 'VAR1'); + if (Blockly.Names.equals(oldName, this.getFieldValue('VAR2'))) + this.setTitleValue(newName, 'VAR2'); } }; Blockly.propc.lsm9ds1_tilt = function () { - var t_axis = this.getFieldValue('T_AXIS'); - var g_axis = this.getFieldValue('G_AXIS'); - var storage = Blockly.propc.variableDB_.getName(this.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE); + var t1_axis = '__imu' + this.getFieldValue('A1')[0].toUpperCase(); + var t2_axis = '__imu' + this.getFieldValue('A2')[0].toUpperCase(); + var g_axis = '__imu' + this.getFieldValue('G_AXIS'); + var storage1 = Blockly.propc.variableDB_.getName(this.getFieldValue('VAR1'), Blockly.Variables.NAME_TYPE); + var storage2 = Blockly.propc.variableDB_.getName(this.getFieldValue('VAR2'), Blockly.Variables.NAME_TYPE); var code = ''; - if(Blockly.propc.definitions_["include_lsm9ds1"] === '#include "lsm9ds1.h"') { + if (Blockly.propc.definitions_["include_lsm9ds1"] === '#include "lsm9ds1.h"') { code += 'imu_readAccelCalculated(&__imuX, &__imuY, &__imuZ);\n'; - code += storage + ' = (int) (atan2(' + t_axis + ', ' + g_axis + ') * 180.0/PI);\n'; + code += storage1 + ' = (int) (atan2(' + t1_axis + ', ' + g_axis + ') * 180.0/PI);\n'; + code += storage2 + ' = (int) (atan2(' + t2_axis + ', ' + g_axis + ') * 180.0/PI);\n'; } else { code += "// LSM9DS1 IMU is not initialized!\n"; } - + return code; }; Blockly.Blocks.lsm9ds1_heading = { helpUrl: Blockly.MSG_IMU_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_LSM9DS1_HEADING_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_LSM9DS1_HEADING_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() .appendField("IMU heading") - .appendField(new Blockly.FieldDropdown([["Z-axis points forward", "__imuZ"], ["Z-axis points backward", "(-1.0*__imuZ)"], ["Y-axis points forward", "__imuY"], ["Y axis points backward", "(-1.0*__imuY)"], ["X-axis points forward", "(-1.0*__imuX)"], ["X-axis points backward", "__imuX"]]), "FB_AXIS") - .appendField(new Blockly.FieldDropdown([["Y-axis points left", "__imuY"], ["Y-axis points right", "(-1.0*__imuY)"], ["X-axis points left", "(-1.0*__imuX)"], ["X-axis points right", "__imuX"], ["Z-axis points left", "__imuZ"], ["Z-axis points right", "(-1.0*__imuZ)"]]), "LR_AXIS") + .appendField(new Blockly.FieldDropdown([ + ["z-axis points forward", "__imuZ"], + ["z-axis points backward", "(-1.0*__imuZ)"], + ["y-axis points forward", "__imuY"], + ["y axis points backward", "(-1.0*__imuY)"], + ["x-axis points forward", "(-1.0*__imuX)"], + ["x-axis points backward", "__imuX"]], + function (action) { + this.sourceBlock_.setAxes_({"ACTION": action}); + }), "FB_AXIS") + .appendField(' '); + this.appendDummyInput('MENU2') + .appendField(new Blockly.FieldDropdown([ + ["y-axis points left", "__imuY"], + ["y-axis points right", "(-1.0*__imuY)"], + ["x-axis points left", "(-1.0*__imuX)"], + ["x-axis points right", "__imuX"] + ]), "LR_AXIS") .appendField("store in") .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR'); - this.setInputsInline(false); + this.setInputsInline(true); this.setNextStatement(true, null); this.setPreviousStatement(true, null); }, + mutationToDom: function () { + var container = document.createElement('mutation'); + var action = this.getFieldValue('FB_AXIS'); + container.setAttribute('action', action); + return container; + }, + domToMutation: function (xmlElement) { + var action = xmlElement.getAttribute('action'); + this.setAxes_({"ACTION": action}); + }, + setAxes_: function (details) { + var theVar = this.getFieldValue('VAR'); + this.removeInput('MENU2'); + var wh = details['ACTION'][details['ACTION'].length - 1]; + if (wh === ')') + wh = details['ACTION'][details['ACTION'].length - 2]; + if (wh === 'X') { + this.appendDummyInput('MENU2') + .appendField(new Blockly.FieldDropdown([ + ["y-axis points left", "__imuY"], + ["y-axis points right", "(-1.0*__imuY)"], + ["z-axis points left", "__imuZ"], + ["z-axis points right", "(-1.0*__imuZ)"] + ]), "LR_AXIS") + .appendField("store in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR'); + } else if (wh === 'Y') { + this.appendDummyInput('MENU2') + .appendField(new Blockly.FieldDropdown([ + ["x-axis points left", "(-1.0*__imuX)"], + ["x-axis points right", "__imuX"], + ["z-axis points left", "__imuZ"], + ["z-axis points right", "(-1.0*__imuZ)"] + ]), "LR_AXIS") + .appendField("store in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR'); + } else { + this.appendDummyInput('MENU2') + .appendField(new Blockly.FieldDropdown([ + ["y-axis points left", "__imuY"], + ["y-axis points right", "(-1.0*__imuY)"], + ["x-axis points left", "(-1.0*__imuX)"], + ["x-axis points right", "__imuX"] + ]), "LR_AXIS") + .appendField("store in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'VAR'); + } + this.setFieldValue(theVar, 'VAR'); + }, getVars: function () { return [this.getFieldValue('VAR')]; }, @@ -751,15 +1043,15 @@ Blockly.propc.lsm9ds1_heading = function () { var storage = Blockly.propc.variableDB_.getName(this.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE); var code = ''; - if(Blockly.propc.definitions_["include_lsm9ds1"] === '#include "lsm9ds1.h"') { + if (Blockly.propc.definitions_["include_lsm9ds1"] === '#include "lsm9ds1.h"') { code += 'imu_readMagCalculated(&__imuX, &__imuY, &__imuZ);\n'; code += '__compI = atan2(' + lr_axis + ', ' + fb_axis + ') * 180.0/PI;\n'; code += 'if(__compI < 0.0) __compI = (360.0 + __compI);\n'; - code += storage + ' = (int) __compI;\n'; + code += storage + ' = (int) __compI;\n'; } else { code += "// LSM9DS1 IMU is not initialized!\n"; } - + return code; }; @@ -768,23 +1060,23 @@ Blockly.Blocks.PAM_7Q_Init = { init: function () { this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("PAM7Q GPS Module"); + .appendField("PAM7Q GPS Module"); this.appendDummyInput() - .appendField("RX pin#") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "RXPIN"); + .appendField("RX pin#") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "RXPIN"); this.appendDummyInput() - .appendField("TX pin#") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "TXPIN"); + .appendField("TX pin#") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "TXPIN"); this.appendDummyInput() - .appendField("baud") - .appendField(new Blockly.FieldDropdown([["2400", "2400"], ["9600", "9600"], ["19200", "19200"]]), "BAUD"); + .appendField("baud") + .appendField(new Blockly.FieldDropdown([["2400", "2400"], ["9600", "9600"], ["19200", "19200"]]), "BAUD"); this.setNextStatement(true, null); this.setPreviousStatement(true, null); } }; -Blockly.propc.PAM_7Q_Init = function() { +Blockly.propc.PAM_7Q_Init = function () { var rx_pin = this.getFieldValue('RXPIN'); var tx_pin = this.getFieldValue('TXPIN'); var baud = this.getFieldValue('BAUD'); @@ -799,7 +1091,7 @@ Blockly.Blocks.PAM_7Q_Latitude = { init: function () { this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("get latitude"); + .appendField("get latitude"); this.setOutput(true, 'Number'); this.setPreviousStatement(false, null); @@ -807,7 +1099,7 @@ Blockly.Blocks.PAM_7Q_Latitude = { } }; -Blockly.propc.PAM_7Q_Latitude = function() { +Blockly.propc.PAM_7Q_Latitude = function () { Blockly.propc.definitions_["include PAM7Q"] = '#include "gps.h"'; var code = 'gps_latitude()'; @@ -818,7 +1110,7 @@ Blockly.Blocks.PAM_7Q_Longitude = { init: function () { this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("get longitude"); + .appendField("get longitude"); this.setOutput(true, 'Number'); this.setPreviousStatement(false, null); @@ -826,7 +1118,7 @@ Blockly.Blocks.PAM_7Q_Longitude = { } }; -Blockly.propc.PAM_7Q_Longitude = function() { +Blockly.propc.PAM_7Q_Longitude = function () { Blockly.propc.definitions_["include PAM7Q"] = '#include "gps.h"'; var code = 'gps_longitude()'; @@ -837,7 +1129,7 @@ Blockly.Blocks.PAM_7Q_Heading = { init: function () { this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("get heading"); + .appendField("get heading"); this.setOutput(true, 'Number'); this.setPreviousStatement(false, null); @@ -845,7 +1137,7 @@ Blockly.Blocks.PAM_7Q_Heading = { } }; -Blockly.propc.PAM_7Q_Heading = function() { +Blockly.propc.PAM_7Q_Heading = function () { Blockly.propc.definitions_["include PAM7Q"] = '#include "gps.h"'; var code = '(int)gps_heading()'; @@ -856,7 +1148,7 @@ Blockly.Blocks.PAM_7Q_Altitude = { init: function () { this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("get altitude"); + .appendField("get altitude"); this.setOutput(true, 'Number'); this.setPreviousStatement(false, null); @@ -864,7 +1156,7 @@ Blockly.Blocks.PAM_7Q_Altitude = { } }; -Blockly.propc.PAM_7Q_Altitude = function() { +Blockly.propc.PAM_7Q_Altitude = function () { Blockly.propc.definitions_["include PAM7Q"] = '#include "gps.h"'; var code = 'gps_altitude()'; @@ -875,7 +1167,7 @@ Blockly.Blocks.PAM_7Q_SatsTracked = { init: function () { this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("get # of satellites tracked"); + .appendField("get # of satellites tracked"); this.setOutput(true, 'Number'); this.setPreviousStatement(false, null); @@ -883,7 +1175,7 @@ Blockly.Blocks.PAM_7Q_SatsTracked = { } }; -Blockly.propc.PAM_7Q_SatsTracked = function() { +Blockly.propc.PAM_7Q_SatsTracked = function () { Blockly.propc.definitions_["include PAM7Q"] = '#include "gps.h"'; var code = 'gps_satsTracked()'; @@ -894,8 +1186,8 @@ Blockly.Blocks.PAM_7Q_Velocity = { init: function () { this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("get velocity in units") - .appendField(new Blockly.FieldDropdown([["mph", "MPH"], ["knots", "KNOTS"]]), "VELOCITYUNITS"); + .appendField("get velocity in units") + .appendField(new Blockly.FieldDropdown([["mph", "MPH"], ["knots", "KNOTS"]]), "VELOCITYUNITS"); this.setOutput(true, 'Number'); this.setNextStatement(false, null); @@ -903,7 +1195,7 @@ Blockly.Blocks.PAM_7Q_Velocity = { } }; -Blockly.propc.PAM_7Q_Velocity = function() { +Blockly.propc.PAM_7Q_Velocity = function () { var velocity_units = this.getFieldValue('VELOCITYUNITS'); Blockly.propc.definitions_["include PAM7Q"] = '#include "gps.h"'; @@ -915,12 +1207,12 @@ Blockly.propc.PAM_7Q_Velocity = function() { // ------------------ RFID Reader Blocks --------------------------------------- Blockly.Blocks.rfid_get = { helpUrl: Blockly.MSG_RFID_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_RFID_GET_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_RFID_GET_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("RFID store reading in") - .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'BUFFER'); + .appendField("RFID store reading in") + .appendField(new Blockly.FieldVariable(Blockly.LANG_VARIABLES_GET_ITEM), 'BUFFER'); this.setPreviousStatement(true, null); this.setNextStatement(true, null); @@ -935,7 +1227,7 @@ Blockly.Blocks.rfid_get = { } }; -Blockly.propc.rfid_get = function() { +Blockly.propc.rfid_get = function () { var saveVariable = Blockly.propc.variableDB_.getName(this.getFieldValue('BUFFER'), Blockly.Variables.NAME_TYPE); Blockly.propc.global_vars_["rfid_buffer"] = "char *rfidBfr;"; @@ -947,43 +1239,43 @@ Blockly.propc.rfid_get = function() { Blockly.Blocks.rfid_disable = { helpUrl: Blockly.MSG_RFID_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_RFID_DISABLE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_RFID_DISABLE_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("RFID") - .appendField(new Blockly.FieldDropdown([ - ["disable", "DISABLE"], - ["enable", "ENABLE"] - ]), "ACTION"); + .appendField("RFID") + .appendField(new Blockly.FieldDropdown([ + ["disable", "DISABLE"], + ["enable", "ENABLE"] + ]), "ACTION"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.rfid_disable = function() { +Blockly.propc.rfid_disable = function () { var data = this.getFieldValue('ACTION'); Blockly.propc.definitions_["rfidser"] = '#include "rfidser.h"'; - if(data === "ENABLE") { + if (data === "ENABLE") { return 'rfid_enable(rfid);'; } else { - return 'rfid_disable(rfid);'; + return 'rfid_disable(rfid);'; } }; Blockly.Blocks.rfid_enable = { helpUrl: Blockly.MSG_RFID_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_RFID_ENABLE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_RFID_ENABLE_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("RFID initialize EN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN_IN"); + .appendField("RFID initialize EN") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN_IN"); this.appendDummyInput() - .appendField("SOUT") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN_OUT"); + .appendField("SOUT") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN_OUT"); this.setInputsInline(true); this.setPreviousStatement(true, null); @@ -991,7 +1283,7 @@ Blockly.Blocks.rfid_enable = { } }; -Blockly.propc.rfid_enable = function() { +Blockly.propc.rfid_enable = function () { var pin_in = this.getFieldValue('PIN_IN'); var pin_out = this.getFieldValue('PIN_OUT'); @@ -1004,18 +1296,18 @@ Blockly.propc.rfid_enable = function() { Blockly.Blocks.rfid_close = { helpUrl: Blockly.MSG_RFID_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_RFID_CLOSE_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_RFID_CLOSE_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("RFID close"); + .appendField("RFID close"); this.setPreviousStatement(true, null); this.setNextStatement(true, null); } }; -Blockly.propc.rfid_close = function() { +Blockly.propc.rfid_close = function () { Blockly.propc.definitions_["rfidser"] = '#include "rfidser.h"'; return 'rfidser_close(rfid);\n'; @@ -1024,12 +1316,12 @@ Blockly.propc.rfid_close = function() { // ------------------ Sony TV Remote (Using 40 kHz IR sensor) Blocks ----------- Blockly.Blocks.sirc_get = { helpUrl: Blockly.MSG_SONY_REMOTE_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_SIRC_GET_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_SIRC_GET_TOOLTIP); this.setColour(colorPalette.getColor('input')); this.appendDummyInput() - .appendField("Sony Remote value received from PIN") - .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); + .appendField("Sony Remote value received from PIN") + .appendField(new Blockly.FieldDropdown(profile.default.digital), "PIN"); this.setInputsInline(true); this.setPreviousStatement(false, null); @@ -1038,7 +1330,7 @@ Blockly.Blocks.sirc_get = { } }; -Blockly.propc.sirc_get = function() { +Blockly.propc.sirc_get = function () { var pin = this.getFieldValue('PIN'); Blockly.propc.definitions_["sirc"] = '#include "sirc.h"'; diff --git a/src/main/webapp/cdn/blockly/generators/propc/variables.js b/src/main/webapp/cdn/blockly/generators/propc/variables.js index 4ca5df03..8bd54626 100644 --- a/src/main/webapp/cdn/blockly/generators/propc/variables.js +++ b/src/main/webapp/cdn/blockly/generators/propc/variables.js @@ -30,12 +30,13 @@ if (!Blockly.Blocks) Blockly.Blocks = {}; +var tempArrayNumber = 0; Blockly.Blocks.variables_get = { // Variable getter. helpUrl: Blockly.MSG_VARIABLES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_VARIABLES_GET_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_VARIABLES_GET_TOOLTIP); this.setColour(colorPalette.getColor('variables')); this.appendDummyInput("") .appendField(Blockly.LANG_VARIABLES_GET_TITLE_1) @@ -82,8 +83,8 @@ Blockly.Blocks.variables_declare = { Blockly.Blocks.variables_set = { // Variable setter. helpUrl: Blockly.MSG_VARIABLES_HELPURL, - init: function() { - this.setTooltip(Blockly.MSG_VARIABLES_SET_TOOLTIP); + init: function () { + this.setTooltip(Blockly.MSG_VARIABLES_SET_TOOLTIP); this.setColour(colorPalette.getColor('variables')); this.appendValueInput('VALUE') .appendField(Blockly.LANG_VARIABLES_SET_TITLE_1) @@ -136,38 +137,242 @@ Blockly.propc.variables_set = function () { var varName = Blockly.propc.variableDB_.getName(this.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE); if (Blockly.propc.vartype_[varName] === undefined) { - if (argument0.indexOf("int") > -1) { - Blockly.propc.vartype_[varName] = 'int'; - Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; - } else if (argument0.indexOf("float") > -1) { - Blockly.propc.vartype_[varName] = 'float'; - Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; - } else if (argument0.indexOf("char") > -1) { - Blockly.propc.vartype_[varName] = 'char'; - Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; - } else if (argument0.indexOf("char\[\]") > -1) { - Blockly.propc.vartype_[varName] = 'char *'; - } else if (argument0.indexOf("\"") > -1) { - Blockly.propc.vartype_[varName] = 'char *'; - } else if (argument0.indexOf(".") > -1) { - Blockly.propc.vartype_[varName] = 'float'; - } else if (argument0.indexOf("true") > -1 || argument0.indexOf("false") > -1) { - Blockly.propc.vartype_[varName] = 'boolean'; - } else { - Blockly.propc.vartype_[varName] = 'int'; - } + if (argument0.indexOf("int") > -1) { + Blockly.propc.vartype_[varName] = 'int'; + //Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; + } else if (argument0.indexOf("float") > -1) { + Blockly.propc.vartype_[varName] = 'float'; + Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; + } else if (argument0.indexOf("char") > -1) { + Blockly.propc.vartype_[varName] = 'char'; + Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; + } else if (argument0.indexOf("char\[\]") > -1) { + Blockly.propc.vartype_[varName] = 'char *'; + } else if (argument0.indexOf("\"") > -1) { + Blockly.propc.vartype_[varName] = 'char *'; + } else if (argument0.indexOf(".") > -1) { + Blockly.propc.vartype_[varName] = 'float'; + } else if (argument0.indexOf("true") > -1 || argument0.indexOf("false") > -1) { + Blockly.propc.vartype_[varName] = 'boolean'; + } else { + Blockly.propc.vartype_[varName] = 'int'; + } } else if (argument0.indexOf("int") > -1) { - Blockly.propc.vartype_[varName] = 'int'; - Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; + Blockly.propc.vartype_[varName] = 'int'; + //Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; } else if (argument0.indexOf("float") > -1) { - Blockly.propc.vartype_[varName] = 'float'; - Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; + Blockly.propc.vartype_[varName] = 'float'; + Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; } else if (argument0.indexOf("char") > -1) { - Blockly.propc.vartype_[varName] = 'char'; - Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; + Blockly.propc.vartype_[varName] = 'char'; + Blockly.propc.varlength_[varName] = '{{$var_length_' + varName + '}};'; } else if (argument0.indexOf("char\[\]") > -1) { - Blockly.propc.vartype_[varName] = 'char *'; + Blockly.propc.vartype_[varName] = 'char *'; } return varName + ' = ' + argument0 + ';\n'; }; + + + + +Blockly.Blocks.array_get = { + helpUrl: Blockly.MSG_ARRAYS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_ARRAY_GET_TOOLTIP); + this.setColour(colorPalette.getColor('variables')); + this.appendValueInput('NUM') + .appendField('array') + .appendField(new Blockly.FieldTextInput('list'), 'VAR') + .appendField('element'); + this.setInputsInline(true); + this.setOutput(true, null); + } +}; + +Blockly.propc.array_get = function () { + var varName = this.getFieldValue('VAR'); + varName = varName.replace(" ", "_"); + varName = varName.replace(/\W/g, ""); + var element = Blockly.propc.valueToCode(this, 'NUM', Blockly.propc.ORDER_NONE) || '0'; + var list = Blockly.propc.global_vars_; + + var code = varName + '[' + element + ']'; + + if (Object.keys(list).indexOf('__ARRAY' + varName) < 0) { + return '// ERROR: The array "' + varName + '" has not been initialized!\n'; + } else { + return [code, Blockly.propc.ORDER_ATOMIC]; + } +}; + +Blockly.Blocks.array_init = { + helpUrl: Blockly.MSG_ARRAYS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_ARRAY_INIT_TOOLTIP); + this.setColour(colorPalette.getColor('variables')); + this.appendDummyInput() + .appendField('array initialize') + .appendField(new Blockly.FieldTextInput('list'), 'VAR') + .appendField("with") + .appendField(new Blockly.FieldTextInput('10', + Blockly.FieldTextInput.numberValidator), 'NUM') + .appendField("elements"); + + this.setPreviousStatement(true); + this.setNextStatement(true); + } +}; + +Blockly.propc.array_init = function () { + var varName = this.getFieldValue('VAR'); + varName = varName.replace(" ", "_"); + varName = varName.replace(/\W/g, ""); + var element = this.getFieldValue('NUM') || '10'; + + Blockly.propc.global_vars_['__ARRAY' + varName] = 'int ' + varName + '[' + element + '];'; + + return ''; +}; + +Blockly.Blocks.array_fill = { + helpUrl: Blockly.MSG_ARRAYS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_ARRAY_FILL_TOOLTIP); + this.setColour(colorPalette.getColor('variables')); + this.appendDummyInput() + .appendField('array fill') + .appendField(new Blockly.FieldTextInput('list'), 'VAR') + .appendField("with values") + .appendField(new Blockly.FieldTextInput('10,20,30,40,50'), 'NUM'); + this.setPreviousStatement(true); + this.setNextStatement(true); + } +}; + +Blockly.propc.array_fill = function () { + var varName = this.getFieldValue('VAR'); + varName = varName.replace(" ", "_"); + varName = varName.replace(/\W/g, ""); + var varVals = this.getFieldValue('NUM'); + + varVals = varVals.replace(/[^0-9,-\.]/g, ""); + varVals = varVals.replace(/,\./g, ",0."); + varVals = varVals.replace(/\b\.[0-9-]+,\b/g, ","); + varVals = varVals.replace(/\.[0-9],/g, ","); + varVals = varVals.replace(/,,/g, ",0,"); + varVals = varVals.replace(/,\s*$/, ""); + varVals = varVals.split(".")[0]; + var noCommas = varVals.replace(/,/g, ""); + + var elements = varVals.length - noCommas.length + 1; + var elemCount = 0; + + var initStr = Blockly.propc.global_vars_['__ARRAY' + varName]; + + /* DONT DELETE - MAY WANT TO USE THIS CODE ELSEWHERE + + // Find all Array-type variables, and find the largest one. + var ArrayList = Object.keys(Blockly.propc.global_vars_); + var ArrayMaxSize = 1; + for (var k = 0; k < ArrayList.length; k++) { + if (ArrayList[k].indexOf('__ARRAY') >= 0) { + var t = Blockly.propc.global_vars_[ArrayList[k]]; + t = t.replace(/[^0-9]/g, ""); + var z = parseInt(t, 10); + if (z > ArrayMaxSize) + ArrayMaxSize = z; + } + } + + Blockly.propc.global_vars_['__TEMP_ARR'] = 'int __tmpArr[' + ArrayMaxSize.toString() + '];'; + + */ + + var code = ''; + + if (initStr) { + initStr = initStr.replace(/[^0-9]/g, ""); + elemCount = parseInt(initStr, 10); + + if (elements > elemCount) { + code += '// WARNING: You are trying to add more elements to your\n'; + code += '// array than you initialized your array with!\n'; + elements = elemCount; + } + code += 'int __tmpArr' + tempArrayNumber.toString() + '[] = {' + varVals + '};\n'; + code += 'memcpy(' + varName + ', __tmpArr' + tempArrayNumber.toString() + ', ' + elements + ' * sizeof(int));\n'; + tempArrayNumber++; + } else { + code += '// ERROR: The array "' + varName + '" has not been initialized!\n'; + } + + return code; +}; + +Blockly.Blocks.array_set = { + helpUrl: Blockly.MSG_ARRAYS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_ARRAY_SET_TOOLTIP); + this.setColour(colorPalette.getColor('variables')); + this.appendValueInput('NUM') + .appendField('array') + .appendField(new Blockly.FieldTextInput('list'), 'VAR') + .appendField('element'); + this.appendValueInput('VALUE') + .appendField('='); + this.setInputsInline(true); + this.setPreviousStatement(true); + this.setNextStatement(true); + } +}; + +Blockly.propc.array_set = function () { + var varName = this.getFieldValue('VAR'); + varName = varName.replace(" ", "_"); + varName = varName.replace(/\W/g, ""); + var element = Blockly.propc.valueToCode(this, 'NUM', Blockly.propc.ORDER_NONE) || '0'; + var value = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_NONE) || '0'; + var list = Blockly.propc.global_vars_; + var elemCount = '0'; + + var initStr = Blockly.propc.global_vars_['__ARRAY' + varName]; + + + if (initStr) { + initStr = initStr.replace(/[^0-9]/g, ""); + elemCount = parseInt(initStr, 10).toString(); + } + + if (Object.keys(list).indexOf('__ARRAY' + varName) < 0) { + return '// ERROR: The array "' + varName + '" has not been initialized!\n'; + } else { + return 'if(' + element + ' < ' + elemCount + ' && ' + element + ' >= 0) ' + varName + '[' + element + '] = ' + value + ';\n'; + } +}; + +Blockly.Blocks.array_clear = { + helpUrl: Blockly.MSG_ARRAYS_HELPURL, + init: function () { + this.setTooltip(Blockly.MSG_ARRAY_CLEAR_TOOLTIP); + this.setColour(colorPalette.getColor('variables')); + this.appendDummyInput() + .appendField('array clear') + .appendField(new Blockly.FieldTextInput('list'), 'VAR'); + this.setPreviousStatement(true); + this.setNextStatement(true); + } +}; + +Blockly.propc.array_clear = function () { + var varName = this.getFieldValue('VAR'); + varName = varName.replace(" ", "_"); + varName = varName.replace(/\W/g, ""); + var list = Blockly.propc.global_vars_; + + if (Object.keys(list).indexOf('__ARRAY' + varName) < 0) { + return '// ERROR: The array "' + varName + '" has not been initialized!\n'; + } else { + return 'memset(' + varName + ', 0, sizeof ' + varName + ');\n'; + } +}; \ No newline at end of file diff --git a/src/main/webapp/cdn/blockly/generators/spin/scribbler.js b/src/main/webapp/cdn/blockly/generators/spin/scribbler.js index bf148649..1996d8b7 100644 --- a/src/main/webapp/cdn/blockly/generators/spin/scribbler.js +++ b/src/main/webapp/cdn/blockly/generators/spin/scribbler.js @@ -269,7 +269,7 @@ Blockly.Blocks.scribbler_play = { init: function () { this.appendDummyInput() .appendField("play a") - .appendField(new Blockly.FieldDropdown([['double high', '1'], ['soprano', '2'], ['tenor', '3'], ['middle', '4'], ['low', '5'], ['deep', '6'], ['pedal', '7']]), 'NOTE_OCTAVE') + .appendField(new Blockly.FieldDropdown([['soprano', '2'], ['tenor', '3'], ['middle', '4'], ['low', '5'], ['deep', '6']]), 'NOTE_OCTAVE') //.appendField(new Blockly.FieldDropdown([['double high', '1'], ['soprano', '2'], ['tenor', '3'], ['middle', '4'], ['low', '5'], ['deep', '6'], ['pedal', '7']]), 'NOTE_OCTAVE') .appendField(new Blockly.FieldDropdown([['A\u266D', '3322'], ['A', '3520'], ['A\u266F/B\u266D', '3729'], ['B', '3951'], ['C', '4186'], ['C\u266F/D\u266D', '4435'], ['D', '4699'], ['D\u266F/E\u266D', '4978'], ['E', '5274'], ['F', '5588'], ['F\u266F/G\u266D', '5920'], ['G', '6272'], ['G\u266F', '6645']]), 'NOTE_FREQUENCY') .appendField("for a") @@ -389,10 +389,10 @@ Blockly.Blocks.play_polyphony = { init: function () { this.appendValueInput("FREQUENCY_1") .setCheck("Number") - .appendField("play a tone of (1 to 10,000) Hz"); + .appendField("play a tone of (1 to 2,000) Hz"); this.appendValueInput("FREQUENCY_2") .setCheck("Number") - .appendField("and a tone of (1 to 10,000) Hz"); + .appendField("and a tone of (1 to 2,000) Hz"); this.appendValueInput("POLYPHONY_DURATION") .setCheck("Number") .appendField("for a duration of (1 to 8,000) ms"); diff --git a/src/main/webapp/cdn/blockly/language/en/_messages.js b/src/main/webapp/cdn/blockly/language/en/_messages.js index d40d41f0..c574adad 100644 --- a/src/main/webapp/cdn/blockly/language/en/_messages.js +++ b/src/main/webapp/cdn/blockly/language/en/_messages.js @@ -199,6 +199,7 @@ Blockly.Msg.PROCEDURES_DEFRETURN_COMMENT = Blockly.Msg.PROCEDURES_DEFNORETURN_CO Blockly.MSG_CONTROL_HELPURL = "http://learn.parallax.com/ab-blocks/control"; Blockly.MSG_NUMBERS_HELPURL = "http://learn.parallax.com/ab-blocks/numbers"; Blockly.MSG_STRINGS_HELPURL = "http://learn.parallax.com/ab-blocks/strings"; +Blockly.MSG_ARRAYS_HELPURL = "http://learn.parallax.com/ab-blocks/arrays"; Blockly.MSG_VALUES_HELPURL = "http://learn.parallax.com/ab-blocks/values"; Blockly.MSG_VARIABLES_HELPURL = "http://learn.parallax.com/ab-blocks/variables"; Blockly.MSG_FUNCTIONS_HELPURL = "http://learn.parallax.com/ab-blocks/functions"; @@ -207,7 +208,10 @@ Blockly.MSG_SERIAL_LCD_HELPURL = "http://learn.parallax.com/ab-blocks/serial-lcd Blockly.MSG_OLED_HELPURL = "http://learn.parallax.com/ab-blocks/oled"; Blockly.MSG_TERMINAL_HELPURL = "http://learn.parallax.com/ab-blocks/terminal"; Blockly.MSG_PROTOCOLS_HELPURL = "http://learn.parallax.com/ab-blocks/protocols"; +Blockly.MSG_SWX_HELPURL = "http://learn.parallax.com/ab-blocks/simple-wx"; +Blockly.MSG_AWX_HELPURL = "http://learn.parallax.com/ab-blocks/advanced-wx"; Blockly.MSG_XBEE_HELPURL = "http://learn.parallax.com/ab-blocks/xbee"; +Blockly.MSG_FPS_HELPURL = "http://learn.parallax.com/ab-blocks/fingerprint"; Blockly.MSG_COMPASS_HELPURL = "http://learn.parallax.com/ab-blocks/compass"; Blockly.MSG_JOYSTICK_HELPURL = "http://learn.parallax.com/ab-blocks/joystick"; Blockly.MSG_MEMSIC_HELPURL = "http://learn.parallax.com/ab-blocks/memsic"; @@ -233,9 +237,15 @@ Blockly.MSG_WS2812B_HELPURL = "http://learn.parallax.com/ab-blocks/ws2812b"; //----------Activity Board (Propeller C) block tooltips ---------------------------- Blockly.MSG_COMMENT_TOOLTIP = "add comment: Leave a note for people that will not affect the program."; Blockly.MSG_CONTROLS_IF_TOOLTIP = "If...do: when condition attached is true. Click the gear to add conditions."; +Blockly.MSG_CONTROLS_SELECT_TOOLTIP = "switch...case: does statements when case condition is true. Click the gear to add conditions."; Blockly.MSG_CONTROLS_REPEAT_TOOLTIP = "conditional repeat: forever, x times , until, or while attached condition is true."; Blockly.MSG_CONTROL_REPEAT_FOR_LOOP_TOOLTIP = "repeat item: use variable and value blocks for counted loop."; Blockly.MSG_CONTROLS_BREAK_TOOLTIP = "break: Exit loop and skip to the next block."; +Blockly.MSG_ARRAY_GET_TOOLTIP = "array get element: gets a the value of the specified element in the array."; +Blockly.MSG_ARRAY_INIT_TOOLTIP = "array initialize: sets up the array with the specified number of elements."; +Blockly.MSG_ARRAY_FILL_TOOLTIP = "array fill: fills the array with the specified values. Must be a comma seperated list of integers."; +Blockly.MSG_ARRAY_SET_TOOLTIP = "array set element: sets the value of the specified element in the array."; +Blockly.MSG_ARRAY_CLEAR_TOOLTIP = "array clear: sets all of the elements of the array to 0 (zero)."; Blockly.MSG_BASE_DELAY_TOOLTIP = "pause: wait for specified time (in milliseconds) then continue."; Blockly.MSG_COG_NEW_TOOLTIP = "new processor: launch attached “run function” block if processor is available."; Blockly.MSG_CONTROLS_RETURN_TOOLTIP = "return: Required at the end of code enclosed in a “define function” block."; @@ -273,6 +283,8 @@ Blockly.MSG_MAKE_PIN_INPUT_TOOLTIP = "make PIN (programmable): Select I/O pin wi Blockly.MSG_CHECK_PIN_TOOLTIP = "check PIN (dropdown): Get the state of I/O pin; high = 1, low = 0."; Blockly.MSG_CHECK_PIN_INPUT_TOOLTIP = "check PIN (programmable): Get state of I/O pin at inserted value; high = 1, low = 0."; Blockly.MSG_SET_PINS_TOOLTIP = "set multiple pins: define group then set each pin. Do not use on P29-P31."; +Blockly.MSG_GET_PINS_TOOLTIP = "binary get pins: gets the value of a group of pins as a binary value. Highest pin is MSB."; +Blockly.MSG_SET_PINS_BINARY_TOOLTIP = "binary set pins: define group then set each pins using a binary value. Highest pin is MSB. Do not use on P29-P31."; Blockly.MSG_DEBUG_LCD_INIT_TOOLTIP = "LCD initialize: set I/O pin to LCD; match baud to LCD switches."; Blockly.MSG_DEBUG_LCD_PRINT_TOOLTIP = "LCD print text: display on serial LCD."; Blockly.MSG_DEBUG_LCD_NUMBER_TOOLTIP = "LCD print number: display on serial LCD."; @@ -283,7 +295,7 @@ Blockly.MSG_OLED_INITIALIZE_TOOLTIP = "OLED initialize: match to Propeller I/O p Blockly.MSG_OLED_FONT_LOADER_TOOLTIP = "OLED font loader: run alone to add fonts to EEPROM."; Blockly.MSG_OLED_GET_MAX_HEIGHT_TOOLTIP = "OLED max height"; Blockly.MSG_OLED_GET_MAX_WIDTH_TOOLTIP = "OLED max width"; -Blockly.MSG_OLED_CLEAR_SCREEN_TOOLTIP = "OLED clear screen: all pixels go black."; +Blockly.MSG_OLED_CLEAR_SCREEN_TOOLTIP = "OLED command: clear screen, sleep, wake, invert screen."; Blockly.MSG_OLED_TEXT_COLOR_TOOLTIP = "OLED font color: background is transparent if matched to font."; Blockly.MSG_OLED_TEXT_SIZE_TOOLTIP = "OLED set text: Med, large, script and bubble require font loader."; Blockly.MSG_OLED_SET_CURSOR_TOOLTIP = "OLED set cursor: 0,0 is top-left corner of display."; @@ -306,12 +318,36 @@ Blockly.MSG_SERIAL_TX_TOOLTIP = "Serial transmit number: sends 32-bit integer as Blockly.MSG_SERIAL_SEND_TEXT_TOOLTIP = "Serial transmit text: sends text as characters terminated by a 0 (NULL)."; Blockly.MSG_SERIAL_RX_TOOLTIP = "Serial receive number: receives 4 bytes MSB first and stores a a 32-bit integer."; Blockly.MSG_SERIAL_RECEIVE_TEXT_TOOLTIP = "Serial receive text: receives and stores characters into a variable until a 0 (NULL)."; +Blockly.MSG_SHIFT_IN_TOOLTIP = "shift in: serially shift in a specified number of bits and provides an integer value."; +Blockly.MSG_SHIFT_OUT_TOOLTIP = "shift out: serially shift out a specified number of bits from the specified value."; +Blockly.MSG_SWX_INIT_TOOLTIP = "Simple WX initialize: Requires simplewx.html file. Match DO/DI to Propeller I/O pin connections, set terminal and program routing."; +Blockly.MSG_SWX_CONFIG_PAGE_TOOLTIP = "Simple WX configure page: Requires simplewx.html file. Set terminal page title and background color."; +Blockly.MSG_SWX_SET_TOOLTIP = "Simple WX set widget: Requires simplewx.html file. Set location, type, color, and values for a new widget."; +Blockly.MSG_SWX_READ_TOOLTIP = "Simple WX read widgets: Requires simplewx.html file. Reads the current values of all the widgets."; +Blockly.MSG_SWX_GET_TOOLTIP = "Simple WX widget value: Requires simplewx.html file. Provides the value of a widget from when it was last read."; +Blockly.MSG_SWX_SEND_TOOLTIP = "Simple WX send to widget: Requires simplewx.html file. Send a value to a widget."; +Blockly.MSG_AWX_INIT_ADV_TOOLTIP = "Advanced WX initialize: Match DO/DI to Propeller I/O pin connections, set terminal and program routing."; +Blockly.MSG_AWX_SCAN_MULTIPLE_TOOLTIP = "Advanced WX scan multiple: scans the incoming string and stores the data as specified."; +Blockly.MSG_AWX_PRINT_TOOLTIP = "Advanced WX print: prints the specified data to the WX module."; +Blockly.MSG_AWX_SCAN_STRING_TOOLTIP = "Advanced WX scan string: stores an incoming string in the specified variable."; +Blockly.MSG_AWX_SEND_TOOLTIP = "Advanced WX send: sends the specified data to the TCP connection."; +Blockly.MSG_AWX_RECEIVE_TOOLTIP = "Advanced WX receive: receives and stores TCP data."; +Blockly.MSG_AWX_POLL_TOOLTIP = "Advanced WX poll: Instructs the WX module to monitor for a connection and data."; +Blockly.MSG_AWX_LISTEN_TOOLTIP = "Advanced WX connect: listens for incoming data and provides the connection information."; +Blockly.MSG_AWX_CODE_TOOLTIP = "Advanced WX code: provides the value for one of the codes used by the WX module."; +Blockly.MSG_AWX_MODE_TOOLTIP = "Advanced WX mode: sets or gets the current mode of the WX module."; +Blockly.MSG_AWX_BUFFER_TOOLTIP = "Advanced WX buffer: use to set a different receive buffer and/or size for the receive buffer"; +Blockly.MSG_AWX_DISCONNECT_TOOLTIP = "Advanced WX disconnect: disconnected from the specified connection."; +Blockly.MSG_AWX_GET_IP_TOOLTIP = "Advanced WX get IP address: provides the IP address of the specified mode as a string."; Blockly.MSG_XBEE_SETUP_TOOLTIP = "XBee initialize: match to Propeller I/O pin connections and XBee Baud rate."; Blockly.MSG_XBEE_TRANSMIT_TOOLTIP = "XBee transmit: sends information to an XBee. Strings and numbers are terminated with an ASCII 13"; Blockly.MSG_XBEE_RECEIVE_TOOLTIP = "XBee receive: receives information from an XBee. Expects strings and numbers to be terminated with an ASCII 13"; Blockly.MSG_WS2812B_INIT_TOOLTIP = "RGB-LED init: match to Propeller I/O pin connections and number of LEDs."; Blockly.MSG_WS2812B_SET_TOOLTIP = "RGB-LED set: specify color for a specific LED."; Blockly.MSG_WS2812B_UPDATE_TOOLTIP = "RGB-LED update: update colors of all connected RGB-LEDs."; +Blockly.MSG_FPS_INIT_TOOLTIP = "Fingerprint scanner initialize: match to Propeller I/O pin connections."; +Blockly.MSG_FPS_ADD_TOOLTIP = "Fingerprint scanner capture: capture and save or delete a capture or captures and their ID(s)."; +Blockly.MSG_FPS_SCAN_TOOLTIP = "Fingerprint scanner scan: scan and identify or scan and compare a fingerprint, or count the number of saved captures."; Blockly.MSG_HMC5883L_INIT_TOOLTIP = "Compass initialize: match to Propeller I/O pin connections."; Blockly.MSG_HMC5883L_READ_TOOLTIP = "Compass heading: get current heading in degrees."; Blockly.MSG_JOYSTICK_INPUT_XAXIS_TOOLTIP = "Joystick x-axis: gets horizontal position of Joystick, match to A/D socket."; @@ -325,6 +361,7 @@ Blockly.MSG_MMA7455_INIT_TOOLTIP = "Accelerometer initialize: match to Propeller Blockly.MSG_MMA7455_ACCELERATION_TOOLTIP = "Accelerometer store values: stores measured x, y, & z acceleration in specified variables."; Blockly.MSG_LSM9DS1_INIT_TOOLTIP = "IMU initialize: match to Propeller I/O pin connections."; Blockly.MSG_LSM9DS1_READ_TOOLTIP = "IMU read: get measurements from specified sensor."; +Blockly.MSG_LSM9DS1_MAG_CALIBRATE_TOOLTIP = "IMU Calibrate Magnetometer: Initialize first. Rotate slowly thru all 3 axes until P26/P27 LEDs turn off."; Blockly.MSG_LSM9DS1_TILT_TOOLTIP = "IMU tilt: gets tilt along specified axis."; Blockly.MSG_LSM9DS1_HEADING_TOOLTIP = "IMU heading: specify axes, get current heading in degrees."; Blockly.MSG_SENSOR_PING_TOOLTIP = "Ping))) distance: gets distance measured in the specified units, match to Propeller I/O pin."; @@ -350,6 +387,8 @@ Blockly.MSG_PULSE_OUT_TOOLTIP = "Pulse-out: outputs a high or low pulse to the s Blockly.MSG_PWM_START_TOOLTIP = "PWM initialize: sets up PWM object in the Propeller."; Blockly.MSG_PWM_SET_TOOLTIP = "PWM set: sends the specified PWM pulses out the Propeller I/O pin specified. Set duty cycle to 0 to stop sending pulses."; Blockly.MSG_PWM_STOP_TOOLTIP = "PWM stop: Stops PWM object, frees up resources used on the Propeller."; +Blockly.MSG_MCP320X_SET_VREF_TOOLTIP = "MCP320X set Vref: Set to the Vref voltage of the A/D chip."; +Blockly.MSG_MCP320X_READ_TOOLTIP = "MCP320X read: Reads an analog voltage from the specified channel. Match to Propeller I/O pin connections."; Blockly.MSG_WAV_PLAY_TOOLTIP = "WAV play: Plays the specified .WAV file stored on the SD card."; Blockly.MSG_WAV_STATUS_TOOLTIP = "WAV status: returns 1/true if a .WAV file is playing, returns 0/false if not."; Blockly.MSG_WAV_VOLUME_TOOLTIP = "WAV volume: sets the volume of the WAV player - 0 (quietest) to 10 (loudest)."; diff --git a/src/main/webapp/cdn/blockly/toolboxfilter.js b/src/main/webapp/cdn/blockly/toolboxfilter.js index 8eb1e491..fc56965e 100644 --- a/src/main/webapp/cdn/blockly/toolboxfilter.js +++ b/src/main/webapp/cdn/blockly/toolboxfilter.js @@ -19,6 +19,24 @@ function filterToolbox(profileName, peripherals) { } } + var exclude = toolboxEntry.attr('exclude'); + if (exclude) { + var excludes = exclude.split(","); + if (findOne(componentlist, excludes)) { + toolboxEntry.remove(); + } + } + }); + $("#toolbox").find('sep').each(function () { + var toolboxEntry = $(this); + var include = toolboxEntry.attr('include'); + if (include) { + var includes = include.split(","); + if (!findOne(componentlist, includes)) { + toolboxEntry.remove(); + } + } + var exclude = toolboxEntry.attr('exclude'); if (exclude) { var excludes = exclude.split(","); diff --git a/src/main/webapp/cdn/blocklyc.js b/src/main/webapp/cdn/blocklyc.js index 180d2878..0be53bc5 100644 --- a/src/main/webapp/cdn/blocklyc.js +++ b/src/main/webapp/cdn/blocklyc.js @@ -81,14 +81,14 @@ function tabClick(id) { function renderContent() { var content = document.getElementById('content_' + selected); // Initialize the pane. - if (content.id == 'content_blocks') { + if (content.id === 'content_blocks') { Blockly.mainWorkspace.render(); - } else if (content.id == 'content_xml') { + } else if (content.id === 'content_xml') { var xmlDom = Blockly.Xml.workspaceToDom(Blockly.mainWorkspace); var xmlText = Blockly.Xml.domToPrettyText(xmlDom); codeXml.setValue(xmlText); codeXml.gotoLine(0); - } else if (content.id == 'content_propc') { + } else if (content.id === 'content_propc') { var code = Blockly.propc.workspaceToCode(Blockly.mainWorkspace); codePropC.setValue(js_beautify(code, { 'brace_style': 'expand' @@ -304,14 +304,17 @@ check_com_ports = function () { }).fail(function () { $("#comPort").empty(); $("#comPort").append($('