Skip to content

Commit

Permalink
Merge pull request #150 from gyroflow/improve-canvas-layer
Browse files Browse the repository at this point in the history
Improve canvas layer
  • Loading branch information
DusKing1 authored Jul 25, 2022
2 parents d70bf54 + a0532fc commit 2725f7d
Show file tree
Hide file tree
Showing 8 changed files with 469 additions and 466 deletions.
25 changes: 0 additions & 25 deletions src/gui/core/canvas.py

This file was deleted.

122 changes: 55 additions & 67 deletions src/gui/lib/canvas_128x32.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,12 @@

# You should have received a copy of the GNU Affero General Public License
# along with flowshutter. If not, see <https://www.gnu.org/licenses/>.
from gui.core.writer import Writer
from gui.fonts.icons import Icons
import gui.fonts.arial10 as a10
import target
import framebuf, time
from gui.lib.common import Canvas_Abstract

class Canvas_128x32(Icons):
class Canvas(Canvas_Abstract):
def __init__(self,screen):
self.settings = {
'version': '0.66',
'camera_protocol': 'NO',
'device_mode': 'MASTER',
'inject_mode': 'OFF',
'ota_source': 'GitHub',
'ota_channel': 'stable',
'target_name': target.name
}
self.vol = 0
self.erase_flag = False
self.screen = screen
self.a10 = Writer(self.screen, a10)
self.animation = False
super().__init__()

def update(self, info, sub_state, sub_menu, sub_info):
if sub_info != '':
if sub_info == 'BATTERY':
self.display_battery()
else:
self.display_hint(sub_info)
elif info == "home":
self.display_state(sub_state)
elif info == "menu":
self.display_menu(sub_menu)
else:
print(str(time.ticks_us()) + " [ Error] Unkown info: " + info)
super().__init__(screen)

def draw_batterymask(self, voltage):

Expand Down Expand Up @@ -83,19 +53,19 @@ def draw_batterymask(self, voltage):
self.screen.fill_rect(5,5,108,22,0)
# else: # less than 0%, then do nothing

def display_state(self, state):
if state == 'WELCOME':
def display_work_state(self, state):
if state == 0:
self.screen.fill(0)
self.screen.blit(self.icon_gyroflow, 0, 2)
self.screen.show()
else:
if state == 'HOME':
if state == 1:
fb, header, content1, content2, content3 = self.icon_cam, 'Flowshutter', 'Powered by', 'DusKing', ''.join(tuple(self.settings['version']))
elif state == 'STARTING':
elif state == 2:
fb, header, content1, content2, content3 = self.icon_cam, 'Starting', 'FC Disarmed', 'Camera start', ''
elif state == 'RECORDING':
elif state == 3:
fb, header, content1, content2, content3 = self.icon_cam_wk, 'Flowshutter', 'FC Armed', 'Recording', ''
elif state == 'STOPPING':
elif state == 4:
fb, header, content1, content2, content3 = self.icon_cam_wk, 'Stopping', 'FC Armed', 'Camera stop', ''
else:
print('Unkown state: ' + state)
Expand All @@ -117,35 +87,49 @@ def display_battery(self):
self.screen.text(voltage_str,44,13,1)
self.screen.show()

def display_menu(self, sub_cat):
if sub_cat == 'camera_protocol':
index, head, content, fb = 1, 'Camera Protocol',''.join(tuple(self.settings['camera_protocol'])), self.icon_settings
elif sub_cat == 'device_mode':
index, head, content, fb = 2, 'Device Mode', ''.join(tuple(self.settings['device_mode'])), self.icon_settings
elif sub_cat == 'inject_mode':
def display_menu(self, sub_menu, field,field_state):
self.screen.fill(0)
if sub_menu == 0:
index, head, content, fb = 0, 'General Infomation','Land Page', self.icon_settings
elif sub_menu == 1:
index, head, content, fb = 1, 'Camera Protocol',''.join(tuple(self.settings['camera_protocol'])), self.icon_settings
elif sub_menu == 2:
index, head, content, fb = 2, 'Device Mode', ''.join(tuple(self.settings['device_mode'])), self.icon_settings
elif sub_menu == 3:
index, head, content, fb = 3, 'Audio Injection',''.join(tuple(self.settings['inject_mode'])), (self.icon_audio if self.settings['inject_mode'] == "ON" else self.icon_audio_off)
elif sub_cat == 'erase_blackbox':
elif sub_menu == 4:
index, head, content, fb = 4, 'Blackbox Erase', ('Erasing...' if self.erase_flag else 'Erase stop'),self.icon_blackbox
elif sub_cat == 'internet':
import mwlan
index, head, content, fb = 5, 'Internet', ''.join(tuple(mwlan.wlan_state)), (self.self.icon_wifi if mwlan.wlan_state == "CONNECTED" else self.self.icon_wifi_dis)
elif sub_cat == 'ota_source':
index, head, content, fb = 6, 'OTA Source', ''.join(tuple(self.settings['ota_source'])), (self.icon_github if self.settings['ota_source'] == "GitHub" else self.icon_gitee)
elif sub_cat == 'ota_channel':
index, head, content, fb = 7, 'OTA Channel', ''.join(tuple(self.settings['ota_channel'])), self.icon_settings
elif sub_cat == 'ota_check':
index, head, content, fb = 8, 'OTA Check', "".join(tuple(self.settings['ota_source']))+"/"+"".join(tuple(self.settings['ota_channel'])),self.icon_settings
elif sub_cat == 'ota_update':
index, head, content, fb = 9, 'OTA Update', 'ENT = START', self.icon_settings
else:
print('Unknown sub_menu:', sub_cat)
self.screen.fill(0)
print('Unknown sub_menu:', sub_menu)

self.screen.blit(fb, 95, 0)
self.a10.set_textpos(self.screen,0,0)
self.a10.printstring(head)
self.screen.hline(0,10,94,1)
self.screen.text(content, 0, 14, 1)
self.screen.text('<< '+str(index)+'/4 >>', 0, 24, 1)

if field == 0:
self.screen.text(('<< '+str(index)+'/4 >>'),0, 24, 1)
cont_color = 1
elif field == 1:
self.screen.fill_rect(40,23,40,11,1)
self.screen.text('SAVE',0, 24, 1)
self.screen.text('LEAVE',40, 24, 0)
cont_color = 1
elif field == 2:
self.screen.text('SAVE',0, 24, 1)
self.screen.text('LEAVE',40, 24, 1)
if field_state ==0:
self.screen.fill_rect(0,12,int(len(content)*8),11,1)
cont_color = 0
else:
self.screen.rect(0,12,int(len(content)*8),11,1)
cont_color = 1
elif field == 3:
self.screen.fill_rect(0,23,32,11,1)
self.screen.text('SAVE',0, 24, 0)
self.screen.text('LEAVE',40, 24, 1)
cont_color = 1
self.screen.text(content, 0, 14, cont_color)
self.screen.show()

def display_hint(self, sub_info):
Expand All @@ -161,13 +145,17 @@ def display_hint(self, sub_info):
elif sub_info == 'STARTING_TIMEOUT':
self.screen.text('No ACK back', 17, 6, 1)
self.screen.text('Start failed', 17, 16, 1)
elif sub_info == 'AP_HINT':
self.screen.text('SSID:'+ 'Flowshutter', 3, 6, 1)
self.screen.text('Pswd:'+ 'ilovehugo', 3, 16, 1)
elif sub_info == 'WLAN_CONNECTING':
self.screen.text('Connecting', 21, 6, 1)
self.screen.text('Please wait', 21, 16, 1)
elif sub_info == 'SETTINGS_FAULT':
self.screen.text('Settings Fault', 26, 8, 1)
self.screen.text('Please Reboot', 26, 20, 1)
self.screen.show()

def display_reboot_page(self, state):
self.screen.fill(0)
self.screen.text('Exit',0,0,1)
self.screen.text('Reboot',0,12,1)
if state == 0:
self.screen.text('<<',56,0,1)
elif state == 1:
self.screen.text('<<',56,12,1)
self.screen.show()
137 changes: 61 additions & 76 deletions src/gui/lib/canvas_128x64.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,12 @@

# You should have received a copy of the GNU Affero General Public License
# along with flowshutter. If not, see <https://www.gnu.org/licenses/>.
from gui.core.writer import Writer
from gui.fonts.icons import Icons
import gui.fonts.arial10 as a10
import gui.fonts.font6 as f6
import gui.fonts.font10 as f10
import target
import framebuf, time
from gui.lib.common import Canvas_Abstract

class Canvas_128x64(Icons):
class Canvas(Canvas_Abstract):
def __init__(self,screen):
self.settings = {
'version': '0.66',
'camera_protocol': 'NO',
'device_mode': 'MASTER',
'inject_mode': 'OFF',
'ota_source': 'GitHub',
'ota_channel': 'stable',
'target_name': target.name
}
self.vol = 0
self.erase_flag = False
self.screen = screen
self.f6 = Writer(self.screen, f6)
self.a10 = Writer(self.screen, a10)
self.f10 = Writer(self.screen, f10)
self.animation = True
super().__init__()

def update(self, info, sub_state, sub_menu, sub_info):
if sub_info != '':
if sub_info == 'BATTERY':
self.display_battery()
else:
self.display_hint(sub_info)
elif info == "home":
self.display_state(sub_state)
elif info == "menu":
self.display_menu(sub_menu)
else:
print(str(time.ticks_us()) + " [ Error] Unkown info: " + info)
self.animation = False
super().__init__(screen)

def draw_batterymask(self, voltage):

Expand Down Expand Up @@ -87,19 +53,19 @@ def draw_batterymask(self, voltage):
self.screen.fill_rect(5,5,108,22,0)
# else: # less than 0%, then do nothing

def display_state(self, state):
if state == "WELCOME":
def display_work_state(self, state):
if state == 0:
self.screen.fill(0)
self.screen.blit(self.icon_gyroflow, 0, 2+16)
self.screen.blit(self.icon_gyroflow, 0, 18)
self.screen.show()
else:
if state == 'HOME':
if state == 1:
fb, header, content1, content2, content3 = self.icon_cam, 'Flowshutter', 'Powered by', 'DusKing', ''.join(tuple(self.settings['version']))
elif state == 'STARTING':
elif state == 2:
fb, header, content1, content2, content3 = self.icon_cam, 'Starting', 'FC Disarmed', 'Camera start', ''
elif state == 'RECORDING':
elif state == 3:
fb, header, content1, content2, content3 = self.icon_cam_wk, 'Flowshutter', 'FC Armed', 'Recording', ''
elif state == 'STOPPING':
elif state == 4:
fb, header, content1, content2, content3 = self.icon_cam_wk, 'Stopping', 'FC Armed', 'Camera stop', ''
else:
print('Unkown state: ' + state)
Expand All @@ -121,37 +87,52 @@ def display_battery(self):
self.screen.text(voltage_str,44,13,1)
self.screen.show()

def display_menu(self, sub_cat):
if sub_cat == 'camera_protocol':
index, head, content, fb = 1, 'Camera Protocol',''.join(tuple(self.settings['camera_protocol'])), self.icon_settings
elif sub_cat == 'device_mode':
index, head, content, fb = 2, 'Device Mode', ''.join(tuple(self.settings['device_mode'])), self.icon_settings
elif sub_cat == 'inject_mode':
def display_menu(self, sub_menu, field,field_state):
self.screen.fill(0)
if sub_menu == 0:
index, head, content, fb = 0, 'General Infomation','Land Page', self.icon_settings
elif sub_menu == 1:
index, head, content, fb = 1, 'Camera Protocol',''.join(tuple(self.settings['camera_protocol'])), self.icon_settings
elif sub_menu == 2:
index, head, content, fb = 2, 'Device Mode', ''.join(tuple(self.settings['device_mode'])), self.icon_settings
elif sub_menu == 3:
index, head, content, fb = 3, 'Audio Injection',''.join(tuple(self.settings['inject_mode'])), (self.icon_audio if self.settings['inject_mode'] == "ON" else self.icon_audio_off)
elif sub_cat == 'erase_blackbox':
elif sub_menu == 4:
index, head, content, fb = 4, 'Blackbox Erase', ('Erasing...' if self.erase_flag else 'Erase stop'),self.icon_blackbox
elif sub_cat == 'internet':
import mwlan
index, head, content, fb = 5, 'Internet', ''.join(tuple(mwlan.wlan_state)), (self.self.icon_wifi if mwlan.wlan_state == "CONNECTED" else self.self.icon_wifi_dis)
elif sub_cat == 'ota_source':
index, head, content, fb = 6, 'OTA Source', ''.join(tuple(self.settings['ota_source'])), (self.icon_github if self.settings['ota_source'] == "GitHub" else self.icon_gitee)
elif sub_cat == 'ota_channel':
index, head, content, fb = 7, 'OTA Channel', ''.join(tuple(self.settings['ota_channel'])), self.icon_settings
elif sub_cat == 'ota_check':
index, head, content, fb = 8, 'OTA Check', "".join(tuple(self.settings['ota_source']))+"/"+"".join(tuple(self.settings['ota_channel'])),self.icon_settings
elif sub_cat == 'ota_update':
index, head, content, fb = 9, 'OTA Update', 'ENT = START', self.icon_settings
else:
print('Unknown sub_menu:', sub_cat)
self.screen.fill(0)
# self.screen.blit(fb, 95, 0)
self.a10.set_textpos(self.screen,0,int(64-self.a10.stringlen(head)/2))
print('Unknown sub_menu:', sub_menu)

self.screen.blit(fb, 95, 0)
self.a10.set_textpos(self.screen,0,0)
self.a10.printstring(head)
# self.screen.hline(0,10,94,1)
# self.screen.text(content, 0, 14, 1)
# self.screen.text('<< '+str(index)+'/4 >>', 0, 24, 1)
self.screen.hline(0,10,94,1)

if field == 0:
cont_color = 1
elif field == 1:
self.screen.fill_rect(40,23,40,11,1)
self.screen.text('SAVE',0, 24, 1)
self.screen.text('LEAVE',40, 24, 0)
cont_color = 1
elif field == 2:
self.screen.text('SAVE',0, 24, 1)
self.screen.text('LEAVE',40, 24, 1)
if field_state ==0:
self.screen.fill_rect(0,12,int(len(content)*8),11,1)
cont_color = 0
else:
self.screen.rect(0,12,int(len(content)*8),11,1)
cont_color = 1
elif field == 3:
self.screen.fill_rect(0,23,32,11,1)
self.screen.text('SAVE',0, 24, 0)
self.screen.text('LEAVE',40, 24, 1)
cont_color = 1
self.screen.text(content, 0, 14, cont_color)
self.screen.text(('<< '+str(index)+'/4 >>'),0, 34, 1)
self.screen.show()


def display_hint(self, sub_info):
self.screen.fill(0)
self.screen.fill_rect(2,1,124,30,1)
Expand All @@ -165,13 +146,17 @@ def display_hint(self, sub_info):
elif sub_info == 'STARTING_TIMEOUT':
self.screen.text('No ACK back', 17, 6, 1)
self.screen.text('Start failed', 17, 16, 1)
elif sub_info == 'AP_HINT':
self.screen.text('SSID:'+ 'Flowshutter', 3, 6, 1)
self.screen.text('Pswd:'+ 'ilovehugo', 3, 16, 1)
elif sub_info == 'WLAN_CONNECTING':
self.screen.text('Connecting', 21, 6, 1)
self.screen.text('Please wait', 21, 16, 1)
elif sub_info == 'SETTINGS_FAULT':
self.screen.text('Settings Fault', 26, 8, 1)
self.screen.text('Please Reboot', 26, 20, 1)
self.screen.show()

def display_reboot_page(self, state):
self.screen.fill(0)
self.screen.text('Exit',0,0,1)
self.screen.text('Reboot',0,12,1)
if state == 0:
self.screen.text('<<',56,0,1)
elif state == 1:
self.screen.text('<<',56,12,1)
self.screen.show()
Loading

0 comments on commit 2725f7d

Please sign in to comment.