summaryrefslogtreecommitdiff
path: root/apps/plugins/lua/ldebug.h
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-07-02 00:42:10 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-07-02 00:45:00 +0200
commit20ee453edce207a4285638f0399926b0b9f506df (patch)
treee5a035e8a841fee8fee3a14a607e31290e48ed28 /apps/plugins/lua/ldebug.h
parentd8024df1052966aa554424d88712244ae5978f2a (diff)
downloadrockbox-20ee453edce207a4285638f0399926b0b9f506df.zip
rockbox-20ee453edce207a4285638f0399926b0b9f506df.tar.gz
rockbox-20ee453edce207a4285638f0399926b0b9f506df.tar.bz2
rockbox-20ee453edce207a4285638f0399926b0b9f506df.tar.xz
imx233: fix sd init sequence
Implement the switch function as specified by the specification, that is wait for the response AND transfer 64 bytes of data. This fixes some issue when the SD card take a long time to switch. In particular waiting 100ms (max per spec) will not work if no data is transfered in some cases. Change-Id: Ia22350468018b842e57ce6f6c1a8d676eba97fb8
Diffstat (limited to 'apps/plugins/lua/ldebug.h')
0 files changed, 0 insertions, 0 deletions
a> 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
--[[
             __________               __   ___.
   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
                     \/            \/     \/    \/            \/
 $Id$

 Port of Stopwatch to Lua for touchscreen targets.
 Original copyright: Copyright (C) 2004 Mike Holden

 Copyright (C) 2009 by Maurus Cuelenaere

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 KIND, either express or implied.

]]--

require "actions"
require "buttons"

STOPWATCH_FILE = rb.PLUGIN_APPS_DATA_DIR .. "/stopwatch.dat"


local LapsView = {
    lapTimes = {},
    timer = {
        counting = false,
        prevTotal = 0,
        startAt = 0,
        current = 0
    },
    vp = {
        x = 80,
        y = 0,
        width = rb.LCD_WIDTH - 80,
        height = rb.LCD_HEIGHT,
        font = rb.FONT_UI,
        fg_pattern = rb.lcd_get_foreground()
    },
    scroll = {
        prevY = 0,
        cursorPos = 0
    }
}

function LapsView:init()
    local _, _, h = rb.font_getstringsize("", self.vp.font)

    self.vp.maxLaps = self.vp.height / h
    self.vp.lapHeight = h

    self:loadState()
end

function LapsView:display()
    rb.set_viewport(self.vp)
    rb.clear_viewport()

    local nrOfLaps =  math.min(self.vp.maxLaps, #self.lapTimes)
    rb.lcd_puts_scroll(0, 0, ticksToString(self.timer.current))

    for i=1, nrOfLaps do
        local idx = #self.lapTimes - self.scroll.cursorPos - i + 1
        if self.lapTimes[idx] ~= nil then
            rb.lcd_puts_scroll(0, i, ticksToString(self.lapTimes, idx))
        end
    end

    rb.set_viewport(nil)
end

function LapsView:checkForScroll(btn, x, y)
    if x > self.vp.x and x < self.vp.x + self.vp.width and
       y > self.vp.y and y < self.vp.y + self.vp.height then

        if bit.band(btn, rb.buttons.BUTTON_REL) == rb.buttons.BUTTON_REL then
            self.scroll.prevY = 0
        else
            if #self.lapTimes > self.vp.maxLaps and self.scroll.prevY ~= 0 then
                self.scroll.cursorPos = self.scroll.cursorPos -
                                        (y - self.scroll.prevY) / self.vp.lapHeight

                local maxLaps =  math.min(self.vp.maxLaps, #self.lapTimes)
                if self.scroll.cursorPos < 0 then
                    self.scroll.cursorPos = 0
                elseif self.scroll.cursorPos >= maxLaps then
                    self.scroll.cursorPos = maxLaps
                end
            end

            self.scroll.prevY = y
        end

       return true
    else
        return false
    end
end

function LapsView:incTimer()
    if self.timer.counting then
        self.timer.current = self.timer.prevTotal + rb.current_tick()
                                                  - self.timer.startAt
    else
        self.timer.current = self.timer.prevTotal
    end
end

function LapsView:startTimer()
    self.timer.startAt = rb.current_tick()
    self.timer.currentLap = self.timer.prevTotal
    self.timer.counting = true
end

function LapsView:stopTimer()
    self.timer.prevTotal = self.timer.prevTotal + rb.current_tick()
                                                - self.timer.startAt
    self.timer.counting = false
end

function LapsView:newLap()
    table.insert(self.lapTimes, self.timer.current)
end

function LapsView:resetTimer()
    self.lapTimes = {}
    self.timer.counting = false
    self.timer.current, self.timer.prevTotal, self.timer.startAt = 0, 0, 0
    self.scroll.cursorPos = 0
end

function LapsView:saveState()
    local fd = assert(io.open(STOPWATCH_FILE, "w"))

    for _, v in ipairs({"current", "startAt", "prevTotal", "counting"}) do
        assert(fd:write(tostring(self.timer[v]) .. "\n"))
    end
    for _, v in ipairs(self.lapTimes) do
        assert(fd:write(tostring(v) .. "\n"))
    end

    fd:close()
end

function LapsView:loadState()
    local fd = io.open(STOPWATCH_FILE, "r")
    if fd == nil then return end

    for _, v in ipairs({"current", "startAt", "prevTotal"}) do
        self.timer[v] = tonumber(fd:read("*line"))
    end
    self.timer.counting = toboolean(fd:read("*line"))

    local line = fd:read("*line")
    while line do
        table.insert(self.lapTimes, tonumber(line))
        line = fd:read("*line")
    end

    fd:close()
end