Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Initial release.

## [Unreleased]

- Added support for printer Epson TM-T20III via a 'model' parameter.
- Added 'nopokedex' parameter to skip pokedex QR code generation.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PaulHoule on Hacker
News](https://news.ycombinator.com/item?id=44257382).

> [!IMPORTANT]
> `taskemon` only supports the Epson TM-T20II thermal printer via USB
> `taskemon` only supports the Epson TM-T20II and TM-T20III thermal printers via USB
> right now, and was only tested on macOS Sequoia. Patches or PRs to
> support other models or networked printers are welcome!

Expand All @@ -32,7 +32,7 @@ News](https://news.ycombinator.com/item?id=44257382).
- Prints styled task tickets with owner, category, and task description.
- Generates a QR code linking to a random Pokémon Pokédex entry, or,
rarely, a fun surprise.
- Supports the Epson TM-T20II thermal printer via USB out of the box.
- Supports the Epson TM-T20II and TM-T20III thermal printers via USB out of the box.

## Installation

Expand Down Expand Up @@ -60,10 +60,14 @@ sudo make install
```bash
$ taskemon --help
Usage of taskemon:
-model string
the thermal printer model (TM-T20X-II or TM-T20III) (default: TM-T20X-II)
-nopokedex
if set to true, no Pokedex QR code will be included (default: false)
-owner string
the person responsible for the task
the person responsible for the task
-task string
the task description
the task description
```

## Contributing
Expand Down
38 changes: 31 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
epsonVendorID = 0x04b8

// epsonProductID is the USB product ID for the Epson TM-T20X-II printer.
epsonProductID = 0x0e27
// epsonProductID = 0x0e27

// pokedexBaseURL is the base URL for the Pokédex.
pokedexBaseURL = "https://www.pokemon.com/us/pokedex/"
Expand All @@ -34,10 +34,22 @@ const (
numberOfPokemons = 1025
)

var (
epsonProductID int
)

func Use(vals ...interface{}) {
for _, val := range vals {
_ = val
}
}

func main() {
var (
task = flag.String("task", "", "the task description")
owner = flag.String("owner", "", "the person responsible for the task")
task = flag.String("task", "", "the task description")
owner = flag.String("owner", "", "the person responsible for the task")
model = flag.String("model", "TM-T20X-II", "the thermal printer model (TM-T20X-II or TM-T20III)")
noPokedex = flag.Bool("nopokedex", false, "if set to true, no Pokedex QR code will be included")
)

flag.Parse()
Expand All @@ -48,25 +60,35 @@ func main() {
os.Exit(1)
}

epsonProductID = 0x0e27

switch *model {
case "TM-T20III":
epsonProductID = 0x0e28
_ = epsonProductID
case "TM-T20X-II":
epsonProductID = 0x0e27
_ = epsonProductID
}

ctx := gousb.NewContext()
defer ctx.Close()

dev, err := ctx.OpenDeviceWithVIDPID(epsonVendorID, epsonProductID)
dev, err := ctx.OpenDeviceWithVIDPID(epsonVendorID, gousb.ID(epsonProductID))
if err != nil {
fmt.Fprintf(os.Stderr, "Error: Cannot open USB device: %q\n", err)

os.Exit(1)
}

if dev == nil {
fmt.Fprintln(os.Stderr, "Error: Printer not found. Check USB connection and make sure the printer is turned on.")

os.Exit(1)
}

defer dev.Close()

intf, done, err := dev.DefaultInterface()

if err != nil {
fmt.Fprintf(os.Stderr, "Error: Cannot claim interface: %q\n", err)

Expand Down Expand Up @@ -94,7 +116,9 @@ func main() {

printer.Bold(true).Size(2, 2).Write(*task + "\n\n")

printer.QRCode(pokemonRoulette(), true, 4, escpos.QRCodeErrorCorrectionLevelH)
if !*noPokedex {
printer.QRCode(pokemonRoulette(), true, 4, escpos.QRCodeErrorCorrectionLevelH)
}

printer.LineFeed()

Expand Down