jsinteractive.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * This file is part of Espruino, a JavaScript interpreter for Microcontrollers
  3. *
  4. * Copyright (C) 2013 Gordon Williams <gw@pur3.co.uk>
  5. *
  6. * This Source Code Form is subject to the terms of the Mozilla Public
  7. * License, v. 2.0. If a copy of the MPL was not distributed with this
  8. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. *
  10. * ----------------------------------------------------------------------------
  11. * Interactive Shell implementation
  12. * ----------------------------------------------------------------------------
  13. */
  14. #ifndef JSINTERACTIVE_H_
  15. #define JSINTERACTIVE_H_
  16. #include "jsparse.h"
  17. #include "jshardware.h"
  18. #define JSI_WATCHES_NAME ">watches"
  19. #define JSI_TIMERS_NAME ">timers"
  20. #define JSI_HISTORY_NAME ">history"
  21. #define JSI_INIT_CODE_NAME ">init"
  22. #define JSI_ONINIT_NAME "onInit"
  23. /// autoLoad = do we load the current state if it exists?
  24. void jsiInit(bool autoLoad);
  25. void jsiKill();
  26. void jsiLoop();
  27. /// Tries to get rid of some memory (by clearing command history). Returns true if it got rid of something, false if it didn't.
  28. bool jsiFreeMoreMemory();
  29. bool jsiHasTimers(); // are there timers still left to run?
  30. JsParse *jsiGetParser();
  31. /// Queue up callbacks for other things (touchscreen? network?)
  32. void jsiQueueObjectCallbacks(JsVar *object, const char *callbackName, JsVar *arg0, JsVar *arg1);
  33. IOEventFlags jsiGetDeviceFromClass(JsVar *deviceClass);
  34. JsVar *jsiGetClassNameFromDevice(IOEventFlags device);
  35. /// Change the console to a new location
  36. void jsiSetConsoleDevice(IOEventFlags device);
  37. /// Get the device that the console is currently on
  38. IOEventFlags jsiGetConsoleDevice();
  39. /// Transmit a byte
  40. void jsiConsolePrintChar(char data);
  41. /// Transmit a string
  42. void jsiConsolePrint(const char *str);
  43. /// Write the formatted string to the console (see vcbprintf)
  44. void jsiConsolePrintf(const char *fmt, ...);
  45. /// Print the contents of a string var - directly
  46. void jsiConsolePrintStringVar(JsVar *v);
  47. /// Transmit an integer
  48. void jsiConsolePrintInt(JsVarInt d);
  49. /// Transmit a position in the lexer (for reporting errors)
  50. void jsiConsolePrintPosition(struct JsLex *lex, int tokenPos);
  51. /// Transmit the current line, along with a marker of where the error was (for reporting errors)
  52. void jsiConsolePrintTokenLineMarker(struct JsLex *lex, int tokenPos);
  53. /// Print the contents of a string var to a device - directly
  54. void jsiTransmitStringVar(IOEventFlags device, JsVar *v);
  55. /// If the input line was shown in the console, remove it
  56. void jsiConsoleRemoveInputLine();
  57. /// Change what is in the inputline into something else (and update the console)
  58. void jsiReplaceInputLine(JsVar *newLine);
  59. /// Flags for jsiSetBusy - THESE SHOULD BE 2^N
  60. typedef enum {
  61. BUSY_INTERACTIVE = 1,
  62. BUSY_TRANSMIT = 2,
  63. // ??? = 4
  64. } JsiBusyDevice;
  65. /// Shows a busy indicator, if one is set up
  66. void jsiSetBusy(JsiBusyDevice device, bool isBusy);
  67. /// Shows a sleep indicator, if one is set up
  68. void jsiSetSleep(bool isSleep);
  69. // for jswrap_interactive/io.c ----------------------------------------------------
  70. typedef enum {
  71. TODO_NOTHING = 0,
  72. TODO_FLASH_SAVE = 1,
  73. TODO_FLASH_LOAD = 2,
  74. TODO_RESET = 4,
  75. } TODOFlags;
  76. #define USART_CALLBACK_NAME "_callback"
  77. #define USART_BAUDRATE_NAME "_baudrate"
  78. #define DEVICE_OPTIONS_NAME "_options"
  79. extern Pin pinBusyIndicator;
  80. extern Pin pinSleepIndicator;
  81. extern bool echo;
  82. extern bool allowDeepSleep;
  83. void jsiDumpState();
  84. void jsiSetTodo(TODOFlags newTodo);
  85. #define TIMER_MIN_INTERVAL 0.1 // in milliseconds
  86. extern JsVarRef timerArray; // Linked List of timers to check and run
  87. extern JsVarRef watchArray; // Linked List of input watches to check and run
  88. // end for jswrap_interactive/io.c ------------------------------------------------
  89. #endif /* JSINTERACTIVE_H_ */