[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pocketbook: simplify device model detection #11721

Conversation

benoit-pierre
Copy link
Contributor
@benoit-pierre benoit-pierre commented Apr 26, 2024

To avoid avoid having to manually handle the multiple ways a model name reported by inkview can be formatted.

Close #11714.


This change is Reviewable

To avoid avoid having to manually handle the multiple
ways a model name reported by inkview can be formatted.
@hius07
Copy link
Member
hius07 commented Apr 26, 2024

Can it be a hash table instead of many elseif?

@benoit-pierre
Copy link
Contributor Author

@hius07:

-- Pocketbook codenames are all over the place:
local codename = full_codename
-- "PocketBook 615 (PB615)"
codename = codename:match(" [(]([^()]+)[)]$") or codename
-- "PocketBook 615"
codename = codename:match("^PocketBook ([^ ].*)$") or codename
-- "PB615"
codename = codename:match("^PB(.+)$") or codename

local device = ({
    ["515"]           = PocketBook515,
    ["606"]           = PocketBook606,
…
    ["741"]           = PocketBook741,
    ["743C"]          = PocketBook743C,
    ["743K3"]         = PocketBook743K3,
    ["743G"]          = PocketBook743G,
    ["743g"]          = PocketBook743G,
    ["840"]           = PocketBook840,
    ["Reader InkPad"] = PocketBook840,
    ["970"]           = PocketBook970,
    ["1040"]          = PocketBook1040,
    ["Color Lux"]     = PocketBookColorLux,
})[codename]
if not device then
    error("unrecognized PocketBook model " .. full_codename)
end
return device

Like this?

@Frenzie
Copy link
Member
Frenzie commented Apr 26, 2024

I don't know if I find that nicer than the if/elseif but if other people prefer it I have no objections.

@hius07
Copy link
Member
hius07 commented Apr 26, 2024

Hash tables are quicker: https://gammon.com.au/forum/?id=7891

But here we have a one-time operation, so it's not about efficiency, but just readability. Matter of taste, yes.

local device = ({

Without ( I think.

@benoit-pierre
Copy link
Contributor Author

Without ( I think.

You need it to use the table inline, without a temporary assignment.

@hius07
Copy link
Member
hius07 commented Apr 26, 2024

Okay, I see the measurement in my link is doubtful.

No objections to elseif, of course.

@hius07
Copy link
Member
hius07 commented Apr 26, 2024

to use the table inline

I see, thanks.

@Frenzie
Copy link
Member
Frenzie commented Apr 26, 2024

Okay, I see the measurement in my link is doubtful.

I think the result is very likely to be the other way around (if/elseif faster) but either way it doesn't matter.

@Frenzie Frenzie merged commit e854431 into koreader:master Apr 29, 2024
1 of 2 checks passed
@benoit-pierre benoit-pierre deleted the pr/simple_and_fix_pocketbook_dev_detection branch April 29, 2024 18:59
NiLuJe added a commit to NiLuJe/FBInk that referenced this pull request May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can not launch koreader on PocketBook 615 plus
3 participants