diff --git a/escher/src/run_loop.cpp b/escher/src/run_loop.cpp index 559a77899..37cc78ff6 100644 --- a/escher/src/run_loop.cpp +++ b/escher/src/run_loop.cpp @@ -19,7 +19,7 @@ Timer * RunLoop::timerAtIndex(int i) { void RunLoop::run() { #ifdef __EMSCRIPTEN__ - emscripten_set_main_loop_arg([](void * ctx){ ((Container *)ctx)->step(); }, this, 0, 1); + emscripten_set_main_loop_arg([](void * ctx){ ((RunLoop *)ctx)->step(); }, this, 0, 1); #else while(step()) { } diff --git a/ion/src/blackbox/Makefile b/ion/src/blackbox/Makefile index 7b50f7042..535277e16 100644 --- a/ion/src/blackbox/Makefile +++ b/ion/src/blackbox/Makefile @@ -3,7 +3,6 @@ objs += $(addprefix ion/src/blackbox/, \ ion.o \ display.o \ events.o \ - keyboard.o \ ) objs += $(addprefix ion/src/shared/, \ @@ -14,6 +13,11 @@ objs += $(addprefix ion/src/shared/, \ power.o \ dummy/backlight.o \ dummy/battery.o \ + dummy/events_modifier.o \ + dummy/led.o \ + dummy/keyboard.o \ + dummy/serial_number.o \ + dummy/usb.o \ ) ion/src/shared/log_printf.o: SFLAGS=-Iion/include diff --git a/ion/src/blackbox/events.cpp b/ion/src/blackbox/events.cpp index d58df4211..fca70f840 100644 --- a/ion/src/blackbox/events.cpp +++ b/ion/src/blackbox/events.cpp @@ -9,7 +9,7 @@ namespace Events { static int sLogAfterNumberOfEvents = -1; static int sEventCount = 0; -Ion::Events::Event Ion::Events::getEvent(int * timeout) { +Event getEvent(int * timeout) { Ion::Events::Event event = Ion::Events::None; while (!(event.isDefined() && event.isKeyboardEvent())) { int c = getchar(); @@ -29,22 +29,6 @@ Ion::Events::Event Ion::Events::getEvent(int * timeout) { return event; } -bool isShiftActive() { - return false; -} - -bool isAlphaActive() { - return false; -} - -bool isAlphaLocked() { - return false; -} - -bool isShiftAlphaLocked() { - return false; -} - namespace Blackbox { void dumpEventCount(int i) { diff --git a/ion/src/blackbox/ion.cpp b/ion/src/blackbox/ion.cpp index 377701740..d946ac29b 100644 --- a/ion/src/blackbox/ion.cpp +++ b/ion/src/blackbox/ion.cpp @@ -1,16 +1,5 @@ #include #include -bool Ion::USB::isPlugged() { - return false; -} - void Ion::msleep(long ms) { } - -const char * Ion::serialNumber() { - return "123"; -} - -void Ion::LED::setColor(KDColor) { -} diff --git a/ion/src/emscripten/Makefile b/ion/src/emscripten/Makefile index d10b149a9..c144b0df8 100644 --- a/ion/src/emscripten/Makefile +++ b/ion/src/emscripten/Makefile @@ -1,10 +1,18 @@ objs += $(addprefix ion/src/emscripten/, \ - main.o\ + display.o \ + events.o \ + main.o \ ) objs += $(addprefix ion/src/shared/, \ crc32.o \ events.o \ - events_keyboard.o \ power.o \ + dummy/backlight.o \ + dummy/battery.o \ + dummy/events_modifier.o \ + dummy/keyboard.o \ + dummy/led.o \ + dummy/serial_number.o \ + dummy/usb.o \ ) diff --git a/ion/src/emscripten/display.cpp b/ion/src/emscripten/display.cpp new file mode 100644 index 000000000..4fc647955 --- /dev/null +++ b/ion/src/emscripten/display.cpp @@ -0,0 +1,56 @@ +#include "display.h" +extern "C" { +#include +#include +} + +SDL_Surface * screen = nullptr; + +namespace Ion { +namespace Display { + +void pushRect(KDRect r, const KDColor * pixels) { + if (SDL_MUSTLOCK(screen)) { + SDL_LockSurface(screen); + } + int pixelNumber = 0; + for (int j=r.top(); jpixels + j * Ion::Display::Width + i) = SDL_MapRGB(screen->format, c.red(), c.green(), c.blue()); + } + } + if (SDL_MUSTLOCK(screen)) { + SDL_UnlockSurface(screen); + } + SDL_UpdateRect(screen, r.x(), r.y(), r.width(), r.height()); +} + +void pushRectUniform(KDRect r, KDColor c) { + Uint32 sdlColor = SDL_MapRGB(screen->format, c.red(), c.green(), c.blue()); + SDL_Rect sdlRect = { r.x(), r.y(), r.width(), r.height() }; + SDL_FillRect(screen, &sdlRect, sdlColor); + SDL_UpdateRect(screen, r.x(), r.y(), r.width(), r.height()); +} + +void pullRect(KDRect r, KDColor * pixels) { +} + +void waitForVBlank() { +} + +} +} + +namespace Ion { +namespace Display { +namespace Emscripten { + +void init() { + SDL_Init(SDL_INIT_VIDEO); + screen = SDL_SetVideoMode(Ion::Display::Width, Ion::Display::Height, 32, SDL_HWSURFACE); +} + +} +} +} diff --git a/ion/src/emscripten/display.h b/ion/src/emscripten/display.h new file mode 100644 index 000000000..0dcfa63ee --- /dev/null +++ b/ion/src/emscripten/display.h @@ -0,0 +1,16 @@ +#ifndef ION_EMSCRIPTEN_DISPLAY_H +#define ION_EMSCRIPTEN_DISPLAY_H + +#include + +namespace Ion { +namespace Display { +namespace Emscripten { + +void init(); + +} +} +} + +#endif diff --git a/ion/src/emscripten/events.cpp b/ion/src/emscripten/events.cpp new file mode 100644 index 000000000..65eb378b7 --- /dev/null +++ b/ion/src/emscripten/events.cpp @@ -0,0 +1,76 @@ +#include +extern "C" { +#include +} + +Ion::Events::Event sEvent = Ion::Events::None; + +void IonEventsEmscriptenPushEvent(int eventNumber) { + sEvent = Ion::Events::Event(eventNumber); +} + +namespace Ion { +namespace Events { + +static constexpr Event sEventForASCIICharAbove32[95] = { + Space, Exclamation, DoubleQuotes, None, None, None, None, None, + LeftParenthesis, RightParenthesis, Multiplication, Plus, Comma, Minus, Dot, Division, + Zero, One, Two, Three, Four, Five, Six, Seven, + Eight, Nine, Colon, SemiColon, Lower, Equal, Greater, Question, + None, UpperA, UpperB, UpperC, UpperD, UpperE, UpperF, UpperG, + UpperH, UpperI, UpperJ, UpperK, UpperL, UpperM, UpperN, UpperO, + UpperP, UpperQ, UpperR, UpperS, UpperT, UpperU, UpperV, UpperW, + UpperX, UpperY, UpperZ, LeftBracket, None, RightBracket, Power, Underscore, + None, LowerA, LowerB, LowerC, LowerD, LowerE, LowerF, LowerG, + LowerH, LowerI, LowerJ, LowerK, LowerL, LowerM, LowerN, LowerO, + LowerP, LowerQ, LowerR, LowerS, LowerT, LowerU, LowerV, LowerW, + LowerX, LowerY, LowerZ, LeftBrace, None, RightBrace, None +}; + +Event getEvent(int * timeout) { + if (sEvent != Ion::Events::None) { + Ion::Events::Event event = sEvent; + sEvent = Ion::Events::None; + return event; + } + SDL_Event event; + if (SDL_PollEvent(&event)) { + if (event.type == SDL_KEYDOWN) { + switch(event.key.keysym.sym) { + case SDLK_UP: + return Ion::Events::Up; + case SDLK_DOWN: + return Ion::Events::Down; + case SDLK_LEFT: + return Ion::Events::Left; + case SDLK_RIGHT: + return Ion::Events::Right; + case SDLK_RETURN: + return Ion::Events::OK; + case SDLK_ESCAPE: + return Ion::Events::Back; + case SDLK_BACKSPACE: + return Ion::Events::Backspace; + } + if (event.key.keysym.unicode >= 32 && event.key.keysym.unicode < 127) { + return sEventForASCIICharAbove32[event.key.keysym.unicode-32]; + } + } + } + return Ion::Events::None; +} + +} +} + +namespace Ion { +namespace Events { +namespace Emscripten { + +void init() { + SDL_EnableUNICODE(1); // We're using Unicode values from Keyboard input +} + +} +} +} diff --git a/ion/src/emscripten/events.h b/ion/src/emscripten/events.h new file mode 100644 index 000000000..ad4ecec2b --- /dev/null +++ b/ion/src/emscripten/events.h @@ -0,0 +1,20 @@ +#ifndef ION_EMSCRIPTEN_EVENTS_H +#define ION_EMSCRIPTEN_EVENTS_H + +#include + +extern "C" { +void IonEventsEmscriptenPushEvent(int e); +} + +namespace Ion { +namespace Events { +namespace Emscripten { + +void init(); + +} +} +} + +#endif diff --git a/ion/src/emscripten/main.cpp b/ion/src/emscripten/main.cpp index 4dfa0c116..d60a34691 100644 --- a/ion/src/emscripten/main.cpp +++ b/ion/src/emscripten/main.cpp @@ -1,112 +1,13 @@ #include -extern "C" { -#include -#include -#include -#include -} - -extern "C" { -void IonEmscriptenPushEvent(int e); -} - -SDL_Surface * screen = nullptr; -Ion::Events::Event sEvent = Ion::Events::None; - -void IonEmscriptenPushEvent(int eventNumber) { - sEvent = Ion::Events::Event(eventNumber); -} +#include "display.h" +#include "events.h" int main(int argc, char * argv[]) { - SDL_EnableUNICODE(1); // We're using Unicode values from Keyboard input - SDL_Init(SDL_INIT_VIDEO); - screen = SDL_SetVideoMode(Ion::Display::Width, Ion::Display::Height, 32, SDL_HWSURFACE); + Ion::Display::Emscripten::init(); + Ion::Events::Emscripten::init(); ion_app(); return 0; } -void Ion::Display::pushRect(KDRect r, const KDColor * pixels) { - if (SDL_MUSTLOCK(screen)) { - SDL_LockSurface(screen); - } - int pixelNumber = 0; - for (int j=r.top(); jpixels + j * Ion::Display::Width + i) = SDL_MapRGB(screen->format, c.red(), c.green(), c.blue()); - } - } - if (SDL_MUSTLOCK(screen)) { - SDL_UnlockSurface(screen); - } - SDL_UpdateRect(screen, r.x(), r.y(), r.width(), r.height()); -} - -void Ion::Display::pushRectUniform(KDRect r, KDColor c) { - Uint32 sdlColor = SDL_MapRGB(screen->format, c.red(), c.green(), c.blue()); - SDL_Rect sdlRect = { r.x(), r.y(), r.width(), r.height() }; - SDL_FillRect(screen, &sdlRect, sdlColor); - SDL_UpdateRect(screen, r.x(), r.y(), r.width(), r.height()); -} - -void Ion::Display::pullRect(KDRect r, KDColor * pixels) { -} - -using namespace Ion::Events; - -static constexpr Event sEventForASCIICharAbove32[95] = { - Space, Exclamation, DoubleQuotes, None, None, None, None, None, - LeftParenthesis, RightParenthesis, Multiplication, Plus, Comma, Minus, Dot, Division, - Zero, One, Two, Three, Four, Five, Six, Seven, - Eight, Nine, Colon, SemiColon, Lower, Equal, Greater, Question, - None, UpperA, UpperB, UpperC, UpperD, UpperE, UpperF, UpperG, - UpperH, UpperI, UpperJ, UpperK, UpperL, UpperM, UpperN, UpperO, - UpperP, UpperQ, UpperR, UpperS, UpperT, UpperU, UpperV, UpperW, - UpperX, UpperY, UpperZ, LeftBracket, None, RightBracket, Power, Underscore, - None, LowerA, LowerB, LowerC, LowerD, LowerE, LowerF, LowerG, - LowerH, LowerI, LowerJ, LowerK, LowerL, LowerM, LowerN, LowerO, - LowerP, LowerQ, LowerR, LowerS, LowerT, LowerU, LowerV, LowerW, - LowerX, LowerY, LowerZ, LeftBrace, None, RightBrace, None -}; - -Ion::Events::Event Ion::Events::getEvent() { - if (sEvent != Ion::Events::None) { - Ion::Events::Event event = sEvent; - sEvent = Ion::Events::None; - return event; - } - SDL_Event event; - if (SDL_PollEvent(&event)) { - if (event.type == SDL_KEYDOWN) { - switch(event.key.keysym.sym) { - case SDLK_UP: - return Ion::Events::Up; - case SDLK_DOWN: - return Ion::Events::Down; - case SDLK_LEFT: - return Ion::Events::Left; - case SDLK_RIGHT: - return Ion::Events::Right; - case SDLK_RETURN: - return Ion::Events::OK; - case SDLK_ESCAPE: - return Ion::Events::Back; - case SDLK_BACKSPACE: - return Ion::Events::Backspace; - } - if (event.key.keysym.unicode >= 32 && event.key.keysym.unicode < 127) { - return sEventForASCIICharAbove32[event.key.keysym.unicode-32]; - } - } - } - return Ion::Events::None; -} - -bool Ion::Keyboard::keyDown(Ion::Keyboard::Key key) { - //SDL_Quit(); - return false; -} - void Ion::msleep(long ms) { - usleep(1000*ms); } diff --git a/ion/src/shared/dummy/events_modifier.cpp b/ion/src/shared/dummy/events_modifier.cpp new file mode 100644 index 000000000..5fd5e9d75 --- /dev/null +++ b/ion/src/shared/dummy/events_modifier.cpp @@ -0,0 +1,23 @@ +#include + +namespace Ion { +namespace Events { + +bool isShiftActive() { + return false; +} + +bool isAlphaActive() { + return false; +} + +bool isAlphaLocked() { + return false; +} + +bool isShiftAlphaLocked() { + return false; +} + +} +} diff --git a/ion/src/blackbox/keyboard.cpp b/ion/src/shared/dummy/keyboard.cpp similarity index 100% rename from ion/src/blackbox/keyboard.cpp rename to ion/src/shared/dummy/keyboard.cpp diff --git a/ion/src/shared/dummy/led.cpp b/ion/src/shared/dummy/led.cpp new file mode 100644 index 000000000..12452f37b --- /dev/null +++ b/ion/src/shared/dummy/led.cpp @@ -0,0 +1,4 @@ +#include + +void Ion::LED::setColor(KDColor c) { +} diff --git a/ion/src/shared/dummy/serial_number.cpp b/ion/src/shared/dummy/serial_number.cpp new file mode 100644 index 000000000..8afe325a4 --- /dev/null +++ b/ion/src/shared/dummy/serial_number.cpp @@ -0,0 +1,5 @@ +#include + +const char * Ion::serialNumber() { + return "UNKNOWN"; +} diff --git a/ion/src/shared/dummy/usb.cpp b/ion/src/shared/dummy/usb.cpp new file mode 100644 index 000000000..208058977 --- /dev/null +++ b/ion/src/shared/dummy/usb.cpp @@ -0,0 +1,5 @@ +#include + +bool Ion::USB::isPlugged() { + return false; +}