app tweaks

This commit is contained in:
kepler155c@gmail.com
2018-12-03 15:40:51 -05:00
parent 93d2aa331c
commit a49d2d820d
4 changed files with 38 additions and 62 deletions

View File

@@ -3,23 +3,32 @@ _G.requireInjector()
local Event = require('event') local Event = require('event')
local UI = require('ui') local UI = require('ui')
local colors = _G.colors local colors = _G.colors
local device = _G.device local peripheral = _G.peripheral
local turtle = _G.turtle
if not turtle then local speaker = peripheral.find('speaker') or
error('This program can only be run on a turtle') error('Speaker must be attached')
end
local radio = device.drive or error('No drive attached')
if radio.side ~= 'top' and radio.side ~= 'bottom' then
error('Disk drive must be above or below turtle')
end
UI:configure('Music', ...) UI:configure('Music', ...)
UI.Button.defaults.backgroundFocusColor = colors.gray UI.Button.defaults.backgroundFocusColor = colors.gray
local songs = {
{ record = 'record.11', title = '11' },
{ record = 'record.13', title = '13' },
{ record = 'record.block', title = 'Block' },
{ record = 'record.cat', title = 'Cat' },
{ record = 'record.chirp', title = 'Chirp' },
{ record = 'record.far', title = 'Faf' },
{ record = 'record.mall', title = 'Mall' },
{ record = 'record.mellohi', title = 'Mellohi' },
{ record = 'record.stal', title = 'Stal' },
{ record = 'record.strad', title = 'Strad' },
{ record = 'record.wait', title = 'Wait' },
{ record = 'record.ward', title = 'Ward' },
}
local songNo = 1
local page = UI.Page({ local page = UI.Page({
volume = 15, volume = 15,
stationName = UI.Text({ stationName = UI.Text({
@@ -168,41 +177,18 @@ function page:setVolume(volume)
end end
function page:seek() function page:seek()
songNo = songNo + 1
local actions = { if songNo > #songs then
top = { songNo = 1
suck = turtle.suckUp, end
drop = turtle.dropUp,
},
bottom = {
suck = turtle.suckDown,
drop = turtle.dropDown,
},
}
local slot = turtle.selectOpenSlot()
actions[radio.side].suck()
repeat
slot = slot + 1
if (slot > 16) then
slot = 1
end
until turtle.getItemCount(slot) >= 1
turtle.select(slot)
actions[radio.side].drop()
self:updateStationName() self:updateStationName()
end end
function page:play(onOff) function page:play(onOff)
self.playing = onOff self.playing = onOff
if self.playing then if self.playing then
if not radio.hasAudio() then
self:seek()
end
self:updateStationName() self:updateStationName()
radio.playAudio() speaker.playSound(songs[songNo])
Event.addNamedTimer('songTimer', 180, false, function() Event.addNamedTimer('songTimer', 180, false, function()
if self.playing then if self.playing then
@@ -213,7 +199,7 @@ function page:play(onOff)
end) end)
else else
radio.stopAudio() --radio.stopAudio()
end end
end end
@@ -223,7 +209,7 @@ function page.stationName:draw()
end end
function page:updateStationName() function page:updateStationName()
local title = radio.getAudioTitle() local title = songs[songNo].title
if title then if title then
self.stationName.value = title self.stationName.value = title
@@ -248,9 +234,7 @@ page:setVolume(page.volume, true)
UI:setPage(page) UI:setPage(page)
turtle.setStatus('Jamming')
UI:pullEvents() UI:pullEvents()
turtle.setStatus('idle')
page:play(false) page:play(false)
UI.term:reset() UI.term:reset()

View File

@@ -43,7 +43,7 @@ local page = UI.Page {
}, },
tabs = UI.Tabs { tabs = UI.Tabs {
x = 1, y = 5, ey = -2, x = 1, y = 5, ey = -2,
scripts = UI.Grid { scripts = UI.ScrollingGrid {
tabTitle = 'Run', tabTitle = 'Run',
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
columns = { columns = {
@@ -53,7 +53,7 @@ local page = UI.Page {
sortColumn = 'label', sortColumn = 'label',
autospace = true, autospace = true,
}, },
turtles = UI.Grid { turtles = UI.ScrollingGrid {
tabTitle = 'Select', tabTitle = 'Select',
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
columns = { columns = {
@@ -66,7 +66,7 @@ local page = UI.Page {
sortColumn = 'label', sortColumn = 'label',
autospace = true, autospace = true,
}, },
inventory = UI.Grid { inventory = UI.ScrollingGrid {
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
tabTitle = 'Inv', tabTitle = 'Inv',
columns = { columns = {
@@ -78,7 +78,7 @@ local page = UI.Page {
sortColumn = 'index', sortColumn = 'index',
}, },
--[[ --[[
policy = UI.Grid { policy = UI.ScrollingGrid {
tabTitle = 'Mod', tabTitle = 'Mod',
backgroundColor = UI.TabBar.defaults.selectedBackgroundColor, backgroundColor = UI.TabBar.defaults.selectedBackgroundColor,
columns = { columns = {
@@ -196,7 +196,7 @@ function page.tabs.inventory:getRowTextColor(row, selected)
if page.turtle and row.selected then if page.turtle and row.selected then
return colors.yellow return colors.yellow
end end
return UI.Grid.getRowTextColor(self, row, selected) return UI.ScrollingGrid.getRowTextColor(self, row, selected)
end end
function page.tabs.inventory:draw() function page.tabs.inventory:draw()
@@ -217,7 +217,7 @@ function page.tabs.inventory:draw()
end end
self:adjustWidth() self:adjustWidth()
self:update() self:update()
UI.Grid.draw(self) UI.ScrollingGrid.draw(self)
end end
function page.tabs.inventory:eventHandler(event) function page.tabs.inventory:eventHandler(event)
@@ -225,7 +225,7 @@ function page.tabs.inventory:eventHandler(event)
local fn = string.format('turtle.select(%d)', event.selected.index) local fn = string.format('turtle.select(%d)', event.selected.index)
page:runFunction(fn) page:runFunction(fn)
else else
return UI.Grid.eventHandler(self, event) return UI.ScrollingGrid.eventHandler(self, event)
end end
return true return true
end end
@@ -238,14 +238,14 @@ function page.tabs.scripts:draw()
table.insert(self.values, { label = path, path = fs.combine(SCRIPTS_PATH, path) }) table.insert(self.values, { label = path, path = fs.combine(SCRIPTS_PATH, path) })
end end
self:update() self:update()
UI.Grid.draw(self) UI.ScrollingGrid.draw(self)
end end
function page.tabs.scripts:eventHandler(event) function page.tabs.scripts:eventHandler(event)
if event.type == 'grid_select' then if event.type == 'grid_select' then
page:runScript(event.selected.label) page:runScript(event.selected.label)
else else
return UI.Grid.eventHandler(self, event) return UI.ScrollingGrid.eventHandler(self, event)
end end
return true return true
end end
@@ -269,7 +269,7 @@ function page.tabs.turtles:draw()
end end
end end
self:update() self:update()
UI.Grid.draw(self) UI.ScrollingGrid.draw(self)
end end
function page.tabs.turtles:eventHandler(event) function page.tabs.turtles:eventHandler(event)
@@ -283,7 +283,7 @@ function page.tabs.turtles:eventHandler(event)
socket = nil socket = nil
end end
else else
return UI.Grid.eventHandler(self, event) return UI.ScrollingGrid.eventHandler(self, event)
end end
return true return true
end end

View File

@@ -15,7 +15,6 @@ function Storage:init(nodes)
dirty = true, dirty = true,
activity = { }, activity = { },
storageOnline = true, storageOnline = true,
lastRefresh = os.clock(),
} }
Util.merge(self, defaults) Util.merge(self, defaults)
@@ -148,7 +147,6 @@ end
function Storage:refresh(throttle) function Storage:refresh(throttle)
self.dirty = true self.dirty = true
self.lastRefresh = os.clock()
_G._debug('STORAGE: Forcing full refresh') _G._debug('STORAGE: Forcing full refresh')
for _, adapter in self:onlineAdapters() do for _, adapter in self:onlineAdapters() do
adapter.dirty = true adapter.dirty = true

View File

@@ -1,7 +1,5 @@
local Milo = require('milo') local Milo = require('milo')
-- Do a full scan of inventories every minute
local RefreshTask = { local RefreshTask = {
name = 'refresher', name = 'refresher',
priority = 0, priority = 0,
@@ -20,10 +18,6 @@ function RefreshTask:cycle(context)
end end
end end
end end
-- if os.clock() - context.storage.lastRefresh > 60 then
-- context.storage:refresh()
-- end
end end
Milo:registerTask(RefreshTask) Milo:registerTask(RefreshTask)