My sketch allows you to log in to Digispark, execute several commands, and then log out. It works on the default Digispark with micronucleus bootloader installed, and uses the DigiCDC module to emulate USB communication, because Digispark itself does not have any additional USB chip and everything is done in the AtTiny85 software.
When powering the Digispark via the VIN pin, you can connect to it via USB at any time, and after performing the commands, disconnect the terminal and the device – Digispark will continue to execute the code taking into account to sent commands - as in the video below:
https://www.youtube.com/watch?v=Ns_7tm4fF6sAvailable commands:
p[0–2] [on|off] - sends HIGH and LOW signals to individual pins (from 0 to 2)
uptime - displays the time from launching the Digispark in the linux format uptime pretty
vcc - gives the power supply voltage of Digispark in millivolts
reboot - software restart of Digispark
clear - clears a display
ls - it displays
GPIO status list in the small table
temp - specifies the temperature of the chip
login - prompts you to enter your password
clock [0–7] - reduces clock timing (energy saving); values: 1 – 8mHz, 2 – 4mHz, 3 – 2mHz, 4 – 1mHz, 5 – 500kHz, 6 – 250kHz, 7 – 125kHz, 0 – 16,5 mHz
help - displays the help screen
logout, exit - logs out the user
Sketch was intended to take up as little space as possible – instead of strings I used character arrays, instead of pinMode/digitalWrite registers and bit operations, thanks to which it was possible to push so many functions on such a small device. All three components together occupy almost 100% of Digispark’s memory, but to increase the amount of available space for your own code, it is enough to remove the reference to unnecessary functions (e.g. temp, uptime, vcc). These references are marked in a special code block – after deleting them, more than 30% of the memory will be available (excluding bootloader).
More information:
https://jm.iq.pl/mini-os-emulator-for-digispark/There is also a DigiLx version with a login window and a Linux-style prompt
https://github.com/jaromaz/DigiOS