Add: components, progress bar
This commit is contained in:
		| @@ -9,7 +9,11 @@ import ( | ||||
| ) | ||||
|  | ||||
| type Display interface { | ||||
| 	IsReady() error // Nil if it is ready, error with some info otherwise | ||||
|  | ||||
| 	Flush(crystal, page byte) | ||||
| 	FlushByMask(mask uint32) | ||||
| 	GetFlushMaskBit(crystal, page byte) uint32 | ||||
|  | ||||
| 	// Image functions | ||||
| 	GetImg() *image.Gray | ||||
| @@ -17,7 +21,7 @@ type Display interface { | ||||
| 	UnlockImg() | ||||
| 	GetBounds() image.Rectangle | ||||
|  | ||||
| 	Test(ctx context.Context) error | ||||
| 	Test(ctx context.Context) error // DEBUG ONLY | ||||
|  | ||||
| 	io.Closer | ||||
| } | ||||
|   | ||||
| @@ -19,11 +19,16 @@ const ( | ||||
| 	mt12232aW    = 122 | ||||
| 	mt12232aH    = 32 | ||||
| 	flushChanCap = 24 // Flush channel capacity | ||||
|  | ||||
| 	flushUpdateTimeout = 5 * time.Millisecond | ||||
| ) | ||||
|  | ||||
| type displayMt12232a struct { | ||||
| 	logger *log.Logger | ||||
|  | ||||
| 	// Some state flags | ||||
| 	isTurnedOn bool | ||||
|  | ||||
| 	// Image | ||||
| 	img      *image.Gray | ||||
| 	imgMutex sync.Mutex | ||||
| @@ -145,6 +150,14 @@ func (d *displayMt12232a) powerOn() error { | ||||
| 	if d.dev.ReadStatus(1)&0x20 != 0 { | ||||
| 		return fmt.Errorf("Right cristal is off") | ||||
| 	} | ||||
| 	d.isTurnedOn = true | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func (d *displayMt12232a) IsReady() error { | ||||
| 	if !d.isTurnedOn { | ||||
| 		return fmt.Errorf("display is turned off") | ||||
| 	} | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| @@ -217,12 +230,22 @@ func (d *displayMt12232a) Flush(crystal, page byte) { | ||||
| 	d.pagesFlushFlags.Store(d.pagesFlushFlags.Load() | bit) | ||||
| } | ||||
|  | ||||
| func (d *displayMt12232a) FlushByMask(mask uint32) { | ||||
| 	// !!! TODO Need to update GO to 1.23 to use .Or !!! | ||||
| 	d.pagesFlushFlags.Store(d.pagesFlushFlags.Load() | mask) | ||||
| } | ||||
|  | ||||
| func (d *displayMt12232a) GetFlushMaskBit(crystal, page byte) uint32 { | ||||
| 	return uint32(1 << (crystal*4 + page)) | ||||
| } | ||||
|  | ||||
| func (d *displayMt12232a) Close() error { | ||||
| 	if d.flushCancel != nil { | ||||
| 		d.flushCancel() | ||||
| 		d.flushCancel = nil | ||||
| 		<-d.flushDone | ||||
| 	} | ||||
| 	d.isTurnedOn = false | ||||
| 	return d.dev.Close() | ||||
| } | ||||
|  | ||||
| @@ -233,10 +256,10 @@ func (d *displayMt12232a) flushLoop(ctx context.Context) { | ||||
| 		case <-ctx.Done(): | ||||
| 			close(d.flushDone) | ||||
| 			return | ||||
| 		case <-time.After(time.Millisecond): | ||||
| 		case <-time.After(flushUpdateTimeout): | ||||
| 			forUpdate := d.pagesFlushFlags.Swap(0) | ||||
| 			checkBit := uint32(1) | ||||
| 			st := time.Now() | ||||
| 			//st := time.Now() | ||||
| 			d.LockImg() | ||||
| 			for p := byte(0); p < 4; p++ { | ||||
| 				if forUpdate&(checkBit) != 0 { | ||||
| @@ -257,7 +280,7 @@ func (d *displayMt12232a) flushLoop(ctx context.Context) { | ||||
| 				} | ||||
| 				checkBit = checkBit << 1 | ||||
| 			} | ||||
| 			d.logger.Printf("%08b - %s\n", forUpdate, time.Since(st)) | ||||
| 			//d.logger.Printf("%08b - %s\n", forUpdate, time.Since(st)) | ||||
| 			for p := byte(0); p < 4; p++ { | ||||
| 				if forUpdate&(checkBit) != 0 { | ||||
| 					d.dev.WriteCode(1, (3-p)|0xB8) | ||||
|   | ||||
| @@ -37,7 +37,8 @@ func newMt12864a(logger *log.Logger) (Display, error) { | ||||
| 	d.test() | ||||
| 	d.logger.Println("Draw finished") | ||||
|  | ||||
| 	return &d, nil | ||||
| 	//return &d, nil | ||||
| 	return nil, fmt.Errorf("IMPLEMENTATION COMMENTED") | ||||
| } | ||||
|  | ||||
| func (d *displayMt12864a) Test(ctx context.Context) error { | ||||
| @@ -145,6 +146,9 @@ func (d *displayMt12864a) GetBounds() image.Rectangle { | ||||
| func (d *displayMt12864a) Flush(crystal, page byte) { | ||||
| } | ||||
|  | ||||
| func (d *displayMt12864a) FlushByMask(mask uint32) { | ||||
| } | ||||
|  | ||||
| func (d *displayMt12864a) Close() error { | ||||
| 	return rpio.Close() | ||||
| } | ||||
|   | ||||
| @@ -42,11 +42,13 @@ func newSsd1306(logger *log.Logger) (Display, error) { | ||||
| 		return nil, fmt.Errorf("create i2c: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	return &displaySsd1306{ | ||||
| 	_ = displaySsd1306{ | ||||
| 		logger: logger, | ||||
| 		bus:    bus, | ||||
| 		dev:    dev, | ||||
| 	}, nil | ||||
| 	} | ||||
|  | ||||
| 	return nil, fmt.Errorf("IMPLEMENTATION COMMENTED") | ||||
| } | ||||
|  | ||||
| func (d *displaySsd1306) GetBounds() image.Rectangle { | ||||
| @@ -61,6 +63,10 @@ func (d *displaySsd1306) Flush(crystal, page byte) { | ||||
| 	//return d.dev.Draw(img.Bounds(), d.img, image.Point{}) | ||||
| } | ||||
|  | ||||
| func (d *displaySsd1306) FlushByMask(mask uint32) { | ||||
| 	//return d.dev.Draw(img.Bounds(), d.img, image.Point{}) | ||||
| } | ||||
|  | ||||
| func (d *displaySsd1306) Close() error { | ||||
| 	if err := d.bus.Close(); err != nil { | ||||
| 		d.logger.Println("ERROR: close i2c bus:", err.Error()) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user