Difference between revisions of "HackerHotel2019Badge/splash"

From Badge team
Jump to navigation Jump to search
(Created page with "The Hackerhotel badge starts with a splash screen showing the nickname and an image. It is also responsible for putting the ESP32 to sleep when the badge is idle. '''Custom i...")
 
 
(2 intermediate revisions by the same user not shown)
Line 24: Line 24:
  
 
I've made a small example showing some things you can do to create a service:
 
I've made a small example showing some things you can do to create a service:
<nowiki>import ugfx, virtualtimers
+
 
 +
<pre>import ugfx, virtualtimers
  
 
seconds = 0
 
seconds = 0
Line 59: Line 60:
 
redraw()
 
redraw()
 
return 1000
 
return 1000
</nowiki>
+
</pre>
  
  
Line 68: Line 69:
  
 
'''init()''' this function gets called once when the device wakes up
 
'''init()''' this function gets called once when the device wakes up
 +
 
'''step()''' this function gets called when the badge is ready to display the next step of your LED animation. The function should return the amount of milliseconds you want to wait until the next step of your animation is executed. The homescreen application will automatically call your function again after the provided amount of milliseconds.
 
'''step()''' this function gets called when the badge is ready to display the next step of your LED animation. The function should return the amount of milliseconds you want to wait until the next step of your animation is executed. The homescreen application will automatically call your function again after the provided amount of milliseconds.
 +
 +
'''Example'''
 +
<pre>import badge
 +
 +
def init():
 +
  print("LED init")
 +
  global ledStep
 +
  ledStep = 0
 +
 +
def step():
 +
  global ledStep
 +
  if ledStep >= 6:
 +
ledStep = 0
 +
  data = [0]*6*4 #6 leds, 4 colors
 +
  data[ledStep*4] = 100
 +
  badge.leds_send_data(bytes(data))
 +
  ledStep += 1
 +
  return 100
 +
</pre>
 +
 +
You can choose which LED service to enable by selecting one using the serial port menu.

Latest revision as of 17:26, 18 February 2019

The Hackerhotel badge starts with a splash screen showing the nickname and an image. It is also responsible for putting the ESP32 to sleep when the badge is idle.

Custom image 1. Get a .png image on your badge, either by bundling it with an app or by using the file downloader tool ("Tools -> File downloader" in serial port menu) 2. Select the image you want to show on the homescreen ("Settings -> Homescreen logo" in the serial port menu).

Services 1. Get an app which supports homescreen services using the API described below. 2. Enable the app ("Settings -> Homescreen services (beta)" in the serial port menu)

Services API Create a file called "srv.py" and bundle it with your app. The file should define a set of Python functions, which will be called by the splash screen application.

init(redraw_request_callback) this function is called on boot and provides your app with a function pointer which can be called to request a screen redraw. Please do NOT draw anything to the screen in this function. Keep it's contents to an absolute minimum to avoid causing irritating your users :-)

draw(y) this function is called whenever the display gets refreshed and your app is being shown. Please try not to overwrite anything on the last 16 pixels of the display, as the status bar is shown there. Also try not to draw anything above the y-coordinate passed to the function, as the nickname is shown there. Otherwise be creative :-)

focus(in_focus) called when your app gains focus and called again when your app loses focus. Please do NOT interrupt other apps by doing stuff when your app is not in focus.

Services have to be enabled manually due to people making misbehaving apps in the past. Should you get stuck on a non-functional homescreen: hold the START button while resetting your badge to jump directly into the launcher. From there you can also access the serial port menu to disable any misbehaving apps.

Please also have a look at the section on LED specific services, down below.

I've made a small example showing some things you can do to create a service:

import ugfx, virtualtimers

seconds = 0
task_active = False

def init(cb):
	global redraw
	redraw = cb
	print("This is the service init function.")

def draw(position):
	global seconds
	print("This is the service draw function.")
	ugfx.string(5, position, "Hello world", "Roboto_Regular18", ugfx.BLACK)
	ugfx.string(5, position+24, str(seconds), "Roboto_Regular18", ugfx.BLACK)

def focus(in_focus):
	global task_active, seconds
	print("Focus changed to", in_focus)
	if in_focus:
		if not task_active:
			virtualtimers.new(0, counterTask, False)
			task_active = True
	else:
		if task_active:
			virtualtimers.delete(counterTask)
			task_active = False
		seconds = 0

def counterTask():
	global seconds, redraw
	seconds += 1
	print("CounterTask", seconds)
	redraw()
	return 1000


LEDS So you want to create a cool LED animation, shown on the homescreen? Sure! On the SHA badge we noticed that conflicts were caused when multiple LED specific services were in use at the same time. Therefor LED specific services now have a separate API.

Create a file called "ledsrv.py" in your app and define the following functions:

init() this function gets called once when the device wakes up

step() this function gets called when the badge is ready to display the next step of your LED animation. The function should return the amount of milliseconds you want to wait until the next step of your animation is executed. The homescreen application will automatically call your function again after the provided amount of milliseconds.

Example

import badge

def init():
  print("LED init")
  global ledStep
  ledStep = 0

def step():
  global ledStep
  if ledStep >= 6:
	ledStep = 0
  data = [0]*6*4 #6 leds, 4 colors
  data[ledStep*4] = 100
  badge.leds_send_data(bytes(data))
  ledStep += 1
  return 100

You can choose which LED service to enable by selecting one using the serial port menu.