• Stars
    star
    360
  • Rank 118,230 (Top 3 %)
  • Language
    C
  • Created about 5 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📟 A React Renderer for SSD1306 OLED chip on Raspberry Pi.

React SSD1306

A React Renderer for SSD1306 OLED chip on Raspberry Pi

For those who doesn't have the device, a canvas-based web emulator is also included!

Introduction

This project demonstrates how to:

  • Use React together with QuickJS on Raspberry Pi.
  • Develop basic C module for QuickJS.
  • Build a custom "native & dynamic" renderer for React.

Checkout the Tutorial, or my Chinese blog post for details.

Getting Started

This project is originally designed to work on Raspberry Pi, but a web emulator is also available and works out of the box. Notice that no matter you run it on web or native, the whole React-related codebase is exactly the same.

Web Approach

You can try out the reconciler example, even if you don't have a Raspberry Pi. In this way only Node.js and ParcelJS are required:

cd react-ssd1306/app
parcel src/index.html

Then just open https://localhost:1234 to see the emulator.

Native Approach

Connect the chip, make sure you have QuickJS and Node.js installed on your Raspberry Pi, with I2C interface enabled. Few extra packages are also required:

sudo apt-get install i2c-tools libi2c-dev

Node.js is only required for JS module bundling and package management here.

Init the project:

cd react-ssd1306/app
npm install && cd ..
npm run build # build JS and C modules
npm start # start the compiled binary

Usage

Simply edit ./app/index.js as main entrance:

import './polyfill.js'
import React from 'react'
import { SSD1306Renderer, Text, Pixel } from './renderer.js'

class App extends React.Component {
  constructor () {
    super()
    this.state = { hello: 'Hello React!', p: 0 }
  }

  render () {
    const { hello, p } = this.state
    return (
      <React.Fragment>
        <Text row={0} col={0}>{hello}</Text>
        <Text row={1} col={0}>Hello QuickJS!</Text>
        <Pixel x={p} y={p} />
      </React.Fragment>
    )
  }

  componentDidMount () {
    // XXX: Emulate event driven update
    setTimeout(() => this.setState({ hello: 'Hello Pi!', p: 42 }), 2000)
    setTimeout(() => this.setState({ hello: '', p: -1 }), 4000)
  }
}

SSD1306Renderer.render(<App />)

License

MIT

More Repositories

1

jshistory-cn

🇨🇳 《JavaScript 二十年》中文版
TypeScript
4,205
star
2

beam

✨ Expressive WebGL
JavaScript
516
star
3

mocha1995

☕️ The world's first JavaScript engine written in 1995 by Brendan Eich, now compiled back to JS and WASM!
C
290
star
4

freecube

⚛ Solve Rubik's Cube with WebGL in 10KB.
JavaScript
127
star
5

sinomap

🌎 Super lightweight canvas map lib.
JavaScript
107
star
6

webgl-seminar

代码清晰、直接、可追溯的一系列 WebGL 示例
JavaScript
105
star
7

learn-wgpu-cn

🇨🇳 《Learn Wgpu》中文版
Rust
104
star
8

nativebird

🐦 Bluebird alternative within ~200 loc
JavaScript
78
star
9

minimal-js-runtime

A toy JavaScript runtime based on QuickJS and libuv.
C
66
star
10

bumpover

🚧 Async data transforming with simple rules.
JavaScript
65
star
11

merry8

📺 Chip-8 emulator for web.
JavaScript
53
star
12

vue-cmap

Vue China map visualizing component, supports drilldown and lazy loading.
JavaScript
39
star
13

fe-native-lang

Native language guide for FE developers.
C
31
star
14

crdt-and-local-first

A slide - WIP
Vue
28
star
15

HTML-Toy-Parser

一个玩具级的 HTML 转虚拟 DOM 编译器
JavaScript
27
star
16

ove-lang

👓 ove-lang, a language for his true fans.
HTML
26
star
17

vue-springbud

不是最简洁的 Vue 生产环境模板
JavaScript
24
star
18

MiyooSDK

🐳 Docker environment for developing Miyoo Linux apps.
Dockerfile
23
star
19

blog

📝 My tech blog.
JavaScript
22
star
20

psp-js

Modern JavaScript runtime for Sony PSP, based on rust-psp and QuickJS.
Rust
19
star
21

nano-mvc

Demo MVC framework in 40 lines, 1KB
JavaScript
18
star
22

slate-doc-cn

🇨🇳 Translation of Slate.js official doc.
14
star
23

rx-elevator-demo

Reactive Demo
JavaScript
14
star
24

flylog

Front end AOP logging and monotoring tool.
Vue
13
star
25

naming-style-demo

前端框架命名风格比较
JavaScript
12
star
26

learn-cs

💾 Resources learning basics.
Assembly
11
star
27

ustc-gpa

GPA calculator for USTCers
JavaScript
10
star
28

naiveScroll

Tiny jQuery full page scroll effect plugin.
JavaScript
10
star
29

repeater

📼 Record browser events as visual test case.
JavaScript
9
star
30

js-framework-intro

JavaScript 框架设计入门
9
star
31

render-adapters-poc

POC for customizing UI framework renderers.
JavaScript
6
star
32

gomoku

JavaScript Gomuku AI for Web
JavaScript
5
star
33

eslint-plugin-pangu-comment

Pangu whitespace for Chinese comments.
JavaScript
4
star
34

zlayer

⚡️ Image render layer with GPU acceleration.
JavaScript
4
star
35

psp-test-app

Simple test app based on rust-psp
Rust
4
star
36

icard-ustc

Consume record analyzer for USTCers
Python
3
star
37

examples

Static HTML examples just for fun :)
HTML
2
star
38

pages-cn

My Blog Dist HTML Pages
HTML
2
star
39

compilExpt

Experimental compiler-related JS project.
JavaScript
2
star
40

rollup-scaffold

A simple rollup config scaffold
JavaScript
2
star
41

visue

vue visualizing dev tool
JavaScript
2
star
42

slate-playground

Pluggable editor playground.
JavaScript
1
star
43

sikuli-coc

HTML
1
star
44

ck.js

cookie lib in 2 lines
JavaScript
1
star
45

legs

Light Easy Gulp Scaffold
JavaScript
1
star
46

n7books

Second hand book exchange platform for USTCers
PHP
1
star
47

nano-computed

explain how computed works in 30 lines.
JavaScript
1
star
48

imdoc

markdown documentation generator
CSS
1
star
49

Markdown-Table-Converter

Edit and reformat markdown table.
JavaScript
1
star
50

tennis-match-recorder

Tennis match recorder and more
JavaScript
1
star
51

ustc-ring

Graduation Ring Exchange Platfrom for USTCers
HTML
1
star