/
freqshow.py
126 lines (106 loc) · 4.35 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# FreqShow main application and configuration.
# Author: Tony DiCola (tony@tonydicola.com)
#
# 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.
# Enhancements over the original Freqshow by Dan Stixrud, WQ7T
import os
import time
import pygame
import controller
import model
import ui
from ft5406 import Touchscreen, TS_PRESS, TS_RELEASE, TS_MOVE
# Application configuration.
#SDR_SAMPLE_SIZE = 512 # Number of samples per frequency bin to grab from the radio. Should be
#SDR_SAMPLE_SIZE = 1024 # larger than the maximum display width.
#SDR_SAMPLE_SIZE = 2048
#SDR_SAMPLE_SIZE = 4096
SDR_SAMPLE_SIZE = 8192 # This ithe default value to allow zooming the display to a 10kHz span in 320 pixels with a sample rate of 0.230 MHz.
#SDR_SAMPLE_SIZE = 16384
CLICK_DEBOUNCE = 0.04 # 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 = 26
NUM_FONT = 30
# Color configuration (RGB tuples, 0 to 255).
MAIN_BG = ( 5, 45, 45) # Dark Brown
INPUT_BG = MAIN_BG
INPUT_FG = ( 60, 255, 255) # Cyan-ish
CANCEL_BG = MAIN_BG
ACCEPT_BG = MAIN_BG
BUTTON_BG = MAIN_BG
BUTTON_FG = INPUT_FG
BUTTON_BORDER = MAIN_BG
SYMBOL_FG = ( 255, 255, 0) # Bright Yellow
INSTANT_LINE = ( 150, 255, 255) # Bright yellow green.
GRID_LINE = ( 119, 119, 130) # Light Grey
GRID_BG = ( 10, 10, 30) # Dark Blue
CENTER_LINE = ( 125, 0, 0) # Red
BLACK = ( 0, 0, 0) # Black
LINE_SHADOW = ( 96, 96, 96) # Medium Grey
# Define gradient of colors for the waterfall graph. Gradient goes from black to blue to cyan
# to yellow to red to white.
WATERFALL_GRAD = [(0, 0, 0), (0, 0, 70), (0, 0, 140), (60, 125, 255), (255, 255, 0), (255, 0, 0), (255, 255, 255)]
# 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/fb0')
os.putenv('SDL_NOMOUSE', '1')
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(0.25)
# Main loop to process events and render current view.
ts = Touchscreen()
def touch_handler(event, touch):
fscontroller.current().click((touch.x, touch.y))
for touch in ts.touches:
touch.on_press = touch_handler
while True:
# Ignore pygame events
for event in pygame.event.get():
pass
ts.poll()
# Update and render the current view.
fscontroller.current().render(screen)
pygame.display.update()