-
Notifications
You must be signed in to change notification settings - Fork 67
/
freqshow.py
104 lines (93 loc) · 3.85 KB
/
freqshow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# FreqShow main application and configuration.
# Author: Tony DiCola ([email protected])
#
# The MIT License (MIT)
#
# Copyright (c) 2014 Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import os
import time
import pygame
import controller
import model
import ui
# Application configuration.
SDR_SAMPLE_SIZE = 1024 # Number of samples to grab from the radio. Should be
# larger than the maximum display width.
CLICK_DEBOUNCE = 0.4 # Number of seconds to wait between clicks events. Set
# to a few hunded milliseconds to prevent accidental
# double clicks from hard screen presses.
# Font size configuration.
MAIN_FONT = 33
NUM_FONT = 50
# Color configuration (RGB tuples, 0 to 255).
MAIN_BG = ( 0, 0, 0) # Black
INPUT_BG = ( 60, 255, 255) # Cyan-ish
INPUT_FG = ( 0, 0, 0) # Black
CANCEL_BG = (128, 45, 45) # Dark red
ACCEPT_BG = ( 45, 128, 45) # Dark green
BUTTON_BG = ( 60, 60, 60) # Dark gray
BUTTON_FG = (255, 255, 255) # White
BUTTON_BORDER = (200, 200, 200) # White/light gray
INSTANT_LINE = ( 0, 255, 128) # Bright yellow green.
# Define gradient of colors for the waterfall graph. Gradient goes from blue to
# yellow to cyan to red.
WATERFALL_GRAD = [(0, 0, 255), (0, 255, 255), (255, 255, 0), (255, 0, 0)]
# Configure default UI and button values.
ui.MAIN_FONT = MAIN_FONT
ui.Button.fg_color = BUTTON_FG
ui.Button.bg_color = BUTTON_BG
ui.Button.border_color = BUTTON_BORDER
ui.Button.padding_px = 2
ui.Button.border_px = 2
if __name__ == '__main__':
# Initialize pygame and SDL to use the PiTFT display and touchscreen.
os.putenv('SDL_VIDEODRIVER', 'fbcon')
os.putenv('SDL_FBDEV' , '/dev/fb1')
os.putenv('SDL_MOUSEDRV' , 'TSLIB')
os.putenv('SDL_MOUSEDEV' , '/dev/input/touchscreen')
pygame.display.init()
pygame.font.init()
pygame.mouse.set_visible(False)
# Get size of screen and create main rendering surface.
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
# Display splash screen.
splash = pygame.image.load('freqshow_splash.png')
screen.fill(MAIN_BG)
screen.blit(splash, ui.align(splash.get_rect(), (0, 0, size[0], size[1])))
pygame.display.update()
splash_start = time.time()
# Create model and controller.
fsmodel = model.FreqShowModel(size[0], size[1])
fscontroller = controller.FreqShowController(fsmodel)
time.sleep(2.0)
# Main loop to process events and render current view.
lastclick = 0
while True:
# Process any events (only mouse events for now).
for event in pygame.event.get():
if event.type is pygame.MOUSEBUTTONDOWN \
and (time.time() - lastclick) >= CLICK_DEBOUNCE:
lastclick = time.time()
fscontroller.current().click(pygame.mouse.get_pos())
# Update and render the current view.
fscontroller.current().render(screen)
pygame.display.update()